diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index 0dcae204824..57859b2f371 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -164,6 +164,20 @@ stdenv.mkDerivation { set +u ''; + emulation = let + fmt = + /**/ if targetPlatform.isDarwin then "mach-o" + else if targetPlatform.isWindows then "pe" + else "elf" + toString targetPlatform.parsed.cpu.bits; + endianPrefix = if targetPlatform.isBigEndian then "big" else "little"; + arch = + /**/ if targetPlatform.isAarch64 then endianPrefix + "aarch64" + else if targetPlatform.isArm then endianPrefix + "arm" + else if targetPlatform.isx86_64 then "x86-64" + else if targetPlatform.isi686 then "i386" + else throw "unknown emulation for platform: " + targetPlatform.config; + in targetPlatform.platform.bfdEmulation or (fmt + "-" + arch); + propagatedBuildInputs = extraPackages; setupHook = ./setup-hook.sh; diff --git a/pkgs/build-support/bintools-wrapper/ld-wrapper.sh b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh index 136621d27af..991ed0fe263 100644 --- a/pkgs/build-support/bintools-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/bintools-wrapper/ld-wrapper.sh @@ -67,6 +67,11 @@ fi extraAfter+=($NIX_@infixSalt@_LDFLAGS_AFTER) +# Specify the target emulation if nothing is passed in ("-m" overrides this +# environment variable). Ensures we never blindly fallback on targeting the host +# platform. +: ${LDEMULATION:=@emulation@} + # Three tasks: # # 1. Find all -L... switches for rpath diff --git a/pkgs/development/tools/misc/binutils/always-search-rpath.patch b/pkgs/development/tools/misc/binutils/always-search-rpath.patch new file mode 100644 index 00000000000..2e9956e6b6e --- /dev/null +++ b/pkgs/development/tools/misc/binutils/always-search-rpath.patch @@ -0,0 +1,14 @@ +diff --git a/ld/genscripts.sh b/ld/genscripts.sh +index b6940d376d..0feb1adfd0 100755 +--- a/ld/genscripts.sh ++++ b/ld/genscripts.sh +@@ -125,6 +125,9 @@ if test "x$NATIVE" = "xyes" ; then + USE_LIBPATH=yes + fi + ++# TODO: why is this needed? ++USE_LIBPATH=yes ++ + # Set the library search path, for libraries named by -lfoo. + # If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used. + # Otherwise, the default is set here. diff --git a/pkgs/development/tools/misc/binutils/default.nix b/pkgs/development/tools/misc/binutils/default.nix index 7628e37ae1c..1b016652699 100644 --- a/pkgs/development/tools/misc/binutils/default.nix +++ b/pkgs/development/tools/misc/binutils/default.nix @@ -53,6 +53,14 @@ stdenv.mkDerivation rec { # elf32-littlearm-vxworks in favor of the first. # https://github.com/NixOS/nixpkgs/pull/30484#issuecomment-345472766 ./disambiguate-arm-targets.patch + + # 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. + ./always-search-rpath.patch ]; outputs = [ "out" "info" "man" ]; diff --git a/pkgs/stdenv/adapters.nix b/pkgs/stdenv/adapters.nix index 1a55b06ef36..f7d2c49a66d 100644 --- a/pkgs/stdenv/adapters.nix +++ b/pkgs/stdenv/adapters.nix @@ -74,8 +74,7 @@ rec { }; in stdenv // { mkDerivation = - { buildInputs ? [], nativeBuildInputs ? [] - , propagatedBuildInputs ? [], propagatedNativeBuildInputs ? [] + { nativeBuildInputs ? [] , selfNativeBuildInput ? args.crossAttrs.selfNativeBuildInput or false , ... } @ args: @@ -98,14 +97,6 @@ rec { ++ stdenv.lib.optional hostPlatform.isAarch64 pkgs.updateAutotoolsGnuConfigScriptsHook ; - # Cross-linking dynamic libraries, every buildInput should - # be propagated because ld needs the -rpath-link to find - # any library needed to link the program dynamically at - # loader time. ld(1) explains it. - buildInputs = []; - propagatedBuildInputs = propagatedBuildInputs ++ buildInputs; - propagatedNativeBuildInputs = propagatedNativeBuildInputs; - crossConfig = hostPlatform.config; } // args.crossAttrs or {}); };