lol
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 17.09-beta 178 lines 5.8 kB view raw
1#! @shell@ 2set -eu -o pipefail 3shopt -s nullglob 4 5path_backup="$PATH" 6 7# phase separation makes this look useless 8# shellcheck disable=SC2157 9if [ -n "@coreutils_bin@" ]; then 10 PATH="@coreutils_bin@/bin" 11fi 12 13if [ -z "${NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET:-}" ]; then 14 source @out@/nix-support/add-flags.sh 15fi 16 17if [ -n "$NIX_LD_WRAPPER_@infixSalt@_START_HOOK" ]; then 18 source "$NIX_LD_WRAPPER_@infixSalt@_START_HOOK" 19fi 20 21source @out@/nix-support/utils.sh 22 23 24# Optionally filter out paths not refering to the store. 25expandResponseParams "$@" 26if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "${NIX_STORE:-}" 27 && ( -z "$NIX_@infixSalt@_IGNORE_LD_THROUGH_GCC" || -z "${NIX_@infixSalt@_LDFLAGS_SET:-}" ) ]]; then 28 rest=() 29 nParams=${#params[@]} 30 declare -i n=0 31 while (( "$n" < "$nParams" )); do 32 p=${params[n]} 33 p2=${params[n+1]:-} # handle `p` being last one 34 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then 35 skip "${p:2}" 36 elif [ "$p" = -L ] && badPath "$p2"; then 37 n+=1; skip "$p2" 38 elif [ "$p" = -rpath ] && badPath "$p2"; then 39 n+=1; skip "$p2" 40 elif [ "$p" = -dynamic-linker ] && badPath "$p2"; then 41 n+=1; skip "$p2" 42 elif [ "${p:0:1}" = / ] && badPath "$p"; then 43 # We cannot skip this; barf. 44 echo "impure path \`$p' used in link" >&2 45 exit 1 46 elif [ "${p:0:9}" = --sysroot ]; then 47 # Our ld is not built with sysroot support (Can we fix that?) 48 : 49 else 50 rest+=("$p") 51 fi 52 n+=1 53 done 54 # Old bash empty array hack 55 params=(${rest+"${rest[@]}"}) 56fi 57 58source @out@/nix-support/add-hardening.sh 59 60extraAfter=("${hardeningLDFlags[@]}") 61extraBefore=() 62 63if [ -z "${NIX_@infixSalt@_LDFLAGS_SET:-}" ]; then 64 extraAfter+=($NIX_@infixSalt@_LDFLAGS) 65 extraBefore+=($NIX_@infixSalt@_LDFLAGS_BEFORE) 66fi 67 68extraAfter+=($NIX_@infixSalt@_LDFLAGS_AFTER $NIX_@infixSalt@_LDFLAGS_HARDEN) 69 70declare -a libDirs 71declare -A libs 72relocatable= 73 74# Find all -L... switches for rpath, and relocatable flags for build id. 75if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ] || [ "$NIX_@infixSalt@_SET_BUILD_ID" = 1 ]; then 76 prev= 77 # Old bash thinks empty arrays are undefined, ugh. 78 for p in \ 79 ${extraBefore+"${extraBefore[@]}"} \ 80 ${params+"${params[@]}"} \ 81 ${extraAfter+"${extraAfter[@]}"} 82 do 83 case "$prev" in 84 -L) 85 libDirs+=("$p") 86 ;; 87 -l) 88 libs["lib${p}.so"]=1 89 ;; 90 -dynamic-linker | -plugin) 91 # Ignore this argument, or it will match *.so and be added to rpath. 92 ;; 93 *) 94 case "$p" in 95 -L/*) 96 libDirs+=("${p:2}") 97 ;; 98 -l?*) 99 libs["lib${p:2}.so"]=1 100 ;; 101 "${NIX_STORE:-}"/*.so | "${NIX_STORE:-}"/*.so.*) 102 # This is a direct reference to a shared library. 103 libDirs+=("${p%/*}") 104 libs["${p##*/}"]=1 105 ;; 106 -r | --relocatable | -i) 107 relocatable=1 108 esac 109 ;; 110 esac 111 prev="$p" 112 done 113fi 114 115 116# Add all used dynamic libraries to the rpath. 117if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ]; then 118 # For each directory in the library search path (-L...), 119 # see if it contains a dynamic library used by a -l... flag. If 120 # so, add the directory to the rpath. 121 # It's important to add the rpath in the order of -L..., so 122 # the link time chosen objects will be those of runtime linking. 123 declare -A rpaths 124 for dir in ${libDirs+"${libDirs[@]}"}; do 125 if [[ "$dir" =~ [/.][/.] ]] && dir2=$(readlink -f "$dir"); then 126 dir="$dir2" 127 fi 128 if [ -n "${rpaths[$dir]:-}" ] || [[ "$dir" != "${NIX_STORE:-}"/* ]]; then 129 # If the path is not in the store, don't add it to the rpath. 130 # This typically happens for libraries in /tmp that are later 131 # copied to $out/lib. If not, we're screwed. 132 continue 133 fi 134 for path in "$dir"/*; do 135 file="${path##*/}" 136 if [ "${libs[$file]:-}" ]; then 137 # This library may have been provided by a previous directory, 138 # but if that library file is inside an output of the current 139 # derivation, it can be deleted after this compilation and 140 # should be found in a later directory, so we add all 141 # directories that contain any of the libraries to rpath. 142 rpaths["$dir"]=1 143 extraAfter+=(-rpath "$dir") 144 break 145 fi 146 done 147 done 148fi 149 150 151# Only add --build-id if this is a final link. FIXME: should build gcc 152# with --enable-linker-build-id instead? 153if [ "$NIX_@infixSalt@_SET_BUILD_ID" = 1 ] && [ ! "$relocatable" ]; then 154 extraAfter+=(--build-id) 155fi 156 157 158# Optionally print debug info. 159if [ -n "${NIX_DEBUG:-}" ]; then 160 # Old bash workaround, see above. 161 echo "extra flags before to @prog@:" >&2 162 printf " %q\n" ${extraBefore+"${extraBefore[@]}"} >&2 163 echo "original flags to @prog@:" >&2 164 printf " %q\n" ${params+"${params[@]}"} >&2 165 echo "extra flags after to @prog@:" >&2 166 printf " %q\n" ${extraAfter+"${extraAfter[@]}"} >&2 167fi 168 169if [ -n "$NIX_LD_WRAPPER_@infixSalt@_EXEC_HOOK" ]; then 170 source "$NIX_LD_WRAPPER_@infixSalt@_EXEC_HOOK" 171fi 172 173PATH="$path_backup" 174# Old bash workaround, see above. 175exec @prog@ \ 176 ${extraBefore+"${extraBefore[@]}"} \ 177 ${params+"${params[@]}"} \ 178 ${extraAfter+"${extraAfter[@]}"}