|
|
0b26f7 |
#!/bin/bash
|
|
|
0b26f7 |
# Wrapper script for find-debuginfo.sh
|
|
|
0b26f7 |
#
|
|
|
0b26f7 |
# Usage:
|
|
|
0b26f7 |
# wrap-find-debuginfo.sh SYSROOT-PATH SCRIPT-PATH SCRIPT-ARGS...
|
|
|
0b26f7 |
#
|
|
|
0b26f7 |
# The wrapper saves the original version of ld.so found in SYSROOT-PATH,
|
|
|
0b26f7 |
# invokes SCRIPT-PATH with SCRIPT-ARGS, and then restores the
|
|
|
0b26f7 |
# LDSO-PATH file, followed by note merging and DWZ compression.
|
|
|
0b26f7 |
# As a result, ld.so has (mostly) unchanged debuginfo even
|
|
|
0b26f7 |
# after debuginfo extraction.
|
|
|
0b26f7 |
#
|
|
|
0b26f7 |
# For libc.so.6, a set of strategic symbols is preserved in .symtab
|
|
|
0b26f7 |
# that are frequently used in valgrind suppressions and elsewhere.
|
|
|
0b26f7 |
|
|
|
0b26f7 |
set -ex
|
|
|
0b26f7 |
|
|
|
0b26f7 |
ldso_tmp="$(mktemp)"
|
|
|
0b26f7 |
libc_tmp="$(mktemp)"
|
|
|
0b26f7 |
|
|
|
0b26f7 |
# Prefer a separately installed debugedit over the RPM-integrated one.
|
|
|
0b26f7 |
if command -v debugedit >/dev/null ; then
|
|
|
0b26f7 |
debugedit=debugedit
|
|
|
0b26f7 |
else
|
|
|
0b26f7 |
debugedit=/usr/lib/rpm/debugedit
|
|
|
0b26f7 |
fi
|
|
|
0b26f7 |
|
|
|
0b26f7 |
cleanup () {
|
|
|
0b26f7 |
rm -f "$ldso_tmp" "$libc_tmp"
|
|
|
0b26f7 |
}
|
|
|
0b26f7 |
trap cleanup 0
|
|
|
0b26f7 |
|
|
|
0b26f7 |
sysroot_path="$1"
|
|
|
0b26f7 |
shift
|
|
|
0b26f7 |
script_path="$1"
|
|
|
0b26f7 |
shift
|
|
|
0b26f7 |
|
|
|
0b26f7 |
# See ldso_path setting in glibc.spec.
|
|
|
0b26f7 |
ldso_path=
|
|
|
0b26f7 |
for ldso_candidate in `find "$sysroot_path" -regextype posix-extended \
|
|
|
0b26f7 |
-regex '.*/ld(-.*|64|)\.so\.[0-9]+$' -type f` ; do
|
|
|
0b26f7 |
if test -z "$ldso_path" ; then
|
|
|
0b26f7 |
ldso_path="$ldso_candidate"
|
|
|
0b26f7 |
else
|
|
|
0b26f7 |
echo "error: multiple ld.so candidates: $ldso_path, $ldso_candidate"
|
|
|
0b26f7 |
exit 1
|
|
|
0b26f7 |
fi
|
|
|
0b26f7 |
done
|
|
|
0b26f7 |
|
|
|
0b26f7 |
# libc.so.6 always uses this name, so it is simpler to locate.
|
|
|
0b26f7 |
libc_path=
|
|
|
0b26f7 |
for libc_candidate in `find "$sysroot_path" -name libc.so.6`; do
|
|
|
0b26f7 |
if test -z "$libc_path" ; then
|
|
|
0b26f7 |
libc_path="$libc_candidate"
|
|
|
0b26f7 |
else
|
|
|
0b26f7 |
echo "error: multiple libc.so.6 candidates: $libc_path, $libc_candidate"
|
|
|
0b26f7 |
exit 1
|
|
|
0b26f7 |
fi
|
|
|
0b26f7 |
done
|
|
|
0b26f7 |
|
|
|
0b26f7 |
|
|
|
0b26f7 |
# Preserve the original files.
|
|
|
0b26f7 |
cp "$ldso_path" "$ldso_tmp"
|
|
|
0b26f7 |
cp "$libc_path" "$libc_tmp"
|
|
|
0b26f7 |
|
|
|
0b26f7 |
# Run the debuginfo extraction.
|
|
|
0b26f7 |
"$script_path" "$@"
|
|
|
0b26f7 |
|
|
|
0b26f7 |
# Restore the original files.
|
|
|
0b26f7 |
cp "$ldso_tmp" "$ldso_path"
|
|
|
0b26f7 |
cp "$libc_tmp" "$libc_path"
|
|
|
0b26f7 |
|
|
|
0b26f7 |
# Reduce the size of notes. Primarily for annobin.
|
|
|
0b26f7 |
objcopy --merge-notes "$ldso_path"
|
|
|
0b26f7 |
objcopy --merge-notes "$libc_path"
|
|
|
0b26f7 |
|
|
|
0b26f7 |
# libc.so.6: Reduce to valuable symbols. Eliminate file symbols,
|
|
|
0b26f7 |
# annobin symbols, and symbols used by the glibc build to implement
|
|
|
0b26f7 |
# hidden aliases (__EI_*). We would also like to remove __GI_*
|
|
|
0b26f7 |
# symbols, but even listing them explicitly (as in -K __GI_strlen)
|
|
|
0b26f7 |
# still causes strip to remove them, so there is no filtering of
|
|
|
0b26f7 |
# __GI_* here. (Debuginfo is gone after this, so no need to optimize
|
|
|
0b26f7 |
# it.)
|
|
|
0b26f7 |
strip -w \
|
|
|
0b26f7 |
-K '*' \
|
|
|
0b26f7 |
-K '!*.c' \
|
|
|
0b26f7 |
-K '!*.os' \
|
|
|
0b26f7 |
-K '!.annobin_*' \
|
|
|
0b26f7 |
-K '!__EI_*' \
|
|
|
0b26f7 |
-K '!__PRETTY_FUNCTION__*' \
|
|
|
0b26f7 |
"$libc_path"
|
|
|
0b26f7 |
|
|
|
0b26f7 |
# ld.so: Rewrite the source file paths to match the extracted
|
|
|
0b26f7 |
# locations. First compute the arguments for invoking debugedit.
|
|
|
0b26f7 |
# See find-debuginfo.sh.
|
|
|
0b26f7 |
debug_dest_name="/usr/src/debug"
|
|
|
0b26f7 |
last_arg=
|
|
|
0b26f7 |
while true ; do
|
|
|
0b26f7 |
arg="$1"
|
|
|
0b26f7 |
shift || break
|
|
|
0b26f7 |
case "$arg" in
|
|
|
0b26f7 |
(--unique-debug-src-base)
|
|
|
0b26f7 |
debug_dest_name="/usr/src/debug/$1"
|
|
|
0b26f7 |
shift
|
|
|
0b26f7 |
;;
|
|
|
0b26f7 |
(-*)
|
|
|
0b26f7 |
;;
|
|
|
0b26f7 |
(*)
|
|
|
0b26f7 |
last_arg="$arg"
|
|
|
0b26f7 |
;;
|
|
|
0b26f7 |
esac
|
|
|
0b26f7 |
done
|
|
|
0b26f7 |
debug_base_name=${last_arg:-$RPM_BUILD_ROOT}
|
|
|
0b26f7 |
$debugedit -b "$debug_base_name" -d "$debug_dest_name" -n $ldso_path
|
|
|
0b26f7 |
|
|
|
0b26f7 |
# Apply single-file DWARF optimization.
|
|
|
0b26f7 |
dwz $ldso_path
|