diff --git a/lib/systems/default.nix b/lib/systems/default.nix index 534af380738d2..f24156eecfbcd 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -490,13 +490,6 @@ let } .${cpu.name} or cpu.name; vendor_ = final.rust.platform.vendor; - abi_ = - # We're very explicit about the POWER ELF ABI w/ glibc in our parsing, while Rust is not. - # TODO: Somehow ensure that Rust actually *uses* the correct ABI, and not just a libc-based default. - if (lib.strings.hasPrefix "powerpc" cpu.name) && (lib.strings.hasPrefix "gnuabielfv" abi.name) then - "gnu" - else - abi.name; in # TODO: deprecate args.rustc in favour of args.rust after 23.05 is EOL. args.rust.rustcTarget or args.rustc.config or ( @@ -507,7 +500,7 @@ let if final.isWasi then "${cpu_}-wasip1" else - "${cpu_}-${vendor_}-${kernel.name}${optionalString (abi.name != "unknown") "-${abi_}"}" + "${cpu_}-${vendor_}-${kernel.name}${optionalString (abi.name != "unknown") "-${abi.name}"}" ); # The name of the rust target if it is standard, or the json file diff --git a/lib/systems/examples.nix b/lib/systems/examples.nix index 64f329f2a3db9..376af5701065e 100644 --- a/lib/systems/examples.nix +++ b/lib/systems/examples.nix @@ -22,10 +22,12 @@ rec { }; ppc64-elfv1 = { - config = "powerpc64-unknown-linux-gnuabielfv1"; + # system instead of config, need environment to get parsed during pkgsCross + system = "powerpc64-unknown-linux-gnuabielfv1"; }; ppc64-elfv2 = { - config = "powerpc64-unknown-linux-gnuabielfv2"; + # system instead of config, need environment to get parsed during pkgsCross + system = "powerpc64-unknown-linux-gnuabielfv2"; }; ppc64 = ppc64-elfv2; ppc64-musl = { diff --git a/lib/systems/inspect.nix b/lib/systems/inspect.nix index 0a8e1ac8e7026..aad545c3dfa55 100644 --- a/lib/systems/inspect.nix +++ b/lib/systems/inspect.nix @@ -69,8 +69,8 @@ rec { abi = "elfv1"; }; }; - # This ABI is the default in NixOS PowerPC64 BE, but not on mainline GCC, - # so it sometimes causes issues in certain packages that makes the wrong + # This ABI is not the default when building mainline GCC against glibc, + # so it sometimes causes issues in certain packages that make the wrong # assumption on the used ABI. isAbiElfv2 = [ { diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index 86f8c169d9019..b18d9fdc1e40f 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -727,10 +727,13 @@ rec { abi = "n32"; }; + # Clang does not understand these, ABI set via .gcc.abi & cc-wrapper gnuabielfv2 = { + name = "gnu"; abi = "elfv2"; }; gnuabielfv1 = { + name = "gnu"; abi = "elfv1"; }; diff --git a/lib/systems/platforms.nix b/lib/systems/platforms.nix index d34eed4c38b9f..070c555bc6aff 100644 --- a/lib/systems/platforms.nix +++ b/lib/systems/platforms.nix @@ -6,6 +6,21 @@ # optional fields; currently these are: linux-kernel, gcc, and rustc. { lib }: +let + ppc64ForAbi = abi: { + linux-kernel = { + name = "powerpc64"; + + baseConfig = "ppc64_defconfig"; + target = "vmlinux"; + autoModules = true; + }; + + gcc = { + inherit abi; + }; + }; +in rec { pc = { linux-kernel = { @@ -36,15 +51,8 @@ rec { }; }; - ppc64 = { - linux-kernel = { - name = "powerpc64"; - - baseConfig = "ppc64_defconfig"; - target = "vmlinux"; - autoModules = true; - }; - }; + ppc64-elfv1 = ppc64ForAbi "elfv1"; + ppc64-elfv2 = ppc64ForAbi "elfv2"; ## ## ARM @@ -630,7 +638,12 @@ rec { (import ./examples.nix { inherit lib; }).mipsel-linux-gnu else if platform.isPower64 then - if platform.isLittleEndian then powernv else ppc64 + if platform.isLittleEndian then + powernv + else if platform.isAbiElfv2 then + ppc64-elfv2 + else + ppc64-elfv1 else if platform.isLoongArch64 then loongarch64-multiplatform diff --git a/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh b/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh index 865e0d0548203..0340657a6ad60 100644 --- a/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh +++ b/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh @@ -30,10 +30,6 @@ if $targetPassed && [[ "$targetValue" != "@defaultTarget@" ]] && (( "${NIX_CC_WR echo "Warning: supplying the --target $targetValue != @defaultTarget@ argument to a nix-wrapped compiler may not work correctly - cc-wrapper is currently not designed with multi-target compilers in mind. You may want to use an un-wrapped compiler instead." >&2 elif [[ $0 != *cpp ]]; then extraBefore+=(-target @defaultTarget@ @machineFlags@) - - if [[ "@explicitAbiValue@" != "" ]]; then - extraBefore+=(-mabi=@explicitAbiValue@) - fi fi if [[ "@darwinMinVersion@" ]]; then diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 808fe5db27808..010f289102bcf 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -93,14 +93,12 @@ let getLib getName getVersion - hasPrefix mapAttrsToList optional optionalAttrs optionals optionalString removePrefix - removeSuffix replaceStrings toList versionAtLeast @@ -331,6 +329,7 @@ let optional ( targetPlatform ? gcc.cpu && !(targetPlatform.isDarwin && targetPlatform.isAarch64) ) "-mcpu=${targetPlatform.gcc.cpu}" + ++ optional (targetPlatform ? gcc.abi) "-mabi=${targetPlatform.gcc.abi}" ++ # -mfloat-abi only matters on arm32 but we set it here # unconditionally just in case. If the abi specifically sets hard @@ -942,24 +941,12 @@ stdenvNoCC.mkDerivation { ## General Clang support ## Needs to go after ^ because the for loop eats \n and makes this file an invalid script ## - + optionalString isClang ( - let - hasUnsupportedGnuSuffix = hasPrefix "gnuabielfv" targetPlatform.parsed.abi.name; - clangCompatibleConfig = - if hasUnsupportedGnuSuffix then - removeSuffix (removePrefix "gnu" targetPlatform.parsed.abi.name) targetPlatform.config - else - targetPlatform.config; - explicitAbiValue = if hasUnsupportedGnuSuffix then targetPlatform.parsed.abi.abi else ""; - in - '' - # Escape twice: once for this script, once for the one it gets substituted into. - export machineFlags=${escapeShellArg (escapeShellArgs machineFlags)} - export defaultTarget=${clangCompatibleConfig} - export explicitAbiValue=${explicitAbiValue} - substituteAll ${./add-clang-cc-cflags-before.sh} $out/nix-support/add-local-cc-cflags-before.sh - '' - ) + + optionalString isClang '' + # Escape twice: once for this script, once for the one it gets substituted into. + export machineFlags=${escapeShellArg (escapeShellArgs machineFlags)} + export defaultTarget=${targetPlatform.config} + substituteAll ${./add-clang-cc-cflags-before.sh} $out/nix-support/add-local-cc-cflags-before.sh + '' ## ## Extra custom steps