Discussion:
[PATCH] S12Z: New 32 bit Reloc.
John Darrington
2018-10-12 00:41:42 UTC
Permalink
Change 808325d203f629208ed1988c8a90321c470ebcff fixed a lot of test failures
in binutils and ld - unfortunately it also meant that dwarf objects produced
by codewarrior and subsequently linked by ld became unusable. This turned out
to be because of some strangeness in their relocs.

This change tries to address the problem by introducing a new reloc. So now
we have one well behaved 32bit reloc, and an oddly behaved one for compatibility.
John Darrington
2018-10-12 00:41:43 UTC
Permalink
Third party tools produce 32 bit relocs at index 6 with strange properties.
This change moves the existing 32 bit reloc (R_S12Z_EXT32) to index 7
and introduces a new one (R_S12Z_CW32) at index 6 to try to support code
generated by these tools.

* bfd/elf32-s12z.c (elf_s12z_howto_table) [R_S12Z_CW32]: New member.
* inutils/readelf.c (is_32bit_abs_reloc): Reloc type 7 is also 32 bit.
* include/elf/s12z.h (elf_s12z_reloc_tpe) [RELOC_NUMBER (R_S12Z_CW32)]: New enum.
---
bfd/elf32-s12z.c | 23 +++++++++++++++++++++++
binutils/readelf.c | 3 ++-
include/elf/s12z.h | 3 ++-
3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/bfd/elf32-s12z.c b/bfd/elf32-s12z.c
index d2ea4ecaf2..05e5153263 100644
--- a/bfd/elf32-s12z.c
+++ b/bfd/elf32-s12z.c
@@ -183,6 +183,29 @@ static reloc_howto_type elf_s12z_howto_table[] =
0x0005ffff, /* dst_mask */
FALSE), /* pcrel_offset */

+ /* A 32 bit absolute relocation. This kind of relocation is
+ schizophrenic - Although they appear in sections named .rela.debug.*
+ in some sections they behave as RELA relocs, but in others they have
+ an added of zero and behave as REL.
+
+ It is not recommended that new code emits this reloc. It is here
+ only to support existing elf files generated by third party
+ applications. */
+
+ HOWTO (R_S12Z_CW32, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_S12Z_CW32", /* name */
+ FALSE, /* partial_inplace */
+ 0xffffffff, /* src_mask */
+ 0xffffffff, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
/* A 32 bit absolute relocation */
HOWTO (R_S12Z_EXT32, /* type */
0, /* rightshift */
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 41f55ee4ed..6f274d9f14 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -12386,7 +12386,8 @@ is_32bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
case EM_68HC12:
return reloc_type == 6; /* R_M68HC11_32. */
case EM_S12Z:
- return reloc_type == 6; /* R_S12Z_EXT32. */
+ return reloc_type == 7 || /* R_S12Z_EXT32 */
+ reloc_type == 6; /* R_S12Z_CW32. */
case EM_MCORE:
return reloc_type == 1; /* R_MCORE_ADDR32. */
case EM_CYGNUS_MEP:
diff --git a/include/elf/s12z.h b/include/elf/s12z.h
index fc74b9a7b8..f42fa11032 100644
--- a/include/elf/s12z.h
+++ b/include/elf/s12z.h
@@ -30,7 +30,8 @@ START_RELOC_NUMBERS (elf_s12z_reloc_type)
RELOC_NUMBER (R_S12Z_PCREL_7_15, 3)
RELOC_NUMBER (R_S12Z_EXT24, 4)
RELOC_NUMBER (R_S12Z_EXT18, 5)
- RELOC_NUMBER (R_S12Z_EXT32, 6)
+ RELOC_NUMBER (R_S12Z_CW32, 6)
+ RELOC_NUMBER (R_S12Z_EXT32, 7)
END_RELOC_NUMBERS (R_S12Z_max)

#endif
--
2.11.0
Alan Modra
2018-10-15 01:51:01 UTC
Permalink
Post by John Darrington
Third party tools produce 32 bit relocs at index 6 with strange properties.
This change moves the existing 32 bit reloc (R_S12Z_EXT32) to index 7
and introduces a new one (R_S12Z_CW32) at index 6 to try to support code
generated by these tools.
Do you have an ABI document for s12z?

Is your goal to be compatible with these "third party tools"?
--
Alan Modra
Australia Development Lab, IBM
John Darrington
2018-10-15 07:29:35 UTC
Permalink
Post by John Darrington
Third party tools produce 32 bit relocs at index 6 with strange properties.
This change moves the existing 32 bit reloc (R_S12Z_EXT32) to index 7
and introduces a new one (R_S12Z_CW32) at index 6 to try to support code
generated by these tools.
Do you have an ABI document for s12z?

No. So far as I'm aware, no such document exists (that is publically
available).

Is your goal to be compatible with these "third party tools"?

It is a secondary goal, yes. But I don't want that to conflict with
binutils other tools and/or gcc (if and when gcc targets s12z).

J'
--
Avoid eavesdropping. Send strong encrypted email.
PGP Public key ID: 1024D/2DE827B3
fingerprint = 8797 A26D 0854 2EAB 0285 A290 8A67 719C 2DE8 27B3
See http://sks-keyservers.net or any PGP keyserver for public key.
Alan Modra
2018-10-15 13:35:26 UTC
Permalink
Post by Alan Modra
Post by John Darrington
Third party tools produce 32 bit relocs at index 6 with strange properties.
This change moves the existing 32 bit reloc (R_S12Z_EXT32) to index 7
and introduces a new one (R_S12Z_CW32) at index 6 to try to support code
generated by these tools.
Do you have an ABI document for s12z?
No. So far as I'm aware, no such document exists (that is publically
available).
That's a pity.
Post by Alan Modra
Is your goal to be compatible with these "third party tools"?
It is a secondary goal, yes. But I don't want that to conflict with
binutils other tools and/or gcc (if and when gcc targets s12z).
Introducing a new 32-bit absolute reloc of course makes gas generate
objects incompatible with the third party linker and other tools..

It's not impossible to work with RELA relocs that sum symbol + addend
+ contents. In fact, it's necessary if you want to apply multiple
relocations with cumulative effect on the same location. You just
need to ensure that the assembler doesn't put the offset from an
expression symbol+offset into both section contents and the relocation
addend, and also that ld -r doesn't modify both contents and addend.
--
Alan Modra
Australia Development Lab, IBM
John Darrington
2018-10-15 14:23:56 UTC
Permalink
Post by Alan Modra
Is your goal to be compatible with these "third party tools"?
It is a secondary goal, yes. But I don't want that to conflict with
binutils other tools and/or gcc (if and when gcc targets s12z).
Introducing a new 32-bit absolute reloc of course makes gas generate
objects incompatible with the third party linker and other tools.

I should have been more specific. My secondary goal is to have ld be
able to link objects created by the third party compiler + assembler.
I don't currently care about the third party linker being able to link
objects created by gas.

However, so far as I've been able to assertain so far, these 32 bit
relocs are used only in the debug sections. So if they break it's only
going to affect the ability to run a debugger on the final elf file.

J'

Loading...