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)
Sep 17 2023, 3:48 AM
Unknown Object (File)
Sep 6 2023, 8:30 AM
Unknown Object (File)
Aug 15 2023, 1:49 PM
Unknown Object (File)
Aug 15 2023, 1:42 PM
Unknown Object (File)
Aug 5 2023, 8:44 PM
Unknown Object (File)
Aug 5 2023, 8:43 PM
Unknown Object (File)
Aug 5 2023, 8:43 PM
Unknown Object (File)
Aug 5 2023, 8:29 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.