Path: blob/main/Mk/Scripts/generate-symbols.sh
16461 views
#! /bin/sh1# Maintainer: [email protected]2#3# This script will find all ELF files in STAGEDIR and then strip and move4# the symbols to LOCALBASE/lib/debug/<original path>.5# For example:6# /var/qmail/bin/qmaild -> /usr/local/lib/debug/var/qmail/bin/qmaild.debug7# /usr/local/bin/ssh -> /usr/local/lib/debug/usr/local/bin/ssh.debug89set -o pipefail1011msg() {12echo "====> $*"13}141516if [ -z "${PREFIX}" -o -z "${LOCALBASE}" -o -z "${STAGEDIR}" -o -z "${TMPPLIST}" ]; then17echo "PREFIX, LOCALBASE, STAGEDIR and TMPPLIST are required in environment." >&218exit 119fi2021if [ ! -z "${PREPEND_SUBPACKAGE_PREFIX}" ]; then22subpkg_prefix="@@debuginfo@@"23fi2425# Find all ELF files26ELF_FILES=$(mktemp -t elf_files)27find ${STAGEDIR} -type f ! -name '*.a' \28-exec /usr/bin/readelf -S /dev/null {} + 2>/dev/null | awk ' \29/File:/ {sub(/File: /, "", $0); file=$0}30/[[:space:]]\.debug_info[[:space:]]*PROGBITS/ {print file}' \31> ${ELF_FILES}3233# Create all of the /usr/local/lib/* dirs34lib_dir="${STAGEDIR}${LOCALBASE}/lib/debug"35sed -e "s,^${STAGEDIR}/,${lib_dir}/," -e 's,/[^/]*$,,' \36${ELF_FILES} | sort -u | xargs mkdir -p3738while read -r staged_elf_file; do39elf_file_name="${staged_elf_file##*/}"40lib_dir_dest="${lib_dir}/${staged_elf_file#${STAGEDIR}/}"41# Strip off filename42lib_dir_dest="${lib_dir_dest%/*}"43# Save symbols to f.debug44debug_file_name="${lib_dir_dest}/${elf_file_name}.debug"45objcopy --only-keep-debug "${staged_elf_file}" "${debug_file_name}"46# Strip and add a reference to f.debug for finding the symbols.47objcopy --strip-debug --strip-unneeded \48--add-gnu-debuglink="${debug_file_name}" "${staged_elf_file}"49msg "Saved symbols for ${staged_elf_file#${STAGEDIR}}"50echo "${subpkg_prefix}${debug_file_name#${STAGEDIR}}" >&351done < ${ELF_FILES} 3>> ${TMPPLIST}5253# Need @dir entries if PREFIX != LOCALBASE54if [ "${PREFIX}" != "${LOCALBASE}" ] && [ -d "${lib_dir}" ]; then55find -sd "${lib_dir}" -type d | sed -e "s,^${STAGEDIR},," \56-e 's,^,@dir ,' \57>> ${TMPPLIST}58fi5960rm -f ${ELF_FILES}616263