From cc44e04472bf8d0774e09a6cc4bd47175e531b8e Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 27 Nov 2017 00:12:13 -0500 Subject: bintools-wrapper: Define fallback default emulation This ensures we by-default cross-compile to the intended platform. --- pkgs/build-support/bintools-wrapper/default.nix | 14 ++++++++++++++ pkgs/build-support/bintools-wrapper/ld-wrapper.sh | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index 0dcae204824d..57859b2f371b 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 136621d27af5..991ed0fe263c 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 -- cgit 1.4.1