about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJon Gjengset <jongje@amazon.com>2022-02-11 12:03:51 -0800
committerJon Gjengset <jongje@amazon.com>2022-02-11 16:09:57 -0800
commit36692741a2edef04a92021dcde05d9fa124f25e6 (patch)
treeefb528ee33c39d63db342af8ce61c67433111f14
parent07dae5a97b64100f5abd511f1e2d5a6263a54006 (diff)
downloadrust-36692741a2edef04a92021dcde05d9fa124f25e6.tar.gz
rust-36692741a2edef04a92021dcde05d9fa124f25e6.zip
bootstrap: -static-libstdc++ is a linker flag
Fixes #70468. Closes #89983.
-rw-r--r--src/bootstrap/native.rs22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs
index 4af9edbae40..f0087523904 100644
--- a/src/bootstrap/native.rs
+++ b/src/bootstrap/native.rs
@@ -262,18 +262,19 @@ impl Step for Llvm {
             cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
         }
 
-        // For distribution we want the LLVM tools to be *statically* linked to libstdc++
-        if builder.config.llvm_tools_enabled {
-            if !target.contains("msvc") {
+        // For distribution we want the LLVM tools to be *statically* linked to libstdc++.
+        // We also do this if the user explicitly requested static libstdc++.
+        if builder.config.llvm_tools_enabled || builder.config.llvm_static_stdcpp {
+            if !target.contains("msvc") && !target.contains("netbsd") {
                 if target.contains("apple") {
-                    ldflags.exe.push(" -static-libstdc++");
+                    ldflags.push_all("-static-libstdc++");
                 } else {
-                    ldflags.exe.push(" -Wl,-Bsymbolic -static-libstdc++");
+                    ldflags.push_all("-Wl,-Bsymbolic -static-libstdc++");
                 }
             }
         }
 
-        if !target.contains("freebsd") && target.starts_with("riscv") {
+        if target.starts_with("riscv") && !target.contains("freebsd") {
             // RISC-V GCC erroneously requires linking against
             // `libatomic` when using 1-byte and 2-byte C++
             // atomics but the LLVM build system check cannot
@@ -281,11 +282,7 @@ impl Step for Llvm {
             // FreeBSD uses Clang as its system compiler and
             // provides no libatomic in its base system so does
             // not want this.
-            if !builder.config.llvm_tools_enabled {
-                ldflags.exe.push(" -latomic");
-            } else {
-                ldflags.exe.push(" -latomic -static-libstdc++");
-            }
+            ldflags.exe.push(" -latomic");
             ldflags.shared.push(" -latomic");
         }
 
@@ -554,9 +551,6 @@ fn configure_cmake(
     }
     cfg.define("CMAKE_C_FLAGS", cflags);
     let mut cxxflags: OsString = builder.cflags(target, GitRepo::Llvm).join(" ").into();
-    if builder.config.llvm_static_stdcpp && !target.contains("msvc") && !target.contains("netbsd") {
-        cxxflags.push(" -static-libstdc++");
-    }
     if let Some(ref s) = builder.config.llvm_cxxflags {
         cxxflags.push(" ");
         cxxflags.push(s);