From 72b3badb6197a042c52397fcea467f630628c75c Mon Sep 17 00:00:00 2001 From: Ryan Burns Date: Fri, 29 Jan 2021 19:23:04 -0800 Subject: [PATCH] lib.systems: add powerpc64-linux PPC64 supports two ABIs: ELF v1 and v2. ELFv1 is historically what GCC and most packages expect, but this is changing because musl outright does not work with ELFv1. So any distro which uses musl must use ELFv2. Many other platforms are moving to ELFv2 too, such as FreeBSD (as of v13) and Gentoo (as of late 2020). Since we use musl extensively, let's default to ELFv2. Nix gives us the power to specify this declaratively for the entire system, so ELFv1 is not dropped entirely. It can be specified explicitly in the target config, e.g. "powerpc64-unknown-linux-elfv1". Otherwise the default is "powerpc64-unknown-linux-elfv2". For musl, "powerpc64-unknown-linux-musl" must use elfv2 internally to function. --- lib/systems/doubles.nix | 5 +++-- lib/systems/examples.nix | 13 +++++++++++++ lib/systems/parse.nix | 9 +++++++++ lib/tests/systems.nix | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/systems/doubles.nix b/lib/systems/doubles.nix index b0bc7dd1188a..07327fa22736 100644 --- a/lib/systems/doubles.nix +++ b/lib/systems/doubles.nix @@ -24,6 +24,7 @@ let "x86_64-redox" + "powerpc64-linux" "powerpc64le-linux" "riscv32-linux" "riscv64-linux" @@ -72,7 +73,7 @@ in { darwin = filterDoubles predicates.isDarwin; freebsd = filterDoubles predicates.isFreeBSD; # Should be better, but MinGW is unclear. - gnu = filterDoubles (matchAttrs { kernel = parse.kernels.linux; abi = parse.abis.gnu; }) ++ filterDoubles (matchAttrs { kernel = parse.kernels.linux; abi = parse.abis.gnueabi; }) ++ filterDoubles (matchAttrs { kernel = parse.kernels.linux; abi = parse.abis.gnueabihf; }); + gnu = filterDoubles (matchAttrs { kernel = parse.kernels.linux; abi = parse.abis.gnu; }) ++ filterDoubles (matchAttrs { kernel = parse.kernels.linux; abi = parse.abis.gnueabi; }) ++ filterDoubles (matchAttrs { kernel = parse.kernels.linux; abi = parse.abis.gnueabihf; }) ++ filterDoubles (matchAttrs { kernel = parse.kernels.linux; abi = parse.abis.elfv1; }) ++ filterDoubles (matchAttrs { kernel = parse.kernels.linux; abi = parse.abis.elfv2; }); illumos = filterDoubles predicates.isSunOS; linux = filterDoubles predicates.isLinux; netbsd = filterDoubles predicates.isNetBSD; @@ -85,5 +86,5 @@ in { embedded = filterDoubles predicates.isNone; - mesaPlatforms = ["i686-linux" "x86_64-linux" "x86_64-darwin" "armv5tel-linux" "armv6l-linux" "armv7l-linux" "armv7a-linux" "aarch64-linux" "powerpc64le-linux"]; + mesaPlatforms = ["i686-linux" "x86_64-linux" "x86_64-darwin" "armv5tel-linux" "armv6l-linux" "armv7l-linux" "armv7a-linux" "aarch64-linux" "powerpc64-linux" "powerpc64le-linux"]; } diff --git a/lib/systems/examples.nix b/lib/systems/examples.nix index e8cf15479c05..fbb697f1fe1b 100644 --- a/lib/systems/examples.nix +++ b/lib/systems/examples.nix @@ -21,6 +21,19 @@ rec { config = "powerpc64le-unknown-linux-musl"; }; + ppc64-elfv1 = { + config = "powerpc64-unknown-linux-elfv1"; + }; + ppc64-elfv2 = { + config = "powerpc64-unknown-linux-elfv2"; + }; + ppc64 = ppc64-elfv2; # default to modern elfv2 + + ppc64-musl = { + config = "powerpc64-unknown-linux-musl"; + gcc = { abi = "elfv2"; }; # for gcc configuration + }; + sheevaplug = { config = "armv5tel-unknown-linux-gnueabi"; } // platforms.sheevaplug; diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix index a06ac0d11f74..8e012622ccd0 100644 --- a/lib/systems/parse.nix +++ b/lib/systems/parse.nix @@ -337,10 +337,18 @@ rec { The "gnu" ABI is ambiguous on 32-bit ARM. Use "gnueabi" or "gnueabihf" instead. ''; } + { assertion = platform: platform.system != "powerpc64-linux"; + message = '' + The "gnu" ABI is ambiguous on big-endian 64-bit PPC. Use "elfv1" or "elfv2" instead. + ''; + } ]; }; gnuabi64 = { abi = "64"; }; + elfv1 = { abi = "elfv1"; }; + elfv2 = { abi = "elfv2"; }; + musleabi = { float = "soft"; }; musleabihf = { float = "hard"; }; musl = {}; @@ -444,6 +452,7 @@ rec { if lib.versionAtLeast (parsed.cpu.version or "0") "6" then abis.gnueabihf else abis.gnueabi + else if cpu == "powerpc64" then abis.elfv2 else abis.gnu else abis.unknown; }; diff --git a/lib/tests/systems.nix b/lib/tests/systems.nix index eed7ee725bc4..c0800df25ed7 100644 --- a/lib/tests/systems.nix +++ b/lib/tests/systems.nix @@ -28,7 +28,7 @@ with lib.systems.doubles; lib.runTests { testredox = mseteq redox [ "x86_64-redox" ]; testgnu = mseteq gnu (linux /* ++ kfreebsd ++ ... */); testillumos = mseteq illumos [ "x86_64-solaris" ]; - testlinux = mseteq linux [ "aarch64-linux" "armv5tel-linux" "armv6l-linux" "armv7a-linux" "armv7l-linux" "i686-linux" "mipsel-linux" "riscv32-linux" "riscv64-linux" "x86_64-linux" "powerpc64le-linux" ]; + testlinux = mseteq linux [ "aarch64-linux" "armv5tel-linux" "armv6l-linux" "armv7a-linux" "armv7l-linux" "i686-linux" "mipsel-linux" "riscv32-linux" "riscv64-linux" "x86_64-linux" "powerpc64-linux" "powerpc64le-linux" ]; testnetbsd = mseteq netbsd [ "i686-netbsd" "x86_64-netbsd" ]; testopenbsd = mseteq openbsd [ "i686-openbsd" "x86_64-openbsd" ]; testwindows = mseteq windows [ "i686-cygwin" "x86_64-cygwin" "i686-windows" "x86_64-windows" ];