commit: 56eb135c8100d026c096937c1f0322a0cf111280
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Tue Jun 3 07:19:26 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Jun 3 13:34:44 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=56eb135c
estrip: use an associative array to store the tool paths
Presently, estrip employs the questionable methodology of utilising eval
to dynamically declare variables that are subsequently treated as simple
commands in order to invoke the preferred instances of the strip(1),
objcopy(1), readelf(1) and ranlib(1) utilities. Instead, compose an
associative array to store their respective names/paths.
Further, render the code easier to understand and eliminate four SC2086
warnings and two SC2128 warnings into the bargain.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/estrip | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/bin/estrip b/bin/estrip
index 13397e1ebc..dffdf90dbf 100755
--- a/bin/estrip
+++ b/bin/estrip
@@ -158,16 +158,17 @@ if [[ ${KERNEL} == linux ]] && (( has_feature[xattr] ));
then
fi
# Look up the tools we might be using
-for t in STRIP:strip OBJCOPY:objcopy READELF:readelf RANLIB:ranlib ; do
- v=${t%:*} # STRIP
- t=${t#*:} # strip
- eval ${v}=\"${!v:-${CHOST}-${t}}\"
- type -P -- ${!v} >/dev/null || eval ${v}=${t}
+declare -A path_of
+for bin in strip objcopy readelf ranlib; do
+ if [[ $CHOST ]] && path_of[$bin]=$(type -P -- "${CHOST}-${bin}"
2>/dev/null); then
+ continue
+ fi
+ path_of[$bin]=$bin
done
# 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
+case $("${path_of[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
@@ -320,8 +321,8 @@ save_elf_debug() {
if (( has_feature[compressdebug] )); then
objcopy_flags+=( --compress-debug-sections )
fi
- ${OBJCOPY} "${objcopy_flags[@]}" "${src}" "${dst}" \
- && ${OBJCOPY} --add-gnu-debuglink="${dst}" "${src}"
+ "${path_of[objcopy]}" "${objcopy_flags[@]}" "${src}"
"${dst}" \
+ && "${path_of[objcopy]}" --add-gnu-debuglink="${dst}"
"${src}"
fi
# Only do the following if the debug file was
@@ -337,7 +338,7 @@ save_elf_debug() {
# 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} -n "${src}" 2>/dev/null |
awk '/Build ID:/{ print $NF; exit }')
+ buildid=$("${path_of[readelf]}" -n "${src}"
2>/dev/null | awk '/Build ID:/{ print $NF; exit }')
fi
if [[ -n ${buildid} ]] ; then
@@ -392,7 +393,7 @@ process_elf() {
local
splitdebug="${tmpdir}/splitdebug/${shortname}.${BASHPID}"
if (( ! already_stripped )); then
- ${STRIP} "${strip_flags[@]}" -f "${splitdebug}"
-F "${shortname}" "${x}"
+ "${path_of[strip]}" "${strip_flags[@]}" -f
"${splitdebug}" -F "${shortname}" "${x}"
fi
save_elf_debug "${x}" "${inode_link}_debug"
"${splitdebug}"
else
@@ -400,7 +401,7 @@ process_elf() {
save_elf_debug "${x}" "${inode_link}_debug"
fi
if (( ! already_stripped )); then
- ${STRIP} "${strip_flags[@]}" "${x}"
+ "${path_of[strip]}" "${strip_flags[@]}" "${x}"
fi
fi
fi
@@ -431,7 +432,7 @@ process_ar() {
# linked in (only for finally linked ELFs), so we have to
# retain the debug info in the archive itself.
if (( ! do_splitdebug )); then
- ${STRIP} -g "${x}" && ${RANLIB} "${x}"
+ "${path_of[strip]}" -g "${x}" && "${path_of[ranlib]}"
"${x}"
fi
fi
}
@@ -519,7 +520,7 @@ for inode_link in *; do
do
if (( do_banner )); then
- __vecho "strip: ${STRIP} ${portage_strip_flags[*]}"
+ __vecho "strip: ${path_of[strip]}
${portage_strip_flags[*]}"
do_banner=0
fi