diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index 5be8bd466f854..ef262a5b19b08 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -160,6 +160,12 @@ impl<'a> IntoIterator for &'a LlvmConfigOutput { } } +fn is_libstdcxx_cxx11_abi_flag(flag: &str) -> bool { + flag == "-D_GLIBCXX_USE_CXX11_ABI" + || flag.starts_with("-D_GLIBCXX_USE_CXX11_ABI=") + || flag == "-U_GLIBCXX_USE_CXX11_ABI" +} + fn main() { if cfg!(feature = "check_only") { return; @@ -255,6 +261,14 @@ fn main() { continue; } + // This is a libstdc++ implementation detail for the C++ library that + // built the runnable llvm-config. When cross-compiling, target LLVM may + // have been built against a target libstdc++ with a different default. + // Let the target compiler/toolchain select its ABI instead. + if is_crossed && is_libstdcxx_cxx11_abi_flag(flag.as_ref()) { + continue; + } + if flag.starts_with("-flto") { continue; }