ELF Tool Chain/elftoolchain 3646trunk/elfcopy sections.c

elfcopy: avoid stripping relocations from static binaries

elfcopy contains logic to filter individual relocations in STRIP_ALL
mode, but this is not quite 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).  This logic resulted in
broken output when stripping a statically linked binary that contains
relocations (as may happen with ifunc use, for example).

Even though stripping required relocations produces output that is
arguably broken some things rely on it - for exmaple, GCC's build
process strips objects and compares the results of two build stages,
to ensure thare are no unexpected changes.  These stripped objects are
otherwise not useful; they cannot be linked into a working binary.

Change filter_reloc() to omit relocations referencing removed symbols,
while retaining relocations with no symbol reference, and retain the
entire relocation section if it references the dynamic symbol table.
This allows us to strip statically linked binaries while retaining the
existing behaviour of stripping objects into relocationless output.

Obtained from:  FreeBSD r339451
DeltaFile
+39-25trunk/elfcopy/sections.c
+39-251 files

UnifiedSplitRaw