Select the types of activity you want to include in your feed.
cc-wrapper: Use `set -u` throughout
Now is an opportune time to do this, as the infixSalt conversion in `add-flags.sh` ensures that all the relevant `NIX_*` vars will be defined even if empty.
···11hardeningFlags=(fortify stackprotector pic strictoverflow format relro bindnow)
22-# Intentionally word-split in case 'hardeningEnable' is defined in Nix.
33-hardeningFlags+=(${hardeningEnable[@]})
22+# Intentionally word-split in case 'hardeningEnable' is defined in
33+# Nix. Also, our bootstrap tools version of bash is old enough that
44+# undefined arrays trip `set -u`.
55+if [[ -v hardeningEnable[@] ]]; then
66+ hardeningFlags+=(${hardeningEnable[@]})
77+fi
48hardeningCFlags=()
59hardeningLDFlags=()
610711declare -A hardeningDisableMap
81299-# 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+# Intentionally word-split in case 'hardeningDisable' is defined in Nix.
1414+for flag in ${hardeningDisable[@]:-IGNORED_KEY} @hardening_unsupported_flags@
1315do
1416 hardeningDisableMap[$flag]=1
1517done
16181717-if [[ -n "$NIX_DEBUG" ]]; then
1919+if [[ -n "${NIX_DEBUG:-}" ]]; then
1820 printf 'HARDENING: disabled flags:' >&2
1921 (( "${#hardeningDisableMap[@]}" )) && printf ' %q' "${!hardeningDisableMap[@]}" >&2
2022 echo >&2
2123fi
22242323-if [[ -z "${hardeningDisableMap[all]}" ]]; then
2424- if [[ -n "$NIX_DEBUG" ]]; then
2525+if [[ -z "${hardeningDisableMap[all]:-}" ]]; then
2626+ if [[ -n "${NIX_DEBUG:-}" ]]; then
2527 echo 'HARDENING: Is active (not completely disabled with "all" flag)' >&2;
2628 fi
2729 for flag in "${hardeningFlags[@]}"
2830 do
2929- if [[ -z "${hardeningDisableMap[$flag]}" ]]; then
3131+ if [[ -z "${hardeningDisableMap[$flag]:-}" ]]; then
3032 case $flag in
3133 fortify)
3232- if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling fortify >&2; fi
3434+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling fortify >&2; fi
3335 hardeningCFlags+=('-O2' '-D_FORTIFY_SOURCE=2')
3436 ;;
3537 stackprotector)
3636- if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling stackprotector >&2; fi
3838+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling stackprotector >&2; fi
3739 hardeningCFlags+=('-fstack-protector-strong' '--param' 'ssp-buffer-size=4')
3840 ;;
3941 pie)
4040- if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling CFlags -fPIE >&2; fi
4242+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling CFlags -fPIE >&2; fi
4143 hardeningCFlags+=('-fPIE')
4244 if [[ ! ("$*" =~ " -shared " || "$*" =~ " -static ") ]]; then
4343- if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling LDFlags -pie >&2; fi
4545+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling LDFlags -pie >&2; fi
4446 hardeningLDFlags+=('-pie')
4547 fi
4648 ;;
4749 pic)
4848- if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling pic >&2; fi
5050+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling pic >&2; fi
4951 hardeningCFlags+=('-fPIC')
5052 ;;
5153 strictoverflow)
5252- if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling strictoverflow >&2; fi
5454+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling strictoverflow >&2; fi
5355 hardeningCFlags+=('-fno-strict-overflow')
5456 ;;
5557 format)
5656- if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling format >&2; fi
5858+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling format >&2; fi
5759 hardeningCFlags+=('-Wformat' '-Wformat-security' '-Werror=format-security')
5860 ;;
5961 relro)
6060- if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling relro >&2; fi
6262+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling relro >&2; fi
6163 hardeningLDFlags+=('-z' 'relro')
6264 ;;
6365 bindnow)
6464- if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling bindnow >&2; fi
6666+ if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling bindnow >&2; fi
6567 hardeningLDFlags+=('-z' 'now')
6668 ;;
6769 *)
+12-9
pkgs/build-support/cc-wrapper/cc-wrapper.sh
···11#! @shell@
22-set -e -o pipefail
22+set -eu -o pipefail
33shopt -s nullglob
4455path_backup="$PATH"
···1111 PATH="@coreutils_bin@/bin:@gnugrep_bin@/bin"
1212fi
13131414-if [ -n "$NIX_CC_WRAPPER_@infixSalt@_START_HOOK" ]; then
1515- source "$NIX_CC_WRAPPER_@infixSalt@_START_HOOK"
1414+if [ -z "${NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET:-}" ]; then
1515+ source @out@/nix-support/add-flags.sh
1616fi
17171818-if [ -z "$NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET" ]; then
1919- source @out@/nix-support/add-flags.sh
1818+if [ -n "$NIX_CC_WRAPPER_@infixSalt@_START_HOOK" ]; then
1919+ source "$NIX_CC_WRAPPER_@infixSalt@_START_HOOK"
2020fi
21212222source @out@/nix-support/utils.sh
···3636nParams=${#params[@]}
3737while [ "$n" -lt "$nParams" ]; do
3838 p=${params[n]}
3939- p2=${params[n+1]}
3939+ p2=${params[n+1]:-} # handle `p` being last one
4040 if [ "$p" = -c ]; then
4141 dontLink=1
4242 elif [ "$p" = -S ]; then
···7979fi
80808181# Optionally filter out paths not refering to the store.
8282-if [[ "$NIX_ENFORCE_PURITY" = 1 && -n "$NIX_STORE" ]]; then
8282+if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE" ]]; then
8383 rest=()
8484 nParams=${#params[@]}
8585 declare -i n=0
8686 while [ "$n" -lt "$nParams" ]; do
8787 p=${params[n]}
8888- p2=${params[n+1]}
8888+ p2=${params[n+1]:-} # handle `p` being last one
8989 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
9090 skip "${p:2}"
9191 elif [ "$p" = -L ] && badPath "$p2"; then
···162162fi
163163164164# Optionally print debug info.
165165-if [ -n "$NIX_DEBUG" ]; then
165165+if [ -n "${NIX_DEBUG:-}" ]; then
166166+ set +u # Old bash workaround, see ld-wrapper for explanation.
166167 echo "extra flags before to @prog@:" >&2
167168 printf " %q\n" "${extraBefore[@]}" >&2
168169 echo "original flags to @prog@:" >&2
169170 printf " %q\n" "${params[@]}" >&2
170171 echo "extra flags after to @prog@:" >&2
171172 printf " %q\n" "${extraAfter[@]}" >&2
173173+ set -u
172174fi
173175174176if [ -n "$NIX_CC_WRAPPER_@infixSalt@_EXEC_HOOK" ]; then
···176178fi
177179178180PATH="$path_backup"
181181+set +u # Old bash workaround, see above.
179182exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"
+10-7
pkgs/build-support/cc-wrapper/gnat-wrapper.sh
···11#! @shell@
22-set -e -o pipefail
22+set -eu -o pipefail
33shopt -s nullglob
44+55+# N.B. Gnat is not used during bootstrapping, so we don't need to
66+# worry about the old bash empty array `set -u` workarounds.
4758path_backup="$PATH"
69···811# shellcheck disable=SC2157
912if [ -n "@coreutils_bin@" ]; then
1013 PATH="@coreutils_bin@/bin"
1414+fi
1515+1616+if [ -z "${NIX_@infixSalt@_GNAT_WRAPPER_FLAGS_SET:-}" ]; then
1717+ source @out@/nix-support/add-flags.sh
1118fi
12191320if [ -n "$NIX_@infixSalt@_GNAT_WRAPPER_START_HOOK" ]; then
1421 source "$NIX_@infixSalt@_GNAT_WRAPPER_START_HOOK"
1522fi
16231717-if [ -z "$NIX_@infixSalt@_GNAT_WRAPPER_FLAGS_SET" ]; then
1818- source @out@/nix-support/add-flags.sh
1919-fi
2020-2124source @out@/nix-support/utils.sh
22252326···52555356# Optionally filter out paths not refering to the store.
5457params=("$@")
5555-if [[ "$NIX_ENFORCE_PURITY" = 1 && -n "$NIX_STORE" ]]; then
5858+if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE" ]]; then
5659 rest=()
5760 for p in "${params[@]}"; do
5861 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
···110113#fi
111114112115# Optionally print debug info.
113113-if [ -n "$NIX_DEBUG" ]; then
116116+if [ -n "${NIX_DEBUG:-}" ]; then
114117 echo "extra flags before to @prog@:" >&2
115118 printf " %q\n" "${extraBefore[@]}" >&2
116119 echo "original flags to @prog@:" >&2
+5-2
pkgs/build-support/cc-wrapper/gnatlink-wrapper.sh
···11#! @shell@
22-set -e -o pipefail
22+set -eu -o pipefail
33shopt -s nullglob
44+55+# N.B. Gnat is not used during bootstrapping, so we don't need to
66+# worry about the old bash empty array `set -u` workarounds.
4758# Add the flags for the GNAT compiler proper.
69extraAfter=("--GCC=@out@/bin/gcc")
···2124#export NIX_@infixSalt@_LDFLAGS_SET=1
22252326# Optionally print debug info.
2424-if [ -n "$NIX_DEBUG" ]; then
2727+if [ -n "${NIX_DEBUG:-}" ]; then
2528 echo "extra flags before to @prog@:" >&2
2629 printf " %q\n" "${extraBefore[@]}" >&2
2730 echo "original flags to @prog@:" >&2
+19-12
pkgs/build-support/cc-wrapper/ld-wrapper.sh
···1010 PATH="@coreutils_bin@/bin"
1111fi
12121313-if [ -n "$NIX_LD_WRAPPER_@infixSalt@_START_HOOK" ]; then
1414- source "$NIX_LD_WRAPPER_@infixSalt@_START_HOOK"
1313+if [ -z "${NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET:-}" ]; then
1414+ source @out@/nix-support/add-flags.sh
1515fi
16161717-if [ -z "$NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET" ]; then
1818- source @out@/nix-support/add-flags.sh
1717+if [ -n "$NIX_LD_WRAPPER_@infixSalt@_START_HOOK" ]; then
1818+ source "$NIX_LD_WRAPPER_@infixSalt@_START_HOOK"
1919fi
20202121source @out@/nix-support/utils.sh
···23232424# Optionally filter out paths not refering to the store.
2525expandResponseParams "$@"
2626-if [[ "$NIX_ENFORCE_PURITY" = 1 && -n "$NIX_STORE"
2727- && ( -z "$NIX_@infixSalt@_IGNORE_LD_THROUGH_GCC" || -z "$NIX_@infixSalt@_LDFLAGS_SET" ) ]]; then
2626+if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE"
2727+ && ( -z "$NIX_@infixSalt@_IGNORE_LD_THROUGH_GCC" || -z "${NIX_@infixSalt@_LDFLAGS_SET:-}" ) ]]; then
2828 rest=()
2929 nParams=${#params[@]}
3030 declare -i n=0
3131 while [ "$n" -lt "$nParams" ]; do
3232 p=${params[n]}
3333- p2=${params[n+1]}
3333+ p2=${params[n+1]:-} # handle `p` being last one
3434 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
3535 skip "${p:2}"
3636 elif [ "$p" = -L ] && badPath "$p2"; then
···5959extraAfter=("${hardeningLDFlags[@]}")
6060extraBefore=()
61616262-if [ -z "$NIX_@infixSalt@_LDFLAGS_SET" ]; then
6262+if [ -z "${NIX_@infixSalt@_LDFLAGS_SET:-}" ]; then
6363 extraAfter+=($NIX_@infixSalt@_LDFLAGS)
6464 extraBefore+=($NIX_@infixSalt@_LDFLAGS_BEFORE)
6565fi
···7373# Find all -L... switches for rpath, and relocatable flags for build id.
7474if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ] || [ "$NIX_@infixSalt@_SET_BUILD_ID" = 1 ]; then
7575 prev=
7676+ # Old bash thinks empty arrays are undefined, ugh, so temporarily disable
7777+ # `set -u`.
7878+ set +u
7679 for p in "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"; do
8080+ set -u
7781 case "$prev" in
7882 -L)
7983 libDirs+=("$p")
···119123 if [[ "$dir" =~ [/.][/.] ]] && dir2=$(readlink -f "$dir"); then
120124 dir="$dir2"
121125 fi
122122- if [ "${rpaths[$dir]}" ] || [[ "$dir" != "$NIX_STORE"/* ]]; then
126126+ if [ -n "${rpaths[$dir]:-}" ] || [[ "$dir" != "$NIX_STORE"/* ]]; then
123127 # If the path is not in the store, don't add it to the rpath.
124128 # This typically happens for libraries in /tmp that are later
125129 # copied to $out/lib. If not, we're screwed.
···127131 fi
128132 for path in "$dir"/lib*.so; do
129133 file="${path##*/}"
130130- if [ "${libs[$file]}" ]; then
134134+ if [ "${libs[$file]:-}" ]; then
131135 libs["$file"]=
132132- if [ ! "${rpaths[$dir]}" ]; then
136136+ if [ -z "${rpaths[$dir]:-}" ]; then
133137 rpaths["$dir"]=1
134138 extraAfter+=(-rpath "$dir")
135139 fi
···147151148152149153# Optionally print debug info.
150150-if [ -n "$NIX_DEBUG" ]; then
154154+if [ -n "${NIX_DEBUG:-}" ]; then
155155+ set +u # Old bash workaround, see above.
151156 echo "extra flags before to @prog@:" >&2
152157 printf " %q\n" "${extraBefore[@]}" >&2
153158 echo "original flags to @prog@:" >&2
154159 printf " %q\n" "${params[@]}" >&2
155160 echo "extra flags after to @prog@:" >&2
156161 printf " %q\n" "${extraAfter[@]}" >&2
162162+ set -u
157163fi
158164159165if [ -n "$NIX_LD_WRAPPER_@infixSalt@_EXEC_HOOK" ]; then
···161167fi
162168163169PATH="$path_backup"
170170+set +u # Old bash workaround, see above.
164171exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"
+1-1
pkgs/build-support/cc-wrapper/utils.sh
···11skip () {
22- if [ -n "$NIX_DEBUG" ]; then
22+ if [ -n "${NIX_DEBUG:-}" ]; then
33 echo "skipping impure path $1" >&2
44 fi
55}