nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ stdenv, buildPackages
2, fetchurl, zlib
3, buildPlatform, hostPlatform, targetPlatform
4, noSysDirs, gold ? true, bison ? null
5}:
6
7let
8 # Note to whoever is upgrading this: 2.29 is broken.
9 # ('nix-build pkgs/stdenv/linux/make-bootstrap-tools.nix -A test' segfaults on aarch64)
10 # Also glibc might need patching, see commit 733e20fee4a6700510f71fbe1a58ac23ea202f6a.
11 version = "2.28.1";
12 basename = "binutils-${version}";
13 inherit (stdenv.lib) optional optionals optionalString;
14 # The prefix prepended to binary names to allow multiple binuntils on the
15 # PATH to both be usable.
16 prefix = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-";
17in
18
19stdenv.mkDerivation rec {
20 name = prefix + basename;
21
22 src = fetchurl {
23 url = "mirror://gnu/binutils/${basename}.tar.bz2";
24 sha256 = "1sj234nd05cdgga1r36zalvvdkvpfbr12g5mir2n8i1dwsdrj939";
25 };
26
27 patches = [
28 # Turn on --enable-new-dtags by default to make the linker set
29 # RUNPATH instead of RPATH on binaries. This is important because
30 # RUNPATH can be overriden using LD_LIBRARY_PATH at runtime.
31 ./new-dtags.patch
32
33 # Since binutils 2.22, DT_NEEDED flags aren't copied for dynamic outputs.
34 # That requires upstream changes for things to work. So we can patch it to
35 # get the old behaviour by now.
36 ./dtneeded.patch
37
38 # Make binutils output deterministic by default.
39 ./deterministic.patch
40
41 # Always add PaX flags section to ELF files.
42 # This is needed, for instance, so that running "ldd" on a binary that is
43 # PaX-marked to disable mprotect doesn't fail with permission denied.
44 ./pt-pax-flags.patch
45
46 # Bfd looks in BINDIR/../lib for some plugins that don't
47 # exist. This is pointless (since users can't install plugins
48 # there) and causes a cycle between the lib and bin outputs, so
49 # get rid of it.
50 ./no-plugins.patch
51 ];
52
53 outputs = [ "out" ]
54 ++ optional (targetPlatform == hostPlatform && !hostPlatform.isDarwin) "lib" # problems in Darwin stdenv
55 ++ [ "info" ]
56 ++ optional (targetPlatform == hostPlatform) "dev";
57
58 nativeBuildInputs = [ bison ]
59 ++ optional (hostPlatform != buildPlatform) buildPackages.stdenv.cc;
60 buildInputs = [ zlib ];
61
62 inherit noSysDirs;
63
64 # FIXME needs gcc 4.9 in bootstrap tools
65 hardeningDisable = [ "stackprotector" ];
66
67 preConfigure = ''
68 # Clear the default library search path.
69 if test "$noSysDirs" = "1"; then
70 echo 'NATIVE_LIB_DIRS=' >> ld/configure.tgt
71 fi
72
73 # Use symlinks instead of hard links to save space ("strip" in the
74 # fixup phase strips each hard link separately).
75 for i in binutils/Makefile.in gas/Makefile.in ld/Makefile.in gold/Makefile.in; do
76 sed -i "$i" -e 's|ln |ln -s |'
77 done
78 '';
79
80 # As binutils takes part in the stdenv building, we don't want references
81 # to the bootstrap-tools libgcc (as uses to happen on arm/mips)
82 NIX_CFLAGS_COMPILE = if hostPlatform.isDarwin
83 then "-Wno-string-plus-int -Wno-deprecated-declarations"
84 else "-static-libgcc";
85
86 # TODO(@Ericson2314): Always pass "--target" and always prefix.
87 configurePlatforms =
88 # TODO(@Ericson2314): Figure out what's going wrong with Arm
89 if hostPlatform == targetPlatform && targetPlatform.isArm
90 then []
91 else [ "build" "host" ] ++ stdenv.lib.optional (targetPlatform != hostPlatform) "target";
92
93 configureFlags =
94 [ "--enable-shared" "--enable-deterministic-archives" "--disable-werror" ]
95 ++ optional (stdenv.system == "mips64el-linux") "--enable-fix-loongson2f-nop"
96 ++ optionals gold [ "--enable-gold" "--enable-plugins" ]
97 ++ optional (stdenv.system == "i686-linux") "--enable-targets=x86_64-linux-gnu";
98
99 enableParallelBuilding = true;
100
101 passthru = {
102 inherit prefix;
103 };
104
105 meta = with stdenv.lib; {
106 description = "Tools for manipulating binaries (linker, assembler, etc.)";
107 longDescription = ''
108 The GNU Binutils are a collection of binary tools. The main
109 ones are `ld' (the GNU linker) and `as' (the GNU assembler).
110 They also include the BFD (Binary File Descriptor) library,
111 `gprof', `nm', `strip', etc.
112 '';
113 homepage = http://www.gnu.org/software/binutils/;
114 license = licenses.gpl3Plus;
115 platforms = platforms.unix;
116
117 /* Give binutils a lower priority than gcc-wrapper to prevent a
118 collision due to the ld/as wrappers/symlinks in the latter. */
119 priority = 10;
120 };
121}