cc-wrapper: Unconditionally use @infixSalt@ accross the board

This is basically a sed job, in preparation of the next commit. The
rules are more or less:

- s"NIX_(.._WRAPPER_)?([a-zA-Z0-9@]*)"NIX_\1@infixSalt@_\2"g

- except for non-cc-wrapper-specific vars like `NIX_DEBUG`

+63 -63
+14 -14
pkgs/build-support/cc-wrapper/add-flags.sh
··· 1 # `-B@out@/bin' forces cc to use ld-wrapper.sh when calling ld. 2 - export NIX_CFLAGS_COMPILE="-B@out@/bin/ $NIX_CFLAGS_COMPILE" 3 4 # Export and assign separately in order that a failing $(..) will fail 5 # the script. 6 7 if [ -e @out@/nix-support/libc-cflags ]; then 8 - export NIX_CFLAGS_COMPILE 9 - NIX_CFLAGS_COMPILE="$(< @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE" 10 fi 11 12 if [ -e @out@/nix-support/cc-cflags ]; then 13 - export NIX_CFLAGS_COMPILE 14 - NIX_CFLAGS_COMPILE="$(< @out@/nix-support/cc-cflags) $NIX_CFLAGS_COMPILE" 15 fi 16 17 if [ -e @out@/nix-support/gnat-cflags ]; then 18 - export NIX_GNATFLAGS_COMPILE 19 - NIX_GNATFLAGS_COMPILE="$(< @out@/nix-support/gnat-cflags) $NIX_GNATFLAGS_COMPILE" 20 fi 21 22 if [ -e @out@/nix-support/libc-ldflags ]; then 23 - export NIX_LDFLAGS 24 - NIX_LDFLAGS+=" $(< @out@/nix-support/libc-ldflags)" 25 fi 26 27 if [ -e @out@/nix-support/cc-ldflags ]; then 28 - export NIX_LDFLAGS 29 - NIX_LDFLAGS+=" $(< @out@/nix-support/cc-ldflags)" 30 fi 31 32 if [ -e @out@/nix-support/libc-ldflags-before ]; then 33 - export NIX_LDFLAGS_BEFORE 34 - NIX_LDFLAGS_BEFORE="$(< @out@/nix-support/libc-ldflags-before) $NIX_LDFLAGS_BEFORE" 35 fi 36 37 - export NIX_CC_WRAPPER_FLAGS_SET=1
··· 1 # `-B@out@/bin' forces cc to use ld-wrapper.sh when calling ld. 2 + export NIX_@infixSalt@_CFLAGS_COMPILE="-B@out@/bin/ $NIX_@infixSalt@_CFLAGS_COMPILE" 3 4 # Export and assign separately in order that a failing $(..) will fail 5 # the script. 6 7 if [ -e @out@/nix-support/libc-cflags ]; then 8 + export NIX_@infixSalt@_CFLAGS_COMPILE 9 + NIX_@infixSalt@_CFLAGS_COMPILE="$(< @out@/nix-support/libc-cflags) $NIX_@infixSalt@_CFLAGS_COMPILE" 10 fi 11 12 if [ -e @out@/nix-support/cc-cflags ]; then 13 + export NIX_@infixSalt@_CFLAGS_COMPILE 14 + NIX_@infixSalt@_CFLAGS_COMPILE="$(< @out@/nix-support/cc-cflags) $NIX_@infixSalt@_CFLAGS_COMPILE" 15 fi 16 17 if [ -e @out@/nix-support/gnat-cflags ]; then 18 + export NIX_@infixSalt@_GNATFLAGS_COMPILE 19 + NIX_@infixSalt@_GNATFLAGS_COMPILE="$(< @out@/nix-support/gnat-cflags) $NIX_@infixSalt@_GNATFLAGS_COMPILE" 20 fi 21 22 if [ -e @out@/nix-support/libc-ldflags ]; then 23 + export NIX_@infixSalt@_LDFLAGS 24 + NIX_@infixSalt@_LDFLAGS+=" $(< @out@/nix-support/libc-ldflags)" 25 fi 26 27 if [ -e @out@/nix-support/cc-ldflags ]; then 28 + export NIX_@infixSalt@_LDFLAGS 29 + NIX_@infixSalt@_LDFLAGS+=" $(< @out@/nix-support/cc-ldflags)" 30 fi 31 32 if [ -e @out@/nix-support/libc-ldflags-before ]; then 33 + export NIX_@infixSalt@_LDFLAGS_BEFORE 34 + NIX_@infixSalt@_LDFLAGS_BEFORE="$(< @out@/nix-support/libc-ldflags-before) $NIX_@infixSalt@_LDFLAGS_BEFORE" 35 fi 36 37 + export NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET=1
+15 -15
pkgs/build-support/cc-wrapper/cc-wrapper.sh
··· 11 PATH="@coreutils_bin@/bin:@gnugrep_bin@/bin" 12 fi 13 14 - if [ -n "$NIX_CC_WRAPPER_START_HOOK" ]; then 15 - source "$NIX_CC_WRAPPER_START_HOOK" 16 fi 17 18 - if [ -z "$NIX_CC_WRAPPER_FLAGS_SET" ]; then 19 source @out@/nix-support/add-flags.sh 20 fi 21 ··· 63 nonFlagArgs=1 64 elif [ "$p" = -m32 ]; then 65 if [ -e @out@/nix-support/dynamic-linker-m32 ]; then 66 - NIX_LDFLAGS+=" -dynamic-linker $(< @out@/nix-support/dynamic-linker-m32)" 67 fi 68 fi 69 n+=1 ··· 106 107 108 # Clear march/mtune=native -- they bring impurity. 109 - if [ "$NIX_ENFORCE_NO_NATIVE" = 1 ]; then 110 rest=() 111 for p in "${params[@]}"; do 112 if [[ "$p" = -m*=native ]]; then ··· 120 121 if [[ "$isCpp" = 1 ]]; then 122 if [[ "$cppInclude" = 1 ]]; then 123 - NIX_CFLAGS_COMPILE+=" ${NIX_CXXSTDLIB_COMPILE-@default_cxx_stdlib_compile@}" 124 fi 125 - NIX_CFLAGS_LINK+=" $NIX_CXXSTDLIB_LINK" 126 fi 127 128 source @out@/nix-support/add-hardening.sh 129 130 # Add the flags for the C compiler proper. 131 - extraAfter=($NIX_CFLAGS_COMPILE "${hardeningCFlags[@]}") 132 extraBefore=() 133 134 if [ "$dontLink" != 1 ]; then 135 136 # Add the flags that should only be passed to the compiler when 137 # linking. 138 - extraAfter+=($NIX_CFLAGS_LINK "${hardeningLDFlags[@]}") 139 140 # Add the flags that should be passed to the linker (and prevent 141 - # `ld-wrapper' from adding NIX_LDFLAGS again). 142 - for i in $NIX_LDFLAGS_BEFORE; do 143 extraBefore+=("-Wl,$i") 144 done 145 - for i in $NIX_LDFLAGS; do 146 if [ "${i:0:3}" = -L/ ]; then 147 extraAfter+=("$i") 148 else 149 extraAfter+=("-Wl,$i") 150 fi 151 done 152 - export NIX_LDFLAGS_SET=1 153 fi 154 155 # As a very special hack, if the arguments are just `-v', then don't ··· 171 printf " %q\n" "${extraAfter[@]}" >&2 172 fi 173 174 - if [ -n "$NIX_CC_WRAPPER_EXEC_HOOK" ]; then 175 - source "$NIX_CC_WRAPPER_EXEC_HOOK" 176 fi 177 178 PATH="$path_backup"
··· 11 PATH="@coreutils_bin@/bin:@gnugrep_bin@/bin" 12 fi 13 14 + if [ -n "$NIX_CC_WRAPPER_@infixSalt@_START_HOOK" ]; then 15 + source "$NIX_CC_WRAPPER_@infixSalt@_START_HOOK" 16 fi 17 18 + if [ -z "$NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET" ]; then 19 source @out@/nix-support/add-flags.sh 20 fi 21 ··· 63 nonFlagArgs=1 64 elif [ "$p" = -m32 ]; then 65 if [ -e @out@/nix-support/dynamic-linker-m32 ]; then 66 + NIX_@infixSalt@_LDFLAGS+=" -dynamic-linker $(< @out@/nix-support/dynamic-linker-m32)" 67 fi 68 fi 69 n+=1 ··· 106 107 108 # Clear march/mtune=native -- they bring impurity. 109 + if [ "$NIX_@infixSalt@_ENFORCE_NO_NATIVE" = 1 ]; then 110 rest=() 111 for p in "${params[@]}"; do 112 if [[ "$p" = -m*=native ]]; then ··· 120 121 if [[ "$isCpp" = 1 ]]; then 122 if [[ "$cppInclude" = 1 ]]; then 123 + NIX_@infixSalt@_CFLAGS_COMPILE+=" ${NIX_@infixSalt@_CXXSTDLIB_COMPILE-@default_cxx_stdlib_compile@}" 124 fi 125 + NIX_@infixSalt@_CFLAGS_LINK+=" $NIX_@infixSalt@_CXXSTDLIB_LINK" 126 fi 127 128 source @out@/nix-support/add-hardening.sh 129 130 # Add the flags for the C compiler proper. 131 + extraAfter=($NIX_@infixSalt@_CFLAGS_COMPILE "${hardeningCFlags[@]}") 132 extraBefore=() 133 134 if [ "$dontLink" != 1 ]; then 135 136 # Add the flags that should only be passed to the compiler when 137 # linking. 138 + extraAfter+=($NIX_@infixSalt@_CFLAGS_LINK "${hardeningLDFlags[@]}") 139 140 # Add the flags that should be passed to the linker (and prevent 141 + # `ld-wrapper' from adding NIX_@infixSalt@_LDFLAGS again). 142 + for i in $NIX_@infixSalt@_LDFLAGS_BEFORE; do 143 extraBefore+=("-Wl,$i") 144 done 145 + for i in $NIX_@infixSalt@_LDFLAGS; do 146 if [ "${i:0:3}" = -L/ ]; then 147 extraAfter+=("$i") 148 else 149 extraAfter+=("-Wl,$i") 150 fi 151 done 152 + export NIX_@infixSalt@_LDFLAGS_SET=1 153 fi 154 155 # As a very special hack, if the arguments are just `-v', then don't ··· 171 printf " %q\n" "${extraAfter[@]}" >&2 172 fi 173 174 + if [ -n "$NIX_CC_WRAPPER_@infixSalt@_EXEC_HOOK" ]; then 175 + source "$NIX_CC_WRAPPER_@infixSalt@_EXEC_HOOK" 176 fi 177 178 PATH="$path_backup"
+12 -12
pkgs/build-support/cc-wrapper/gnat-wrapper.sh
··· 10 PATH="@coreutils_bin@/bin" 11 fi 12 13 - if [ -n "$NIX_GNAT_WRAPPER_START_HOOK" ]; then 14 - source "$NIX_GNAT_WRAPPER_START_HOOK" 15 fi 16 17 - if [ -z "$NIX_GNAT_WRAPPER_FLAGS_SET" ]; then 18 source @out@/nix-support/add-flags.sh 19 fi 20 ··· 35 nonFlagArgs=1 36 elif [ "$i" = -m32 ]; then 37 if [ -e @out@/nix-support/dynamic-linker-m32 ]; then 38 - NIX_LDFLAGS+=" -dynamic-linker $(< @out@/nix-support/dynamic-linker-m32)" 39 fi 40 fi 41 done ··· 72 73 74 # Clear march/mtune=native -- they bring impurity. 75 - if [ "$NIX_ENFORCE_NO_NATIVE" = 1 ]; then 76 rest=() 77 for p in "${params[@]}"; do 78 if [[ "$p" = -m*=native ]]; then ··· 86 87 88 # Add the flags for the GNAT compiler proper. 89 - extraAfter=($NIX_GNATFLAGS_COMPILE) 90 extraBefore=() 91 92 if [ "$(basename "$0")x" = "gnatmakex" ]; then ··· 95 96 #if [ "$dontLink" != 1 ]; then 97 # # Add the flags that should be passed to the linker (and prevent 98 - # # `ld-wrapper' from adding NIX_LDFLAGS again). 99 - # for i in $NIX_LDFLAGS_BEFORE; do 100 # extraBefore+=("-largs" "$i") 101 # done 102 - # for i in $NIX_LDFLAGS; do 103 # if [ "${i:0:3}" = -L/ ]; then 104 # extraAfter+=("$i") 105 # else 106 # extraAfter+=("-largs" "$i") 107 # fi 108 # done 109 - # export NIX_LDFLAGS_SET=1 110 #fi 111 112 # Optionally print debug info. ··· 119 printf " %q\n" "${extraAfter[@]}" >&2 120 fi 121 122 - if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then 123 - source "$NIX_GNAT_WRAPPER_EXEC_HOOK" 124 fi 125 126 PATH="$path_backup"
··· 10 PATH="@coreutils_bin@/bin" 11 fi 12 13 + if [ -n "$NIX_@infixSalt@_GNAT_WRAPPER_START_HOOK" ]; then 14 + source "$NIX_@infixSalt@_GNAT_WRAPPER_START_HOOK" 15 fi 16 17 + if [ -z "$NIX_@infixSalt@_GNAT_WRAPPER_FLAGS_SET" ]; then 18 source @out@/nix-support/add-flags.sh 19 fi 20 ··· 35 nonFlagArgs=1 36 elif [ "$i" = -m32 ]; then 37 if [ -e @out@/nix-support/dynamic-linker-m32 ]; then 38 + NIX_@infixSalt@_LDFLAGS+=" -dynamic-linker $(< @out@/nix-support/dynamic-linker-m32)" 39 fi 40 fi 41 done ··· 72 73 74 # Clear march/mtune=native -- they bring impurity. 75 + if [ "$NIX_@infixSalt@_ENFORCE_NO_NATIVE" = 1 ]; then 76 rest=() 77 for p in "${params[@]}"; do 78 if [[ "$p" = -m*=native ]]; then ··· 86 87 88 # Add the flags for the GNAT compiler proper. 89 + extraAfter=($NIX_@infixSalt@_GNATFLAGS_COMPILE) 90 extraBefore=() 91 92 if [ "$(basename "$0")x" = "gnatmakex" ]; then ··· 95 96 #if [ "$dontLink" != 1 ]; then 97 # # Add the flags that should be passed to the linker (and prevent 98 + # # `ld-wrapper' from adding NIX_@infixSalt@_LDFLAGS again). 99 + # for i in $NIX_@infixSalt@_LDFLAGS_BEFORE; do 100 # extraBefore+=("-largs" "$i") 101 # done 102 + # for i in $NIX_@infixSalt@_LDFLAGS; do 103 # if [ "${i:0:3}" = -L/ ]; then 104 # extraAfter+=("$i") 105 # else 106 # extraAfter+=("-largs" "$i") 107 # fi 108 # done 109 + # export NIX_@infixSalt@_LDFLAGS_SET=1 110 #fi 111 112 # Optionally print debug info. ··· 119 printf " %q\n" "${extraAfter[@]}" >&2 120 fi 121 122 + if [ -n "$NIX_@infixSalt@_GNAT_WRAPPER_EXEC_HOOK" ]; then 123 + source "$NIX_@infixSalt@_GNAT_WRAPPER_EXEC_HOOK" 124 fi 125 126 PATH="$path_backup"
+14 -14
pkgs/build-support/cc-wrapper/ld-wrapper.sh
··· 1 #! @shell@ 2 - set -e -o pipefail 3 shopt -s nullglob 4 5 path_backup="$PATH" ··· 10 PATH="@coreutils_bin@/bin" 11 fi 12 13 - if [ -n "$NIX_LD_WRAPPER_START_HOOK" ]; then 14 - source "$NIX_LD_WRAPPER_START_HOOK" 15 fi 16 17 - if [ -z "$NIX_CC_WRAPPER_FLAGS_SET" ]; then 18 source @out@/nix-support/add-flags.sh 19 fi 20 ··· 24 # Optionally filter out paths not refering to the store. 25 expandResponseParams "$@" 26 if [[ "$NIX_ENFORCE_PURITY" = 1 && -n "$NIX_STORE" 27 - && ( -z "$NIX_IGNORE_LD_THROUGH_GCC" || -z "$NIX_LDFLAGS_SET" ) ]]; then 28 rest=() 29 nParams=${#params[@]} 30 declare -i n=0 ··· 59 extraAfter=("${hardeningLDFlags[@]}") 60 extraBefore=() 61 62 - if [ -z "$NIX_LDFLAGS_SET" ]; then 63 - extraAfter+=($NIX_LDFLAGS) 64 - extraBefore+=($NIX_LDFLAGS_BEFORE) 65 fi 66 67 - extraAfter+=($NIX_LDFLAGS_AFTER $NIX_LDFLAGS_HARDEN) 68 69 declare -a libDirs 70 declare -A libs 71 relocatable= 72 73 # Find all -L... switches for rpath, and relocatable flags for build id. 74 - if [ "$NIX_DONT_SET_RPATH" != 1 ] || [ "$NIX_SET_BUILD_ID" = 1 ]; then 75 prev= 76 for p in "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"; do 77 case "$prev" in ··· 108 109 110 # Add all used dynamic libraries to the rpath. 111 - if [ "$NIX_DONT_SET_RPATH" != 1 ]; then 112 # For each directory in the library search path (-L...), 113 # see if it contains a dynamic library used by a -l... flag. If 114 # so, add the directory to the rpath. ··· 141 142 # Only add --build-id if this is a final link. FIXME: should build gcc 143 # with --enable-linker-build-id instead? 144 - if [ "$NIX_SET_BUILD_ID" = 1 ] && [ ! "$relocatable" ]; then 145 extraAfter+=(--build-id) 146 fi 147 ··· 156 printf " %q\n" "${extraAfter[@]}" >&2 157 fi 158 159 - if [ -n "$NIX_LD_WRAPPER_EXEC_HOOK" ]; then 160 - source "$NIX_LD_WRAPPER_EXEC_HOOK" 161 fi 162 163 PATH="$path_backup"
··· 1 #! @shell@ 2 + set -eu -o pipefail 3 shopt -s nullglob 4 5 path_backup="$PATH" ··· 10 PATH="@coreutils_bin@/bin" 11 fi 12 13 + if [ -n "$NIX_LD_WRAPPER_@infixSalt@_START_HOOK" ]; then 14 + source "$NIX_LD_WRAPPER_@infixSalt@_START_HOOK" 15 fi 16 17 + if [ -z "$NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET" ]; then 18 source @out@/nix-support/add-flags.sh 19 fi 20 ··· 24 # Optionally filter out paths not refering to the store. 25 expandResponseParams "$@" 26 if [[ "$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 ··· 59 extraAfter=("${hardeningLDFlags[@]}") 60 extraBefore=() 61 62 + if [ -z "$NIX_@infixSalt@_LDFLAGS_SET" ]; then 63 + extraAfter+=($NIX_@infixSalt@_LDFLAGS) 64 + extraBefore+=($NIX_@infixSalt@_LDFLAGS_BEFORE) 65 fi 66 67 + extraAfter+=($NIX_@infixSalt@_LDFLAGS_AFTER $NIX_@infixSalt@_LDFLAGS_HARDEN) 68 69 declare -a libDirs 70 declare -A libs 71 relocatable= 72 73 # Find all -L... switches for rpath, and relocatable flags for build id. 74 + if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ] || [ "$NIX_@infixSalt@_SET_BUILD_ID" = 1 ]; then 75 prev= 76 for p in "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"; do 77 case "$prev" in ··· 108 109 110 # Add all used dynamic libraries to the rpath. 111 + if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ]; then 112 # For each directory in the library search path (-L...), 113 # see if it contains a dynamic library used by a -l... flag. If 114 # so, add the directory to the rpath. ··· 141 142 # Only add --build-id if this is a final link. FIXME: should build gcc 143 # with --enable-linker-build-id instead? 144 + if [ "$NIX_@infixSalt@_SET_BUILD_ID" = 1 ] && [ ! "$relocatable" ]; then 145 extraAfter+=(--build-id) 146 fi 147 ··· 156 printf " %q\n" "${extraAfter[@]}" >&2 157 fi 158 159 + if [ -n "$NIX_LD_WRAPPER_@infixSalt@_EXEC_HOOK" ]; then 160 + source "$NIX_LD_WRAPPER_@infixSalt@_EXEC_HOOK" 161 fi 162 163 PATH="$path_backup"
+2 -2
pkgs/build-support/cc-wrapper/setup-hook.sh
··· 1 - addCVars () { 2 if [[ -d "$1/include" ]]; then 3 export NIX_CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include" 4 fi ··· 16 fi 17 } 18 19 - envHooks+=(addCVars) 20 21 # Note 1: these come *after* $out in the PATH (see setup.sh). 22 # Note 2: phase separation makes this look useless to shellcheck.
··· 1 + ccWrapper_addCVars () { 2 if [[ -d "$1/include" ]]; then 3 export NIX_CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include" 4 fi ··· 16 fi 17 } 18 19 + envHooks+=(ccWrapper_addCVars) 20 21 # Note 1: these come *after* $out in the PATH (see setup.sh). 22 # Note 2: phase separation makes this look useless to shellcheck.