2021-04-29 15:56:01 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Wrapper script for find-debuginfo.sh
|
|
|
|
#
|
|
|
|
# Usage:
|
2021-06-15 11:09:37 +00:00
|
|
|
# wrap-find-debuginfo.sh SYSROOT-PATH SCRIPT-PATH SCRIPT-ARGS...
|
2021-04-29 15:56:01 +00:00
|
|
|
#
|
2021-06-15 11:09:37 +00:00
|
|
|
# The wrapper saves the original version of ld.so found in SYSROOT-PATH,
|
2021-04-29 15:56:01 +00:00
|
|
|
# invokes SCRIPT-PATH with SCRIPT-ARGS, and then restores the
|
2021-06-15 11:09:37 +00:00
|
|
|
# LDSO-PATH file, followed by note merging and DWZ compression.
|
|
|
|
# As a result, ld.so has (mostly) unchanged debuginfo even
|
2021-04-29 15:56:01 +00:00
|
|
|
# after debuginfo extraction.
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
|
|
|
ldso_tmp="$(mktemp)"
|
|
|
|
|
2021-05-21 14:22:23 +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-04-29 15:56:01 +00:00
|
|
|
cleanup () {
|
2021-06-17 08:31:26 +00:00
|
|
|
rm -f "$ldso_tmp"
|
2021-04-29 15:56:01 +00:00
|
|
|
}
|
|
|
|
trap cleanup 0
|
|
|
|
|
2021-06-15 11:09:37 +00:00
|
|
|
sysroot_path="$1"
|
2021-04-29 15:56:01 +00:00
|
|
|
shift
|
|
|
|
script_path="$1"
|
|
|
|
shift
|
|
|
|
|
2021-06-15 11:09:37 +00:00
|
|
|
# See ldso_path setting in glibc.spec.
|
|
|
|
ldso_path=
|
|
|
|
for ldso_candidate in `find "$sysroot_path" -regextype posix-extended \
|
|
|
|
-regex '.*/ld(-.*|64|)\.so\.[0-9]+$' -type f` ; do
|
|
|
|
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
|
|
|
|
|
2021-06-17 08:31:26 +00:00
|
|
|
# Preserve the original file.
|
2021-04-29 15:56:01 +00:00
|
|
|
cp "$ldso_path" "$ldso_tmp"
|
|
|
|
|
|
|
|
# Run the debuginfo extraction.
|
|
|
|
"$script_path" "$@"
|
|
|
|
|
2021-06-17 08:31:26 +00:00
|
|
|
# Restore the original file.
|
2021-04-29 15:56:01 +00:00
|
|
|
cp "$ldso_tmp" "$ldso_path"
|
|
|
|
|
|
|
|
# Reduce the size of notes. Primarily for annobin.
|
|
|
|
objcopy --merge-notes "$ldso_path"
|
|
|
|
|
2021-06-17 08:31:26 +00:00
|
|
|
# Rewrite the source file paths to match the extracted locations.
|
|
|
|
# First compute the arguments for invoking debugedit. See
|
|
|
|
# find-debuginfo.sh.
|
2021-04-29 15:56:01 +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-05-21 14:22:23 +00:00
|
|
|
$debugedit -b "$debug_base_name" -d "$debug_dest_name" -n $ldso_path
|
2021-04-29 15:56:01 +00:00
|
|
|
|
|
|
|
# Apply single-file DWARF optimization.
|
|
|
|
dwz $ldso_path
|