Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-gnome
Path: blob/main/Mk/Scripts/generate-symbols.sh
16124 views
1
#! /bin/sh
2
# Maintainer: [email protected]
3
#
4
# This script will find all ELF files in STAGEDIR and then strip and move
5
# the symbols to LOCALBASE/lib/debug/<original path>.
6
# For example:
7
# /var/qmail/bin/qmaild -> /usr/local/lib/debug/var/qmail/bin/qmaild.debug
8
# /usr/local/bin/ssh -> /usr/local/lib/debug/usr/local/bin/ssh.debug
9
LIB_DIR_PREFIX="${LOCALBASE}/lib/debug"
10
11
set -o pipefail
12
13
msg() {
14
echo "====> $*"
15
}
16
17
msg "Finding symbols"
18
19
# Find all ELF files
20
ELF_FILES=$(mktemp -t elf_files)
21
find ${STAGEDIR} -type f ! -name '*.a' \
22
-exec /usr/bin/readelf -S /dev/null {} + 2>/dev/null | awk ' \
23
/File:/ {sub(/File: /, "", $0); file=$0}
24
/[[:space:]]\.debug_info[[:space:]]*PROGBITS/ {print file}' \
25
> ${ELF_FILES}
26
27
# Create all of the /usr/local/lib/* dirs
28
lib_dir="${STAGEDIR}${LIB_DIR_PREFIX}"
29
sed -e "s,^${STAGEDIR}/,${lib_dir}/," -e 's,/[^/]*$,,' \
30
${ELF_FILES} | sort -u | xargs mkdir -p
31
32
while read -r staged_elf_file; do
33
elf_file_name="${staged_elf_file##*/}"
34
lib_dir_dest="${lib_dir}/${staged_elf_file#${STAGEDIR}/}"
35
# Strip off filename
36
lib_dir_dest="${lib_dir_dest%/*}"
37
# Save symbols to f.debug
38
debug_file_name="${lib_dir_dest}/${elf_file_name}.debug"
39
objcopy --only-keep-debug "${staged_elf_file}" "${debug_file_name}"
40
# Strip and add a reference to f.debug for finding the symbols.
41
objcopy --strip-debug --strip-unneeded \
42
--add-gnu-debuglink="${debug_file_name}" "${staged_elf_file}"
43
msg "Saved symbols for ${staged_elf_file}"
44
echo "${debug_file_name#${STAGEDIR}}" >&3
45
done < ${ELF_FILES} 3>> ${TMPPLIST}
46
47
# Need @dir entries if PREFIX != LOCALBASE
48
if [ "${PREFIX}" != "${LOCALBASE}" ] && [ -d "${lib_dir}" ]; then
49
find -sd "${lib_dir}" -type d | sed -e "s,^${STAGEDIR},," \
50
-e 's,^,@dir ,' \
51
>> ${TMPPLIST}
52
fi
53
54
rm -f ${ELF_FILES}
55
56