strip: Treat bare object files like static libs, not shared libs

Debug symbols should only be split from finally linked ELFs, not bare
object files. We're already excluding static libraries from splitting
for a similar reason.

The `.gnu_debuglink` sections are also mishandled by LLVM's LLD, which
copies them to its output. For example, this affects Arch Linux's
`/usr/lib/Scrt1.o`.

While we're here (and it changes the code less), also strip GNU LTO data
from bare objects, again for the same reason we're removing it from
static libraries, and apply static library stripping instead of shared
library stripping.

See: https://bugs.gentoo.org/787623
This commit is contained in:
Jan Alexander Steffens (heftig) 2024-10-18 03:20:17 +02:00 committed by Allan McRae
parent e0162a6868
commit 9154600490

View file

@ -166,7 +166,7 @@ tidy_strip() {
# guile-2.2 # guile-2.2
[[ "$binary" =~ .*/guile/.*\.go$ ]] && continue [[ "$binary" =~ .*/guile/.*\.go$ ]] && continue
local STATICLIB=0 local STATICOBJ=0
case "$(LC_ALL=C readelf -h "$binary" 2>/dev/null)" in case "$(LC_ALL=C readelf -h "$binary" 2>/dev/null)" in
*Type:*'DYN (Shared object file)'*) # Libraries (.so) or Relocatable binaries *Type:*'DYN (Shared object file)'*) # Libraries (.so) or Relocatable binaries
strip_flags="$STRIP_SHARED";; strip_flags="$STRIP_SHARED";;
@ -180,10 +180,10 @@ tidy_strip() {
fi fi
;; ;;
*Type:*'REL (Relocatable file)'*) # Libraries (.a) or objects *Type:*'REL (Relocatable file)'*) # Libraries (.a) or objects
if ar t "$binary" &>/dev/null; then # Libraries (.a) if [[ $binary = *'.o' ]] || ar t "$binary" &>/dev/null; then
strip_flags="$STRIP_STATIC" strip_flags="$STRIP_STATIC"
STATICLIB=1 STATICOBJ=1
elif [[ $binary = *'.ko' || $binary = *'.o' ]]; then # Kernel module or object file elif [[ $binary = *'.ko' ]]; then # Kernel modules
strip_flags="$STRIP_SHARED" strip_flags="$STRIP_SHARED"
else else
continue continue
@ -192,9 +192,9 @@ tidy_strip() {
*) *)
continue ;; continue ;;
esac esac
(( ! STATICLIB )) && collect_debug_symbols "$binary" (( ! STATICOBJ )) && collect_debug_symbols "$binary"
strip_file "$binary" ${strip_flags} strip_file "$binary" ${strip_flags}
(( STATICLIB )) && strip_lto "$binary" (( STATICOBJ )) && strip_lto "$binary"
done done
elif check_option "debug" "y"; then elif check_option "debug" "y"; then