2018-09-01 21:30:41 +01:00
|
|
|
{ stdenv, lib, buildPackages
|
2019-11-02 15:47:38 +00:00
|
|
|
, fetchFromGitHub, fetchurl, zlib, autoreconfHook, gettext
|
2018-09-01 21:30:41 +01:00
|
|
|
# Enabling all targets increases output size to a multiple.
|
|
|
|
, withAllTargets ? false, libbfd, libopcodes
|
2020-12-20 06:11:26 +00:00
|
|
|
, enableShared ? !stdenv.hostPlatform.isStatic
|
2019-05-11 02:49:26 +01:00
|
|
|
, noSysDirs
|
2021-01-15 00:06:22 +00:00
|
|
|
, gold ? true
|
2019-05-11 02:49:26 +01:00
|
|
|
, bison ? null
|
2019-11-02 15:47:38 +00:00
|
|
|
, flex
|
|
|
|
, texinfo
|
2020-06-08 22:01:59 +01:00
|
|
|
, perl
|
2014-01-07 12:57:42 +00:00
|
|
|
}:
|
2004-03-09 17:16:02 +00:00
|
|
|
|
2020-06-26 21:44:45 +01:00
|
|
|
# Note: this package is used for bootstrapping fetchurl, and thus
|
|
|
|
# cannot use fetchpatch! All mutable patches (generated by GitHub or
|
|
|
|
# cgit) that are needed here should be included directly in Nixpkgs as
|
|
|
|
# files.
|
|
|
|
|
2017-06-04 01:28:05 +01:00
|
|
|
let
|
2018-09-01 21:30:41 +01:00
|
|
|
reuseLibs = enableShared && withAllTargets;
|
|
|
|
|
2021-01-05 03:52:46 +00:00
|
|
|
version = "2.35.1";
|
2019-11-24 17:43:43 +00:00
|
|
|
basename = "binutils";
|
2017-11-25 18:43:57 +00:00
|
|
|
# The targetPrefix prepended to binary names to allow multiple binuntils on the
|
2017-06-23 22:45:27 +01:00
|
|
|
# PATH to both be usable.
|
2018-09-01 21:30:41 +01:00
|
|
|
targetPrefix = lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform)
|
|
|
|
"${stdenv.targetPlatform.config}-";
|
2019-11-02 15:47:38 +00:00
|
|
|
vc4-binutils-src = fetchFromGitHub {
|
|
|
|
owner = "itszor";
|
|
|
|
repo = "binutils-vc4";
|
|
|
|
rev = "708acc851880dbeda1dd18aca4fd0a95b2573b36";
|
|
|
|
sha256 = "1kdrz6fki55lm15rwwamn74fnqpy0zlafsida2zymk76n3656c63";
|
|
|
|
};
|
2020-11-14 16:35:53 +00:00
|
|
|
# HACK to ensure that we preserve source from bootstrap binutils to not rebuild LLVM
|
|
|
|
normal-src = stdenv.__bootPackages.binutils-unwrapped.src or (fetchurl {
|
2019-11-25 20:59:05 +00:00
|
|
|
url = "mirror://gnu/binutils/${basename}-${version}.tar.bz2";
|
2021-01-05 03:52:46 +00:00
|
|
|
sha256 = "sha256-Mg56HQ9G/Nn0E/EEbiFsviO7K85t62xqYzBEJeSLGUI=";
|
2019-11-02 15:47:38 +00:00
|
|
|
});
|
2017-06-04 01:28:05 +01:00
|
|
|
in
|
2013-09-02 14:54:12 +01:00
|
|
|
|
2019-08-13 22:52:01 +01:00
|
|
|
stdenv.mkDerivation {
|
2019-11-24 17:43:43 +00:00
|
|
|
pname = targetPrefix + basename;
|
2020-11-14 16:35:53 +00:00
|
|
|
inherit version;
|
|
|
|
|
|
|
|
src = if stdenv.targetPlatform.isVc4 then vc4-binutils-src else normal-src;
|
2008-05-29 15:16:35 +01:00
|
|
|
|
|
|
|
patches = [
|
2014-01-07 12:57:42 +00:00
|
|
|
# Make binutils output deterministic by default.
|
2020-11-14 16:35:53 +00:00
|
|
|
./deterministic.patch
|
2014-03-08 20:57:18 +00:00
|
|
|
|
2017-11-19 03:30:43 +00:00
|
|
|
# Help bfd choose between elf32-littlearm, elf32-littlearm-symbian, and
|
|
|
|
# elf32-littlearm-vxworks in favor of the first.
|
|
|
|
# https://github.com/NixOS/nixpkgs/pull/30484#issuecomment-345472766
|
2020-11-14 16:35:53 +00:00
|
|
|
./disambiguate-arm-targets.patch
|
2017-10-26 21:00:37 +01:00
|
|
|
|
|
|
|
# For some reason bfd ld doesn't search DT_RPATH when cross-compiling. It's
|
|
|
|
# not clear why this behavior was decided upon but it has the unfortunate
|
|
|
|
# consequence that the linker will fail to find transitive dependencies of
|
|
|
|
# shared objects when cross-compiling. Consequently, we are forced to
|
|
|
|
# override this behavior, forcing ld to search DT_RPATH even when
|
|
|
|
# cross-compiling.
|
2020-11-14 16:35:53 +00:00
|
|
|
./always-search-rpath.patch
|
|
|
|
|
2021-03-18 16:19:07 +00:00
|
|
|
./CVE-2020-35448.patch
|
2020-11-14 16:35:53 +00:00
|
|
|
] ++ lib.optional stdenv.targetPlatform.isiOS ./support-ios.patch
|
|
|
|
++ # This patch was suggested by Nick Clifton to fix
|
|
|
|
# https://sourceware.org/bugzilla/show_bug.cgi?id=16177
|
|
|
|
# It can be removed when that 7-year-old bug is closed.
|
|
|
|
# This binutils bug causes GHC to emit broken binaries on armv7, and
|
|
|
|
# indeed GHC will refuse to compile with a binutils suffering from it. See
|
|
|
|
# this comment for more information:
|
|
|
|
# https://gitlab.haskell.org/ghc/ghc/issues/4210#note_78333
|
|
|
|
lib.optional stdenv.targetPlatform.isAarch32 ./R_ARM_COPY.patch;
|
2009-11-08 00:32:12 +00:00
|
|
|
|
2017-11-26 19:46:34 +00:00
|
|
|
outputs = [ "out" "info" "man" ];
|
2016-02-28 00:10:35 +00:00
|
|
|
|
2017-06-26 04:10:03 +01:00
|
|
|
depsBuildBuild = [ buildPackages.stdenv.cc ];
|
2018-04-16 00:22:08 +01:00
|
|
|
nativeBuildInputs = [
|
|
|
|
bison
|
2020-06-08 22:01:59 +01:00
|
|
|
perl
|
|
|
|
texinfo
|
2019-11-02 15:47:38 +00:00
|
|
|
] ++ (lib.optionals stdenv.targetPlatform.isiOS [
|
2019-01-20 18:03:00 +00:00
|
|
|
autoreconfHook
|
2020-06-08 22:01:59 +01:00
|
|
|
]) ++ lib.optionals stdenv.targetPlatform.isVc4 [ flex ];
|
2019-05-01 03:50:21 +01:00
|
|
|
buildInputs = [ zlib gettext ];
|
2010-12-12 23:35:16 +00:00
|
|
|
|
2004-03-29 18:23:01 +01:00
|
|
|
inherit noSysDirs;
|
2008-05-29 15:16:35 +01:00
|
|
|
|
|
|
|
preConfigure = ''
|
|
|
|
# Clear the default library search path.
|
|
|
|
if test "$noSysDirs" = "1"; then
|
2013-09-02 14:54:12 +01:00
|
|
|
echo 'NATIVE_LIB_DIRS=' >> ld/configure.tgt
|
2008-05-29 15:16:35 +01:00
|
|
|
fi
|
2010-01-19 17:41:54 +00:00
|
|
|
|
|
|
|
# Use symlinks instead of hard links to save space ("strip" in the
|
|
|
|
# fixup phase strips each hard link separately).
|
2014-01-07 13:55:55 +00:00
|
|
|
for i in binutils/Makefile.in gas/Makefile.in ld/Makefile.in gold/Makefile.in; do
|
2012-01-19 15:02:47 +00:00
|
|
|
sed -i "$i" -e 's|ln |ln -s |'
|
2010-01-19 17:41:54 +00:00
|
|
|
done
|
2008-05-29 15:16:35 +01:00
|
|
|
'';
|
2009-11-08 00:32:12 +00:00
|
|
|
|
2011-10-25 19:35:17 +01:00
|
|
|
# As binutils takes part in the stdenv building, we don't want references
|
|
|
|
# to the bootstrap-tools libgcc (as uses to happen on arm/mips)
|
2018-08-20 19:43:41 +01:00
|
|
|
NIX_CFLAGS_COMPILE = if stdenv.hostPlatform.isDarwin
|
2015-06-12 01:58:26 +01:00
|
|
|
then "-Wno-string-plus-int -Wno-deprecated-declarations"
|
|
|
|
else "-static-libgcc";
|
2011-10-25 19:35:17 +01:00
|
|
|
|
2018-11-10 19:49:36 +00:00
|
|
|
hardeningDisable = [ "format" "pie" ];
|
2018-06-13 03:54:10 +01:00
|
|
|
|
2017-11-25 18:43:57 +00:00
|
|
|
# TODO(@Ericson2314): Always pass "--target" and always targetPrefix.
|
2018-09-01 21:30:41 +01:00
|
|
|
configurePlatforms = [ "build" "host" ] ++ lib.optional (stdenv.targetPlatform != stdenv.hostPlatform) "target";
|
2017-08-18 18:00:24 +01:00
|
|
|
|
2018-09-01 21:30:41 +01:00
|
|
|
configureFlags =
|
|
|
|
(if enableShared then [ "--enable-shared" "--disable-static" ]
|
|
|
|
else [ "--disable-shared" "--enable-static" ])
|
|
|
|
++ lib.optional withAllTargets "--enable-targets=all"
|
|
|
|
++ [
|
2018-09-01 17:13:31 +01:00
|
|
|
"--enable-64-bit-bfd"
|
2017-10-17 21:44:24 +01:00
|
|
|
"--with-system-zlib"
|
|
|
|
|
|
|
|
"--enable-deterministic-archives"
|
|
|
|
"--disable-werror"
|
|
|
|
"--enable-fix-loongson2f-nop"
|
Enable new dtags in a way that works with binutils 2.30.
In 3027bca, binutils was upgraded from 2.28.1 to 2.30. However, in 2.30,
the ldmain.c file within binutils, which the nixpkgs new-dtags.patch
file is meant to modify, was changed in such a way that the patch no
longer works. As a result, the new dtags are not actually enabled, and
binaries are built with RPATH set instead of RUNPATH, thereby preventing
LD_LIBRARY_PATH from overriding this built-in path. This change corrects
this. The patch file is no longer necessary because binutils's ldmain.c
now sets link_info.new_dtags based on the configuration flags.
This was probably not noticed immediately because, when the derivation
is built with nix-build, the fixupPhase runs patchelf --shrink-rpath.
patchelf converts any RPATH in the binary into RUNPATH (unless
--force-rpath is specified). Of course, if the binary is built without
nix-build (such as in a nix-shell), this never occurs, and any RPATH in
the binary is left in place.
2018-07-14 16:32:10 +01:00
|
|
|
|
|
|
|
# Turn on --enable-new-dtags by default to make the linker set
|
|
|
|
# RUNPATH instead of RPATH on binaries. This is important because
|
|
|
|
# RUNPATH can be overriden using LD_LIBRARY_PATH at runtime.
|
|
|
|
"--enable-new-dtags"
|
2018-09-01 21:30:41 +01:00
|
|
|
] ++ lib.optionals gold [ "--enable-gold" "--enable-plugins" ];
|
2007-04-28 00:30:07 +01:00
|
|
|
|
2018-04-25 04:20:18 +01:00
|
|
|
doCheck = false; # fails
|
|
|
|
|
2018-09-01 21:30:41 +01:00
|
|
|
postFixup = lib.optionalString reuseLibs ''
|
|
|
|
rm "$out"/lib/lib{bfd,opcodes}-${version}.so
|
|
|
|
ln -s '${lib.getLib libbfd}/lib/libbfd-${version}.so' "$out/lib/"
|
|
|
|
ln -s '${lib.getLib libopcodes}/lib/libopcodes-${version}.so' "$out/lib/"
|
|
|
|
'';
|
|
|
|
|
2018-08-08 22:09:49 +01:00
|
|
|
# else fails with "./sanity.sh: line 36: $out/bin/size: not found"
|
2018-08-20 19:43:41 +01:00
|
|
|
doInstallCheck = stdenv.buildPlatform == stdenv.hostPlatform && stdenv.hostPlatform == stdenv.targetPlatform;
|
2018-08-08 22:09:49 +01:00
|
|
|
|
2011-12-14 14:31:56 +00:00
|
|
|
enableParallelBuilding = true;
|
2013-09-02 14:54:12 +01:00
|
|
|
|
2017-06-23 22:45:27 +01:00
|
|
|
passthru = {
|
2020-11-14 16:35:53 +00:00
|
|
|
inherit targetPrefix;
|
2017-06-23 22:45:27 +01:00
|
|
|
};
|
|
|
|
|
2018-09-01 21:30:41 +01:00
|
|
|
meta = with lib; {
|
2014-08-24 15:21:08 +01:00
|
|
|
description = "Tools for manipulating binaries (linker, assembler, etc.)";
|
2009-02-03 19:36:56 +00:00
|
|
|
longDescription = ''
|
|
|
|
The GNU Binutils are a collection of binary tools. The main
|
|
|
|
ones are `ld' (the GNU linker) and `as' (the GNU assembler).
|
|
|
|
They also include the BFD (Binary File Descriptor) library,
|
|
|
|
`gprof', `nm', `strip', etc.
|
|
|
|
'';
|
2020-04-01 02:11:51 +01:00
|
|
|
homepage = "https://www.gnu.org/software/binutils/";
|
2016-01-25 10:16:23 +00:00
|
|
|
license = licenses.gpl3Plus;
|
2017-11-14 15:49:30 +00:00
|
|
|
maintainers = with maintainers; [ ericson2314 ];
|
2016-01-25 10:16:23 +00:00
|
|
|
platforms = platforms.unix;
|
2007-04-28 00:30:07 +01:00
|
|
|
|
|
|
|
/* Give binutils a lower priority than gcc-wrapper to prevent a
|
|
|
|
collision due to the ld/as wrappers/symlinks in the latter. */
|
2017-04-29 04:02:37 +01:00
|
|
|
priority = 10;
|
2007-04-28 00:30:07 +01:00
|
|
|
};
|
2012-03-12 15:34:00 +00:00
|
|
|
}
|