From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 851C11580E0 for ; Tue, 03 Jun 2025 13:34:54 +0000 (UTC) Received: from lists.gentoo.org (bobolink.gentoo.org [140.211.166.189]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: relay-lists.gentoo.org@gentoo.org) by smtp.gentoo.org (Postfix) with ESMTPSA id 59C1D3430EC for ; Tue, 03 Jun 2025 13:34:54 +0000 (UTC) Received: from bobolink.gentoo.org (localhost [127.0.0.1]) by bobolink.gentoo.org (Postfix) with ESMTP id 5C5671103C1; Tue, 03 Jun 2025 13:34:51 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bobolink.gentoo.org (Postfix) with ESMTPS id 511801103C1 for ; Tue, 03 Jun 2025 13:34:51 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 06A36343079 for ; Tue, 03 Jun 2025 13:34:51 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 6D71228EF for ; Tue, 03 Jun 2025 13:34:49 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1748957682.c4624b0e1650605718941d8dc45a0171c30d3aa1.sam@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/estrip X-VCS-Directories: bin/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: c4624b0e1650605718941d8dc45a0171c30d3aa1 X-VCS-Branch: master Date: Tue, 03 Jun 2025 13:34:49 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 05ee464a-1a8c-424a-aeb1-8307d71c8213 X-Archives-Hash: 0c46efaa633158a7ac8da7bd4d260eee commit: c4624b0e1650605718941d8dc45a0171c30d3aa1 Author: Kerin Millar plushkava net> AuthorDate: Tue Jun 3 02:35:47 2025 +0000 Commit: Sam James gentoo org> CommitDate: Tue Jun 3 13:34:42 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=c4624b0e estrip: rectify some defects in categories SC{2035,2086,2164,2199,2995} The estrip script is in need of some refactoring. Beforehand, address some of the most obvious defects of which shellcheck complains - often rightly. These are described herewith. Signify end of options to cat(1), per SC2035. Use read to safely split any of PORTAGE_STRIP_FLAGS, SAFE_STRIP_FLAGS and DEF_STRIP_FLAGS. The resulting words are stored by the new 'portage_strip_flags' array, which is properly conveyed to - and expanded by - the process_elf() function. This addresses several instances of SC2086. Use read to safely split SAFE_STRIP_FLAGS, duly addressing another instance of SC2086. Compose 'objcopy_flags' as an array and quote the expansion of 'arg' (formerly named 'args'), duly addressing two more instances of SC2086. Don't execute the cd builtin without checking its exit status, per SC2164. Perform array length checks correctly, per SC2199. Quote nested parameter expansions that are employed by string-replacing parameter expansions, per SC2995. Signed-off-by: Kerin Millar plushkava.net> Signed-off-by: Sam James gentoo.org> bin/estrip | 55 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/bin/estrip b/bin/estrip index 2bd2cbab8f..eb7eb0d014 100755 --- a/bin/estrip +++ b/bin/estrip @@ -47,7 +47,7 @@ while [[ $# -gt 0 ]] ; do fi done - if [[ ${skip_dirs[@]} ]]; then + if (( ${#skip_dirs[@]} )); then find "${skip_dirs[@]}" -name '*.estrip' -delete || die fi @@ -92,7 +92,7 @@ while [[ $# -gt 0 ]] ; do # matches the path given # e.g. find_path="/usr/lib64" will match needed_entry="/usr/lib64/libfoo.so libc.so". needed_entry_file="${needed_entry% *}" - if [[ "${needed_entry_file}" =~ ^${find_path##${D}} ]] ; then + if [[ "${needed_entry_file}" =~ ^${find_path##"${D}"} ]] ; then scanelf_results+=( "${D}${needed_entry_file}" ) fi done @@ -182,7 +182,8 @@ case $(${STRIP} --version 2>/dev/null) in SPLIT_STRIP_FLAGS= ;; esac -: ${PORTAGE_STRIP_FLAGS=${SAFE_STRIP_FLAGS} ${DEF_STRIP_FLAGS}} + +read -rd '' -a portage_strip_flags <<<"${PORTAGE_STRIP_FLAGS-${SAFE_STRIP_FLAGS} ${DEF_STRIP_FLAGS}}" prepstrip_sources_dir=${EPREFIX}/usr/src/debug/${CATEGORY}/${PF} @@ -296,7 +297,7 @@ save_elf_debug() { local src_dirname=${src%/*} # Destination paths - local dst_dirname=${ED%/}/usr/lib/debug/${src_dirname#${D%/}/} + local dst_dirname=${ED%/}/usr/lib/debug/${src_dirname#"${D%/}"/} local dst_basename dst # dont save debug info twice @@ -320,18 +321,18 @@ save_elf_debug() { if [[ -n ${splitdebug} ]] ; then mv "${splitdebug}" "${dst}" else - local objcopy_flags="--only-keep-debug" - ${FEATURES_compressdebug} && objcopy_flags+=" --compress-debug-sections" - ${OBJCOPY} ${objcopy_flags} "${src}" "${dst}" && + local -a objcopy_flags=( --only-keep-debug ) + ${FEATURES_compressdebug} && objcopy_flags+=( --compress-debug-sections ) + ${OBJCOPY} "${objcopy_flags[@]}" "${src}" "${dst}" && ${OBJCOPY} --add-gnu-debuglink="${dst}" "${src}" fi # Only do the following if the debug file was # successfully created (see bug #446774). if [[ $? -eq 0 ]] ; then - local args="a-x,o-w" - [[ -g ${src} || -u ${src} ]] && args+=",go-r" - chmod ${args} "${dst}" + local arg="a-x,o-w" + [[ -g ${src} || -u ${src} ]] && arg+=",go-r" + chmod "${arg}" "${dst}" # Symlink so we can read the name back. __try_symlink "${dst}" "${inode_debug}" @@ -345,8 +346,8 @@ save_elf_debug() { if [[ -n ${buildid} ]] ; then local buildid_dir="${ED%/}/usr/lib/debug/.build-id/${buildid:0:2}" local buildid_file="${buildid_dir}/${buildid:2}" - local src_buildid_rel="../../../../../${src#${ED%/}/}" - local dst_buildid_rel="../../${dst#${ED%/}/usr/lib/debug/}" + local src_buildid_rel="../../../../../${src#"${ED%/}"/}" + local dst_buildid_rel="../../${dst#"${ED%/}"/usr/lib/debug/}" mkdir -p "${buildid_dir}" || die __try_symlink "${dst_buildid_rel}" "${buildid_file}.debug" __try_symlink "${src_buildid_rel}" "${buildid_file}" @@ -358,7 +359,7 @@ save_elf_debug() { # Usage: process_elf process_elf() { - local x=$1 inode_link=$2 strip_flags=${*:3} + local x=$1 inode_link=$2 strip_flags=("${@:3}") local ed_noslash=${ED%/} local already_stripped xt_data local lockfile=${inode_link}_lockfile @@ -393,7 +394,7 @@ process_elf() { local splitdebug="${tmpdir}/splitdebug/${shortname}.${BASHPID}" ${already_stripped} || \ - ${STRIP} ${strip_flags} \ + ${STRIP} "${strip_flags[@]}" \ -f "${splitdebug}" \ -F "${shortname}" \ "${x}" @@ -402,7 +403,7 @@ process_elf() { if ${splitdebug} ; then save_elf_debug "${x}" "${inode_link}_debug" fi - ${already_stripped} || ${STRIP} ${strip_flags} "${x}" + ${already_stripped} || ${STRIP} "${strip_flags[@]}" "${x}" fi fi @@ -500,7 +501,9 @@ if ${prepstrip}; then # Use sort -u to eliminate duplicates (bug #445336). ( - [[ -n ${needed_contents[@]} ]] && printf "%s\n" "${needed_contents[@]}" + if (( ${#needed_contents[@]} )); then + printf "%s\n" "${needed_contents[@]}" + fi find "$@" -type f ! -type l -name '*.a' ) | LC_ALL=C sort -u ) @@ -518,7 +521,7 @@ for inode_link in *; do do if ! ${banner} ; then - __vecho "strip: ${STRIP} ${PORTAGE_STRIP_FLAGS}" + __vecho "strip: ${STRIP} ${portage_strip_flags[*]}" banner=true fi @@ -538,7 +541,7 @@ for inode_link in *; do set -o noglob strip_this=true for m in $(eval echo ${STRIP_MASK}) ; do - [[ ${x#${ED%/}} == ${m} ]] && strip_this=false && break + [[ ${x#"${ED%/}"} == ${m} ]] && strip_this=false && break done set +o noglob fi @@ -569,10 +572,11 @@ for inode_link in *; do process_ar "${x}" elif [[ ${f} == *"SB executable"* || ${f} == *"SB pie executable"* || ${f} == *"SB shared object"* ]] ; then - process_elf "${x}" "${inode_link}" ${PORTAGE_STRIP_FLAGS} + process_elf "${x}" "${inode_link}" "${portage_strip_flags[@]}" elif [[ ${f} == *"SB relocatable"* ]] ; then [[ ${x} == *.ko ]] || splitdebug=false - process_elf "${x}" "${inode_link}" ${SAFE_STRIP_FLAGS} + read -rd '' -a safe_strip_flags <<<"${SAFE_STRIP_FLAGS}" + process_elf "${x}" "${inode_link}" "${safe_strip_flags[@]}" fi if ${was_not_writable} ; then @@ -588,7 +592,7 @@ done # parallel, but not sure that'd be an overall improvement. __multijob_finish -cd "${tmpdir}"/sources/ && cat * > "${tmpdir}/debug.sources" 2>/dev/null +cd "${tmpdir}"/sources/ && cat -- * > "${tmpdir}/debug.sources" 2>/dev/null if [[ -s ${tmpdir}/debug.sources ]] && \ ${FEATURES_installsources} && \ ! ${PORTAGE_RESTRICT_installsources} && \ @@ -599,9 +603,11 @@ then # Skip installation of ".../" (system headers? why inner slashes are forbidden?) # Skip syncing of ".../foo/" (complete directories) - grep -zv -e '/<[^/>]*>$' -e '/$' "${tmpdir}"/debug.sources | \ - (cd "${WORKDIR}"; LANG=C sort -z -u | \ - rsync -tL0 --chmod=ugo-st,a+r,go-w,Da+x,Fa-x --files-from=- "${WORKDIR}/" "${D%/}/${prepstrip_sources_dir#/}/" ) + grep -zv -e '/<[^/>]*>$' -e '/$' "${tmpdir}"/debug.sources | { + cd "${WORKDIR}" || exit + LANG=C sort -z -u \ + | rsync -tL0 --chmod=ugo-st,a+r,go-w,Da+x,Fa-x --files-from=- "${WORKDIR}/" "${D%/}/${prepstrip_sources_dir#/}/" + } # Preserve directory structure. # Needed after running save_elf_sources. @@ -611,5 +617,4 @@ then done < <(find "${D%/}/${prepstrip_sources_dir#/}/" -type d -empty -print0) fi -cd "${T}" rm -rf "${tmpdir}"