diff --git a/Cargo.lock b/Cargo.lock index fd27f05363832..5821dc9711d7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1660,9 +1660,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.77" +version = "0.2.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235" +checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" dependencies = [ "rustc-std-workspace-core", ] diff --git a/compiler/rustc_target/src/spec/android_base.rs b/compiler/rustc_target/src/spec/android_base.rs index 0ea99af83a1ef..bb11ce8ef28c2 100644 --- a/compiler/rustc_target/src/spec/android_base.rs +++ b/compiler/rustc_target/src/spec/android_base.rs @@ -12,5 +12,6 @@ pub fn opts() -> TargetOptions { base.position_independent_executables = true; base.has_elf_tls = false; base.requires_uwtable = true; + base.crt_static_respected = false; base } diff --git a/compiler/rustc_target/src/spec/linux_base.rs b/compiler/rustc_target/src/spec/linux_base.rs index 52892fc35924e..7ad972b069210 100644 --- a/compiler/rustc_target/src/spec/linux_base.rs +++ b/compiler/rustc_target/src/spec/linux_base.rs @@ -28,6 +28,7 @@ pub fn opts() -> TargetOptions { position_independent_executables: true, relro_level: RelroLevel::Full, has_elf_tls: true, + crt_static_respected: true, ..Default::default() } } diff --git a/compiler/rustc_target/src/spec/linux_musl_base.rs b/compiler/rustc_target/src/spec/linux_musl_base.rs index b90e91d2901a8..16cc3b762f623 100644 --- a/compiler/rustc_target/src/spec/linux_musl_base.rs +++ b/compiler/rustc_target/src/spec/linux_musl_base.rs @@ -10,8 +10,6 @@ pub fn opts() -> TargetOptions { // These targets statically link libc by default base.crt_static_default = true; - // These targets allow the user to choose between static and dynamic linking. - base.crt_static_respected = true; base } diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index b27b056086a64..c08828bc0cde9 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -16,7 +16,7 @@ cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] } panic_unwind = { path = "../panic_unwind", optional = true } panic_abort = { path = "../panic_abort" } core = { path = "../core" } -libc = { version = "0.2.77", default-features = false, features = ['rustc-dep-of-std'] } +libc = { version = "0.2.79", default-features = false, features = ['rustc-dep-of-std'] } compiler_builtins = { version = "0.1.35" } profiler_builtins = { path = "../profiler_builtins", optional = true } unwind = { path = "../unwind" } diff --git a/library/std/src/sys/unix/process/process_unix.rs b/library/std/src/sys/unix/process/process_unix.rs index 32f456266c997..eb600d2465ca0 100644 --- a/library/std/src/sys/unix/process/process_unix.rs +++ b/library/std/src/sys/unix/process/process_unix.rs @@ -461,15 +461,7 @@ impl ExitStatus { } fn exited(&self) -> bool { - // On Linux-like OSes this function is safe, on others it is not. See - // libc issue: https://github.com/rust-lang/libc/issues/1888. - #[cfg_attr( - any(target_os = "linux", target_os = "android", target_os = "emscripten"), - allow(unused_unsafe) - )] - unsafe { - libc::WIFEXITED(self.0) - } + libc::WIFEXITED(self.0) } pub fn success(&self) -> bool { @@ -477,23 +469,11 @@ impl ExitStatus { } pub fn code(&self) -> Option { - // On Linux-like OSes this function is safe, on others it is not. See - // libc issue: https://github.com/rust-lang/libc/issues/1888. - #[cfg_attr( - any(target_os = "linux", target_os = "android", target_os = "emscripten"), - allow(unused_unsafe) - )] - if self.exited() { Some(unsafe { libc::WEXITSTATUS(self.0) }) } else { None } + if self.exited() { Some(libc::WEXITSTATUS(self.0)) } else { None } } pub fn signal(&self) -> Option { - // On Linux-like OSes this function is safe, on others it is not. See - // libc issue: https://github.com/rust-lang/libc/issues/1888. - #[cfg_attr( - any(target_os = "linux", target_os = "android", target_os = "emscripten"), - allow(unused_unsafe) - )] - if !self.exited() { Some(unsafe { libc::WTERMSIG(self.0) }) } else { None } + if !self.exited() { Some(libc::WTERMSIG(self.0)) } else { None } } } diff --git a/library/unwind/Cargo.toml b/library/unwind/Cargo.toml index 8e2db217c3151..7138d0c8fea6d 100644 --- a/library/unwind/Cargo.toml +++ b/library/unwind/Cargo.toml @@ -14,7 +14,7 @@ doc = false [dependencies] core = { path = "../core" } -libc = { version = "0.2.51", features = ['rustc-dep-of-std'], default-features = false } +libc = { version = "0.2.79", features = ['rustc-dep-of-std'], default-features = false } compiler_builtins = "0.1.0" cfg-if = "0.1.8" diff --git a/library/unwind/build.rs b/library/unwind/build.rs index ab09a6e324d8b..24bcd40c3a8ee 100644 --- a/library/unwind/build.rs +++ b/library/unwind/build.rs @@ -12,11 +12,9 @@ fn main() { } else if target.contains("x86_64-fortanix-unknown-sgx") { llvm_libunwind::compile(); } else if target.contains("linux") { + // linking for Linux is handled in lib.rs if target.contains("musl") { - // linking for musl is handled in lib.rs llvm_libunwind::compile(); - } else if !target.contains("android") { - println!("cargo:rustc-link-lib=gcc_s"); } } else if target.contains("freebsd") { println!("cargo:rustc-link-lib=gcc_s"); diff --git a/library/unwind/src/lib.rs b/library/unwind/src/lib.rs index 20a2ca984057e..e7fa37bc9db19 100644 --- a/library/unwind/src/lib.rs +++ b/library/unwind/src/lib.rs @@ -42,6 +42,13 @@ cfg_if::cfg_if! { #[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))] extern "C" {} +// When building with crt-static, we get `gcc_eh` from the `libc` crate, since +// glibc needs it, and needs it listed later on the linker command line. We +// don't want to duplicate it here. +#[cfg(all(target_os = "linux", target_env = "gnu", not(feature = "llvm-libunwind")))] +#[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))] +extern "C" {} + #[cfg(target_os = "redox")] #[link(name = "gcc_eh", kind = "static-nobundle", cfg(target_feature = "crt-static"))] #[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]