diff options
-rwxr-xr-x | bin/prepstrip | 114 |
1 files changed, 64 insertions, 50 deletions
diff --git a/bin/prepstrip b/bin/prepstrip index bce396899..c5b23d3a8 100755 --- a/bin/prepstrip +++ b/bin/prepstrip @@ -5,11 +5,13 @@ source "${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"/isolated-functions.sh -unset NOSTRIP -if hasq nostrip ${FEATURES} ${RESTRICT} || \ +banner=false +SKIP_STRIP=false +if hasq nostrip ${FEATURES} || \ hasq strip ${RESTRICT} then - NOSTRIP=1 + SKIP_STRIP=true + banner=true hasq installsources ${FEATURES} || exit 0 fi @@ -23,43 +25,44 @@ type -P -- ${OBJCOPY} > /dev/null || OBJCOPY=objcopy export SAFE_STRIP_FLAGS="--strip-unneeded" export PORTAGE_STRIP_FLAGS=${PORTAGE_STRIP_FLAGS-${SAFE_STRIP_FLAGS} -R .comment} -banner=1 +save_elf_sources() { + hasq installsources ${FEATURES} || return 0 + type -P debugedit >/dev/null || return 0 -save_elf_debug() { local x=$1 - local y="${D}usr/lib/debug/${x:${#D}}.debug" - - 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 '/<built-in>$' "${T}"/debug.sources | \ - (cd "${WORKDIR}"; LANG=C sort -z -u | \ - rsync -rtL0 --files-from=- "${WORKDIR}/" "${D}${sources_dir}/" ) - fi + 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 '/<built-in>$' "${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 - [[ -z "${NOSTRIP}" ]] || return 0 - # dont save debug info twice. - [[ ${x:7} == ".debug" ]] && return 0 + local x=$1 + local y="${D}usr/lib/debug/${x:${#D}}.debug" + + # dont save debug info twice + [[ ${x} == *".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}" @@ -71,42 +74,53 @@ for x in \ $(scanelf -yqRBF '#k%F' -k '.symtab' "$@") \ $(find "$@" -type f -name '*.a') do - if [[ ${banner} -eq 1 ]] ; then - [[ -z ${NOSTRIP} ]] && vecho "strip: ${STRIP} ${PORTAGE_STRIP_FLAGS}" - banner=0 + if ! ${banner} ; then + vecho "strip: ${STRIP} ${PORTAGE_STRIP_FLAGS}" + banner=true fi f=$(file "${x}") || continue [[ -z ${f} ]] && continue - # 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 ! ${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. if [[ ${f} == *"current ar archive"* ]] ; then vecho " ${x:${#D}}" - [[ -n ${NOSTRIP} ]] && continue - [[ ${stripitbaby} -eq 1 ]] && ${STRIP} -g "${x}" - elif [[ ${f} == *"SB executable"* || ${f} == *"SB shared object"* || ${f} == *"SB relocatable"* ]] ; then + 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}}" - if [[ ${f} != *"SB relocatable"* ]] || [[ ${x} == *.ko ]] ; then - # 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 + save_elf_sources "${x}" + if ${strip_this} ; then save_elf_debug "${x}" + ${STRIP} ${PORTAGE_STRIP_FLAGS} "${x}" fi - [[ -n ${NOSTRIP} ]] && continue - if [[ ${stripitbaby} -eq 1 ]] ; then - [[ ${f} == *"SB relocatable"* ]] \ - && ${STRIP} ${SAFE_STRIP_FLAGS} "${x}" \ - || ${STRIP} ${PORTAGE_STRIP_FLAGS} "${x}" + 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 fi done |