···11# `-B@out@/bin' forces cc to use ld-wrapper.sh when calling ld.
22export NIX_CFLAGS_COMPILE="-B@out@/bin/ $NIX_CFLAGS_COMPILE"
3344+# Export and assign separately in order that a failing $(..) will fail
55+# the script.
66+47if [ -e @out@/nix-support/libc-cflags ]; then
55- export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE"
88+ export NIX_CFLAGS_COMPILE
99+ NIX_CFLAGS_COMPILE="$(< @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE"
610fi
711812if [ -e @out@/nix-support/cc-cflags ]; then
99- export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/cc-cflags) $NIX_CFLAGS_COMPILE"
1313+ export NIX_CFLAGS_COMPILE
1414+ NIX_CFLAGS_COMPILE="$(< @out@/nix-support/cc-cflags) $NIX_CFLAGS_COMPILE"
1015fi
11161217if [ -e @out@/nix-support/gnat-cflags ]; then
1313- export NIX_GNATFLAGS_COMPILE="$(cat @out@/nix-support/gnat-cflags) $NIX_GNATFLAGS_COMPILE"
1818+ export NIX_GNATFLAGS_COMPILE
1919+ NIX_GNATFLAGS_COMPILE="$(< @out@/nix-support/gnat-cflags) $NIX_GNATFLAGS_COMPILE"
1420fi
15211622if [ -e @out@/nix-support/libc-ldflags ]; then
1717- export NIX_LDFLAGS+=" $(cat @out@/nix-support/libc-ldflags)"
2323+ export NIX_LDFLAGS
2424+ NIX_LDFLAGS+=" $(< @out@/nix-support/libc-ldflags)"
1825fi
19262027if [ -e @out@/nix-support/cc-ldflags ]; then
2121- export NIX_LDFLAGS+=" $(cat @out@/nix-support/cc-ldflags)"
2828+ export NIX_LDFLAGS
2929+ NIX_LDFLAGS+=" $(< @out@/nix-support/cc-ldflags)"
2230fi
23312432if [ -e @out@/nix-support/libc-ldflags-before ]; then
2525- export NIX_LDFLAGS_BEFORE="$(cat @out@/nix-support/libc-ldflags-before) $NIX_LDFLAGS_BEFORE"
3333+ export NIX_LDFLAGS_BEFORE
3434+ NIX_LDFLAGS_BEFORE="$(< @out@/nix-support/libc-ldflags-before) $NIX_LDFLAGS_BEFORE"
2635fi
27362837export NIX_CC_WRAPPER_FLAGS_SET=1
+22-8
pkgs/build-support/cc-wrapper/add-hardening.sh
···11hardeningFlags=(fortify stackprotector pic strictoverflow format relro bindnow)
22-hardeningFlags+=("${hardeningEnable[@]}")
22+# Intentionally word-split in case 'hardeningEnable' is defined in Nix.
33+hardeningFlags+=(${hardeningEnable[@]})
34hardeningCFlags=()
45hardeningLDFlags=()
55-hardeningDisable=${hardeningDisable:-""}
6677-hardeningDisable+=" @hardening_unsupported_flags@"
77+declare -A hardeningDisableMap
8899-if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: Value of '$hardeningDisable': $hardeningDisable >&2; fi
99+# Intentionally word-split in case 'hardeningDisable' is defined in Nix. The
1010+# array expansion also prevents undefined variables from causing trouble with
1111+# `set -u`.
1212+for flag in ${hardeningDisable[@]} @hardening_unsupported_flags@
1313+do
1414+ hardeningDisableMap[$flag]=1
1515+done
10161111-if [[ ! $hardeningDisable =~ "all" ]]; then
1212- if [[ -n "$NIX_DEBUG" ]]; then echo 'HARDENING: Is active (not completely disabled with "all" flag)' >&2; fi
1717+if [[ -n "$NIX_DEBUG" ]]; then
1818+ printf 'HARDENING: disabled flags:' >&2
1919+ (( "${#hardeningDisableMap[@]}" )) && printf ' %q' "${!hardeningDisableMap[@]}" >&2
2020+ echo >&2
2121+fi
2222+2323+if [[ -z "${hardeningDisableMap[all]}" ]]; then
2424+ if [[ -n "$NIX_DEBUG" ]]; then
2525+ echo 'HARDENING: Is active (not completely disabled with "all" flag)' >&2;
2626+ fi
1327 for flag in "${hardeningFlags[@]}"
1428 do
1515- if [[ ! "${hardeningDisable}" =~ "$flag" ]]; then
2929+ if [[ -z "${hardeningDisableMap[$flag]}" ]]; then
1630 case $flag in
1731 fortify)
1832 if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling fortify >&2; fi
···2034 ;;
2135 stackprotector)
2236 if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling stackprotector >&2; fi
2323- hardeningCFlags+=('-fstack-protector-strong' '--param ssp-buffer-size=4')
3737+ hardeningCFlags+=('-fstack-protector-strong' '--param' 'ssp-buffer-size=4')
2438 ;;
2539 pie)
2640 if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling CFlags -fPIE >&2; fi
+42-40
pkgs/build-support/cc-wrapper/cc-wrapper.sh
···11-#! @shell@ -e
11+#! @shell@
22+set -e -o pipefail
33+shopt -s nullglob
44+25path_backup="$PATH"
33-if [ -n "@coreutils_bin@" ]; then
44- PATH="@coreutils_bin@/bin:@gnugrep_bin@/bin"
66+77+# That @-vars are substituted separately from bash evaluation makes
88+# shellcheck think this, and others like it, are useless conditionals.
99+# shellcheck disable=SC2157
1010+if [[ -n "@coreutils_bin@" && -n "@gnugrep_bin@" ]]; then
1111+ PATH="@coreutils_bin@/bin:@gnugrep_bin@/bin"
512fi
613714if [ -n "$NIX_CC_WRAPPER_START_HOOK" ]; then
···1926# For instance, figure out if linker flags should be passed.
2027# GCC prints annoying warnings when they are not needed.
2128dontLink=0
2222-getVersion=0
2329nonFlagArgs=0
3030+# shellcheck disable=SC2193
2431[[ "@prog@" = *++ ]] && isCpp=1 || isCpp=0
2532cppInclude=1
26332734expandResponseParams "$@"
2828-n=0
2929-while [ $n -lt ${#params[*]} ]; do
3535+declare -i n=0
3636+nParams=${#params[@]}
3737+while [ "$n" -lt "$nParams" ]; do
3038 p=${params[n]}
3131- p2=${params[$((n+1))]}
3939+ p2=${params[n+1]}
3240 if [ "$p" = -c ]; then
3341 dontLink=1
3442 elif [ "$p" = -S ]; then
···5563 nonFlagArgs=1
5664 elif [ "$p" = -m32 ]; then
5765 if [ -e @out@/nix-support/dynamic-linker-m32 ]; then
5858- NIX_LDFLAGS+=" -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
6666+ NIX_LDFLAGS+=" -dynamic-linker $(< @out@/nix-support/dynamic-linker-m32)"
5967 fi
6068 fi
6161- n=$((n + 1))
6969+ n+=1
6270done
63716472# If we pass a flag like -Wl, then gcc will call the linker unless it
···7179fi
72807381# Optionally filter out paths not refering to the store.
7474-if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then
8282+if [[ "$NIX_ENFORCE_PURITY" = 1 && -n "$NIX_STORE" ]]; then
7583 rest=()
7676- n=0
7777- while [ $n -lt ${#params[*]} ]; do
8484+ nParams=${#params[@]}
8585+ declare -i n=0
8686+ while [ "$n" -lt "$nParams" ]; do
7887 p=${params[n]}
7979- p2=${params[$((n+1))]}
8888+ p2=${params[n+1]}
8089 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
8181- skip $p
9090+ skip "${p:2}"
8291 elif [ "$p" = -L ] && badPath "$p2"; then
8383- n=$((n + 1)); skip $p2
9292+ n+=1; skip "$p2"
8493 elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then
8585- skip $p
9494+ skip "${p:2}"
8695 elif [ "$p" = -I ] && badPath "$p2"; then
8787- n=$((n + 1)); skip $p2
9696+ n+=1; skip "$p2"
8897 elif [ "$p" = -isystem ] && badPath "$p2"; then
8989- n=$((n + 1)); skip $p2
9898+ n+=1; skip "$p2"
9099 else
91100 rest+=("$p")
92101 fi
9393- n=$((n + 1))
102102+ n+=1
94103 done
95104 params=("${rest[@]}")
96105fi
···99108# Clear march/mtune=native -- they bring impurity.
100109if [ "$NIX_ENFORCE_NO_NATIVE" = 1 ]; then
101110 rest=()
102102- for i in "${params[@]}"; do
103103- if [[ "$i" = -m*=native ]]; then
104104- skip $i
111111+ for p in "${params[@]}"; do
112112+ if [[ "$p" = -m*=native ]]; then
113113+ skip "$p"
105114 else
106106- rest+=("$i")
115115+ rest+=("$p")
107116 fi
108117 done
109118 params=("${rest[@]}")
···116125 NIX_CFLAGS_LINK+=" $NIX_CXXSTDLIB_LINK"
117126fi
118127119119-LD=@ldPath@/ld
120128source @out@/nix-support/add-hardening.sh
121129122130# Add the flags for the C compiler proper.
123123-extraAfter=($NIX_CFLAGS_COMPILE ${hardeningCFlags[@]})
131131+extraAfter=($NIX_CFLAGS_COMPILE "${hardeningCFlags[@]}")
124132extraBefore=()
125133126134if [ "$dontLink" != 1 ]; then
127135128136 # Add the flags that should only be passed to the compiler when
129137 # linking.
130130- extraAfter+=($NIX_CFLAGS_LINK ${hardeningLDFlags[@]})
138138+ extraAfter+=($NIX_CFLAGS_LINK "${hardeningLDFlags[@]}")
131139132140 # Add the flags that should be passed to the linker (and prevent
133141 # `ld-wrapper' from adding NIX_LDFLAGS again).
134142 for i in $NIX_LDFLAGS_BEFORE; do
135135- extraBefore=(${extraBefore[@]} "-Wl,$i")
143143+ extraBefore+=("-Wl,$i")
136144 done
137145 for i in $NIX_LDFLAGS; do
138146 if [ "${i:0:3}" = -L/ ]; then
···155163156164# Optionally print debug info.
157165if [ -n "$NIX_DEBUG" ]; then
158158- echo "original flags to @prog@:" >&2
159159- for i in "${params[@]}"; do
160160- echo " $i" >&2
161161- done
162162- echo "extraBefore flags to @prog@:" >&2
163163- for i in ${extraBefore[@]}; do
164164- echo " $i" >&2
165165- done
166166- echo "extraAfter flags to @prog@:" >&2
167167- for i in ${extraAfter[@]}; do
168168- echo " $i" >&2
169169- done
166166+ echo "extra flags before to @prog@:" >&2
167167+ printf " %q\n" "${extraBefore[@]}" >&2
168168+ echo "original flags to @prog@:" >&2
169169+ printf " %q\n" "${params[@]}" >&2
170170+ echo "extra flags after to @prog@:" >&2
171171+ printf " %q\n" "${extraAfter[@]}" >&2
170172fi
171173172174if [ -n "$NIX_CC_WRAPPER_EXEC_HOOK" ]; then
···174176fi
175177176178PATH="$path_backup"
177177-exec @prog@ ${extraBefore[@]} "${params[@]}" "${extraAfter[@]}"
179179+exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"
+43-38
pkgs/build-support/cc-wrapper/gnat-wrapper.sh
···11-#! @shell@ -e
11+#! @shell@
22+set -e -o pipefail
33+shopt -s nullglob
44+25path_backup="$PATH"
66+77+# phase separation makes this look useless
88+# shellcheck disable=SC2157
39if [ -n "@coreutils_bin@" ]; then
44- PATH="@coreutils_bin@/bin"
1010+ PATH="@coreutils_bin@/bin"
511fi
612713if [ -n "$NIX_GNAT_WRAPPER_START_HOOK" ]; then
···1824# Figure out if linker flags should be passed. GCC prints annoying
1925# warnings when they are not needed.
2026dontLink=0
2121-getVersion=0
2227nonFlagArgs=0
23282429for i in "$@"; do
···3035 nonFlagArgs=1
3136 elif [ "$i" = -m32 ]; then
3237 if [ -e @out@/nix-support/dynamic-linker-m32 ]; then
3333- NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
3838+ NIX_LDFLAGS+=" -dynamic-linker $(< @out@/nix-support/dynamic-linker-m32)"
3439 fi
3540 fi
3641done
···47524853# Optionally filter out paths not refering to the store.
4954params=("$@")
5050-if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then
5555+if [[ "$NIX_ENFORCE_PURITY" = 1 && -n "$NIX_STORE" ]]; then
5156 rest=()
5252- n=0
5353- while [ $n -lt ${#params[*]} ]; do
5454- p=${params[n]}
5555- p2=${params[$((n+1))]}
5757+ for p in "${params[@]}"; do
5658 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
5757- skip $p
5959+ skip "${p:2}"
5860 elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then
5959- skip $p
6161+ skip "${p:2}"
6062 elif [ "${p:0:4}" = -aI/ ] && badPath "${p:3}"; then
6161- skip $p
6363+ skip "${p:2}"
6264 elif [ "${p:0:4}" = -aO/ ] && badPath "${p:3}"; then
6363- skip $p
6565+ skip "${p:2}"
6466 else
6567 rest+=("$p")
6668 fi
6767- n=$((n + 1))
6869 done
6970 params=("${rest[@]}")
7071fi
···7374# Clear march/mtune=native -- they bring impurity.
7475if [ "$NIX_ENFORCE_NO_NATIVE" = 1 ]; then
7576 rest=()
7676- for i in "${params[@]}"; do
7777- if [[ "$i" = -m*=native ]]; then
7878- skip $i
7777+ for p in "${params[@]}"; do
7878+ if [[ "$p" = -m*=native ]]; then
7979+ skip "$p"
7980 else
8080- rest+=("$i")
8181+ rest+=("$p")
8182 fi
8283 done
8384 params=("${rest[@]}")
···8889extraAfter=($NIX_GNATFLAGS_COMPILE)
8990extraBefore=()
90919191-if [ "`basename $0`x" = "gnatmakex" ]; then
9292- extraBefore=("--GNATBIND=@out@/bin/gnatbind --GNATLINK=@out@/bin/gnatlink ")
9292+if [ "$(basename "$0")x" = "gnatmakex" ]; then
9393+ extraBefore=("--GNATBIND=@out@/bin/gnatbind" "--GNATLINK=@out@/bin/gnatlink ")
9394fi
94959595-# Add the flags that should be passed to the linker (and prevent
9696-# `ld-wrapper' from adding NIX_LDFLAGS again).
9797-#for i in $NIX_LDFLAGS_BEFORE; do
9898-# extraBefore=(${extraBefore[@]} "-largs $i")
9999-#done
9696+#if [ "$dontLink" != 1 ]; then
9797+# # Add the flags that should be passed to the linker (and prevent
9898+# # `ld-wrapper' from adding NIX_LDFLAGS again).
9999+# for i in $NIX_LDFLAGS_BEFORE; do
100100+# extraBefore+=("-largs" "$i")
101101+# done
102102+# for i in $NIX_LDFLAGS; do
103103+# if [ "${i:0:3}" = -L/ ]; then
104104+# extraAfter+=("$i")
105105+# else
106106+# extraAfter+=("-largs" "$i")
107107+# fi
108108+# done
109109+# export NIX_LDFLAGS_SET=1
110110+#fi
100111101112# Optionally print debug info.
102113if [ -n "$NIX_DEBUG" ]; then
103103- echo "original flags to @prog@:" >&2
104104- for i in "${params[@]}"; do
105105- echo " $i" >&2
106106- done
107107- echo "extraBefore flags to @prog@:" >&2
108108- for i in ${extraBefore[@]}; do
109109- echo " $i" >&2
110110- done
111111- echo "extraAfter flags to @prog@:" >&2
112112- for i in ${extraAfter[@]}; do
113113- echo " $i" >&2
114114- done
114114+ echo "extra flags before to @prog@:" >&2
115115+ printf " %q\n" "${extraBefore[@]}" >&2
116116+ echo "original flags to @prog@:" >&2
117117+ printf " %q\n" "${params[@]}" >&2
118118+ echo "extra flags after to @prog@:" >&2
119119+ printf " %q\n" "${extraAfter[@]}" >&2
115120fi
116121117122if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then
···119124fi
120125121126PATH="$path_backup"
122122-exec @prog@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
127127+exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"
+22-18
pkgs/build-support/cc-wrapper/gnatlink-wrapper.sh
···11-#! @shell@ -e
11+#! @shell@
22+set -e -o pipefail
33+shopt -s nullglob
2435# Add the flags for the GNAT compiler proper.
44-extraAfter="--GCC=@out@/bin/gcc"
66+extraAfter=("--GCC=@out@/bin/gcc")
57extraBefore=()
6877-# Add the flags that should be passed to the linker (and prevent
88-# `ld-wrapper' from adding NIX_LDFLAGS again).
99+## Add the flags that should be passed to the linker (and prevent
1010+## `ld-wrapper' from adding NIX_LDFLAGS again).
911#for i in $NIX_LDFLAGS_BEFORE; do
1010-# extraBefore=(${extraBefore[@]} "-largs $i")
1212+# extraBefore+=("-largs" "$i")
1113#done
1414+#for i in $NIX_LDFLAGS; do
1515+# if [ "${i:0:3}" = -L/ ]; then
1616+# extraAfter+=("$i")
1717+# else
1818+# extraAfter+=("-largs" "$i")
1919+# fi
2020+#done
2121+#export NIX_LDFLAGS_SET=1
12221323# Optionally print debug info.
1424if [ -n "$NIX_DEBUG" ]; then
1515- echo "original flags to @prog@:" >&2
1616- for i in "$@"; do
1717- echo " $i" >&2
1818- done
1919- echo "extraBefore flags to @prog@:" >&2
2020- for i in ${extraBefore[@]}; do
2121- echo " $i" >&2
2222- done
2323- echo "extraAfter flags to @prog@:" >&2
2424- for i in ${extraAfter[@]}; do
2525- echo " $i" >&2
2626- done
2525+ echo "extra flags before to @prog@:" >&2
2626+ printf " %q\n" "${extraBefore[@]}" >&2
2727+ echo "original flags to @prog@:" >&2
2828+ printf " %q\n" "$@" >&2
2929+ echo "extra flags after to @prog@:" >&2
3030+ printf " %q\n" "${extraAfter[@]}" >&2
2731fi
28322933if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then
3034 source "$NIX_GNAT_WRAPPER_EXEC_HOOK"
3135fi
32363333-exec @prog@ ${extraBefore[@]} "$@" ${extraAfter[@]}
3737+exec @prog@ "${extraBefore[@]}" "$@" "${extraAfter[@]}"
···11#!@shell@
22+set -eu -o pipefail
33+shopt -s nullglob
2433-set -e
44-set -u
55-55+declare -a args=("$@")
66# I've also tried adding -z direct and -z lazyload, but it gave too many problems with C++ exceptions :'(
77# Also made sure libgcc would not be lazy-loaded, as suggested here: https://www.illumos.org/issues/2534#note-3
88# but still no success.
99-cmd="@ld@ -z ignore"
1010-1111-args=("$@");
99+declare -a argsBefore=(-z ignore) argsAfter=()
12101311# This loop makes sure all -L arguments are before -l arguments, or ld may complain it cannot find a library.
1412# GNU binutils does not have this problem:
1513# http://stackoverflow.com/questions/5817269/does-the-order-of-l-and-l-options-in-the-gnu-linker-matter
1616-i=0;
1717-while [[ $i -lt $# ]]; do
1414+while (( $# )); do
1815 case "${args[$i]}" in
1919- -L) cmd="$cmd ${args[$i]} ${args[($i+1)]}"; i=($i+1); ;;
2020- -L*) cmd="$cmd ${args[$i]}" ;;
2121- *) ;;
1616+ -L) argsBefore+=("$1" "$2"); shift ;;
1717+ -L?*) argsBefore+=("$1") ;;
1818+ *) argsAfter+=("$1") ;;
2219 esac
2323- i=($i+1);
2424-done
2525-2626-i=0;
2727-while [[ $i -lt $# ]]; do
2828- case "${args[$i]}" in
2929- -L) i=($i+1); ;;
3030- -L*) ;;
3131- *) cmd="$cmd ${args[$i]}" ;;
3232- esac
3333- i=($i+1);
2020+ shift
3421done
35223623# Trace:
3724set -x
3838-exec $cmd
3939-4040-exit 0
2525+exec "@ld@" "${argsBefore[@]}" "${argsAfter[@]}"
+22-16
pkgs/build-support/cc-wrapper/ld-wrapper.sh
···11-#! @shell@ -e
11+#! @shell@
22+set -e -o pipefail
23shopt -s nullglob
44+35path_backup="$PATH"
66+77+# phase separation makes this look useless
88+# shellcheck disable=SC2157
49if [ -n "@coreutils_bin@" ]; then
55- PATH="@coreutils_bin@/bin"
1010+ PATH="@coreutils_bin@/bin"
611fi
712813if [ -n "$NIX_LD_WRAPPER_START_HOOK" ]; then
···18231924# Optionally filter out paths not refering to the store.
2025expandResponseParams "$@"
2121-if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" \
2222- -a \( -z "$NIX_IGNORE_LD_THROUGH_GCC" -o -z "$NIX_LDFLAGS_SET" \) ]; then
2626+if [[ "$NIX_ENFORCE_PURITY" = 1 && -n "$NIX_STORE"
2727+ && ( -z "$NIX_IGNORE_LD_THROUGH_GCC" || -z "$NIX_LDFLAGS_SET" ) ]]; then
2328 rest=()
2429 nParams=${#params[@]}
2530 declare -i n=0
2626- while [ $n -lt $nParams ]; do
3131+ while [ "$n" -lt "$nParams" ]; do
2732 p=${params[n]}
2828- p2=${params[$((n+1))]}
3333+ p2=${params[n+1]}
2934 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
3035 skip "${p:2}"
3136 elif [ "$p" = -L ] && badPath "$p2"; then
···4954 params=("${rest[@]}")
5055fi
51565252-LD=@prog@
5357source @out@/nix-support/add-hardening.sh
54585555-extra=("${hardeningLDFlags[@]}")
5959+extraAfter=("${hardeningLDFlags[@]}")
5660extraBefore=()
57615862if [ -z "$NIX_LDFLAGS_SET" ]; then
5959- extra+=($NIX_LDFLAGS)
6363+ extraAfter+=($NIX_LDFLAGS)
6064 extraBefore+=($NIX_LDFLAGS_BEFORE)
6165fi
62666363-extra+=($NIX_LDFLAGS_AFTER $NIX_LDFLAGS_HARDEN)
6767+extraAfter+=($NIX_LDFLAGS_AFTER $NIX_LDFLAGS_HARDEN)
64686569declare -a libDirs
6670declare -A libs
···6973# Find all -L... switches for rpath, and relocatable flags for build id.
7074if [ "$NIX_DONT_SET_RPATH" != 1 ] || [ "$NIX_SET_BUILD_ID" = 1 ]; then
7175 prev=
7272- for p in "${params[@]}" "${extra[@]}"; do
7676+ for p in "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"; do
7377 case "$prev" in
7478 -L)
7579 libDirs+=("$p")
···127131 libs["$file"]=
128132 if [ ! "${rpaths[$dir]}" ]; then
129133 rpaths["$dir"]=1
130130- extra+=(-rpath "$dir")
134134+ extraAfter+=(-rpath "$dir")
131135 fi
132136 fi
133137 done
···138142# Only add --build-id if this is a final link. FIXME: should build gcc
139143# with --enable-linker-build-id instead?
140144if [ "$NIX_SET_BUILD_ID" = 1 ] && [ ! "$relocatable" ]; then
141141- extra+=(--build-id)
145145+ extraAfter+=(--build-id)
142146fi
143147144148145149# Optionally print debug info.
146150if [ -n "$NIX_DEBUG" ]; then
151151+ echo "extra flags before to @prog@:" >&2
152152+ printf " %q\n" "${extraBefore[@]}" >&2
147153 echo "original flags to @prog@:" >&2
148154 printf " %q\n" "${params[@]}" >&2
149149- echo "extra flags to @prog@:" >&2
150150- printf " %q\n" "${extraBefore[@]}" "${extra[@]}" >&2
155155+ echo "extra flags after to @prog@:" >&2
156156+ printf " %q\n" "${extraAfter[@]}" >&2
151157fi
152158153159if [ -n "$NIX_LD_WRAPPER_EXEC_HOOK" ]; then
···155161fi
156162157163PATH="$path_backup"
158158-exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extra[@]}"
164164+exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"
+14-9
pkgs/build-support/cc-wrapper/setup-hook.sh
···11addCVars () {
22- if [ -d $1/include ]; then
22+ if [[ -d "$1/include" ]]; then
33 export NIX_CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include"
44 fi
5566- if [ -d $1/lib64 -a ! -L $1/lib64 ]; then
66+ if [[ -d "$1/lib64" && ! -L "$1/lib64" ]]; then
77 export NIX_LDFLAGS+=" -L$1/lib64"
88 fi
991010- if [ -d $1/lib ]; then
1010+ if [[ -d "$1/lib" ]]; then
1111 export NIX_LDFLAGS+=" -L$1/lib"
1212 fi
13131414- if test -d $1/Library/Frameworks; then
1515- export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -F$1/Library/Frameworks"
1414+ if [[ -d "$1/Library/Frameworks" ]]; then
1515+ export NIX_CFLAGS_COMPILE+=" -F$1/Library/Frameworks"
1616 fi
1717}
18181919envHooks+=(addCVars)
20202121-# Note: these come *after* $out in the PATH (see setup.sh).
2121+# Note 1: these come *after* $out in the PATH (see setup.sh).
2222+# Note 2: phase separation makes this look useless to shellcheck.
22232424+# shellcheck disable=SC2157
2325if [ -n "@cc@" ]; then
2426 addToSearchPath _PATH @cc@/bin
2527fi
26282929+# shellcheck disable=SC2157
2730if [ -n "@binutils_bin@" ]; then
2831 addToSearchPath _PATH @binutils_bin@/bin
2932fi
30333434+# shellcheck disable=SC2157
3135if [ -n "@libc_bin@" ]; then
3236 addToSearchPath _PATH @libc_bin@/bin
3337fi
34383939+# shellcheck disable=SC2157
3540if [ -n "@coreutils_bin@" ]; then
3641 addToSearchPath _PATH @coreutils_bin@/bin
3742fi
38433939-if [ -z "$crossConfig" ]; then
4040- ENV_PREFIX=""
4444+if [ -z "${crossConfig:-}" ]; then
4545+ ENV_PREFIX=""
4146else
4242- ENV_PREFIX="BUILD_"
4747+ ENV_PREFIX="BUILD_"
4348fi
44494550export NIX_${ENV_PREFIX}CC=@out@
+5-1
pkgs/build-support/cc-wrapper/utils.sh
···2424}
25252626expandResponseParams() {
2727- params=("$@")
2727+ declare -g params=("$@")
2828 local arg
2929 for arg in "$@"; do
3030 if [[ "$arg" == @* ]]; then
3131+ # phase separation makes this look useless
3232+ # shellcheck disable=SC2157
3133 if [ -n "@expandResponseParams@" ]; then
3434+ # params is used by caller
3535+ #shellcheck disable=SC2034
3236 readarray -d '' params < <("@expandResponseParams@" "$@")
3337 return 0
3438 else