@@ -262,30 +262,27 @@ 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- if builder. config . llvm_tools_enabled {
267- if !target. contains ( "msvc" ) {
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" ) {
268269 if target. contains ( "apple" ) {
269- ldflags. exe . push ( " -static-libstdc++") ;
270+ ldflags. push_all ( " -static-libstdc++") ;
270271 } else {
271- ldflags. exe . push ( " -Wl,-Bsymbolic -static-libstdc++") ;
272+ ldflags. push_all ( " -Wl,-Bsymbolic -static-libstdc++") ;
272273 }
273274 }
274275 }
275276
276- if ! target. contains ( "freebsd ") && target. starts_with ( "riscv ") {
277+ if target. starts_with ( "riscv ") && ! target. contains ( "freebsd ") {
277278 // RISC-V GCC erroneously requires linking against
278279 // `libatomic` when using 1-byte and 2-byte C++
279280 // atomics but the LLVM build system check cannot
280281 // detect this. Therefore it is set manually here.
281282 // FreeBSD uses Clang as its system compiler and
282283 // provides no libatomic in its base system so does
283284 // not want this.
284- if !builder. config . llvm_tools_enabled {
285- ldflags. exe . push ( " -latomic" ) ;
286- } else {
287- ldflags. exe . push ( " -latomic -static-libstdc++" ) ;
288- }
285+ ldflags. exe . push ( " -latomic" ) ;
289286 ldflags. shared . push ( " -latomic" ) ;
290287 }
291288
@@ -554,9 +551,6 @@ fn configure_cmake(
554551 }
555552 cfg. define ( "CMAKE_C_FLAGS" , cflags) ;
556553 let mut cxxflags: OsString = builder. cflags ( target, GitRepo :: Llvm ) . join ( " " ) . into ( ) ;
557- if builder. config . llvm_static_stdcpp && !target. contains ( "msvc" ) && !target. contains ( "netbsd" ) {
558- cxxflags. push ( " -static-libstdc++" ) ;
559- }
560554 if let Some ( ref s) = builder. config . llvm_cxxflags {
561555 cxxflags. push ( " " ) ;
562556 cxxflags. push ( s) ;
0 commit comments