Page MenuHomeFreeBSD

elfcopy: delete filter_reloc, it is broken and unnecessary
ClosedPublic

Authored by emaste on Oct 11 2018, 2:46 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Oct 15, 3:55 AM
Unknown Object (File)
Fri, Oct 10, 7:43 PM
Unknown Object (File)
Fri, Oct 10, 7:43 PM
Unknown Object (File)
Fri, Oct 10, 7:43 PM
Unknown Object (File)
Fri, Oct 10, 2:25 PM
Unknown Object (File)
Sun, Sep 28, 1:58 PM
Unknown Object (File)
Wed, Sep 24, 11:34 AM
Unknown Object (File)
Sep 16 2025, 11:57 PM
Subscribers

Details

Summary

elfcopy contained logic to filter individual relocations in STRIP_ALL mode. However, this is not valid; relocations emitted by the linker are required, unless they apply to an entire section being removed (which is handled by other logic in elfcopy).

Note that filter_reloc is also buggy: for RELA relocation sections it operated on uninitialized rel.r_info resulting in invalid operation.

The logic most likely needs to be inverted: instead of removing relocations because their associated symbols are being removed, we must keep symbols referenced by relocations. That said, in practice we do not encounter this code path today: objects being stripped are either dynamically linked binaries which retain .dynsym, or static binaries with no relocations.

Just remove filter_reloc. Stripping binaries with relocations referencing removed symbols was already broken; after this change it may still be broken (in a different way).

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Oct 11 2018, 3:07 PM

As was discussed elsewere, it is fine as far as the reloc sections for stripped sections also go away.

I verified the ifunc reloc patch + a demo ifunc memset + this patch give functional static binaries.

Patch is OK. I've run the test suite with this change and it only breaks a few meaningless test cases. I can investigate more later.

For reference, this was found while developing WIP to introduce ifunc userland support, and in particular for static binaries.

Reference links:

To try the reproduction case first link the binary, with something like:

tar xvf static_rela_sh_info.tar.xz
cd ifunc_reproducer
ld.lld $(cat response.txt)

Then try stripping make.full.

Note that earlier versions of lld do not set sh_info and sh_link, which can still be interesting for comparing GNU and Elf Tool Chain behaviour, but really want to test with up-to-date lld from FreeBSD head or lld head. Can also link make.full with GNU ld.bfd but you'll have to remove the --chroot entry from the response.txt file.

I did start down the path of fixing filter_reloc() (addressing the uninitialized variable, and then retaining relocations which do not have an associated symbol), but I can't see an actual use case.

This revision was automatically updated to reflect the committed changes.