diff --git a/pkgs/build-support/setup-hooks/strip.sh b/pkgs/build-support/setup-hooks/strip.sh index 9d0b163f4c46..80bc064ced7d 100644 --- a/pkgs/build-support/setup-hooks/strip.sh +++ b/pkgs/build-support/setup-hooks/strip.sh @@ -10,6 +10,7 @@ _doStrip() { local -ra debugDirs=(stripDebugList stripDebugListTarget) local -ra allDirs=(stripAllList stripAllListTarget) local -ra stripCmds=(STRIP STRIP_FOR_TARGET) + local -ra ranlibCmds=(RANLIB RANLIB_FOR_TARGET) # Strip only host paths by default. Leave targets as is. stripDebugList=${stripDebugList:-lib lib32 lib64 libexec bin sbin} @@ -23,20 +24,22 @@ _doStrip() { local -n debugDirList="${debugDirs[$i]}" local -n allDirList="${allDirs[$i]}" local -n stripCmd="${stripCmds[$i]}" + local -n ranlibCmd="${ranlibCmds[$i]}" # `dontStrip` disables them all if [[ "${dontStrip-}" || "${flag-}" ]] || ! type -f "${stripCmd-}" 2>/dev/null then continue; fi - stripDirs "$stripCmd" "$debugDirList" "${stripDebugFlags:--S}" - stripDirs "$stripCmd" "$allDirList" "${stripAllFlags:--s}" + stripDirs "$stripCmd" "$ranlibCmd" "$debugDirList" "${stripDebugFlags:--S}" + stripDirs "$stripCmd" "$ranlibCmd" "$allDirList" "${stripAllFlags:--s}" done } stripDirs() { local cmd="$1" - local dirs="$2" - local stripFlags="$3" + local ranlibCmd="$2" + local dirs="$3" + local stripFlags="$4" local dirsNew= local d @@ -50,5 +53,11 @@ stripDirs() { if [ -n "${dirs}" ]; then echo "stripping (with command $cmd and flags $stripFlags) in$dirs" find $dirs -type f -exec $cmd $stripFlags '{}' \; 2>/dev/null + # 'strip' does not normally preserve archive index in .a files. + # This usually causes linking failures against static libs like: + # ld: ...-i686-w64-mingw32-stage-final-gcc-13.0.0-lib/i686-w64-mingw32/lib/libstdc++.dll.a: + # error adding symbols: archive has no index; run ranlib to add one + # Restore the index by running 'ranlib'. + find $dirs -name '*.a' -type f -exec $ranlibCmd '{}' \; 2>/dev/null fi }