···1# `-B@out@/bin' forces cc to use ld-wrapper.sh when calling ld.
2export NIX_CFLAGS_COMPILE="-B@out@/bin/ $NIX_CFLAGS_COMPILE"
30004if [ -e @out@/nix-support/libc-cflags ]; then
5- export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE"
06fi
78if [ -e @out@/nix-support/cc-cflags ]; then
9- export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/cc-cflags) $NIX_CFLAGS_COMPILE"
010fi
1112if [ -e @out@/nix-support/gnat-cflags ]; then
13- export NIX_GNATFLAGS_COMPILE="$(cat @out@/nix-support/gnat-cflags) $NIX_GNATFLAGS_COMPILE"
014fi
1516if [ -e @out@/nix-support/libc-ldflags ]; then
17- export NIX_LDFLAGS+=" $(cat @out@/nix-support/libc-ldflags)"
018fi
1920if [ -e @out@/nix-support/cc-ldflags ]; then
21- export NIX_LDFLAGS+=" $(cat @out@/nix-support/cc-ldflags)"
022fi
2324if [ -e @out@/nix-support/libc-ldflags-before ]; then
25- export NIX_LDFLAGS_BEFORE="$(cat @out@/nix-support/libc-ldflags-before) $NIX_LDFLAGS_BEFORE"
026fi
2728export NIX_CC_WRAPPER_FLAGS_SET=1
···1# `-B@out@/bin' forces cc to use ld-wrapper.sh when calling ld.
2export NIX_CFLAGS_COMPILE="-B@out@/bin/ $NIX_CFLAGS_COMPILE"
34+# Export and assign separately in order that a failing $(..) will fail
5+# the script.
6+7if [ -e @out@/nix-support/libc-cflags ]; then
8+ export NIX_CFLAGS_COMPILE
9+ NIX_CFLAGS_COMPILE="$(< @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE"
10fi
1112if [ -e @out@/nix-support/cc-cflags ]; then
13+ export NIX_CFLAGS_COMPILE
14+ NIX_CFLAGS_COMPILE="$(< @out@/nix-support/cc-cflags) $NIX_CFLAGS_COMPILE"
15fi
1617if [ -e @out@/nix-support/gnat-cflags ]; then
18+ export NIX_GNATFLAGS_COMPILE
19+ NIX_GNATFLAGS_COMPILE="$(< @out@/nix-support/gnat-cflags) $NIX_GNATFLAGS_COMPILE"
20fi
2122if [ -e @out@/nix-support/libc-ldflags ]; then
23+ export NIX_LDFLAGS
24+ NIX_LDFLAGS+=" $(< @out@/nix-support/libc-ldflags)"
25fi
2627if [ -e @out@/nix-support/cc-ldflags ]; then
28+ export NIX_LDFLAGS
29+ NIX_LDFLAGS+=" $(< @out@/nix-support/cc-ldflags)"
30fi
3132if [ -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"
35fi
3637export NIX_CC_WRAPPER_FLAGS_SET=1
+22-8
pkgs/build-support/cc-wrapper/add-hardening.sh
···1hardeningFlags=(fortify stackprotector pic strictoverflow format relro bindnow)
2-hardeningFlags+=("${hardeningEnable[@]}")
03hardeningCFlags=()
4hardeningLDFlags=()
5-hardeningDisable=${hardeningDisable:-""}
67-hardeningDisable+=" @hardening_unsupported_flags@"
89-if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: Value of '$hardeningDisable': $hardeningDisable >&2; fi
0000001011-if [[ ! $hardeningDisable =~ "all" ]]; then
12- if [[ -n "$NIX_DEBUG" ]]; then echo 'HARDENING: Is active (not completely disabled with "all" flag)' >&2; fi
0000000013 for flag in "${hardeningFlags[@]}"
14 do
15- if [[ ! "${hardeningDisable}" =~ "$flag" ]]; then
16 case $flag in
17 fortify)
18 if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling fortify >&2; fi
···20 ;;
21 stackprotector)
22 if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling stackprotector >&2; fi
23- hardeningCFlags+=('-fstack-protector-strong' '--param ssp-buffer-size=4')
24 ;;
25 pie)
26 if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling CFlags -fPIE >&2; fi
···1hardeningFlags=(fortify stackprotector pic strictoverflow format relro bindnow)
2+# Intentionally word-split in case 'hardeningEnable' is defined in Nix.
3+hardeningFlags+=(${hardeningEnable[@]})
4hardeningCFlags=()
5hardeningLDFlags=()
067+declare -A hardeningDisableMap
89+# Intentionally word-split in case 'hardeningDisable' is defined in Nix. The
10+# array expansion also prevents undefined variables from causing trouble with
11+# `set -u`.
12+for flag in ${hardeningDisable[@]} @hardening_unsupported_flags@
13+do
14+ hardeningDisableMap[$flag]=1
15+done
1617+if [[ -n "$NIX_DEBUG" ]]; then
18+ printf 'HARDENING: disabled flags:' >&2
19+ (( "${#hardeningDisableMap[@]}" )) && printf ' %q' "${!hardeningDisableMap[@]}" >&2
20+ echo >&2
21+fi
22+23+if [[ -z "${hardeningDisableMap[all]}" ]]; then
24+ if [[ -n "$NIX_DEBUG" ]]; then
25+ echo 'HARDENING: Is active (not completely disabled with "all" flag)' >&2;
26+ fi
27 for flag in "${hardeningFlags[@]}"
28 do
29+ if [[ -z "${hardeningDisableMap[$flag]}" ]]; then
30 case $flag in
31 fortify)
32 if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling fortify >&2; fi
···34 ;;
35 stackprotector)
36 if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling stackprotector >&2; fi
37+ hardeningCFlags+=('-fstack-protector-strong' '--param' 'ssp-buffer-size=4')
38 ;;
39 pie)
40 if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling CFlags -fPIE >&2; fi
+42-40
pkgs/build-support/cc-wrapper/cc-wrapper.sh
···1-#! @shell@ -e
0002path_backup="$PATH"
3-if [ -n "@coreutils_bin@" ]; then
4- PATH="@coreutils_bin@/bin:@gnugrep_bin@/bin"
00005fi
67if [ -n "$NIX_CC_WRAPPER_START_HOOK" ]; then
···19# For instance, figure out if linker flags should be passed.
20# GCC prints annoying warnings when they are not needed.
21dontLink=0
22-getVersion=0
23nonFlagArgs=0
024[[ "@prog@" = *++ ]] && isCpp=1 || isCpp=0
25cppInclude=1
2627expandResponseParams "$@"
28-n=0
29-while [ $n -lt ${#params[*]} ]; do
030 p=${params[n]}
31- p2=${params[$((n+1))]}
32 if [ "$p" = -c ]; then
33 dontLink=1
34 elif [ "$p" = -S ]; then
···55 nonFlagArgs=1
56 elif [ "$p" = -m32 ]; then
57 if [ -e @out@/nix-support/dynamic-linker-m32 ]; then
58- NIX_LDFLAGS+=" -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
59 fi
60 fi
61- n=$((n + 1))
62done
6364# If we pass a flag like -Wl, then gcc will call the linker unless it
···71fi
7273# Optionally filter out paths not refering to the store.
74-if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then
75 rest=()
76- n=0
77- while [ $n -lt ${#params[*]} ]; do
078 p=${params[n]}
79- p2=${params[$((n+1))]}
80 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
81- skip $p
82 elif [ "$p" = -L ] && badPath "$p2"; then
83- n=$((n + 1)); skip $p2
84 elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then
85- skip $p
86 elif [ "$p" = -I ] && badPath "$p2"; then
87- n=$((n + 1)); skip $p2
88 elif [ "$p" = -isystem ] && badPath "$p2"; then
89- n=$((n + 1)); skip $p2
90 else
91 rest+=("$p")
92 fi
93- n=$((n + 1))
94 done
95 params=("${rest[@]}")
96fi
···99# Clear march/mtune=native -- they bring impurity.
100if [ "$NIX_ENFORCE_NO_NATIVE" = 1 ]; then
101 rest=()
102- for i in "${params[@]}"; do
103- if [[ "$i" = -m*=native ]]; then
104- skip $i
105 else
106- rest+=("$i")
107 fi
108 done
109 params=("${rest[@]}")
···116 NIX_CFLAGS_LINK+=" $NIX_CXXSTDLIB_LINK"
117fi
118119-LD=@ldPath@/ld
120source @out@/nix-support/add-hardening.sh
121122# Add the flags for the C compiler proper.
123-extraAfter=($NIX_CFLAGS_COMPILE ${hardeningCFlags[@]})
124extraBefore=()
125126if [ "$dontLink" != 1 ]; then
127128 # Add the flags that should only be passed to the compiler when
129 # linking.
130- extraAfter+=($NIX_CFLAGS_LINK ${hardeningLDFlags[@]})
131132 # Add the flags that should be passed to the linker (and prevent
133 # `ld-wrapper' from adding NIX_LDFLAGS again).
134 for i in $NIX_LDFLAGS_BEFORE; do
135- extraBefore=(${extraBefore[@]} "-Wl,$i")
136 done
137 for i in $NIX_LDFLAGS; do
138 if [ "${i:0:3}" = -L/ ]; then
···155156# Optionally print debug info.
157if [ -n "$NIX_DEBUG" ]; then
158- echo "original flags to @prog@:" >&2
159- for i in "${params[@]}"; do
160- echo " $i" >&2
161- done
162- echo "extraBefore flags to @prog@:" >&2
163- for i in ${extraBefore[@]}; do
164- echo " $i" >&2
165- done
166- echo "extraAfter flags to @prog@:" >&2
167- for i in ${extraAfter[@]}; do
168- echo " $i" >&2
169- done
170fi
171172if [ -n "$NIX_CC_WRAPPER_EXEC_HOOK" ]; then
···174fi
175176PATH="$path_backup"
177-exec @prog@ ${extraBefore[@]} "${params[@]}" "${extraAfter[@]}"
···1+#! @shell@
2+set -e -o pipefail
3+shopt -s nullglob
4+5path_backup="$PATH"
6+7+# That @-vars are substituted separately from bash evaluation makes
8+# shellcheck think this, and others like it, are useless conditionals.
9+# shellcheck disable=SC2157
10+if [[ -n "@coreutils_bin@" && -n "@gnugrep_bin@" ]]; then
11+ PATH="@coreutils_bin@/bin:@gnugrep_bin@/bin"
12fi
1314if [ -n "$NIX_CC_WRAPPER_START_HOOK" ]; then
···26# For instance, figure out if linker flags should be passed.
27# GCC prints annoying warnings when they are not needed.
28dontLink=0
029nonFlagArgs=0
30+# shellcheck disable=SC2193
31[[ "@prog@" = *++ ]] && isCpp=1 || isCpp=0
32cppInclude=1
3334expandResponseParams "$@"
35+declare -i n=0
36+nParams=${#params[@]}
37+while [ "$n" -lt "$nParams" ]; do
38 p=${params[n]}
39+ p2=${params[n+1]}
40 if [ "$p" = -c ]; then
41 dontLink=1
42 elif [ "$p" = -S ]; then
···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
70done
7172# If we pass a flag like -Wl, then gcc will call the linker unless it
···79fi
8081# Optionally filter out paths not refering to the store.
82+if [[ "$NIX_ENFORCE_PURITY" = 1 && -n "$NIX_STORE" ]]; then
83 rest=()
84+ nParams=${#params[@]}
85+ declare -i n=0
86+ while [ "$n" -lt "$nParams" ]; do
87 p=${params[n]}
88+ p2=${params[n+1]}
89 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
90+ skip "${p:2}"
91 elif [ "$p" = -L ] && badPath "$p2"; then
92+ n+=1; skip "$p2"
93 elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then
94+ skip "${p:2}"
95 elif [ "$p" = -I ] && badPath "$p2"; then
96+ n+=1; skip "$p2"
97 elif [ "$p" = -isystem ] && badPath "$p2"; then
98+ n+=1; skip "$p2"
99 else
100 rest+=("$p")
101 fi
102+ n+=1
103 done
104 params=("${rest[@]}")
105fi
···108# Clear march/mtune=native -- they bring impurity.
109if [ "$NIX_ENFORCE_NO_NATIVE" = 1 ]; then
110 rest=()
111+ for p in "${params[@]}"; do
112+ if [[ "$p" = -m*=native ]]; then
113+ skip "$p"
114 else
115+ rest+=("$p")
116 fi
117 done
118 params=("${rest[@]}")
···125 NIX_CFLAGS_LINK+=" $NIX_CXXSTDLIB_LINK"
126fi
1270128source @out@/nix-support/add-hardening.sh
129130# Add the flags for the C compiler proper.
131+extraAfter=($NIX_CFLAGS_COMPILE "${hardeningCFlags[@]}")
132extraBefore=()
133134if [ "$dontLink" != 1 ]; then
135136 # Add the flags that should only be passed to the compiler when
137 # linking.
138+ extraAfter+=($NIX_CFLAGS_LINK "${hardeningLDFlags[@]}")
139140 # 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
···163164# Optionally print debug info.
165if [ -n "$NIX_DEBUG" ]; then
166+ echo "extra flags before to @prog@:" >&2
167+ printf " %q\n" "${extraBefore[@]}" >&2
168+ echo "original flags to @prog@:" >&2
169+ printf " %q\n" "${params[@]}" >&2
170+ echo "extra flags after to @prog@:" >&2
171+ printf " %q\n" "${extraAfter[@]}" >&2
000000172fi
173174if [ -n "$NIX_CC_WRAPPER_EXEC_HOOK" ]; then
···176fi
177178PATH="$path_backup"
179+exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"
+43-38
pkgs/build-support/cc-wrapper/gnat-wrapper.sh
···1-#! @shell@ -e
0002path_backup="$PATH"
0003if [ -n "@coreutils_bin@" ]; then
4- PATH="@coreutils_bin@/bin"
5fi
67if [ -n "$NIX_GNAT_WRAPPER_START_HOOK" ]; then
···18# Figure out if linker flags should be passed. GCC prints annoying
19# warnings when they are not needed.
20dontLink=0
21-getVersion=0
22nonFlagArgs=0
2324for i in "$@"; do
···30 nonFlagArgs=1
31 elif [ "$i" = -m32 ]; then
32 if [ -e @out@/nix-support/dynamic-linker-m32 ]; then
33- NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
34 fi
35 fi
36done
···4748# Optionally filter out paths not refering to the store.
49params=("$@")
50-if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then
51 rest=()
52- n=0
53- while [ $n -lt ${#params[*]} ]; do
54- p=${params[n]}
55- p2=${params[$((n+1))]}
56 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
57- skip $p
58 elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then
59- skip $p
60 elif [ "${p:0:4}" = -aI/ ] && badPath "${p:3}"; then
61- skip $p
62 elif [ "${p:0:4}" = -aO/ ] && badPath "${p:3}"; then
63- skip $p
64 else
65 rest+=("$p")
66 fi
67- n=$((n + 1))
68 done
69 params=("${rest[@]}")
70fi
···73# Clear march/mtune=native -- they bring impurity.
74if [ "$NIX_ENFORCE_NO_NATIVE" = 1 ]; then
75 rest=()
76- for i in "${params[@]}"; do
77- if [[ "$i" = -m*=native ]]; then
78- skip $i
79 else
80- rest+=("$i")
81 fi
82 done
83 params=("${rest[@]}")
···88extraAfter=($NIX_GNATFLAGS_COMPILE)
89extraBefore=()
9091-if [ "`basename $0`x" = "gnatmakex" ]; then
92- extraBefore=("--GNATBIND=@out@/bin/gnatbind --GNATLINK=@out@/bin/gnatlink ")
93fi
9495-# Add the flags that should be passed to the linker (and prevent
96-# `ld-wrapper' from adding NIX_LDFLAGS again).
97-#for i in $NIX_LDFLAGS_BEFORE; do
98-# extraBefore=(${extraBefore[@]} "-largs $i")
99-#done
0000000000100101# Optionally print debug info.
102if [ -n "$NIX_DEBUG" ]; then
103- echo "original flags to @prog@:" >&2
104- for i in "${params[@]}"; do
105- echo " $i" >&2
106- done
107- echo "extraBefore flags to @prog@:" >&2
108- for i in ${extraBefore[@]}; do
109- echo " $i" >&2
110- done
111- echo "extraAfter flags to @prog@:" >&2
112- for i in ${extraAfter[@]}; do
113- echo " $i" >&2
114- done
115fi
116117if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then
···119fi
120121PATH="$path_backup"
122-exec @prog@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
···1+#! @shell@
2+set -e -o pipefail
3+shopt -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
1213if [ -n "$NIX_GNAT_WRAPPER_START_HOOK" ]; then
···24# Figure out if linker flags should be passed. GCC prints annoying
25# warnings when they are not needed.
26dontLink=0
027nonFlagArgs=0
2829for i in "$@"; do
···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
41done
···5253# Optionally filter out paths not refering to the store.
54params=("$@")
55+if [[ "$NIX_ENFORCE_PURITY" = 1 && -n "$NIX_STORE" ]]; then
56 rest=()
57+ for p in "${params[@]}"; do
00058 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
59+ skip "${p:2}"
60 elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then
61+ skip "${p:2}"
62 elif [ "${p:0:4}" = -aI/ ] && badPath "${p:3}"; then
63+ skip "${p:2}"
64 elif [ "${p:0:4}" = -aO/ ] && badPath "${p:3}"; then
65+ skip "${p:2}"
66 else
67 rest+=("$p")
68 fi
069 done
70 params=("${rest[@]}")
71fi
···74# Clear march/mtune=native -- they bring impurity.
75if [ "$NIX_ENFORCE_NO_NATIVE" = 1 ]; then
76 rest=()
77+ for p in "${params[@]}"; do
78+ if [[ "$p" = -m*=native ]]; then
79+ skip "$p"
80 else
81+ rest+=("$p")
82 fi
83 done
84 params=("${rest[@]}")
···89extraAfter=($NIX_GNATFLAGS_COMPILE)
90extraBefore=()
9192+if [ "$(basename "$0")x" = "gnatmakex" ]; then
93+ extraBefore=("--GNATBIND=@out@/bin/gnatbind" "--GNATLINK=@out@/bin/gnatlink ")
94fi
9596+#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
111112# Optionally print debug info.
113if [ -n "$NIX_DEBUG" ]; then
114+ echo "extra flags before to @prog@:" >&2
115+ printf " %q\n" "${extraBefore[@]}" >&2
116+ echo "original flags to @prog@:" >&2
117+ printf " %q\n" "${params[@]}" >&2
118+ echo "extra flags after to @prog@:" >&2
119+ printf " %q\n" "${extraAfter[@]}" >&2
000000120fi
121122if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then
···124fi
125126PATH="$path_backup"
127+exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"
+22-18
pkgs/build-support/cc-wrapper/gnatlink-wrapper.sh
···1-#! @shell@ -e
0023# Add the flags for the GNAT compiler proper.
4-extraAfter="--GCC=@out@/bin/gcc"
5extraBefore=()
67-# Add the flags that should be passed to the linker (and prevent
8-# `ld-wrapper' from adding NIX_LDFLAGS again).
9#for i in $NIX_LDFLAGS_BEFORE; do
10-# extraBefore=(${extraBefore[@]} "-largs $i")
11#done
000000001213# Optionally print debug info.
14if [ -n "$NIX_DEBUG" ]; then
15- echo "original flags to @prog@:" >&2
16- for i in "$@"; do
17- echo " $i" >&2
18- done
19- echo "extraBefore flags to @prog@:" >&2
20- for i in ${extraBefore[@]}; do
21- echo " $i" >&2
22- done
23- echo "extraAfter flags to @prog@:" >&2
24- for i in ${extraAfter[@]}; do
25- echo " $i" >&2
26- done
27fi
2829if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then
30 source "$NIX_GNAT_WRAPPER_EXEC_HOOK"
31fi
3233-exec @prog@ ${extraBefore[@]} "$@" ${extraAfter[@]}
···1+#! @shell@
2+set -e -o pipefail
3+shopt -s nullglob
45# Add the flags for the GNAT compiler proper.
6+extraAfter=("--GCC=@out@/bin/gcc")
7extraBefore=()
89+## Add the flags that should be passed to the linker (and prevent
10+## `ld-wrapper' from adding NIX_LDFLAGS again).
11#for i in $NIX_LDFLAGS_BEFORE; do
12+# extraBefore+=("-largs" "$i")
13#done
14+#for i in $NIX_LDFLAGS; do
15+# if [ "${i:0:3}" = -L/ ]; then
16+# extraAfter+=("$i")
17+# else
18+# extraAfter+=("-largs" "$i")
19+# fi
20+#done
21+#export NIX_LDFLAGS_SET=1
2223# Optionally print debug info.
24if [ -n "$NIX_DEBUG" ]; then
25+ echo "extra flags before to @prog@:" >&2
26+ printf " %q\n" "${extraBefore[@]}" >&2
27+ echo "original flags to @prog@:" >&2
28+ printf " %q\n" "$@" >&2
29+ echo "extra flags after to @prog@:" >&2
30+ printf " %q\n" "${extraAfter[@]}" >&2
00000031fi
3233if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then
34 source "$NIX_GNAT_WRAPPER_EXEC_HOOK"
35fi
3637+exec @prog@ "${extraBefore[@]}" "$@" "${extraAfter[@]}"
···1#!@shell@
0023-set -e
4-set -u
5-6# I've also tried adding -z direct and -z lazyload, but it gave too many problems with C++ exceptions :'(
7# Also made sure libgcc would not be lazy-loaded, as suggested here: https://www.illumos.org/issues/2534#note-3
8# but still no success.
9-cmd="@ld@ -z ignore"
10-11-args=("$@");
1213# This loop makes sure all -L arguments are before -l arguments, or ld may complain it cannot find a library.
14# GNU binutils does not have this problem:
15# http://stackoverflow.com/questions/5817269/does-the-order-of-l-and-l-options-in-the-gnu-linker-matter
16-i=0;
17-while [[ $i -lt $# ]]; do
18 case "${args[$i]}" in
19- -L) cmd="$cmd ${args[$i]} ${args[($i+1)]}"; i=($i+1); ;;
20- -L*) cmd="$cmd ${args[$i]}" ;;
21- *) ;;
22 esac
23- i=($i+1);
24-done
25-26-i=0;
27-while [[ $i -lt $# ]]; do
28- case "${args[$i]}" in
29- -L) i=($i+1); ;;
30- -L*) ;;
31- *) cmd="$cmd ${args[$i]}" ;;
32- esac
33- i=($i+1);
34done
3536# Trace:
37set -x
38-exec $cmd
39-40-exit 0
···1#!@shell@
2+set -eu -o pipefail
3+shopt -s nullglob
45+declare -a args=("$@")
006# I've also tried adding -z direct and -z lazyload, but it gave too many problems with C++ exceptions :'(
7# Also made sure libgcc would not be lazy-loaded, as suggested here: https://www.illumos.org/issues/2534#note-3
8# but still no success.
9+declare -a argsBefore=(-z ignore) argsAfter=()
001011# This loop makes sure all -L arguments are before -l arguments, or ld may complain it cannot find a library.
12# GNU binutils does not have this problem:
13# http://stackoverflow.com/questions/5817269/does-the-order-of-l-and-l-options-in-the-gnu-linker-matter
14+while (( $# )); do
015 case "${args[$i]}" in
16+ -L) argsBefore+=("$1" "$2"); shift ;;
17+ -L?*) argsBefore+=("$1") ;;
18+ *) argsAfter+=("$1") ;;
19 esac
20+ shift
000000000021done
2223# Trace:
24set -x
25+exec "@ld@" "${argsBefore[@]}" "${argsAfter[@]}"
00
+22-16
pkgs/build-support/cc-wrapper/ld-wrapper.sh
···1-#! @shell@ -e
02shopt -s nullglob
03path_backup="$PATH"
0004if [ -n "@coreutils_bin@" ]; then
5- PATH="@coreutils_bin@/bin"
6fi
78if [ -n "$NIX_LD_WRAPPER_START_HOOK" ]; then
···1819# Optionally filter out paths not refering to the store.
20expandResponseParams "$@"
21-if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" \
22- -a \( -z "$NIX_IGNORE_LD_THROUGH_GCC" -o -z "$NIX_LDFLAGS_SET" \) ]; then
23 rest=()
24 nParams=${#params[@]}
25 declare -i n=0
26- while [ $n -lt $nParams ]; do
27 p=${params[n]}
28- p2=${params[$((n+1))]}
29 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
30 skip "${p:2}"
31 elif [ "$p" = -L ] && badPath "$p2"; then
···49 params=("${rest[@]}")
50fi
5152-LD=@prog@
53source @out@/nix-support/add-hardening.sh
5455-extra=("${hardeningLDFlags[@]}")
56extraBefore=()
5758if [ -z "$NIX_LDFLAGS_SET" ]; then
59- extra+=($NIX_LDFLAGS)
60 extraBefore+=($NIX_LDFLAGS_BEFORE)
61fi
6263-extra+=($NIX_LDFLAGS_AFTER $NIX_LDFLAGS_HARDEN)
6465declare -a libDirs
66declare -A libs
···69# Find all -L... switches for rpath, and relocatable flags for build id.
70if [ "$NIX_DONT_SET_RPATH" != 1 ] || [ "$NIX_SET_BUILD_ID" = 1 ]; then
71 prev=
72- for p in "${params[@]}" "${extra[@]}"; do
73 case "$prev" in
74 -L)
75 libDirs+=("$p")
···127 libs["$file"]=
128 if [ ! "${rpaths[$dir]}" ]; then
129 rpaths["$dir"]=1
130- extra+=(-rpath "$dir")
131 fi
132 fi
133 done
···138# Only add --build-id if this is a final link. FIXME: should build gcc
139# with --enable-linker-build-id instead?
140if [ "$NIX_SET_BUILD_ID" = 1 ] && [ ! "$relocatable" ]; then
141- extra+=(--build-id)
142fi
143144145# Optionally print debug info.
146if [ -n "$NIX_DEBUG" ]; then
00147 echo "original flags to @prog@:" >&2
148 printf " %q\n" "${params[@]}" >&2
149- echo "extra flags to @prog@:" >&2
150- printf " %q\n" "${extraBefore[@]}" "${extra[@]}" >&2
151fi
152153if [ -n "$NIX_LD_WRAPPER_EXEC_HOOK" ]; then
···155fi
156157PATH="$path_backup"
158-exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extra[@]}"
···1+#! @shell@
2+set -e -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
1213if [ -n "$NIX_LD_WRAPPER_START_HOOK" ]; then
···2324# Optionally filter out paths not refering to the store.
25expandResponseParams "$@"
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
31+ while [ "$n" -lt "$nParams" ]; do
32 p=${params[n]}
33+ p2=${params[n+1]}
34 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
35 skip "${p:2}"
36 elif [ "$p" = -L ] && badPath "$p2"; then
···54 params=("${rest[@]}")
55fi
56057source @out@/nix-support/add-hardening.sh
5859+extraAfter=("${hardeningLDFlags[@]}")
60extraBefore=()
6162if [ -z "$NIX_LDFLAGS_SET" ]; then
63+ extraAfter+=($NIX_LDFLAGS)
64 extraBefore+=($NIX_LDFLAGS_BEFORE)
65fi
6667+extraAfter+=($NIX_LDFLAGS_AFTER $NIX_LDFLAGS_HARDEN)
6869declare -a libDirs
70declare -A libs
···73# Find all -L... switches for rpath, and relocatable flags for build id.
74if [ "$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
78 -L)
79 libDirs+=("$p")
···131 libs["$file"]=
132 if [ ! "${rpaths[$dir]}" ]; then
133 rpaths["$dir"]=1
134+ extraAfter+=(-rpath "$dir")
135 fi
136 fi
137 done
···142# Only add --build-id if this is a final link. FIXME: should build gcc
143# with --enable-linker-build-id instead?
144if [ "$NIX_SET_BUILD_ID" = 1 ] && [ ! "$relocatable" ]; then
145+ extraAfter+=(--build-id)
146fi
147148149# Optionally print debug info.
150if [ -n "$NIX_DEBUG" ]; then
151+ echo "extra flags before to @prog@:" >&2
152+ printf " %q\n" "${extraBefore[@]}" >&2
153 echo "original flags to @prog@:" >&2
154 printf " %q\n" "${params[@]}" >&2
155+ echo "extra flags after to @prog@:" >&2
156+ printf " %q\n" "${extraAfter[@]}" >&2
157fi
158159if [ -n "$NIX_LD_WRAPPER_EXEC_HOOK" ]; then
···161fi
162163PATH="$path_backup"
164+exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"
+14-9
pkgs/build-support/cc-wrapper/setup-hook.sh
···1addCVars () {
2- if [ -d $1/include ]; then
3 export NIX_CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include"
4 fi
56- if [ -d $1/lib64 -a ! -L $1/lib64 ]; then
7 export NIX_LDFLAGS+=" -L$1/lib64"
8 fi
910- if [ -d $1/lib ]; then
11 export NIX_LDFLAGS+=" -L$1/lib"
12 fi
1314- if test -d $1/Library/Frameworks; then
15- export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -F$1/Library/Frameworks"
16 fi
17}
1819envHooks+=(addCVars)
2021-# Note: these come *after* $out in the PATH (see setup.sh).
022023if [ -n "@cc@" ]; then
24 addToSearchPath _PATH @cc@/bin
25fi
26027if [ -n "@binutils_bin@" ]; then
28 addToSearchPath _PATH @binutils_bin@/bin
29fi
30031if [ -n "@libc_bin@" ]; then
32 addToSearchPath _PATH @libc_bin@/bin
33fi
34035if [ -n "@coreutils_bin@" ]; then
36 addToSearchPath _PATH @coreutils_bin@/bin
37fi
3839-if [ -z "$crossConfig" ]; then
40- ENV_PREFIX=""
41else
42- ENV_PREFIX="BUILD_"
43fi
4445export NIX_${ENV_PREFIX}CC=@out@
···1addCVars () {
2+ if [[ -d "$1/include" ]]; then
3 export NIX_CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include"
4 fi
56+ if [[ -d "$1/lib64" && ! -L "$1/lib64" ]]; then
7 export NIX_LDFLAGS+=" -L$1/lib64"
8 fi
910+ if [[ -d "$1/lib" ]]; then
11 export NIX_LDFLAGS+=" -L$1/lib"
12 fi
1314+ if [[ -d "$1/Library/Frameworks" ]]; then
15+ export NIX_CFLAGS_COMPILE+=" -F$1/Library/Frameworks"
16 fi
17}
1819envHooks+=(addCVars)
2021+# Note 1: these come *after* $out in the PATH (see setup.sh).
22+# Note 2: phase separation makes this look useless to shellcheck.
2324+# shellcheck disable=SC2157
25if [ -n "@cc@" ]; then
26 addToSearchPath _PATH @cc@/bin
27fi
2829+# shellcheck disable=SC2157
30if [ -n "@binutils_bin@" ]; then
31 addToSearchPath _PATH @binutils_bin@/bin
32fi
3334+# shellcheck disable=SC2157
35if [ -n "@libc_bin@" ]; then
36 addToSearchPath _PATH @libc_bin@/bin
37fi
3839+# shellcheck disable=SC2157
40if [ -n "@coreutils_bin@" ]; then
41 addToSearchPath _PATH @coreutils_bin@/bin
42fi
4344+if [ -z "${crossConfig:-}" ]; then
45+ ENV_PREFIX=""
46else
47+ ENV_PREFIX="BUILD_"
48fi
4950export NIX_${ENV_PREFIX}CC=@out@
+5-1
pkgs/build-support/cc-wrapper/utils.sh
···24}
2526expandResponseParams() {
27- params=("$@")
28 local arg
29 for arg in "$@"; do
30 if [[ "$arg" == @* ]]; then
0031 if [ -n "@expandResponseParams@" ]; then
0032 readarray -d '' params < <("@expandResponseParams@" "$@")
33 return 0
34 else
···24}
2526expandResponseParams() {
27+ declare -g params=("$@")
28 local arg
29 for arg in "$@"; do
30 if [[ "$arg" == @* ]]; then
31+ # phase separation makes this look useless
32+ # shellcheck disable=SC2157
33 if [ -n "@expandResponseParams@" ]; then
34+ # params is used by caller
35+ #shellcheck disable=SC2034
36 readarray -d '' params < <("@expandResponseParams@" "$@")
37 return 0
38 else