cc-wrapper: More quadratic performance fixes

This eliminates the slow lookup of whether we've already seen an rpath
/ library path entry.

Issue #27609.

+21 -23
+21 -23
pkgs/build-support/cc-wrapper/ld-wrapper.sh
··· 64 # Add all used dynamic libraries to the rpath. 65 if [ "$NIX_DONT_SET_RPATH" != 1 ]; then 66 67 - libPath="" 68 addToLibPath() { 69 local path="$1" 70 if [ "${path:0:1}" != / ]; then return 0; fi ··· 76 fi 77 ;; 78 esac 79 - case $libPath in 80 - *\ $path\ *) return 0 ;; 81 - esac 82 - libPath+=" $path " 83 } 84 85 addToRPath() { 86 # If the path is not in the store, don't add it to the rpath. 87 # This typically happens for libraries in /tmp that are later 88 # copied to $out/lib. If not, we're screwed. 89 if [ "${1:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then return 0; fi 90 - case $rpath in 91 - *\ $1\ *) return 0 ;; 92 - esac 93 - rpath+=" $1 " 94 - } 95 - 96 - libs="" 97 - addToLibs() { 98 - libs+=" $1" 99 } 100 101 - rpath="" 102 103 # First, find all -L... switches. 104 allParams=("${params[@]}" ${extra[@]}) ··· 112 addToLibPath ${p2} 113 n=$((n + 1)) 114 elif [ "$p" = -l ]; then 115 - addToLibs ${p2} 116 n=$((n + 1)) 117 elif [ "${p:0:2}" = -l ]; then 118 - addToLibs ${p:2} 119 elif [ "$p" = -dynamic-linker ]; then 120 # Ignore the dynamic linker argument, or it 121 # will get into the next 'elif'. We don't want ··· 135 # so, add the directory to the rpath. 136 # It's important to add the rpath in the order of -L..., so 137 # the link time chosen objects will be those of runtime linking. 138 - 139 - for i in $libPath; do 140 - for j in $libs; do 141 if [ -f "$i/lib$j.so" ]; then 142 addToRPath $i 143 break ··· 145 done 146 done 147 148 - 149 # Finally, add `-rpath' switches. 150 - for i in $rpath; do 151 - extra+=(-rpath $i) 152 done 153 fi 154
··· 64 # Add all used dynamic libraries to the rpath. 65 if [ "$NIX_DONT_SET_RPATH" != 1 ]; then 66 67 + declare -A libDirsSeen 68 + declare -a libDirs 69 + 70 addToLibPath() { 71 local path="$1" 72 if [ "${path:0:1}" != / ]; then return 0; fi ··· 78 fi 79 ;; 80 esac 81 + if [[ -z ${libDirsSeen[$path]} ]]; then 82 + libDirs+=("$path") 83 + libDirsSeen[$path]=1 84 + fi 85 } 86 + 87 + declare -A rpathsSeen 88 + declare -a rpaths 89 90 addToRPath() { 91 # If the path is not in the store, don't add it to the rpath. 92 # This typically happens for libraries in /tmp that are later 93 # copied to $out/lib. If not, we're screwed. 94 if [ "${1:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then return 0; fi 95 + if [[ -z ${rpathsSeen[$1]} ]]; then 96 + rpaths+=("$1") 97 + rpathsSeen[$1]=1 98 + fi 99 } 100 101 + declare -a libs 102 103 # First, find all -L... switches. 104 allParams=("${params[@]}" ${extra[@]}) ··· 112 addToLibPath ${p2} 113 n=$((n + 1)) 114 elif [ "$p" = -l ]; then 115 + libs+=(${p2}) 116 n=$((n + 1)) 117 elif [ "${p:0:2}" = -l ]; then 118 + libs+=(${p:2}) 119 elif [ "$p" = -dynamic-linker ]; then 120 # Ignore the dynamic linker argument, or it 121 # will get into the next 'elif'. We don't want ··· 135 # so, add the directory to the rpath. 136 # It's important to add the rpath in the order of -L..., so 137 # the link time chosen objects will be those of runtime linking. 138 + for i in ${libDirs[@]}; do 139 + for j in ${libs[@]}; do 140 if [ -f "$i/lib$j.so" ]; then 141 addToRPath $i 142 break ··· 144 done 145 done 146 147 # Finally, add `-rpath' switches. 148 + for i in ${rpaths[@]}; do 149 + extra+=(-rpath "$i") 150 done 151 fi 152