nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at 20.03 167 lines 6.4 kB view raw
1{ stdenv, lib, buildPackages 2, fetchFromGitHub, fetchurl, zlib, autoreconfHook, gettext 3# Enabling all targets increases output size to a multiple. 4, withAllTargets ? false, libbfd, libopcodes 5, enableShared ? true 6, noSysDirs 7, gold ? !stdenv.buildPlatform.isDarwin || stdenv.hostPlatform == stdenv.targetPlatform 8, bison ? null 9, flex 10, texinfo 11}: 12 13let 14 reuseLibs = enableShared && withAllTargets; 15 16 # Remove gold-symbol-visibility patch when updating, the proper fix 17 # is now upstream. 18 # https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=330b90b5ffbbc20c5de6ae6c7f60c40fab2e7a4f;hp=99181ccac0fc7d82e7dabb05dc7466e91f1645d3 19 version = "2.31.1"; 20 basename = "binutils"; 21 # The targetPrefix prepended to binary names to allow multiple binuntils on the 22 # PATH to both be usable. 23 targetPrefix = lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) 24 "${stdenv.targetPlatform.config}-"; 25 vc4-binutils-src = fetchFromGitHub { 26 owner = "itszor"; 27 repo = "binutils-vc4"; 28 rev = "708acc851880dbeda1dd18aca4fd0a95b2573b36"; 29 sha256 = "1kdrz6fki55lm15rwwamn74fnqpy0zlafsida2zymk76n3656c63"; 30 }; 31 # HACK to ensure that we preserve source from bootstrap binutils to not rebuild LLVM 32 normal-src = stdenv.__bootPackages.binutils-unwrapped.src or (fetchurl { 33 url = "mirror://gnu/binutils/${basename}-${version}.tar.bz2"; 34 sha256 = "1l34hn1zkmhr1wcrgf0d4z7r3najxnw3cx2y2fk7v55zjlk3ik7z"; 35 }); 36in 37 38stdenv.mkDerivation { 39 pname = targetPrefix + basename; 40 inherit version; 41 42 src = if stdenv.targetPlatform.isVc4 then vc4-binutils-src else normal-src; 43 44 patches = [ 45 # Make binutils output deterministic by default. 46 ./deterministic.patch 47 48 # Bfd looks in BINDIR/../lib for some plugins that don't 49 # exist. This is pointless (since users can't install plugins 50 # there) and causes a cycle between the lib and bin outputs, so 51 # get rid of it. 52 ./no-plugins.patch 53 54 # Help bfd choose between elf32-littlearm, elf32-littlearm-symbian, and 55 # elf32-littlearm-vxworks in favor of the first. 56 # https://github.com/NixOS/nixpkgs/pull/30484#issuecomment-345472766 57 ./disambiguate-arm-targets.patch 58 59 # For some reason bfd ld doesn't search DT_RPATH when cross-compiling. It's 60 # not clear why this behavior was decided upon but it has the unfortunate 61 # consequence that the linker will fail to find transitive dependencies of 62 # shared objects when cross-compiling. Consequently, we are forced to 63 # override this behavior, forcing ld to search DT_RPATH even when 64 # cross-compiling. 65 ./always-search-rpath.patch 66 67 ] ++ lib.optionals (!stdenv.targetPlatform.isVc4) 68 [ 69 # https://sourceware.org/bugzilla/show_bug.cgi?id=22868 70 ./gold-symbol-visibility.patch 71 72 # https://sourceware.org/bugzilla/show_bug.cgi?id=23428 73 # un-break features so linking against musl doesn't produce crash-only binaries 74 ./0001-x86-Add-a-GNU_PROPERTY_X86_ISA_1_USED-note-if-needed.patch 75 ./0001-x86-Properly-merge-GNU_PROPERTY_X86_ISA_1_USED.patch 76 ./0001-x86-Properly-add-X86_ISA_1_NEEDED-property.patch 77 ] ++ lib.optional stdenv.targetPlatform.isiOS ./support-ios.patch; 78 79 outputs = [ "out" "info" "man" ]; 80 81 depsBuildBuild = [ buildPackages.stdenv.cc ]; 82 nativeBuildInputs = [ 83 bison 84 ] ++ (lib.optionals stdenv.targetPlatform.isiOS [ 85 autoreconfHook 86 ]) ++ lib.optionals stdenv.targetPlatform.isVc4 [ texinfo flex ]; 87 buildInputs = [ zlib gettext ]; 88 89 inherit noSysDirs; 90 91 preConfigure = '' 92 # Clear the default library search path. 93 if test "$noSysDirs" = "1"; then 94 echo 'NATIVE_LIB_DIRS=' >> ld/configure.tgt 95 fi 96 97 # Use symlinks instead of hard links to save space ("strip" in the 98 # fixup phase strips each hard link separately). 99 for i in binutils/Makefile.in gas/Makefile.in ld/Makefile.in gold/Makefile.in; do 100 sed -i "$i" -e 's|ln |ln -s |' 101 done 102 ''; 103 104 # As binutils takes part in the stdenv building, we don't want references 105 # to the bootstrap-tools libgcc (as uses to happen on arm/mips) 106 NIX_CFLAGS_COMPILE = if stdenv.hostPlatform.isDarwin 107 then "-Wno-string-plus-int -Wno-deprecated-declarations" 108 else "-static-libgcc"; 109 110 hardeningDisable = [ "format" "pie" ]; 111 112 # TODO(@Ericson2314): Always pass "--target" and always targetPrefix. 113 configurePlatforms = [ "build" "host" ] ++ lib.optional (stdenv.targetPlatform != stdenv.hostPlatform) "target"; 114 115 configureFlags = 116 (if enableShared then [ "--enable-shared" "--disable-static" ] 117 else [ "--disable-shared" "--enable-static" ]) 118 ++ lib.optional withAllTargets "--enable-targets=all" 119 ++ [ 120 "--enable-64-bit-bfd" 121 "--with-system-zlib" 122 123 "--enable-deterministic-archives" 124 "--disable-werror" 125 "--enable-fix-loongson2f-nop" 126 127 # Turn on --enable-new-dtags by default to make the linker set 128 # RUNPATH instead of RPATH on binaries. This is important because 129 # RUNPATH can be overriden using LD_LIBRARY_PATH at runtime. 130 "--enable-new-dtags" 131 ] ++ lib.optionals gold [ "--enable-gold" "--enable-plugins" ]; 132 133 doCheck = false; # fails 134 135 postFixup = lib.optionalString reuseLibs '' 136 rm "$out"/lib/lib{bfd,opcodes}-${version}.so 137 ln -s '${lib.getLib libbfd}/lib/libbfd-${version}.so' "$out/lib/" 138 ln -s '${lib.getLib libopcodes}/lib/libopcodes-${version}.so' "$out/lib/" 139 ''; 140 141 # else fails with "./sanity.sh: line 36: $out/bin/size: not found" 142 doInstallCheck = stdenv.buildPlatform == stdenv.hostPlatform && stdenv.hostPlatform == stdenv.targetPlatform; 143 144 enableParallelBuilding = true; 145 146 passthru = { 147 inherit targetPrefix; 148 }; 149 150 meta = with lib; { 151 description = "Tools for manipulating binaries (linker, assembler, etc.)"; 152 longDescription = '' 153 The GNU Binutils are a collection of binary tools. The main 154 ones are `ld' (the GNU linker) and `as' (the GNU assembler). 155 They also include the BFD (Binary File Descriptor) library, 156 `gprof', `nm', `strip', etc. 157 ''; 158 homepage = https://www.gnu.org/software/binutils/; 159 license = licenses.gpl3Plus; 160 maintainers = with maintainers; [ ericson2314 ]; 161 platforms = platforms.unix; 162 163 /* Give binutils a lower priority than gcc-wrapper to prevent a 164 collision due to the ld/as wrappers/symlinks in the latter. */ 165 priority = 10; 166 }; 167}