diff --git a/build.rs b/build.rs index 966aefc02235..419c9bede482 100644 --- a/build.rs +++ b/build.rs @@ -35,6 +35,7 @@ const ALLOWED_CFGS: &[&str] = &[ // Corresponds to `_REDIR_TIME64` in musl: symbol redirects to __*_time64 "musl_redir_time64", "vxworks_lt_25_09", + "libc_pauthtest", ]; // Extra values to allow for check-cfg. @@ -69,6 +70,14 @@ fn main() { let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); let target_ptr_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap_or_default(); 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. + if target_abi == "pauthtest" { + println!("cargo:rustc-cfg=libc_pauthtest"); + } // FIXME: this can be removed in 1-2 releases println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_FREEBSD_VERSION"); @@ -122,8 +131,12 @@ fn main() { // OpenHarmony uses a fork of the musl libc let musl = target_env == "musl" || target_env == "ohos"; - // loongarch64, hexagon, and ohos only exist with recent musl - if target_arch == "loongarch64" || target_arch == "hexagon" || target_env == "ohos" { + // loongarch64, hexagon, ohos and pauthtest only exist with recent musl + if target_arch == "loongarch64" + || target_arch == "hexagon" + || target_env == "ohos" + || target_abi == "pauthtest" + { musl_v1_2_3 = true; } diff --git a/libc-test/build.rs b/libc-test/build.rs index fbd88af31828..07f06039dd27 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3921,7 +3921,7 @@ fn test_linux(target: &str) { // target_env let gnu = target.contains("gnu"); - let musl = target.contains("musl") || target.contains("ohos"); + let musl = target.contains("musl") || target.contains("ohos") || target.contains("pauthtest"); let uclibc = target.contains("uclibc"); match (l4re, gnu, musl, uclibc) { @@ -3960,10 +3960,12 @@ fn test_linux(target: &str) { let mips = target.contains("mips"); let mips64 = target.contains("mips64"); let mips32 = mips && !mips64; + let pauthtest = target.contains("pauthtest"); let versions = &*VERSIONS; let kernel = versions.linux.unwrap(); - let musl_v1_2_3 = env::var("CARGO_CFG_LIBC_UNSTABLE_MUSL_V1_2_3").is_ok(); + // Force modern musl also for pauthtest. + let musl_v1_2_3 = env::var("CARGO_CFG_LIBC_UNSTABLE_MUSL_V1_2_3").is_ok() || pauthtest; if musl_v1_2_3 { assert!(musl); } @@ -5332,7 +5334,7 @@ fn test_linux(target: &str) { // are included (e.g. because including both sets of headers clashes) fn test_linux_like_apis(target: &str) { let gnu = target.contains("gnu"); - let musl = target.contains("musl") || target.contains("ohos"); + let musl = target.contains("musl") || target.contains("ohos") || target.contains("pauthtest"); let linux = target.contains("linux"); let wali = target.contains("linux") && target.contains("wasm32"); let emscripten = target.contains("emscripten"); diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 8dcc5ca8ebf4..63777583a2e0 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -519,7 +519,17 @@ cfg_if! { #[link(name = "dl", cfg(not(target_feature = "crt-static")))] #[link(name = "c", cfg(not(target_feature = "crt-static")))] extern "C" {} - } else if #[cfg(any(target_env = "musl", target_env = "ohos"))] { + } else if #[cfg(libc_pauthtest)] { + #[link(name = "c")] + #[link(name = "m")] + #[link(name = "rt")] + #[link(name = "pthread")] + #[link(name = "dl")] + extern "C" {} + } else if #[cfg(any( + all(target_env = "musl", not(libc_pauthtest)), + target_env = "ohos" + ))] { #[cfg_attr( feature = "rustc-dep-of-std", link(