[PATCH 2/8] S12Z: Rename reloc R_S12Z_UKNWN_3 to R_S12Z_EXT18 and implement according to recently inferred information about this reloc.

Alan Modra amodra@gmail.com
Mon Jul 23 09:52:00 GMT 2018


On Mon, Jul 16, 2018 at 03:59:58PM +0200, John Darrington wrote:
> * 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   | 55 +++++++++++++++++++++++++++++++++++++++++++++---------
>  include/elf/s12z.h |  2 +-
>  2 files changed, 47 insertions(+), 10 deletions(-)
> 
> diff --git a/bfd/elf32-s12z.c b/bfd/elf32-s12z.c
> index 4b638e6..cda32f2 100644
> --- a/bfd/elf32-s12z.c
> +++ b/bfd/elf32-s12z.c
> @@ -34,6 +34,43 @@ 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)

Formatting.

> +{
> +  /* 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. */

Two spaces before "*/".

> +
> +  bfd_size_type octets = reloc_entry->address * bfd_octets_per_byte (abfd);

Will you ever have s12z support with bfd_octets_per_byte other than 1?
If not you can omit using it in target code.

> +
> +  bfd_vma result = bfd_get_16 (abfd, (unsigned char *) data + octets);
> +  result <<= 8;
> +
> +  result |= bfd_get_8 (abfd, (unsigned char *) data + octets + 2);
> +
> +  /* Keep the wanted bits and discard the rest */
> +  result &= 0x00FA0000;

Seems like you are throwing away most of the bytes you read.  Perhaps
just read the single byte you need?  Either that, or use the
bfd_get_24 macros you defined.

> +
> +  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_16 (abfd, (bfd_vma) result >> 8, (unsigned char *) data + octets);
> +  bfd_put_8 (abfd, (bfd_vma) result, (unsigned char *) data + octets + 2);

bfd_put_24, or since it seems like you might always be big-endian,
you might like to define a bfd_putb24 instead.  (Define bfd_getb24,
bfd_putl24, bfd_getl24 too and then use them in your implementation
of bfd_put_24 and bfd_get_24.)

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list