diff options
author | Juergen Borleis <jbe@pengutronix.de> | 2017-06-14 17:08:59 +0200 |
---|---|---|
committer | Michael Olbrich <m.olbrich@pengutronix.de> | 2017-06-21 09:34:50 +0200 |
commit | 56b1e28fdbf7873ccfc46fa82cef9734691a31e7 (patch) | |
tree | 06caf0a337de44eb85dd668639d70f1722baa29f /scripts | |
parent | e6533aa2d924dcd302ff49b5b71d8ac1ea3876e7 (diff) | |
download | ptxdist-56b1e28fdbf7873ccfc46fa82cef9734691a31e7.tar.gz ptxdist-56b1e28fdbf7873ccfc46fa82cef9734691a31e7.tar.xz |
Debugging: add support for 'build-id's
Recent debugging tools support separate binaries and debug information
files. Providing a unique 'build-id' embedded in the binary enables the
debugging tools to select the correct and matching debug information
files from the system's root filesystem.
The 'build-id' is a 40 character calculated SHA1 from important sections in
the binary. The debug information files get stored at a central direcory at
"/usr/lib/debug/", with a special path based on the 'build-id'. If the
'build-id' is "123456789abcdef", the path and filename will be
".build-id/12/3456789abcdef.debug".
Its possible to have more than one 'build-id' in the binary. This
implementation prefers the first one in the list, which might be the
wrong one. It's unclear yet how the common debugging tools will behave in
this case.
Signed-off-by: Juergen Borleis <jbe@pengutronix.de>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/ptxd_make_xpkg_pkg.sh | 19 | ||||
-rw-r--r-- | scripts/wrapper/libwrapper.sh | 7 |
2 files changed, 24 insertions, 2 deletions
diff --git a/scripts/lib/ptxd_make_xpkg_pkg.sh b/scripts/lib/ptxd_make_xpkg_pkg.sh index fc6b51a77..3b1a21918 100644 --- a/scripts/lib/ptxd_make_xpkg_pkg.sh +++ b/scripts/lib/ptxd_make_xpkg_pkg.sh @@ -243,14 +243,27 @@ install directory: } export -f ptxd_install_dir +ptxd_extract_build_id() { + # accept only the first build-id + ${CROSS_READELF} -n ${src} | awk 'BEGIN { FS=":\\s*" } /Build ID/{ print $2; exit }' +} +export -f ptxd_extract_build_id export ptxd_install_file_objcopy_args="--only-keep-debug --compress-debug-sections" ptxd_install_file_extract_debug() { local dir="${1}" local dst="${2}" - local dbg="$(dirname "${dir}${dst}")/.debug/.$(basename "${dst}").dbg" + local dbg + local bid=$(ptxd_extract_build_id) + if [ -z "${bid}" ]; then + dbg="$(dirname "${dir}${dst}")/.debug/.$(basename "${dst}").dbg" + else + local path_component=${bid::-38} + local name_component=${bid:2:38} + dbg="${dir}/usr/lib/debug/.build-id/${path_component}/${name_component}.debug" + fi install -d "$(dirname "${dbg}")" || return # this can fail if objcopy does not support compressing debug sections or @@ -268,7 +281,9 @@ ptxd_install_file_extract_debug() { fi fi && chmod -x "${dbg}" && - "${CROSS_OBJCOPY}" --add-gnu-debuglink "${dbg}" "${dir}${dst}" + if [ -z "${bid}" ]; then + "${CROSS_OBJCOPY}" --add-gnu-debuglink "${dbg}" "${dir}${dst}" + fi } export -f ptxd_install_file_extract_debug diff --git a/scripts/wrapper/libwrapper.sh b/scripts/wrapper/libwrapper.sh index 2d61d4f73..036dd107f 100644 --- a/scripts/wrapper/libwrapper.sh +++ b/scripts/wrapper/libwrapper.sh @@ -10,6 +10,7 @@ LINKING=true OPTIMIZE=false PIE=true STDLIB=true +BUILDID=true ARG_LIST="" LATE_ARG_LIST="" @@ -41,6 +42,9 @@ cc_check_args() { -D_FORTIFY_SOURCE | -D_FORTIFY_SOURCE=*) FORTIFY=false ;; + -r | -Wl,--build-id | -Wl,--build-id=*) + BUILDID=false + ;; -nostdlib | -ffreestanding) STDLIB=false FPIE=false @@ -133,6 +137,9 @@ add_ld_args() { add_opt_arg TARGET_LINKER_HASH_SYSV "${1}--hash-style=sysv" add_opt_arg TARGET_LINKER_HASH_BOTH "${1}--hash-style=both" add_opt_arg TARGET_LINKER_AS_NEEDED "${1}--as-needed" + if ${BUILDID}; then + add_opt_arg TARGET_BUILD_ID "${1}--build-id=sha1" + fi } ld_add_ld_args() { |