Fix the generation of REL relocs for missing build notes.

* write.c (create_note_reloc): Add desc2_size parameter.  Zero out
	the addend field of REL relocations.  Store the full addend into
	the note for REL relocations.
This commit is contained in:
Nick Clifton 2020-07-15 12:53:59 +01:00
parent 78fede7066
commit 2952e9275c
2 changed files with 24 additions and 9 deletions

View File

@ -1,3 +1,9 @@
2020-07-15 Nick Clifton <nickc@redhat.com>
* write.c (create_note_reloc): Add desc2_size parameter. Zero out
the addend field of REL relocations. Store the full addend into
the note for REL relocations.
2020-07-13 Nick Clifton <nickc@redhat.com> 2020-07-13 Nick Clifton <nickc@redhat.com>
* po/fr.po: Updated French translation. * po/fr.po: Updated French translation.

View File

@ -1897,6 +1897,7 @@ create_note_reloc (segT sec,
symbolS * sym, symbolS * sym,
bfd_size_type note_offset, bfd_size_type note_offset,
bfd_size_type desc2_offset, bfd_size_type desc2_offset,
offsetT desc2_size,
int reloc_type, int reloc_type,
bfd_vma addend, bfd_vma addend,
char * note) char * note)
@ -1931,15 +1932,21 @@ create_note_reloc (segT sec,
but still stores the addend in the word being relocated. */ but still stores the addend in the word being relocated. */
|| strstr (bfd_get_target (stdoutput), "-sh") != NULL) || strstr (bfd_get_target (stdoutput), "-sh") != NULL)
{ {
offsetT i;
/* Zero out the addend, since it is now stored in the note. */
reloc->u.b.r.addend = 0;
if (target_big_endian) if (target_big_endian)
{ {
if (bfd_arch_bits_per_address (stdoutput) <= 32) for (i = desc2_size; addend != 0 && i > 0; addend >>= 8, i--)
note[desc2_offset + 3] = addend; note[desc2_offset + i - 1] = (addend & 0xff);
else
note[desc2_offset + 7] = addend;
} }
else else
note[desc2_offset] = addend; {
for (i = 0; addend != 0 && i < desc2_size; addend >>= 8, i++)
note[desc2_offset + i] = (addend & 0xff);
}
} }
} }
@ -2025,14 +2032,14 @@ maybe_generate_build_notes (void)
if (target_big_endian) if (target_big_endian)
{ {
note[3] = 8; /* strlen (name) + 1. */ note[3] = 8; /* strlen (name) + 1. */
note[7] = desc_size; /* Two 8-byte offsets. */ note[7] = desc_size; /* Two N-byte offsets. */
note[10] = NT_GNU_BUILD_ATTRIBUTE_OPEN >> 8; note[10] = NT_GNU_BUILD_ATTRIBUTE_OPEN >> 8;
note[11] = NT_GNU_BUILD_ATTRIBUTE_OPEN & 0xff; note[11] = NT_GNU_BUILD_ATTRIBUTE_OPEN & 0xff;
} }
else else
{ {
note[0] = 8; /* strlen (name) + 1. */ note[0] = 8; /* strlen (name) + 1. */
note[4] = desc_size; /* Two 8-byte offsets. */ note[4] = desc_size; /* Two N-byte offsets. */
note[8] = NT_GNU_BUILD_ATTRIBUTE_OPEN & 0xff; note[8] = NT_GNU_BUILD_ATTRIBUTE_OPEN & 0xff;
note[9] = NT_GNU_BUILD_ATTRIBUTE_OPEN >> 8; note[9] = NT_GNU_BUILD_ATTRIBUTE_OPEN >> 8;
} }
@ -2042,10 +2049,12 @@ maybe_generate_build_notes (void)
memcpy (note + 12, "GA$3a1", 8); memcpy (note + 12, "GA$3a1", 8);
/* Create a relocation to install the start address of the note... */ /* Create a relocation to install the start address of the note... */
create_note_reloc (sec, sym, total_size, 20, desc_reloc, 0, note); create_note_reloc (sec, sym, total_size, 20, desc_size / 2, desc_reloc, 0, note);
/* ...and another one to install the end address. */ /* ...and another one to install the end address. */
create_note_reloc (sec, sym, total_size, desc2_offset, desc_reloc, create_note_reloc (sec, sym, total_size, desc2_offset,
desc_size / 2,
desc_reloc,
bfd_section_size (bsym->section), bfd_section_size (bsym->section),
note); note);