freebsd-ports/Mk/Scripts/generate-symbols.sh
Mathieu Arnold b234bfd716 SC2162: read without -r will mangle backslashes.
By default, read will interpret backslashes before spaces and line
feeds, and otherwise strip them. This is rarely expected or desired.

Normally you just want to read data, which is what read -r does. You
should always use -r unless you have a good reason not to.

PR:             227109
Submitted by:   mat
Sponsored by:   Absolight
2018-06-08 09:26:34 +00:00

46 lines
1.3 KiB
Bash

#! /bin/sh
# $FreeBSD$
# Maintainer: portmgr@FreeBSD.org
msg() {
echo "====> $*"
}
msg "Finding symbols"
# Find all ELF files, strip them, and move symbols to PREFIX/usr/lib/debug/ORIG_PATH
ELF_FILES=$(mktemp -t elf_files)
LF=$(printf '\nX')
LF=${LF%X}
find ${STAGEDIR} -type f \
-exec /usr/bin/file -nNF "${LF}" {} + | while read -r f; do
read -r output
case "${output}" in
ELF\ *\ executable,\ *FreeBSD*,\ not\ stripped*|\
ELF\ *\ shared\ object,\ *FreeBSD*,\ not\ stripped*)
echo "${f}"
;;
esac
done > ${ELF_FILES}
# Create all of the /usr/local/lib/* dirs
lib_dir="${STAGEDIR}.debug${PREFIX}/lib/debug"
sed -e "s,^${STAGEDIR}${PREFIX}/,${lib_dir}/," -e 's,/[^/]*$,,' \
${ELF_FILES} | sort -u | xargs mkdir -p
while read -r staged_elf_file; do
elf_file_name="${staged_elf_file##*/}"
lib_dir_dest="${lib_dir}/${staged_elf_file#${STAGEDIR}${PREFIX}/}"
# Strip off filename
lib_dir_dest="${lib_dir_dest%/*}"
# Save symbols to f.debug
objcopy --only-keep-debug "${staged_elf_file}" \
"${lib_dir_dest}/${elf_file_name}.debug"
# Strip and add a reference to f.debug for finding the symbols.
objcopy --strip-debug --strip-unneeded \
--add-gnu-debuglink="${lib_dir_dest}/${elf_file_name}.debug" \
"${staged_elf_file}"
msg "Saved symbols for ${staged_elf_file}"
done < ${ELF_FILES}
rm -f ${ELF_FILES}