From f2d2bc4a240b817566e6e69492ece75c4399ee91 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Wed, 22 May 2024 19:14:10 +0300 Subject: [PATCH] check host's libstdc++ version when using ci llvm If the host's libstdc++ version is too old using ci-llvm may result in an ABI mismatch between the local libstdc++ and libLLVM.so. This PR adds a sanity check to immediately fail at the beginning of the bootstrap before starting the actual build. I am not sure if '8.0.0' is the best threshold, but it should be a good start and we can increase it anytime if needed. Signed-off-by: onur-ozkan --- .../ci-llvm-libstdcpp-version-threshold | 1 + src/bootstrap/src/core/sanity.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/bootstrap/ci-llvm-libstdcpp-version-threshold diff --git a/src/bootstrap/ci-llvm-libstdcpp-version-threshold b/src/bootstrap/ci-llvm-libstdcpp-version-threshold new file mode 100644 index 0000000000000..ae9a76b9249ad --- /dev/null +++ b/src/bootstrap/ci-llvm-libstdcpp-version-threshold @@ -0,0 +1 @@ +8.0.0 diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index 9c3df6fa9e39b..8132776fdd9e5 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -99,6 +99,22 @@ pub fn check(build: &mut Build) { cmd_finder.must_have("git"); } + if !build.config.dry_run() && build.config.llvm_from_ci { + let cxx = build.cxx(build.build).unwrap(); + let mut cxx_cmd = Command::new(cxx); + cxx_cmd.arg("-dumpversion"); + + let current_libstdcpp_v = semver::Version::parse(output(&mut cxx_cmd).trim()).unwrap(); + let libstdcpp_v_threshold = semver::Version::parse(include_str!("../../ci-llvm-libstdcpp-version-threshold")).unwrap(); + + if current_libstdcpp_v.lt(&libstdcpp_v_threshold) { + eprintln!("\nCurrent libstdc++ version is '{current_libstdcpp_v}', which is too old and below the required threshold of '{libstdcpp_v_threshold}'."); + // In case the user has a custom setup that includes a recent libstdc++ with an old c++ compiler, this information might be useful to them. + eprintln!("If you think this is a mistake, you can bypass this sanity check by setting 'BOOTSTRAP_SKIP_TARGET_SANITY' env variable to '1'."); + crate::exit!(1); + } + } + // We need cmake, but only if we're actually building LLVM or sanitizers. let building_llvm = build .hosts