]> git.ipfire.org Git - thirdparty/elfutils.git/commit
unstrip: Call adjust_relocs no more than once per section.
authorAaron Merey <amerey@redhat.com>
Mon, 22 Jan 2024 00:44:34 +0000 (19:44 -0500)
committerAaron Merey <amerey@redhat.com>
Tue, 6 Feb 2024 20:08:32 +0000 (15:08 -0500)
commit2f9b180cc1057fb351332689886b2492b3711aad
treee819d41c5210546c2e0d025b7be1bb1e08486396
parentde60eba95b2dd36fc11de33b32391ae9533a15ac
unstrip: Call adjust_relocs no more than once per section.

During symtab merging, adjust_relocs might be called multiple times on
some SHT_REL/SHT_RELA sections.  In these cases it is possible for a
relocation's symbol index to be correctly mapped from X to Y during the
first call to adjust_relocs but then wrongly remapped from Y to Z during
the second call.

Fix this by adjusting relocation symbol indices just once per section.

Also add stable sorting for symbols during symtab merging so that the
symbol order in the output file's symtab does not depend on undefined
behaviour in qsort.

Note that adjust_relocs still might be called a second time on a section
during add_new_section_symbols.  However since add_new_section_symbols
generates its own distinct symbol index map, this should not trigger the
bug described above.

https://sourceware.org/bugzilla/show_bug.cgi?id=31097

Signed-off-by: Aaron Merey <amerey@redhat.com>
src/unstrip.c
tests/.gitignore
tests/Makefile.am
tests/elf-print-reloc-syms.c [new file with mode: 0644]
tests/run-unstrip-test.sh