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
F81564426: D17519.diff
Thu, Apr 18, 3:55 AM
Unknown Object (File)
Thu, Mar 28, 11:52 PM
Unknown Object (File)
Mar 7 2024, 11:47 PM
Unknown Object (File)
Mar 1 2024, 8:21 AM
Unknown Object (File)
Feb 22 2024, 12:36 AM
Unknown Object (File)
Dec 23 2023, 12:11 AM
Unknown Object (File)
Nov 30 2023, 11:30 PM
Unknown Object (File)
Sep 17 2023, 3:48 AM
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.