2021-05-07 11:55:45 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Wrapper script for find-debuginfo.sh
|
|
|
|
#
|
|
|
|
# Usage:
|
2021-06-22 18:28:13 +00:00
|
|
|
# wrap-find-debuginfo.sh SYSROOT-PATH SCRIPT-PATH SCRIPT-ARGS...
|
2021-05-07 11:55:45 +00:00
|
|
|
#
|
2021-06-22 18:28:13 +00:00
|
|
|
# The wrapper saves the original version of ld.so found in SYSROOT-PATH,
|
2021-05-07 11:55:45 +00:00
|
|
|
# invokes SCRIPT-PATH with SCRIPT-ARGS, and then restores the
|
2021-06-22 18:28:13 +00:00
|
|
|
# LDSO-PATH file, followed by note merging and DWZ compression.
|
|
|
|
# As a result, ld.so has (mostly) unchanged debuginfo even
|
2021-05-07 11:55:45 +00:00
|
|
|
# after debuginfo extraction.
|
2021-06-22 18:28:13 +00:00
|
|
|
#
|
|
|
|
# For libc.so.6, a set of strategic symbols is preserved in .symtab
|
2021-07-01 06:32:08 +00:00
|
|
|
# that are frequently used in valgrind suppressions and elsewhere.
|
2021-05-07 11:55:45 +00:00
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
2022-10-04 16:59:41 +00:00
|
|
|
workdir="$(mktemp -d -t find_debuginfo.XXXXXX)"
|
|
|
|
|
|
|
|
ldso_tmp="$workdir/ld.so"
|
2022-12-07 20:43:04 +00:00
|
|
|
libc_tmp_dir="$workdir/"
|
|
|
|
|
|
|
|
# Return the path where a libc should be saved temporarily. This path is
|
|
|
|
# based on its original path received in $1.
|
|
|
|
libc_tmp_path() {
|
|
|
|
echo "$libc_tmp_dir"`dirname "$1"`"/libc.so"
|
|
|
|
}
|
2021-06-22 18:28:13 +00:00
|
|
|
|
|
|
|
# Prefer a separately installed debugedit over the RPM-integrated one.
|
|
|
|
if command -v debugedit >/dev/null ; then
|
|
|
|
debugedit=debugedit
|
|
|
|
else
|
|
|
|
debugedit=/usr/lib/rpm/debugedit
|
|
|
|
fi
|
2021-05-07 11:55:45 +00:00
|
|
|
|
|
|
|
cleanup () {
|
2022-10-04 16:59:41 +00:00
|
|
|
rm -rf "$workdir"
|
2021-05-07 11:55:45 +00:00
|
|
|
}
|
|
|
|
trap cleanup 0
|
|
|
|
|
2021-06-22 18:28:13 +00:00
|
|
|
sysroot_path="$1"
|
2021-05-07 11:55:45 +00:00
|
|
|
shift
|
|
|
|
script_path="$1"
|
|
|
|
shift
|
|
|
|
|
2021-06-22 18:28:13 +00:00
|
|
|
# See ldso_path setting in glibc.spec.
|
|
|
|
ldso_path=
|
2022-12-05 17:01:18 +00:00
|
|
|
for ldso_candidate in `find "$sysroot_path" -maxdepth 2 \
|
|
|
|
-regextype posix-extended -regex '.*/ld(-.*|64|)\.so\.[0-9]+$' -type f` ; do
|
2021-06-22 18:28:13 +00:00
|
|
|
if test -z "$ldso_path" ; then
|
|
|
|
ldso_path="$ldso_candidate"
|
|
|
|
else
|
|
|
|
echo "error: multiple ld.so candidates: $ldso_path, $ldso_candidate"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# libc.so.6 always uses this name, so it is simpler to locate.
|
2022-12-07 20:43:04 +00:00
|
|
|
libc_path=`find "$sysroot_path" -name libc.so.6`
|
2021-06-22 18:28:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Preserve the original files.
|
2021-05-07 11:55:45 +00:00
|
|
|
cp "$ldso_path" "$ldso_tmp"
|
2022-12-07 20:43:04 +00:00
|
|
|
for lib in $libc_path ; do
|
|
|
|
libtmp=`libc_tmp_path $lib`
|
|
|
|
mkdir -p `dirname "$libtmp"`
|
|
|
|
cp "$lib" "$libtmp"
|
|
|
|
done
|
2021-05-07 11:55:45 +00:00
|
|
|
|
|
|
|
# Run the debuginfo extraction.
|
|
|
|
"$script_path" "$@"
|
|
|
|
|
2022-12-07 20:43:04 +00:00
|
|
|
for lib in $libc_path ; do
|
|
|
|
libtmp=`libc_tmp_path "$lib"`
|
|
|
|
# libc.so.6: Extract the .gnu_debuglink section
|
|
|
|
objcopy -j.gnu_debuglink --set-section-flags .gnu_debuglink=alloc \
|
|
|
|
-O binary "$lib" "$libtmp.debuglink"
|
|
|
|
# Restore the original files.
|
|
|
|
cp "$libtmp" "$lib"
|
|
|
|
|
|
|
|
# Reduce the size of libc notes. Primarily for annobin.
|
|
|
|
objcopy --merge-notes "$lib"
|
|
|
|
|
|
|
|
# libc.so.6: Restore the .gnu_debuglink section
|
|
|
|
objcopy --add-section .gnu_debuglink="$libtmp.debuglink" "$lib"
|
|
|
|
|
|
|
|
# libc.so.6: Reduce to valuable symbols. Eliminate file symbols,
|
|
|
|
# annobin symbols, and symbols used by the glibc build to implement
|
|
|
|
# hidden aliases (__EI_*). We would also like to remove __GI_*
|
|
|
|
# symbols, but even listing them explicitly (as in -K __GI_strlen)
|
|
|
|
# still causes strip to remove them, so there is no filtering of
|
|
|
|
# __GI_* here. (Debuginfo is gone after this, so no need to optimize
|
|
|
|
# it.)
|
|
|
|
strip -w \
|
|
|
|
-K '*' \
|
|
|
|
-K '!*.c' \
|
|
|
|
-K '!*.os' \
|
|
|
|
-K '!.annobin_*' \
|
|
|
|
-K '!__EI_*' \
|
|
|
|
-K '!__PRETTY_FUNCTION__*' \
|
|
|
|
"$lib"
|
|
|
|
done
|
2022-09-23 12:38:51 +00:00
|
|
|
|
2022-12-07 20:43:04 +00:00
|
|
|
# Restore the original ld.so.
|
2021-05-07 11:55:45 +00:00
|
|
|
cp "$ldso_tmp" "$ldso_path"
|
|
|
|
|
|
|
|
# Reduce the size of notes. Primarily for annobin.
|
|
|
|
objcopy --merge-notes "$ldso_path"
|
2022-09-23 12:38:51 +00:00
|
|
|
|
|
|
|
# ld.so does not have separated debuginfo and so the debuginfo file
|
|
|
|
# generated by find-debuginfo is redundant. Therefore, remove it.
|
|
|
|
ldso_debug=
|
2022-12-05 17:01:18 +00:00
|
|
|
for ldso_debug_candidate in `find "$sysroot_path" -maxdepth 2 \
|
|
|
|
-regextype posix-extended \
|
2022-09-23 12:38:51 +00:00
|
|
|
-regex '.*/ld(-.*|64|)\.so\.[0-9]+.*debug$' -type f` ; do
|
|
|
|
if test -z "$ldso_debug" ; then
|
|
|
|
ldso_debug="$ldso_debug_candidate"
|
|
|
|
else
|
|
|
|
echo "error: multiple ld.so debug candidates: $ldso_debug, $ldso_debug_candidate"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
rm -f "$ldso_debug"
|
|
|
|
|
2021-06-22 18:28:13 +00:00
|
|
|
# ld.so: Rewrite the source file paths to match the extracted
|
|
|
|
# locations. First compute the arguments for invoking debugedit.
|
|
|
|
# See find-debuginfo.sh.
|
2021-05-07 11:55:45 +00:00
|
|
|
debug_dest_name="/usr/src/debug"
|
|
|
|
last_arg=
|
|
|
|
while true ; do
|
|
|
|
arg="$1"
|
|
|
|
shift || break
|
|
|
|
case "$arg" in
|
|
|
|
(--unique-debug-src-base)
|
|
|
|
debug_dest_name="/usr/src/debug/$1"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
(-*)
|
|
|
|
;;
|
|
|
|
(*)
|
|
|
|
last_arg="$arg"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
debug_base_name=${last_arg:-$RPM_BUILD_ROOT}
|
2021-06-22 18:28:13 +00:00
|
|
|
$debugedit -b "$debug_base_name" -d "$debug_dest_name" -n $ldso_path
|
2022-10-04 16:59:41 +00:00
|
|
|
# Remove the .annobin* symbols (and only them).
|
2022-10-06 15:08:12 +00:00
|
|
|
if nm --format=posix "$ldso_path" | cut -d' ' -f1 \
|
2022-10-04 16:59:41 +00:00
|
|
|
| grep '^\.annobin' > "$ldso_tmp.annobin-symbols"; then
|
|
|
|
objcopy --strip-symbols="$ldso_tmp.annobin-symbols" "$ldso_path"
|
|
|
|
fi
|
2021-05-07 11:55:45 +00:00
|
|
|
|
|
|
|
# Apply single-file DWARF optimization.
|
|
|
|
dwz $ldso_path
|