File 0003-drop-latomic-for-riscv-targets.patch of Package rust
From 5790860531e2fe601bbffcdc6bc7a5f192e8f593 Mon Sep 17 00:00:00 2001 From: Yao Zi <[email protected]> Date: Wed, 21 May 2025 09:45:11 +0000 Subject: [PATCH] drop -latomic for riscv targets Rustc doesn't recognize compiler-rt based Linux distro correctly and tries to link libatomic on these targets. Let's drop the linkflag manually. Signed-off-by: Yao Zi <[email protected]> --- compiler/rustc_llvm/build.rs | 8 -------- src/bootstrap/src/core/build_steps/llvm.rs | 19 ------------------- 2 files changed, 27 deletions(-) diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index 6692ea735401..16f9738a4250 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -383,14 +383,6 @@ fn main() { "stdc++" }; - // RISC-V GCC erroneously requires libatomic for sub-word - // atomic operations. Some BSD uses Clang as its system - // compiler and provides no libatomic in its base system so - // does not want this. - if target.starts_with("riscv") && !target.contains("freebsd") && !target.contains("openbsd") { - println!("cargo:rustc-link-lib=atomic"); - } - // C++ runtime library if !target.contains("msvc") { if let Some(s) = llvm_static_stdcpp { diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index e21804fa3c07..884bf69459bf 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -399,25 +399,6 @@ impl Step for Llvm { cfg.define("LLVM_LINK_LLVM_DYLIB", "ON"); } - if (target.starts_with("csky") - || target.starts_with("riscv") - || target.starts_with("sparc-")) - && !target.contains("freebsd") - && !target.contains("openbsd") - && !target.contains("netbsd") - { - // CSKY and RISC-V GCC erroneously requires linking against - // `libatomic` when using 1-byte and 2-byte C++ - // atomics but the LLVM build system check cannot - // detect this. Therefore it is set manually here. - // Some BSD uses Clang as its system compiler and - // provides no libatomic in its base system so does - // not want this. 32-bit SPARC requires linking against - // libatomic as well. - ldflags.exe.push(" -latomic"); - ldflags.shared.push(" -latomic"); - } - if target.starts_with("mips") && target.contains("netbsd") { // LLVM wants 64-bit atomics, while mipsel is 32-bit only, so needs -latomic ldflags.exe.push(" -latomic"); -- 2.49.0