179894
#!/bin/bash
179894
# Wrapper script for find-debuginfo.sh
179894
#
179894
# Usage:
179894
#  wrap-find-debuginfo.sh SYSROOT-PATH SCRIPT-PATH SCRIPT-ARGS...
179894
#
179894
# The wrapper saves the original version of ld.so found in SYSROOT-PATH,
179894
# invokes SCRIPT-PATH with SCRIPT-ARGS, and then restores the
179894
# LDSO-PATH file, followed by note merging and DWZ compression.
179894
# As a result, ld.so has (mostly) unchanged debuginfo even
179894
# after debuginfo extraction.
179894
#
179894
# For libc.so.6 and other shared objects, a set of strategic symbols
179894
# is preserved in .symtab that are frequently used in valgrind
179894
# suppressions and elsewhere.
179894
179894
set -evx
179894
179894
tar_tmp="$(mktemp)"
179894
179894
# Prefer a separately installed debugedit over the RPM-integrated one.
179894
if command -v debugedit >/dev/null ; then
179894
    debugedit=debugedit
179894
else
179894
    debugedit=/usr/lib/rpm/debugedit
179894
fi
179894
179894
cleanup () {
179894
    rm -f "$tar_tmp"
179894
}
179894
trap cleanup 0
179894
179894
sysroot_path="$1"
179894
shift
179894
script_path="$1"
179894
shift
179894
179894
# See run_ldso setting in glibc.spec.
179894
ldso_list=`cd "$sysroot_path"; find . -name 'ld-*.so' -type f`
179894
libc_list=`cd "$sysroot_path"; find . -name 'libc-*.so' -type f`
179894
libdl_list=`cd "$sysroot_path"; find . -name 'libdl-*.so' -type f`
179894
libpthread_list=`cd "$sysroot_path"; find . -name 'libpthread-*.so' -type f`
179894
librt_list=`cd "$sysroot_path"; find . -name 'librt-*.so' -type f`
179894
179894
full_list="$ldso_list $libc_list $libdl_list $libpthread_list $librt_list"
179894
179894
# Preserve the original files.
179894
(cd "$sysroot_path"; ls -l $full_list)
179894
(cd "$sysroot_path"; tar cvf "$tar_tmp" $full_list)
179894
179894
# Run the debuginfo extraction.
179894
"$script_path" "$@"
179894
179894
# Restore the original files.
179894
(cd "$sysroot_path"; tar xf "$tar_tmp")
179894
(cd "$sysroot_path"; ls -l $full_list)
179894
179894
# Reduce the size of notes.  Primarily for annobin.
179894
for p in $full_list
179894
do
179894
    objcopy --merge-notes "$sysroot_path/$p"
179894
done
179894
179894
# libc.so.6 and other shared objects: Reduce to valuable symbols.
179894
# Eliminate file symbols, annobin symbols, and symbols used by the
179894
# glibc build to implement hidden aliases (__EI_*).  We would also
179894
# like to remove __GI_* symbols, but even listing them explicitly (as
179894
# in -K __GI_strlen) still causes strip to remove them, so there is no
179894
# filtering of __GI_* here.  (Debuginfo is gone after this, so no need
179894
# to optimize it.)
179894
for p in $libc_list $libdl_list $libpthread_list $librt_list ; do
179894
    strip -w \
179894
	  -K '*' \
179894
	  -K '!*.c' \
179894
	  -K '!*.os' \
179894
	  -K '!.annobin_*' \
179894
	  -K '!__EI_*' \
179894
	  -K '!__PRETTY_FUNCTION__*' \
179894
	  "$sysroot_path/$p"
179894
done
179894
179894
# ld.so: Rewrite the source file paths to match the extracted
179894
# locations.  First compute the arguments for invoking debugedit.
179894
# See find-debuginfo.sh.
179894
debug_dest_name="/usr/src/debug"
179894
last_arg=
179894
while true ; do
179894
    arg="$1"
179894
    shift || break
179894
    case "$arg" in
179894
	(--unique-debug-src-base)
179894
	    debug_dest_name="/usr/src/debug/$1"
179894
	    shift
179894
	    ;;
179894
	(-*)
179894
	    ;;
179894
	(*)
179894
	    last_arg="$arg"
179894
	    ;;
179894
    esac
179894
done
179894
debug_base_name=${last_arg:-$RPM_BUILD_ROOT}
179894
for p in $ldso_list
179894
do
179894
    $debugedit -b "$debug_base_name" -d "$debug_dest_name" -n "$sysroot_path/$p"
179894
done
179894
179894
# Apply single-file DWARF optimization.
179894
for ldso in $ldso_list
179894
do
179894
    dwz "$sysroot_path/$p"
179894
done