From 45226ffd3b74dddc5ac27fee12a1e429663541a5 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Thu, 30 Jul 2026 14:32:18 -0400 Subject: [PATCH] linux: select powerpc64 speed symbols by ELF ABI Starting with Rust 1.98, `powerpc64-unknown-linux-gnuelfv2` will be a supported triple. During my attempts to try to build a bunch of projects for this new target, though, libc failed to compile. This is because the `cf*speed` link names assumed all big-endian powerpc64 targets use ELFv1, which was reasonable in the past, but not anymore. Now, this uses the target ABI to select the correct symbol versions instead. --- Cargo.toml | 1 + build.rs | 10 +++++++--- ci/verify-build.py | 1 + src/unix/mod.rs | 25 +++++++++++++++---------- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 446e97ec9f332..d9e4c01bdf492 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -135,6 +135,7 @@ targets = [ "powerpc64-ibm-aix", "powerpc64-unknown-freebsd", "powerpc64-unknown-linux-gnu", + "powerpc64-unknown-linux-gnuelfv2", "powerpc64-wrs-vxworks", "riscv32-wrs-vxworks", "riscv32gc-unknown-linux-musl", diff --git a/build.rs b/build.rs index 07df3af2da2ac..6e0181d2dc09b 100644 --- a/build.rs +++ b/build.rs @@ -30,6 +30,7 @@ const ALLOWED_CFGS: &[&str] = &[ // GNU to expose a 64-bit `time_t`. "gnu_time_bits64", "libc_deny_warnings", + "libc_elfv2", // Corresponds to `__USE_TIME_BITS64` in UAPI "linux_time_bits64", "musl_v1_2_3", @@ -92,9 +93,12 @@ fn main() { let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default(); let target_abi = env::var("CARGO_CFG_TARGET_ABI").unwrap_or_default(); - // FIXME(msrv): Once the MSRV is 1.78, use `cfg(target_abi = "pauthtest")` - // directly instead of translating it to `libc_pauthtest`. `target_abi` - // cannot be used directly in cfg expressions on the current MSRV. + // FIXME(msrv): Once the MSRV is 1.78, use `cfg(target_abi)` directly instead + // of translating its values. `target_abi` cannot be used directly in cfg + // expressions on the current MSRV. + if target_abi == "elfv2" { + set_cfg("libc_elfv2"); + } if target_abi == "pauthtest" { set_cfg("libc_pauthtest"); } diff --git a/ci/verify-build.py b/ci/verify-build.py index 349673cdca7e2..78bd7ad385c8f 100755 --- a/ci/verify-build.py +++ b/ci/verify-build.py @@ -189,6 +189,7 @@ class TargetResult: Target("powerpc-wrs-vxworks-spe", dist=False), Target("powerpc64-ibm-aix", dist=False), Target("powerpc64-unknown-freebsd", dist=False), + Target("powerpc64-unknown-linux-gnuelfv2", dist=False), Target("powerpc64-wrs-vxworks", dist=False), Target("riscv32-wrs-vxworks", dist=False), Target("riscv32gc-unknown-linux-gnu", dist=False), diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 1f30ed060cb21..2f3038bdac6a6 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -1711,7 +1711,8 @@ extern "C" { target_os = "linux", target_env = "gnu", target_arch = "powerpc64", - target_endian = "big" + target_endian = "big", + not(libc_elfv2) ), link_name = "cfgetispeed@GLIBC_2.3" )] @@ -1720,7 +1721,7 @@ extern "C" { target_os = "linux", target_env = "gnu", target_arch = "powerpc64", - target_endian = "little" + any(target_endian = "little", libc_elfv2) ), link_name = "cfgetispeed@GLIBC_2.17" )] @@ -1812,7 +1813,8 @@ extern "C" { target_os = "linux", target_env = "gnu", target_arch = "powerpc64", - target_endian = "big" + target_endian = "big", + not(libc_elfv2) ), link_name = "cfgetospeed@GLIBC_2.3" )] @@ -1821,7 +1823,7 @@ extern "C" { target_os = "linux", target_env = "gnu", target_arch = "powerpc64", - target_endian = "little" + any(target_endian = "little", libc_elfv2) ), link_name = "cfgetospeed@GLIBC_2.17" )] @@ -1913,7 +1915,8 @@ extern "C" { target_os = "linux", target_env = "gnu", target_arch = "powerpc64", - target_endian = "big" + target_endian = "big", + not(libc_elfv2) ), link_name = "cfsetispeed@GLIBC_2.3" )] @@ -1922,7 +1925,7 @@ extern "C" { target_os = "linux", target_env = "gnu", target_arch = "powerpc64", - target_endian = "little" + any(target_endian = "little", libc_elfv2) ), link_name = "cfsetispeed@GLIBC_2.17" )] @@ -2014,7 +2017,8 @@ extern "C" { target_os = "linux", target_env = "gnu", target_arch = "powerpc64", - target_endian = "big" + target_endian = "big", + not(libc_elfv2) ), link_name = "cfsetospeed@GLIBC_2.3" )] @@ -2023,7 +2027,7 @@ extern "C" { target_os = "linux", target_env = "gnu", target_arch = "powerpc64", - target_endian = "little" + any(target_endian = "little", libc_elfv2) ), link_name = "cfsetospeed@GLIBC_2.17" )] @@ -2422,7 +2426,8 @@ cfg_if! { target_os = "linux", target_env = "gnu", target_arch = "powerpc64", - target_endian = "big" + target_endian = "big", + not(libc_elfv2) ), link_name = "cfsetspeed@GLIBC_2.3" )] @@ -2431,7 +2436,7 @@ cfg_if! { target_os = "linux", target_env = "gnu", target_arch = "powerpc64", - target_endian = "little" + any(target_endian = "little", libc_elfv2) ), link_name = "cfsetspeed@GLIBC_2.17" )]