Discussion:
[PATCH] S12Z: Rename reloc R_S12Z_UKNWN_3 to R_S12Z_EXT18 and implement according to recently inferred information about this reloc.
John Darrington
2018-08-18 06:48:16 UTC
Permalink
* bfd/elf32-s12z.c: (opru18_reloc): New function.
* bfd/elf32-s12z.c: (elf_s12z_howto_table): Adjust Howto according to new knowledge.
* include/elf/s12z.h: Rename R_S12Z_UKNWN_3 to R_S12Z_EXT18.
---
bfd/ChangeLog | 6 ++++++
bfd/elf32-s12z.c | 51 ++++++++++++++++++++++++++++++++++++++++++---------
include/ChangeLog | 4 ++++
include/elf/s12z.h | 2 +-
4 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 4fbe0bf6bd..4621c23621 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2018-08-18 John Darrington <***@darrington.wattle.id.au>
+
+ * bfd/elf32-s12z.c (elf_s12z_howto_table): Rename R_S12Z_UKNWN_3 to
+ R_S12Z_EXT18 and adjust parameters accordingly.
+ * bfd/elf32-s12z.c (opru18_reloc) : New function.
+
2018-08-17 H.J. Lu <***@intel.com>

PR ld/23515
diff --git a/bfd/elf32-s12z.c b/bfd/elf32-s12z.c
index 400555d026..fa10877af2 100644
--- a/bfd/elf32-s12z.c
+++ b/bfd/elf32-s12z.c
@@ -34,6 +34,39 @@ static bfd_boolean s12z_info_to_howto_rel
(bfd *, arelent *, Elf_Internal_Rela *);

static bfd_reloc_status_type
+opru18_reloc (bfd *abfd, arelent *reloc_entry, struct bfd_symbol *symbol,
+ void *data, asection *input_section ATTRIBUTE_UNUSED,
+ bfd *output ATTRIBUTE_UNUSED, char **msg ATTRIBUTE_UNUSED)
+{
+ /* This reloc is used for 18 bit General Operand Addressing Postbyte in the
+ INST opru18 form. This is an 18 bit reloc, but the most significant bit
+ is shifted one place to the left of where it would normally be. See
+ Appendix A.4 of the S12Z reference manual. */
+
+ bfd_size_type octets = reloc_entry->address * bfd_octets_per_byte (abfd);
+
+ bfd_vma result = bfd_get_24 (abfd, (unsigned char *) data + octets);
+
+ /* Keep the wanted bits and discard the rest */
+ result &= 0xFA0000;
+
+ bfd_vma val = bfd_asymbol_value (symbol);
+ val += symbol->section->output_section->vma;
+ val += symbol->section->output_offset;
+
+ /* The lowest 17 bits are copied verbatim */
+ result |= val & 0x1FFFF;
+
+ /* The 18th bit is put into the 19th position */
+ result |= (val & 0x020000) << 1;
+
+ bfd_put_24 (abfd, result, (unsigned char *) data + octets);
+
+ return bfd_reloc_ok;
+}
+
+
+static bfd_reloc_status_type
shift_addend_reloc (bfd *abfd, arelent *reloc_entry, struct bfd_symbol *symbol ATTRIBUTE_UNUSED,
void *data ATTRIBUTE_UNUSED, asection *input_section ATTRIBUTE_UNUSED,
bfd *output ATTRIBUTE_UNUSED, char **msg ATTRIBUTE_UNUSED)
@@ -136,19 +169,19 @@ static reloc_howto_type elf_s12z_howto_table[] =
0x00ffffff, /* dst_mask */
FALSE), /* pcrel_offset */

- /* The purpose of this reloc is not known */
- HOWTO (R_S12Z_UKNWN_3, /* type */
+ /* An 18 bit absolute relocation */
+ HOWTO (R_S12Z_EXT18, /* type */
0, /* rightshift */
- 3, /* size (0 = byte, 1 = short, 2 = long) */
- 0, /* bitsize */
+ 5, /* size (0 = byte, 1 = short, 2 = long) */
+ 18, /* bitsize */
FALSE, /* pc_relative */
0, /* bitpos */
- complain_overflow_dont,/* complain_on_overflow */
- bfd_elf_generic_reloc, /* special_function */
- "R_S12Z_UKNWN_3", /* name */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ opru18_reloc, /* special_function */
+ "R_S12Z_EXT18", /* name */
FALSE, /* partial_inplace */
- 0, /* src_mask */
- 0, /* dst_mask */
+ 0x0005ffff, /* src_mask */
+ 0x0005ffff, /* dst_mask */
FALSE), /* pcrel_offset */

/* A 32 bit absolute relocation */
diff --git a/include/ChangeLog b/include/ChangeLog
index f663f9b937..5fc5314270 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,7 @@
+2018-08-18 John Darrington <***@darrington.wattle.id.au>
+
+ * elf/s12z.h: Rename R_S12Z_UNKWN3 to R_S12Z_EXT18.
+
2018-07-27 John Darrington <***@darrington.wattle.id.au>

* opcode/s12z.h: New file.
diff --git a/include/elf/s12z.h b/include/elf/s12z.h
index 72504ee9f4..fc74b9a7b8 100644
--- a/include/elf/s12z.h
+++ b/include/elf/s12z.h
@@ -29,7 +29,7 @@ START_RELOC_NUMBERS (elf_s12z_reloc_type)
RELOC_NUMBER (R_S12Z_UKNWN_2, 2)
RELOC_NUMBER (R_S12Z_PCREL_7_15, 3)
RELOC_NUMBER (R_S12Z_EXT24, 4)
- RELOC_NUMBER (R_S12Z_UKNWN_3, 5)
+ RELOC_NUMBER (R_S12Z_EXT18, 5)
RELOC_NUMBER (R_S12Z_EXT32, 6)
END_RELOC_NUMBERS (R_S12Z_max)
--
2.11.0
Nick Clifton
2018-08-20 14:10:36 UTC
Permalink
Hi John,
Post by John Darrington
* bfd/elf32-s12z.c: (opru18_reloc): New function.
* bfd/elf32-s12z.c: (elf_s12z_howto_table): Adjust Howto according to new knowledge.
* include/elf/s12z.h: Rename R_S12Z_UKNWN_3 to R_S12Z_EXT18.
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 4fbe0bf6bd..4621c23621 100644
Please don't include the ChangeLogs as context diffs. They almost
never apply cleanly. Instead just plain text is fine.
Post by John Darrington
+{
+ /* This reloc is used for 18 bit General Operand Addressing Postbyte in the
+ INST opru18 form. This is an 18 bit reloc, but the most significant bit
+ is shifted one place to the left of where it would normally be. See
+ Appendix A.4 of the S12Z reference manual. */
Comment formatting. Two spaces at the end of the comment, before the closing
*/ (pedantic I know, but it does help to keep the code base consistent).
Post by John Darrington
+ /* Keep the wanted bits and discard the rest */
Also please end comments with a full stop before the two spaces...
Post by John Darrington
+ bfd_vma val = bfd_asymbol_value (symbol);
Can you put variable declarations at the start of the containing block please ?

It would also be nice if there was a test case to check the processing of this
reloc.... (Adding one is not necessary to have this patch approved, but it is
worth thinking about).

Cheers
Nick
John Darrington
2018-08-20 18:01:47 UTC
Permalink
* bfd/elf32-s12z.c: (opru18_reloc): New function.
* bfd/elf32-s12z.c: (elf_s12z_howto_table): Adjust Howto according to new knowledge.
* include/elf/s12z.h: Rename R_S12Z_UKNWN_3 to R_S12Z_EXT18.
---
bfd/elf32-s12z.c | 50 +++++++++++++++++++++++++++++++++++++++++---------
include/elf/s12z.h | 2 +-
4 files changed, 52 insertions(+), 10 deletions(-)

diff --git a/bfd/elf32-s12z.c b/bfd/elf32-s12z.c
index 400555d026..cab54c487b 100644
--- a/bfd/elf32-s12z.c
+++ b/bfd/elf32-s12z.c
@@ -34,6 +34,38 @@ static bfd_boolean s12z_info_to_howto_rel
(bfd *, arelent *, Elf_Internal_Rela *);

static bfd_reloc_status_type
+opru18_reloc (bfd *abfd, arelent *reloc_entry, struct bfd_symbol *symbol,
+ void *data, asection *input_section ATTRIBUTE_UNUSED,
+ bfd *output ATTRIBUTE_UNUSED, char **msg ATTRIBUTE_UNUSED)
+{
+ /* This reloc is used for 18 bit General Operand Addressing Postbyte in the
+ INST opru18 form. This is an 18 bit reloc, but the most significant bit
+ is shifted one place to the left of where it would normally be. See
+ Appendix A.4 of the S12Z reference manual. */
+
+ bfd_size_type octets = reloc_entry->address * bfd_octets_per_byte (abfd);
+ bfd_vma result = bfd_get_24 (abfd, (unsigned char *) data + octets);
+ bfd_vma val = bfd_asymbol_value (symbol);
+
+ /* Keep the wanted bits and discard the rest. */
+ result &= 0xFA0000;
+
+ val += symbol->section->output_section->vma;
+ val += symbol->section->output_offset;
+
+ /* The lowest 17 bits are copied verbatim. */
+ result |= val & 0x1FFFF;
+
+ /* The 18th bit is put into the 19th position. */
+ result |= (val & 0x020000) << 1;
+
+ bfd_put_24 (abfd, result, (unsigned char *) data + octets);
+
+ return bfd_reloc_ok;
+}
+
+
+static bfd_reloc_status_type
shift_addend_reloc (bfd *abfd, arelent *reloc_entry, struct bfd_symbol *symbol ATTRIBUTE_UNUSED,
void *data ATTRIBUTE_UNUSED, asection *input_section ATTRIBUTE_UNUSED,
bfd *output ATTRIBUTE_UNUSED, char **msg ATTRIBUTE_UNUSED)
@@ -136,19 +168,19 @@ static reloc_howto_type elf_s12z_howto_table[] =
0x00ffffff, /* dst_mask */
FALSE), /* pcrel_offset */

- /* The purpose of this reloc is not known */
- HOWTO (R_S12Z_UKNWN_3, /* type */
+ /* An 18 bit absolute relocation */
+ HOWTO (R_S12Z_EXT18, /* type */
0, /* rightshift */
- 3, /* size (0 = byte, 1 = short, 2 = long) */
- 0, /* bitsize */
+ 5, /* size (0 = byte, 1 = short, 2 = long) */
+ 18, /* bitsize */
FALSE, /* pc_relative */
0, /* bitpos */
- complain_overflow_dont,/* complain_on_overflow */
- bfd_elf_generic_reloc, /* special_function */
- "R_S12Z_UKNWN_3", /* name */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ opru18_reloc, /* special_function */
+ "R_S12Z_EXT18", /* name */
FALSE, /* partial_inplace */
- 0, /* src_mask */
- 0, /* dst_mask */
+ 0x0005ffff, /* src_mask */
+ 0x0005ffff, /* dst_mask */
FALSE), /* pcrel_offset */

/* A 32 bit absolute relocation */
diff --git a/include/elf/s12z.h b/include/elf/s12z.h
index 72504ee9f4..fc74b9a7b8 100644
--- a/include/elf/s12z.h
+++ b/include/elf/s12z.h
@@ -29,7 +29,7 @@ START_RELOC_NUMBERS (elf_s12z_reloc_type)
RELOC_NUMBER (R_S12Z_UKNWN_2, 2)
RELOC_NUMBER (R_S12Z_PCREL_7_15, 3)
RELOC_NUMBER (R_S12Z_EXT24, 4)
- RELOC_NUMBER (R_S12Z_UKNWN_3, 5)
+ RELOC_NUMBER (R_S12Z_EXT18, 5)
RELOC_NUMBER (R_S12Z_EXT32, 6)
END_RELOC_NUMBERS (R_S12Z_max)
--
2.11.0
Nick Clifton
2018-08-21 16:32:11 UTC
Permalink
Hi John,
Post by John Darrington
* bfd/elf32-s12z.c: (opru18_reloc): New function.
* bfd/elf32-s12z.c: (elf_s12z_howto_table): Adjust Howto according to new knowledge.
* include/elf/s12z.h: Rename R_S12Z_UKNWN_3 to R_S12Z_EXT18.
Approved - please apply.

Cheers
Nick

Loading...