Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Gentoo Portage Developer (http://www.linux-archive.org/gentoo-portage-developer/)
-   -   prepstrip: add support for elfutils strip (http://www.linux-archive.org/gentoo-portage-developer/586044-prepstrip-add-support-elfutils-strip.html)

Mike Frysinger 10-11-2011 04:50 AM

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 <vapier@gentoo.org>
---
bin/ebuild-helpers/prepstrip | 63 ++++++++++++++++++++++++++++++------------
1 files changed, 45 insertions(+), 18 deletions(-)

diff --git a/bin/ebuild-helpers/prepstrip b/bin/ebuild-helpers/prepstrip
index 7a08aba..6c8c312 100755
--- a/bin/ebuild-helpers/prepstrip
+++ b/bin/ebuild-helpers/prepstrip
@@ -34,10 +34,25 @@ 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}
+# See if we're using GNU binutils or elfutils for stripping
+case $(${STRIP} --version) 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"
+ ;;
+*) # assume 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 +110,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 +136,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 +223,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

--
1.7.6.1

Fabian Groffen 10-11-2011 07:11 AM

prepstrip: add support for elfutils strip
 
On 11-10-2011 00:50:54 -0400, Mike Frysinger wrote:
> If people use strip from the elfutils package, take advantage of some of
> its neat features (like splitting + stripping in one step).

> +# See if we're using GNU binutils or elfutils for stripping
> +case $(${STRIP} --version) 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"
> + ;;
> +*) # assume binutils

For the sake of it, can we try to detect GNU binutils here? Our
profiles restrict strip, so no immediate problem here if not.

% strip --version
strip: unrecognized option: --version
Usage: strip [-AnuSXx] [-] [-d filename] [-s filename] [-R filename] [-o
output] file [...]


--
Fabian Groffen
Gentoo on a different level

Zac Medico 10-11-2011 07:28 AM

prepstrip: add support for elfutils strip
 
On 10/11/2011 12:11 AM, Fabian Groffen wrote:
> On 11-10-2011 00:50:54 -0400, Mike Frysinger wrote:
>> If people use strip from the elfutils package, take advantage of some of
>> its neat features (like splitting + stripping in one step).
>
>> +# See if we're using GNU binutils or elfutils for stripping
>> +case $(${STRIP} --version) 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"
>> + ;;
>> +*) # assume binutils
>
> For the sake of it, can we try to detect GNU binutils here? Our
> profiles restrict strip, so no immediate problem here if not.

Sounds like a good idea. Otherwise, the rest of the patch LGTM.
--
Thanks,
Zac

Mike Frysinger 10-11-2011 02:18 PM

prepstrip: add support for elfutils strip
 
On Tuesday 11 October 2011 03:11:03 Fabian Groffen wrote:
> On 11-10-2011 00:50:54 -0400, Mike Frysinger wrote:
> > If people use strip from the elfutils package, take advantage of some of
> > its neat features (like splitting + stripping in one step).
> >
> > +# See if we're using GNU binutils or elfutils for stripping
> > +case $(${STRIP} --version) 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"
> > + ;;
> > +*) # assume binutils
>
> For the sake of it, can we try to detect GNU binutils here? Our
> profiles restrict strip, so no immediate problem here if not.
>
> % strip --version
> strip: unrecognized option: --version
> Usage: strip [-AnuSXx] [-] [-d filename] [-s filename] [-R filename] [-o
> output] file [...]

adding detection here will fix most, but i don't think all, of your troubles

the code still unconditionally runs `strip -g` which i'm guessing won't work
for you ...

also, we only run strip on ELF files. so if you aren't an ELF system, even
fixing the -g won't help.
-mike

Fabian Groffen 10-11-2011 02:55 PM

prepstrip: add support for elfutils strip
 
On 11-10-2011 10:18:16 -0400, Mike Frysinger wrote:
> > For the sake of it, can we try to detect GNU binutils here? Our
> > profiles restrict strip, so no immediate problem here if not.
> >
> adding detection here will fix most, but i don't think all, of your troubles
>
> the code still unconditionally runs `strip -g` which i'm guessing won't work
> for you ...
>
> also, we only run strip on ELF files. so if you aren't an ELF system, even
> fixing the -g won't help.

Actually, on Solaris (ELF) the way Portage uses strip will damage the
files in such a way that they become unusable. And we're using GNU
binutils there. So I guess it's ok to assume here. In the profiles
stripping is just disabled everywhere it breaks.


--
Fabian Groffen
Gentoo on a different level

Mike Frysinger 10-11-2011 03:13 PM

prepstrip: add support for elfutils strip
 
On Tuesday 11 October 2011 10:55:32 Fabian Groffen wrote:
> On 11-10-2011 10:18:16 -0400, Mike Frysinger wrote:
> > > For the sake of it, can we try to detect GNU binutils here? Our
> > > profiles restrict strip, so no immediate problem here if not.
> >
> > adding detection here will fix most, but i don't think all, of your
> > troubles
> >
> > the code still unconditionally runs `strip -g` which i'm guessing won't
> > work for you ...
> >
> > also, we only run strip on ELF files. so if you aren't an ELF system,
> > even fixing the -g won't help.
>
> Actually, on Solaris (ELF) the way Portage uses strip will damage the
> files in such a way that they become unusable. And we're using GNU
> binutils there. So I guess it's ok to assume here. In the profiles
> stripping is just disabled everywhere it breaks.

so GNU binutils is broken on Solaris ? the flags that portage uses should be
safe (by design) when stripping ELF files.
-mike


All times are GMT. The time now is 04:31 AM.

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