@@ -6,18 +6,17 @@
66# compiler and the linker just "work".
77
88{ name ? "", stdenvNoCC, nativeTools, noLibc ? false, nativeLibc, nativePrefix ? ""
9−, cc ? null, libc ? null, binutils ? null, coreutils ? null, shell ? stdenvNoCC.shell
9+, cc ? null, libc ? null, bintools, coreutils ? null, shell ? stdenvNoCC.shell
1010, zlib ? null, extraPackages ? [], extraBuildCommands ? ""
1111, isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null
1212, buildPackages ? {}
13−, useMacosReexportHack ? false
1413}:
1514
1615with stdenvNoCC.lib;
1716
1817assert nativeTools -> nativePrefix != "";
1918assert !nativeTools ->
20− cc != null && binutils != null && coreutils != null && gnugrep != null;
19+ cc != null && coreutils != null && gnugrep != null;
2120assert !(nativeLibc && noLibc);
2221assert (noLibc || nativeLibc) == (libc == null);
2322
@@ -42,7 +41,6 @@ let
4241 libc_dev = if libc == null then null else getDev libc;
4342 libc_lib = if libc == null then null else getLib libc;
4443 cc_solib = getLib cc;
45− binutils_bin = if nativeTools then "" else getBin binutils;
4644 # The wrapper scripts use 'cat' and 'grep', so we may need coreutils.
4745 coreutils_bin = if nativeTools then "" else getBin coreutils;
4846
@@ -58,21 +56,6 @@ let
5856 # unstable implementation detail, however.
5957 infixSalt = dashlessTarget;
6058
61− # The dynamic linker has different names on different platforms. This is a
62− # shell glob that ought to match it.
63− dynamicLinker =
64− /**/ if libc == null then null
65− else if targetPlatform.system == "i686-linux" then "${libc_lib}/lib/ld-linux.so.2"
66− else if targetPlatform.system == "x86_64-linux" then "${libc_lib}/lib/ld-linux-x86-64.so.2"
67− # ARM with a wildcard, which can be "" or "-armhf".
68− else if (with targetPlatform; isArm && isLinux) then "${libc_lib}/lib/ld-linux*.so.3"
69− else if targetPlatform.system == "aarch64-linux" then "${libc_lib}/lib/ld-linux-aarch64.so.1"
70− else if targetPlatform.system == "powerpc-linux" then "${libc_lib}/lib/ld.so.1"
71− else if targetPlatform.system == "mips64el-linux" then "${libc_lib}/lib/ld.so.1"
72− else if targetPlatform.isDarwin then "/usr/lib/dyld"
73− else if stdenv.lib.hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1"
74− else null;
75−
7659 expand-response-params =
7760 if buildPackages.stdenv.cc or null != null && buildPackages.stdenv.cc != "/dev/null"
7861 then import ../expand-response-params { inherit (buildPackages) stdenv; }
@@ -80,6 +63,14 @@ let
8063
8164in
8265
66+# Ensure bintools matches
67+assert libc_bin == bintools.libc_bin;
68+assert libc_dev == bintools.libc_dev;
69+assert libc_lib == bintools.libc_lib;
70+assert nativeTools == bintools.nativeTools;
71+assert nativeLibc == bintools.nativeLibc;
72+assert nativePrefix == bintools.nativePrefix;
73+
8374stdenv.mkDerivation {
8475 name = targetPrefix
8576 + (if name != "" then name else "${ccName}-wrapper")
@@ -87,8 +78,8 @@ stdenv.mkDerivation {
8778
8879 preferLocalBuild = true;
8980
90− inherit cc libc_bin libc_dev libc_lib binutils_bin coreutils_bin;
91− shell = getBin shell + shell.shellPath or "";
81+ inherit cc libc_bin libc_dev libc_lib bintools coreutils_bin;
82+ shell = getBin shell + stdenv.lib.optionalString (stdenv ? shellPath) stdenv.shellPath;
9283 gnugrep_bin = if nativeTools then "" else gnugrep;
9384
9485 inherit targetPrefix infixSalt;
@@ -98,20 +89,18 @@ stdenv.mkDerivation {
9889 passthru = {
9990 # "cc" is the generic name for a C compiler, but there is no one for package
10091 # providing the linker and related tools. The two we use now are GNU
101− # Binutils, and Apple's "cctools"; "binutils" as an attempt to find an
92+ # Binutils, and Apple's "cctools"; "bintools" as an attempt to find an
10293 # unused middle-ground name that evokes both.
103− bintools = binutils_bin;
94+ inherit bintools;
10495 inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile;
10596
10697 emacsBufferSetup = pkgs: ''
10798 ; We should handle propagation here too
108− (mapc (lambda (arg)
109− (when (file-directory-p (concat arg "/include"))
110− (setenv "NIX_${infixSalt}_CFLAGS_COMPILE" (concat (getenv "NIX_${infixSalt}_CFLAGS_COMPILE") " -isystem " arg "/include")))
111− (when (file-directory-p (concat arg "/lib"))
112− (setenv "NIX_${infixSalt}_LDFLAGS" (concat (getenv "NIX_${infixSalt}_LDFLAGS") " -L" arg "/lib")))
113− (when (file-directory-p (concat arg "/lib64"))
114− (setenv "NIX_${infixSalt}_LDFLAGS" (concat (getenv "NIX_${infixSalt}_LDFLAGS") " -L" arg "/lib64")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)}))
99+ (mapc
100+ (lambda (arg)
101+ (when (file-directory-p (concat arg "/include"))
102+ (setenv "NIX_${infixSalt}_CFLAGS_COMPILE" (concat (getenv "NIX_${infixSalt}_CFLAGS_COMPILE") " -isystem " arg "/include"))))
103+ '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)}))
115104 '';
116105 };
117106
@@ -141,45 +130,18 @@ stdenv.mkDerivation {
141130 echo ${if targetPlatform.isDarwin then cc else nativePrefix} > $out/nix-support/orig-cc
142131
143132 ccPath="${if targetPlatform.isDarwin then cc else nativePrefix}/bin"
144− ldPath="${nativePrefix}/bin"
145133 '' else ''
146134 echo $cc > $out/nix-support/orig-cc
147135
148136 ccPath="${cc}/bin"
149− ldPath="${binutils_bin}/bin"
150− ''
151−
152− + optionalString (targetPlatform.isSunOS && nativePrefix != "") ''
153− # Solaris needs an additional ld wrapper.
154− ldPath="${nativePrefix}/bin"
155− exec="$ldPath/${targetPrefix}ld"
156− wrap ld-solaris ${./ld-solaris-wrapper.sh}
157137 '')
158138
159139 + ''
160− # Create a symlink to as (the assembler). This is useful when a
161− # cc-wrapper is installed in a user environment, as it ensures that
162− # the right assembler is called.
163− if [ -e $ldPath/${targetPrefix}as ]; then
164− ln -s $ldPath/${targetPrefix}as $out/bin/${targetPrefix}as
165− fi
166−
167− '' + (if !useMacosReexportHack then ''
168− wrap ${targetPrefix}ld ${./ld-wrapper.sh} ''${ld:-$ldPath/${targetPrefix}ld}
169− '' else ''
170− ldInner="${targetPrefix}ld-reexport-delegate"
171− wrap "$ldInner" ${./macos-sierra-reexport-hack.bash} ''${ld:-$ldPath/${targetPrefix}ld}
172− wrap "${targetPrefix}ld" ${./ld-wrapper.sh} "$out/bin/$ldInner"
173− unset ldInner
174− '') + ''
175−
176− if [ -e ${binutils_bin}/bin/${targetPrefix}ld.gold ]; then
177− wrap ${targetPrefix}ld.gold ${./ld-wrapper.sh} ${binutils_bin}/bin/${targetPrefix}ld.gold
178− fi
179−
180− if [ -e ${binutils_bin}/bin/ld.bfd ]; then
181− wrap ${targetPrefix}ld.bfd ${./ld-wrapper.sh} ${binutils_bin}/bin/${targetPrefix}ld.bfd
182− fi
140+ # Create symlinks to everything in the bintools wrapper.
141+ for bbin in $bintools/bin/*; do
142+ mkdir -p "$out/bin"
143+ ln -s "$bbin" "$out/bin/$(basename $bbin)"
144+ done
183145
184146 # We export environment variables pointing to the wrapped nonstandard
185147 # cmds, lest some lousy configure script use those to guess compiler
@@ -239,16 +201,28 @@ stdenv.mkDerivation {
239201 ln -s $ccPath/${targetPrefix}ghdl $out/bin/${targetPrefix}ghdl
240202 '';
241203
242− propagatedBuildInputs = extraPackages;
204+ propagatedBuildInputs = [ bintools ] ++ extraPackages;
243205
244206 setupHook = ./setup-hook.sh;
245207
246208 postFixup =
247209 ''
248210 set -u
211+
212+ # Backwards compatability for packages expecting this file, e.g. with
213+ # `$NIX_CC/nix-support/dynamic-linker`.
214+ #
215+ # TODO(@Ericson2314): Remove this after stable release and force
216+ # everyone to refer to bintools-wrapper directly.
217+ if [[ -f "$bintools/nix-support/dynamic-linker" ]]; then
218+ ln -s "$bintools/nix-support/dynamic-linker" "$out/nix-support"
219+ fi
220+ if [[ -f "$bintools/nix-support/dynamic-linker-m32" ]]; then
221+ ln -s "$bintools/nix-support/dynamic-linker-m32" "$out/nix-support"
222+ fi
249223 ''
250224
251− + optionalString (libc != null) (''
225+ + optionalString (libc != null) ''
252226 ##
253227 ## General libc support
254228 ##
@@ -264,50 +238,11 @@ stdenv.mkDerivation {
264238 # compile, because it uses "#include_next <limits.h>" to find the
265239 # limits.h file in ../includes-fixed. To remedy the problem,
266240 # another -idirafter is necessary to add that directory again.
267− echo "-B${libc_lib}/lib/ -idirafter ${libc_dev}/include -idirafter ${cc}/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags
268−
269− echo "-L${libc_lib}/lib" > $out/nix-support/libc-ldflags
241+ echo "-B${libc_lib}/lib/ -idirafter ${libc_dev}/include ${optionalString isGNU "-idirafter ${cc}/lib/gcc/*/*/include-fixed"}" > $out/nix-support/libc-cflags
270242
271243 echo "${libc_lib}" > $out/nix-support/orig-libc
272244 echo "${libc_dev}" > $out/nix-support/orig-libc-dev
273−
274− ##
275− ## Dynamic linker support
276− ##
277−
278− if [[ -z ''${dynamicLinker+x} ]]; then
279− echo "Don't know the name of the dynamic linker for platform '${targetPlatform.config}', so guessing instead." >&2
280− local dynamicLinker="${libc_lib}/lib/ld*.so.?"
281− fi
282−
283− # Expand globs to fill array of options
284− dynamicLinker=($dynamicLinker)
285−
286− case ''${#dynamicLinker[@]} in
287− 0) echo "No dynamic linker found for platform '${targetPlatform.config}'." >&2;;
288− 1) echo "Using dynamic linker: '$dynamicLinker'" >&2;;
289− *) echo "Multiple dynamic linkers found for platform '${targetPlatform.config}'." >&2;;
290− esac
291−
292− if [ -n "''${dynamicLinker:-}" ]; then
293− echo $dynamicLinker > $out/nix-support/dynamic-linker
294−
295− '' + (if targetPlatform.isDarwin then ''
296− printf "export LD_DYLD_PATH=%q\n" "$dynamicLinker" >> $out/nix-support/setup-hook
297− '' else ''
298− if [ -e ${libc_lib}/lib/32/ld-linux.so.2 ]; then
299− echo ${libc_lib}/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
300− fi
301−
302− local ldflagsBefore=(-dynamic-linker "$dynamicLinker")
303− '') + ''
304− fi
305−
306− # The dynamic linker is passed in `ldflagsBefore' to allow
307− # explicit overrides of the dynamic linker by callers to gcc/ld
308− # (the *last* value counts, so ours should come first).
309− printWords "''${ldflagsBefore[@]}" > $out/nix-support/libc-ldflags-before
310− '')
245+ ''
311246
312247 + optionalString (!nativeTools) ''
313248
@@ -348,7 +283,6 @@ stdenv.mkDerivation {
348283 # Propagate the wrapped cc so that if you install the wrapper,
349284 # you get tools like gcov, the manpages, etc. as well (including
350285 # for binutils and Glibc).
351− printWords ${cc} ${binutils_bin} ${if libc == null then "" else libc_bin} > $out/nix-support/propagated-user-env-packages
352286 printWords ${cc.man or ""} > $man/nix-support/propagated-user-env-packages
353287 ''
354288
@@ -358,14 +292,7 @@ stdenv.mkDerivation {
358292 ## Hardening support
359293 ##
360294
361− # some linkers on some platforms don't support specific -z flags
362295 export hardening_unsupported_flags=""
363− if [[ "$($ldPath/${targetPrefix}ld -z now 2>&1 || true)" =~ un(recognized|known)\ option ]]; then
364− hardening_unsupported_flags+=" bindnow"
365− fi
366− if [[ "$($ldPath/${targetPrefix}ld -z relro 2>&1 || true)" =~ un(recognized|known)\ option ]]; then
367− hardening_unsupported_flags+=" relro"
368− fi
369296 ''
370297
371298 + optionalString hostPlatform.isCygwin ''
@@ -384,7 +311,7 @@ stdenv.mkDerivation {
384311 ''
385312 + extraBuildCommands;
386313
387− inherit dynamicLinker expand-response-params;
314+ inherit expand-response-params;
388315
389316 # for substitution in utils.sh
390317 expandResponseParams = "${expand-response-params}/bin/expand-response-params";
@@ -395,7 +322,5 @@ stdenv.mkDerivation {
395322 { description =
396323 stdenv.lib.attrByPath ["meta" "description"] "System C compiler" cc_
397324 + " (wrapper script)";
398− } // optionalAttrs useMacosReexportHack {
399− platforms = stdenv.lib.platforms.darwin;
400325 };
401326}