Skip to content

Commit 1cf8793

Browse files
authored
Rollup merge of #94719 - jonhoo:enable-static-lld, r=Mark-Simulacrum
Statically compile libstdc++ everywhere if asked PR #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, only when building LLVM itself. This moves the logic for setting `-static-libstdc++` in the linker flags 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, whereas previously the `llvm-static-stdcpp` flag had no effect on sanitizers. It also makes it so that LLD will be compiled statically if `llvm-tools-enabled` is set, even though previously it was only linked statically if `llvm-static-stdcpp` was set explicitly. Both of these seem like they match expected behavior than what was there prior to #93918.
2 parents 634a6b0 + b328688 commit 1cf8793

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/bootstrap/native.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -259,18 +259,6 @@ impl Step for Llvm {
259259
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
260260
}
261261

262-
// For distribution we want the LLVM tools to be *statically* linked to libstdc++.
263-
// We also do this if the user explicitly requested static libstdc++.
264-
if builder.config.llvm_tools_enabled || builder.config.llvm_static_stdcpp {
265-
if !target.contains("msvc") && !target.contains("netbsd") {
266-
if target.contains("apple") {
267-
ldflags.push_all("-static-libstdc++");
268-
} else {
269-
ldflags.push_all("-Wl,-Bsymbolic -static-libstdc++");
270-
}
271-
}
272-
}
273-
274262
if target.starts_with("riscv") && !target.contains("freebsd") {
275263
// RISC-V GCC erroneously requires linking against
276264
// `libatomic` when using 1-byte and 2-byte C++
@@ -576,6 +564,18 @@ fn configure_cmake(
576564
ldflags.push_all(&flags);
577565
}
578566

567+
// For distribution we want the LLVM tools to be *statically* linked to libstdc++.
568+
// We also do this if the user explicitly requested static libstdc++.
569+
if builder.config.llvm_tools_enabled || builder.config.llvm_static_stdcpp {
570+
if !target.contains("msvc") && !target.contains("netbsd") {
571+
if target.contains("apple") {
572+
ldflags.push_all("-static-libstdc++");
573+
} else {
574+
ldflags.push_all("-Wl,-Bsymbolic -static-libstdc++");
575+
}
576+
}
577+
}
578+
579579
cfg.define("CMAKE_SHARED_LINKER_FLAGS", &ldflags.shared);
580580
cfg.define("CMAKE_MODULE_LINKER_FLAGS", &ldflags.module);
581581
cfg.define("CMAKE_EXE_LINKER_FLAGS", &ldflags.exe);

0 commit comments

Comments
 (0)