From: Zac Medico Date: Mon, 30 Jul 2007 06:05:58 +0000 (-0000) Subject: remove readable bits for debug files if the souce ELF is setXid (branches/2.1.2 r7232) X-Git-Tag: v2.1.2.11~25 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=01ef8d1618340c29be360a34a8d6ba2a43813533;p=portage.git remove readable bits for debug files if the souce ELF is setXid (branches/2.1.2 r7232) svn path=/main/branches/2.1.2.9/; revision=7492 --- diff --git a/bin/prepstrip b/bin/prepstrip index 178b5c173..b9e51ab53 100755 --- a/bin/prepstrip +++ b/bin/prepstrip @@ -1,17 +1,15 @@ #!/bin/bash -# Copyright 1999-2007 Gentoo Foundation +# Copyright 1999-2006 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id$ source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh -banner=false -SKIP_STRIP=false -if hasq nostrip ${FEATURES} || \ +unset NOSTRIP +if hasq nostrip ${FEATURES} ${RESTRICT} || \ hasq strip ${RESTRICT} then - SKIP_STRIP=true - banner=true + NOSTRIP=1 hasq installsources ${FEATURES} || exit 0 fi @@ -20,54 +18,46 @@ type -P -- ${STRIP} > /dev/null || STRIP=strip OBJCOPY=${OBJCOPY:-${CHOST}-objcopy} type -P -- ${OBJCOPY} > /dev/null || OBJCOPY=objcopy -# 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} +export PORTAGE_STRIP_FLAGS=${PORTAGE_STRIP_FLAGS:---strip-unneeded} -if hasq installsources ${FEATURES} && ! type -P debugedit >/dev/null ; then - ewarn "FEATURES=installsources is enabled but the debugedit binary could not" - ewarn "be found. This feature will not work unless debugedit is installed!" -fi - -save_elf_sources() { - hasq installsources ${FEATURES} || return 0 - type -P debugedit >/dev/null || return 0 +banner=1 - local x=$1 - local sources_dir=/usr/src/debug/${CATEGORY}/${PF} - debugedit -b "${WORKDIR}" -d "${sources_dir}" \ - -l "${T}"/debug.sources "${x}" - if [[ -s ${T}/debug.sources ]] ; then - [[ -d ${D}${sources_dir} ]] || mkdir -p "${D}${sources_dir}" - grep -zv '/$' "${T}"/debug.sources | \ - (cd "${WORKDIR}"; LANG=C sort -z -u | \ - rsync -rtL0 --files-from=- "${WORKDIR}/" "${D}${sources_dir}/" ) - fi -} - save_elf_debug() { - hasq splitdebug ${FEATURES} || return 0 - local x=$1 local y="${D}usr/lib/debug/${x:${#D}}.debug" - # dont save debug info twice - [[ ${x} == *".debug" ]] && return 0 + if hasq installsources ${FEATURES} && [ -x /usr/bin/debugedit ] ; then + local sources_dir=/usr/src/debug/${CATEGORY}/${PF} + debugedit -b "${WORKDIR}" -d "${sources_dir}" \ + -l "${T}"/debug.sources "${x}" + if [[ -s ${T}/debug.sources ]] ; then + [[ -d ${D}${sources_dir} ]] || mkdir -p "${D}${sources_dir}" + grep -zv '/$' "${T}"/debug.sources | \ + (cd "${WORKDIR}"; LANG=C sort -z -u | \ + rsync -rtL0 --files-from=- "${WORKDIR}/" "${D}${sources_dir}/" ) + fi + fi + + hasq splitdebug ${FEATURES} || return 0 + [[ -z "${NOSTRIP}" ]] || return 0 + + # dont save debug info twice. + [[ ${x:7} == ".debug" ]] && return 0 mkdir -p $(dirname "${y}") ${OBJCOPY} --only-keep-debug "${x}" "${y}" ${OBJCOPY} --add-gnu-debuglink="${y}" "${x}" - [[ -g ${x} ]] && chmod go-r "${y}" - [[ -u ${x} ]] && chmod go-r "${y}" + [ -g "${x}" ] && chmod go-r "${y}" + [ -u "${x}" ] && chmod go-r "${y}" chmod a-x,o-w "${y}" + } # 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. -f=$(scanelf -yqRBF '#k%F' -k '!.symtab' "$@") -if [[ -n ${f} ]] ; then +f="$(scanelf -yqRBF '#k%F' -k '!.symtab' "$@")" +if [[ -n "${f}" ]] ; then vecho -e "\a\n" eqawarn "QA Notice: Pre-stripped files found:" eqawarn "${f}" @@ -75,57 +65,34 @@ if [[ -n ${f} ]] ; then fi # Now we look for unstripped binaries. -for x in \ - $(scanelf -yqRBF '#k%F' -k '.symtab' "$@") \ - $(find "$@" -type f -name '*.a') -do - if ! ${banner} ; then - vecho "strip: ${STRIP} ${PORTAGE_STRIP_FLAGS}" - banner=true +for x in $(scanelf -yqRBF '#k%F' -k '.symtab' "$@") $(for y in "$@"; do find "${y}" -type f -name '*.a' -print ; done); do + if [[ ${banner} -eq 1 ]] ; then + [[ -z ${NOSTRIP} ]] && vecho "strip: ${STRIP} ${PORTAGE_STRIP_FLAGS}" + banner=0 fi f=$(file "${x}") || continue [[ -z ${f} ]] && continue - if ! ${SKIP_STRIP} ; then - # The noglob funk is to support STRIP_MASK="/*/booga" and to keep - # the for loop from expanding the globs. - # The eval echo is to support STRIP_MASK="/*/{booga,bar}" sex. - set -o noglob - strip_this=true - for m in $(eval echo ${STRIP_MASK}) ; do - [[ ${x} == ${m} ]] && strip_this=false && break - done - set +o noglob - else - strip_this=false - fi - - # only split debug info for final linked objects - # or kernel modules as debuginfo for intermediatary - # files (think crt*.o from gcc/glibc) is useless and - # actually causes problems. install sources for all - # elf types though cause that stuff is good. + # The noglob funk is to support STRIP_MASK="/*/booga" and to keep + # the for loop from expanding the globs. + # The eval echo is to support STRIP_MASK="/*/{booga,bar}" sex. + set -o noglob + stripitbaby=1 + for m in $(eval echo ${STRIP_MASK}) ; do + [[ ${x} == ${m} ]] && stripitbaby=0 && break + done + set +o noglob if [[ ${f} == *"current ar archive"* ]] ; then vecho " ${x:${#D}}" - if ${strip_this} ; then - # hmm, can we split debug/sources for .a ? - ${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 - elif [[ ${f} == *"SB relocatable"* ]] ; then + [[ -n ${NOSTRIP} ]] && continue + [[ ${stripitbaby} -eq 1 ]] && ${STRIP} -g "${x}" + fi + if [[ ${f} == *"SB executable"* || ${f} == *"SB shared object"* ]] ; then vecho " ${x:${#D}}" - save_elf_sources "${x}" - if ${strip_this} ; then - [[ ${x} == *.ko ]] && save_elf_debug "${x}" - ${STRIP} ${SAFE_STRIP_FLAGS} "${x}" - fi + save_elf_debug "${x}" + [[ -n ${NOSTRIP} ]] && continue + [[ ${stripitbaby} -eq 1 ]] && ${STRIP} ${PORTAGE_STRIP_FLAGS} "${x}" fi done