From 51579fb34c19519a585ce2d052a270b6d84a2d97 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 11 Oct 2011 00:49:48 -0400 Subject: prepstrip: add support for elfutils strip If people use strip from the elfutils package, take advantage of some of its neat features (like splitting + stripping in one step). Signed-off-by: Mike Frysinger --- bin/ebuild-helpers/prepstrip | 64 +++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 18 deletions(-) (limited to 'bin/ebuild-helpers') diff --git a/bin/ebuild-helpers/prepstrip b/bin/ebuild-helpers/prepstrip index 7a08ababb..7f158c29d 100755 --- a/bin/ebuild-helpers/prepstrip +++ b/bin/ebuild-helpers/prepstrip @@ -34,10 +34,26 @@ for t in STRIP:strip OBJCOPY:objcopy READELF:readelf ; do type -P -- ${!v} >/dev/null || eval ${v}=${t} done -# We'll leave out -R .note for now until we can check out the relevance -# of the section when it has the ALLOC flag set on it ... -export SAFE_STRIP_FLAGS="--strip-unneeded" -export PORTAGE_STRIP_FLAGS=${PORTAGE_STRIP_FLAGS-${SAFE_STRIP_FLAGS} -R .comment} +# Figure out what tool set we're using to strip stuff +unset SAFE_STRIP_FLAGS DEF_STRIP_FLAGS SPLIT_STRIP_FLAGS +case $(${STRIP} --version 2>/dev/null) in +*elfutils*) # dev-libs/elfutils + # elfutils default behavior is always safe, so don't need to specify + # any flags at all + SAFE_STRIP_FLAGS="" + DEF_STRIP_FLAGS="--remove-comment" + SPLIT_STRIP_FLAGS="-f" + ;; +*GNU*) # sys-devel/binutils + # We'll leave out -R .note for now until we can check out the relevance + # of the section when it has the ALLOC flag set on it ... + SAFE_STRIP_FLAGS="--strip-unneeded" + DEF_STRIP_FLAGS="-R .comment" + SPLIT_STRIP_FLAGS= + ;; +esac +: ${PORTAGE_STRIP_FLAGS=${SAFE_STRIP_FLAGS} ${DEF_STRIP_FLAGS}} + prepstrip_sources_dir=/usr/src/debug/${CATEGORY}/${PF} type -P debugedit >/dev/null && debugedit_found=true || debugedit_found=false @@ -95,8 +111,12 @@ save_elf_debug() { ln "${D}usr/lib/debug/${!inode:${#D}}.debug" "$y" else eval $inode=\$x - ${OBJCOPY} --only-keep-debug "${x}" "${y}" - ${OBJCOPY} --add-gnu-debuglink="${y}" "${x}" + if [[ -e ${T}/prepstrip.split.debug ]] ; then + mv "${T}"/prepstrip.split.debug "${y}" + else + ${OBJCOPY} --only-keep-debug "${x}" "${y}" + ${OBJCOPY} --add-gnu-debuglink="${y}" "${x}" + fi local args="a-x,o-w" [[ -g ${x} || -u ${x} ]] && args+=",go-r" chmod ${args} "${y}" @@ -117,6 +137,24 @@ save_elf_debug() { fi } +process_elf() { + local x=$1 strip_flags=${*:2} + + vecho " ${x:${#D}}" + save_elf_sources "${x}" + + if ${strip_this} ; then + # see if we can split & strip at the same time + if [[ -n ${SPLIT_STRIP_FLAGS} ]] ; then + ${STRIP} ${strip_flags} -f "${T}"/prepstrip.split.debug "${x}" + save_elf_debug "${x}" + else + save_elf_debug "${x}" + ${STRIP} ${strip_flags} "${x}" + fi + fi +} + # The existance of the section .symtab tells us that a binary is stripped. # We want to log already stripped binaries, as this may be a QA violation. # They prevent us from getting the splitdebug data. @@ -186,19 +224,9 @@ do ${STRIP} -g "${x}" fi elif [[ ${f} == *"SB executable"* || ${f} == *"SB shared object"* ]] ; then - vecho " ${x:${#D}}" - save_elf_sources "${x}" - if ${strip_this} ; then - save_elf_debug "${x}" - ${STRIP} ${PORTAGE_STRIP_FLAGS} "${x}" - fi + process_elf "${x}" ${PORTAGE_STRIP_FLAGS} elif [[ ${f} == *"SB relocatable"* ]] ; then - vecho " ${x:${#D}}" - save_elf_sources "${x}" - if ${strip_this} ; then - [[ ${x} == *.ko ]] && save_elf_debug "${x}" - ${STRIP} ${SAFE_STRIP_FLAGS} "${x}" - fi + process_elf "${x}" ${SAFE_STRIP_FLAGS} fi done -- cgit v1.2.3-1-g7c22