Path: blob/main/Mk/Scripts/generate-symbols.sh
16124 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.debug8LIB_DIR_PREFIX="${LOCALBASE}/lib/debug"910set -o pipefail1112msg() {13echo "====> $*"14}1516msg "Finding symbols"1718# Find all ELF files19ELF_FILES=$(mktemp -t elf_files)20find ${STAGEDIR} -type f ! -name '*.a' \21-exec /usr/bin/readelf -S /dev/null {} + 2>/dev/null | awk ' \22/File:/ {sub(/File: /, "", $0); file=$0}23/[[:space:]]\.debug_info[[:space:]]*PROGBITS/ {print file}' \24> ${ELF_FILES}2526# Create all of the /usr/local/lib/* dirs27lib_dir="${STAGEDIR}${LIB_DIR_PREFIX}"28sed -e "s,^${STAGEDIR}/,${lib_dir}/," -e 's,/[^/]*$,,' \29${ELF_FILES} | sort -u | xargs mkdir -p3031while read -r staged_elf_file; do32elf_file_name="${staged_elf_file##*/}"33lib_dir_dest="${lib_dir}/${staged_elf_file#${STAGEDIR}/}"34# Strip off filename35lib_dir_dest="${lib_dir_dest%/*}"36# Save symbols to f.debug37debug_file_name="${lib_dir_dest}/${elf_file_name}.debug"38objcopy --only-keep-debug "${staged_elf_file}" "${debug_file_name}"39# Strip and add a reference to f.debug for finding the symbols.40objcopy --strip-debug --strip-unneeded \41--add-gnu-debuglink="${debug_file_name}" "${staged_elf_file}"42msg "Saved symbols for ${staged_elf_file}"43echo "${debug_file_name#${STAGEDIR}}" >&344done < ${ELF_FILES} 3>> ${TMPPLIST}4546# Need @dir entries if PREFIX != LOCALBASE47if [ "${PREFIX}" != "${LOCALBASE}" ] && [ -d "${lib_dir}" ]; then48find -sd "${lib_dir}" -type d | sed -e "s,^${STAGEDIR},," \49-e 's,^,@dir ,' \50>> ${TMPPLIST}51fi5253rm -f ${ELF_FILES}545556