Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   ArchLinux Pacman Development (http://www.linux-archive.org/archlinux-pacman-development/)
-   -   makepkg: strip debugging symbols into separate folder (http://www.linux-archive.org/archlinux-pacman-development/706646-makepkg-strip-debugging-symbols-into-separate-folder.html)

Allan McRae 09-23-2012 02:44 PM

makepkg: strip debugging symbols into separate folder
 
When using the "debug" option in combination with "strip", move the
debugging symbols into a separate directory ($pkgdir-debug/usr/lib/debug)
suitable for creating a package from.

Create hardlinks between debugging symbols of hardlinked files and add
symlinks in the .build_id directory if the binary has a build ID.

Signed-off-by: Allan McRae <allan@archlinux.org>
---
scripts/makepkg.sh.in | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ +
1 file changed, 52 insertions(+)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index c857060..df1823d 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1421,8 +1421,55 @@ run_package() {
run_function_safe "$pkgfunc"
}

+build_id() {
+ local id
+ id=$(LANG=C readelf -n $1 | sed -n '/Build ID/ { s/.*: //p; q; }')
+ printf "%s
" "$id"
+}
+
strip_file() {
local binary=$1; shift
+
+ if check_option "debug" "y"; then
+ local bid=$(build_id $binary)
+
+ # has this file already been stripped
+ if [[ -n "$bid" ]]; then
+ if [[ -f $pkgdir-debug/usr/lib/debug/.build_id/${bid:0:2}/${bid:2}.debug ]]; then
+ return
+ fi
+ elif [[ -f $pkgdir-debug/usr/lib/debug/$binary.debug ]]; then
+ return
+ fi
+
+ mkdir -p $pkgdir-debug/usr/lib/debug/${binary%/*}
+ objcopy --only-keep-debug $binary $pkgdir-debug/usr/lib/debug/$binary.debug
+
+ # create any needed hardlinks
+ while read -d ' file ; do
+ if [[ "${binary}" -ef "${file}" &&
+ ! -f $pkgdir-debug/usr/lib/debug/${file}.debug ]]; then
+ mkdir -p $pkgdir-debug/usr/lib/debug/${file%/*}
+ ln $pkgdir-debug/usr/lib/debug/${binary}.debug
+ $pkgdir-debug/usr/lib/debug/${file}.debug
+ return
+ fi
+ done < <(find . -type f -perm -u+w -print0 2>/dev/null)
+
+ if [[ -n "$bid" ]]; then
+ local target
+ mkdir -p $pkgdir-debug/usr/lib/debug/.build_id/${bid:0:2}
+
+ target="../../../../../${binary#./}"
+ target=${target/../../usr/lib/}
+ target=${target/../usr/}
+ ln -s $target $pkgdir-debug/usr/lib/debug/.build_id/${bid:0:2}/${bid:2}
+
+ target="../../${binary#./}.debug"
+ ln -s $target $pkgdir-debug/usr/lib/debug/.build_id/${bid:0:2}/${bid:2}.debug
+ fi
+ fi
+
strip $@ $binary
}

@@ -1480,6 +1527,11 @@ tidy_install() {
# make sure library stripping variables are defined to prevent excess stripping
[[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED="-S"
[[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S"
+
+ if check_option "debug" "y"; then
+ mkdir -p $pkgdir-debug/usr/lib/debug
+ fi
+
local binary strip_flags
find . -type f -perm -u+w -print0 2>/dev/null | while read -d ' binary ; do
case "$(file -bi "$binary")" in
--
1.7.12.1

Allan McRae 09-23-2012 03:33 PM

makepkg: strip debugging symbols into separate folder
 
When using the "debug" option in combination with "strip", move the
debugging symbols into a separate directory ($pkgdir-debug/usr/lib/debug)
suitable for creating a package from.

Create hardlinks between debugging symbols of hardlinked files and add
symlinks in the .build_id directory if the binary has a build ID.

Signed-off-by: Allan McRae <allan@archlinux.org>
---

Fixup:
- remove bad return...
- add add-gnu-debuglink to file

scripts/makepkg.sh.in | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ +
1 file changed, 52 insertions(+)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index c857060..a7971fe 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1421,8 +1421,55 @@ run_package() {
run_function_safe "$pkgfunc"
}

+build_id() {
+ local id
+ id=$(LANG=C readelf -n $1 | sed -n '/Build ID/ { s/.*: //p; q; }')
+ printf "%s
" "$id"
+}
+
strip_file() {
local binary=$1; shift
+
+ if check_option "debug" "y"; then
+ local bid=$(build_id $binary)
+
+ # has this file already been stripped
+ if [[ -n "$bid" ]]; then
+ if [[ -f $pkgdir-debug/usr/lib/debug/.build_id/${bid:0:2}/${bid:2}.debug ]]; then
+ return
+ fi
+ elif [[ -f $pkgdir-debug/usr/lib/debug/$binary.debug ]]; then
+ return
+ fi
+
+ mkdir -p $pkgdir-debug/usr/lib/debug/${binary%/*}
+ objcopy --only-keep-debug $binary $pkgdir-debug/usr/lib/debug/$binary.debug
+ objcopy --add-gnu-debuglink="$pkgdir-debug/usr/lib/debug/${binary#/}.debug" "$binary"
+
+ # create any needed hardlinks
+ while read -d ' file ; do
+ if [[ "${binary}" -ef "${file}" &&
+ ! -f $pkgdir-debug/usr/lib/debug/${file}.debug ]]; then
+ mkdir -p $pkgdir-debug/usr/lib/debug/${file%/*}
+ ln $pkgdir-debug/usr/lib/debug/${binary}.debug
+ $pkgdir-debug/usr/lib/debug/${file}.debug
+ fi
+ done < <(find . -type f -perm -u+w -print0 2>/dev/null)
+
+ if [[ -n "$bid" ]]; then
+ local target
+ mkdir -p $pkgdir-debug/usr/lib/debug/.build_id/${bid:0:2}
+
+ target="../../../../../${binary#./}"
+ target=${target/../../usr/lib/}
+ target=${target/../usr/}
+ ln -s $target $pkgdir-debug/usr/lib/debug/.build_id/${bid:0:2}/${bid:2}
+
+ target="../../${binary#./}.debug"
+ ln -s $target $pkgdir-debug/usr/lib/debug/.build_id/${bid:0:2}/${bid:2}.debug
+ fi
+ fi
+
strip $@ $binary
}

@@ -1480,6 +1527,11 @@ tidy_install() {
# make sure library stripping variables are defined to prevent excess stripping
[[ -z ${STRIP_SHARED+x} ]] && STRIP_SHARED="-S"
[[ -z ${STRIP_STATIC+x} ]] && STRIP_STATIC="-S"
+
+ if check_option "debug" "y"; then
+ mkdir -p $pkgdir-debug/usr/lib/debug
+ fi
+
local binary strip_flags
find . -type f -perm -u+w -print0 2>/dev/null | while read -d ' binary ; do
case "$(file -bi "$binary")" in
--
1.7.12.1


All times are GMT. The time now is 12:43 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.