Gentoo Archives: gentoo-portage-dev

From: Mike Frysinger <vapier@g.o>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] [PATCH 2/2] prepstrip: add support for elfutils strip
Date: Tue, 11 Oct 2011 04:51:21
Message-Id: 1318308654-22337-2-git-send-email-vapier@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH 1/2] prepstrip: extract buildid with readelf to avoid debugedit when possible by Mike Frysinger
1 If people use strip from the elfutils package, take advantage of some of
2 its neat features (like splitting + stripping in one step).
3
4 Signed-off-by: Mike Frysinger <vapier@g.o>
5 ---
6 bin/ebuild-helpers/prepstrip | 63 ++++++++++++++++++++++++++++++------------
7 1 files changed, 45 insertions(+), 18 deletions(-)
8
9 diff --git a/bin/ebuild-helpers/prepstrip b/bin/ebuild-helpers/prepstrip
10 index 7a08aba..6c8c312 100755
11 --- a/bin/ebuild-helpers/prepstrip
12 +++ b/bin/ebuild-helpers/prepstrip
13 @@ -34,10 +34,25 @@ for t in STRIP:strip OBJCOPY:objcopy READELF:readelf ; do
14 type -P -- ${!v} >/dev/null || eval ${v}=${t}
15 done
16
17 -# We'll leave out -R .note for now until we can check out the relevance
18 -# of the section when it has the ALLOC flag set on it ...
19 -export SAFE_STRIP_FLAGS="--strip-unneeded"
20 -export PORTAGE_STRIP_FLAGS=${PORTAGE_STRIP_FLAGS-${SAFE_STRIP_FLAGS} -R .comment}
21 +# See if we're using GNU binutils or elfutils for stripping
22 +case $(${STRIP} --version) in
23 +*elfutils*) # dev-libs/elfutils
24 + # elfutils default behavior is always safe, so don't need to specify
25 + # any flags at all
26 + SAFE_STRIP_FLAGS=""
27 + DEF_STRIP_FLAGS="--remove-comment"
28 + SPLIT_STRIP_FLAGS="-f"
29 + ;;
30 +*) # assume binutils
31 + # We'll leave out -R .note for now until we can check out the relevance
32 + # of the section when it has the ALLOC flag set on it ...
33 + SAFE_STRIP_FLAGS="--strip-unneeded"
34 + DEF_STRIP_FLAGS="-R .comment"
35 + SPLIT_STRIP_FLAGS=
36 + ;;
37 +esac
38 +: ${PORTAGE_STRIP_FLAGS=${SAFE_STRIP_FLAGS} ${DEF_STRIP_FLAGS}}
39 +
40 prepstrip_sources_dir=/usr/src/debug/${CATEGORY}/${PF}
41
42 type -P debugedit >/dev/null && debugedit_found=true || debugedit_found=false
43 @@ -95,8 +110,12 @@ save_elf_debug() {
44 ln "${D}usr/lib/debug/${!inode:${#D}}.debug" "$y"
45 else
46 eval $inode=\$x
47 - ${OBJCOPY} --only-keep-debug "${x}" "${y}"
48 - ${OBJCOPY} --add-gnu-debuglink="${y}" "${x}"
49 + if [[ -e ${T}/prepstrip.split.debug ]] ; then
50 + mv "${T}"/prepstrip.split.debug "${y}"
51 + else
52 + ${OBJCOPY} --only-keep-debug "${x}" "${y}"
53 + ${OBJCOPY} --add-gnu-debuglink="${y}" "${x}"
54 + fi
55 local args="a-x,o-w"
56 [[ -g ${x} || -u ${x} ]] && args+=",go-r"
57 chmod ${args} "${y}"
58 @@ -117,6 +136,24 @@ save_elf_debug() {
59 fi
60 }
61
62 +process_elf() {
63 + local x=$1 strip_flags=${*:2}
64 +
65 + vecho " ${x:${#D}}"
66 + save_elf_sources "${x}"
67 +
68 + if ${strip_this} ; then
69 + # see if we can split & strip at the same time
70 + if [[ -n ${SPLIT_STRIP_FLAGS} ]] ; then
71 + ${STRIP} ${strip_flags} -f "${T}"/prepstrip.split.debug "${x}"
72 + save_elf_debug "${x}"
73 + else
74 + save_elf_debug "${x}"
75 + ${STRIP} ${strip_flags} "${x}"
76 + fi
77 + fi
78 +}
79 +
80 # The existance of the section .symtab tells us that a binary is stripped.
81 # We want to log already stripped binaries, as this may be a QA violation.
82 # They prevent us from getting the splitdebug data.
83 @@ -186,19 +223,9 @@ do
84 ${STRIP} -g "${x}"
85 fi
86 elif [[ ${f} == *"SB executable"* || ${f} == *"SB shared object"* ]] ; then
87 - vecho " ${x:${#D}}"
88 - save_elf_sources "${x}"
89 - if ${strip_this} ; then
90 - save_elf_debug "${x}"
91 - ${STRIP} ${PORTAGE_STRIP_FLAGS} "${x}"
92 - fi
93 + process_elf "${x}" ${PORTAGE_STRIP_FLAGS}
94 elif [[ ${f} == *"SB relocatable"* ]] ; then
95 - vecho " ${x:${#D}}"
96 - save_elf_sources "${x}"
97 - if ${strip_this} ; then
98 - [[ ${x} == *.ko ]] && save_elf_debug "${x}"
99 - ${STRIP} ${SAFE_STRIP_FLAGS} "${x}"
100 - fi
101 + process_elf "${x}" ${SAFE_STRIP_FLAGS}
102 fi
103 done
104
105 --
106 1.7.6.1

Replies