Skip to content

Commit 099acb0

Browse files
Jon GjengsetMark-Simulacrum
Jon Gjengset
authored andcommitted
Statically compile libstdc++ everywhere if asked
PR rust-lang#93918 made it so that `-static-libstdc++` was only set in one place, and was only set during linking, but accidentally also made it so that it is no longer passed when building LLD or sanitizers, only when building LLVM itself. This moves the logic for setting `-static-libstdc++` in the linker flags back to `configure_cmake` so that it takes effect for all CMake invocations in `native.rs`. As a side-effect, this also causes libstdc++ to be statically compiled into sanitizers and LLD if `llvm-tools-enabled` is set but `llvm-static-stdcpp` is not, even though previously it was only linked statically if `llvm-static-stdcpp` was set explicitly. But that seems more like the expected behavior anyway.
1 parent 32fb22d commit 099acb0

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/bootstrap/native.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,6 @@ impl Step for Llvm {
262262
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
263263
}
264264

265-
// For distribution we want the LLVM tools to be *statically* linked to libstdc++.
266-
// We also do this if the user explicitly requested static libstdc++.
267-
if builder.config.llvm_tools_enabled || builder.config.llvm_static_stdcpp {
268-
if !target.contains("msvc") && !target.contains("netbsd") {
269-
if target.contains("apple") {
270-
ldflags.push_all("-static-libstdc++");
271-
} else {
272-
ldflags.push_all("-Wl,-Bsymbolic -static-libstdc++");
273-
}
274-
}
275-
}
276-
277265
if target.starts_with("riscv") && !target.contains("freebsd") {
278266
// RISC-V GCC erroneously requires linking against
279267
// `libatomic` when using 1-byte and 2-byte C++
@@ -587,6 +575,18 @@ fn configure_cmake(
587575
ldflags.push_all(&flags);
588576
}
589577

578+
// For distribution we want the LLVM tools to be *statically* linked to libstdc++.
579+
// We also do this if the user explicitly requested static libstdc++.
580+
if builder.config.llvm_tools_enabled || builder.config.llvm_static_stdcpp {
581+
if !target.contains("msvc") && !target.contains("netbsd") {
582+
if target.contains("apple") {
583+
ldflags.push_all("-static-libstdc++");
584+
} else {
585+
ldflags.push_all("-Wl,-Bsymbolic -static-libstdc++");
586+
}
587+
}
588+
}
589+
590590
cfg.define("CMAKE_SHARED_LINKER_FLAGS", &ldflags.shared);
591591
cfg.define("CMAKE_MODULE_LINKER_FLAGS", &ldflags.module);
592592
cfg.define("CMAKE_EXE_LINKER_FLAGS", &ldflags.exe);

0 commit comments

Comments
 (0)