Bug 31097 - strip/unstrip on ET_REL binary might fail elflint on i386
Summary: strip/unstrip on ET_REL binary might fail elflint on i386
Status: RESOLVED FIXED
Alias: None
Product: elfutils
Classification: Unclassified
Component: tools (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-29 15:54 UTC by Aaron Merey
Modified: 2024-02-06 20:22 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aaron Merey 2023-11-29 15:54:00 UTC
tests/run-strip-strmerge.sh contains tests that strip and unstrip an ET_REL binary. On i386 it is possible for the resulting binary of these tests to fail elflint due to the presence of relocations with type R_386_GOTPC that refer to a non-GOT symbol.

This is caught on i386 because of the presence of an ebl_gotpc_reloc_check for this arch. Most other ebl backends do not implement this check. It is possible that similar problems are going undetected on other arches.

We should ensure that strip/unstrip always produce binaries that pass elflint. We should also implement ebl_gotpc_reloc_check for other backends.
Comment 1 Aaron Merey 2024-02-06 20:22:00 UTC
Fixed in the following commit:

commit 2f9b180cc1057fb351332689886b2492b3711aad
Author: Aaron Merey <amerey@redhat.com>
Date:   Sun Jan 21 19:44:34 2024 -0500

    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.