FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo Portage Developer

 
 
LinkBack Thread Tools
 
Old 10-11-2011, 04:50 AM
Mike Frysinger
 
Default prepstrip: extract buildid with readelf to avoid debugedit when possible

The readelf utility is much more common than debugedit.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
bin/ebuild-helpers/prepstrip | 32 +++++++++++++++++++++++---------
1 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/bin/ebuild-helpers/prepstrip b/bin/ebuild-helpers/prepstrip
index 67ceead..7a08aba 100755
--- a/bin/ebuild-helpers/prepstrip
+++ b/bin/ebuild-helpers/prepstrip
@@ -26,10 +26,13 @@ if ${RESTRICT_strip} || ${FEATURES_nostrip} ; then
${FEATURES_installsources} || exit 0
fi

-STRIP=${STRIP:-${CHOST}-strip}
-type -P -- ${STRIP} > /dev/null || STRIP=strip
-OBJCOPY=${OBJCOPY:-${CHOST}-objcopy}
-type -P -- ${OBJCOPY} > /dev/null || OBJCOPY=objcopy
+# look up the tools we might be using
+for t in STRIP:strip OBJCOPYbjcopy READELF:readelf ; do
+ v=${t%:*} # STRIP
+ t=${t#*:} # strip
+ eval ${v}="${!v:-${CHOST}-${t}}"
+ 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 ...
@@ -65,8 +68,15 @@ save_elf_sources() {
local x=$1
local inode=$(inode_var_name "$x")
[[ -n ${!inode} ]] && return 0
- debugedit -b "${WORKDIR}" -d "${prepstrip_sources_dir}"
- -l "${T}"/debug.sources "${x}"
+
+ # since we're editing the ELF here, we should recompute the build-id
+ # (the -i flag below). save that output so we don't need to recompute
+ # it later on in the save_elf_debug step.
+ buildid=$(debugedit -i
+ -b "${WORKDIR}"
+ -d "${prepstrip_sources_dir}"
+ -l "${T}"/debug.sources
+ "${x}")
}

save_elf_debug() {
@@ -78,9 +88,6 @@ save_elf_debug() {
# dont save debug info twice
[[ ${x} == *".debug" ]] && return 0

- # this will recompute the build-id, but for now that's ok
- local buildid="$( ${debugedit_found} && debugedit -i "${x}" )"
-
mkdir -p "${y%/*}"

local inode=$(inode_var_name "$x")
@@ -95,6 +102,12 @@ save_elf_debug() {
chmod ${args} "${y}"
fi

+ # if we don't already have build-id from debugedit, look it up
+ if [[ -z ${buildid} ]] ; then
+ # convert the readelf output to something useful
+ buildid=$(${READELF} -x .note.gnu.build-id "${x}" 2>/dev/null
+ | awk '$NF ~ /GNU/ { getline; printf $2$3$4$5; getline; print $2 }')
+ fi
if [[ -n ${buildid} ]] ; then
local buildid_dir="${D}usr/lib/debug/.build-id/${buildid:0:2}"
local buildid_file="${buildid_dir}/${buildid:2}"
@@ -165,6 +178,7 @@ do
# actually causes problems. install sources for all
# elf types though cause that stuff is good.

+ buildid=
if [[ ${f} == *"current ar archive"* ]] ; then
vecho " ${x:${#D}}"
if ${strip_this} ; then
--
1.7.6.1
 
Old 10-11-2011, 07:22 AM
Zac Medico
 
Default prepstrip: extract buildid with readelf to avoid debugedit when possible

On 10/10/2011 09:50 PM, Mike Frysinger wrote:
> + # if we don't already have build-id from debugedit, look it up
> + if [[ -z ${buildid} ]] ; then
> + # convert the readelf output to something useful
> + buildid=$(${READELF} -x .note.gnu.build-id "${x}" 2>/dev/null
> + | awk '$NF ~ /GNU/ { getline; printf $2$3$4$5; getline; print $2 }')
> + fi

LGTM.

In case anyone is curious about what that readelf output looks like,
here's an example from util-linux built with -Wl,--build-id in LDFLAGS:

# readelf -x .note.gnu.build-id
/var/tmp/portage/sys-apps/util-linux-2.20/image/usr/lib/debug/.build-id/ff/596c6113f72075beb4a40899b940750f872e72.debug

Hex dump of section '.note.gnu.build-id':
0x08048188 04000000 14000000 03000000 474e5500 ............GNU.
0x08048198 ff596c61 13f72075 beb4a408 99b94075 .Yla.. u......@u
0x080481a8 0f872e72 ...r

--
Thanks,
Zac
 

Thread Tools




All times are GMT. The time now is 02:28 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org