From 77b6476d8e5bcbcec930b81522c446c0211dbe03 Mon Sep 17 00:00:00 2001 From: "Kirill A. Korinsky" Date: Fri, 4 Feb 2022 03:44:38 +0100 Subject: [PATCH] Introduce `llvm-enable-rtti` option This option is controls when LLVM build adds `-fno-rtti`. Some details available here: https://www.llvm.org/docs/HowToSetUpLLVMStyleRTTI.html When this option is enabled, llvm build produces a bit more symbols: ```` rust % nm build/x86_64-apple-darwin/llvm/lib/libLLVMCore.a | grep llvm10CallbackVHE 0000000000007120 S __ZTIN4llvm10CallbackVHE 0000000000007240 S __ZTSN4llvm10CallbackVHE 00000000000070e8 S __ZTVN4llvm10CallbackVHE ```` and just to compare the same build without this option (current behaviour): ``` rust % nm build/x86_64-apple-darwin/llvm/lib/libLLVMCore.a | grep llvm10CallbackVHE 00000000000070b8 S __ZTVN4llvm10CallbackVHE ``` An attempt to bootstrap `rust` with `clang` which was built with enabled RTTI may fail with linking error like: ``` = note: dyld: Symbol not found: __ZTIN4llvm10CallbackVHE Referenced from: /opt/local/libexec/llvm-9.0/bin/../lib/libclang-cpp.dylib Expected in: .../build/x86_64-apple-darwin/stage2/lib/libLLVM.dylib in /opt/local/libexec/llvm-9.0/bin/../lib/libclang-cpp.dylib ``` --- config.toml.example | 3 +++ src/bootstrap/config.rs | 4 ++++ src/bootstrap/configure.py | 1 + src/bootstrap/native.rs | 4 ++++ 4 files changed, 12 insertions(+) diff --git a/config.toml.example b/config.toml.example index f24f8e81a7944..193a9020a55bd 100644 --- a/config.toml.example +++ b/config.toml.example @@ -148,6 +148,9 @@ changelog-seen = 2 # The value specified here will be passed as `-DLLVM_USE_LINKER` to CMake. #use-linker = (path) +# Whether or not to specify `-DLLVM_ENABLE_RTTI=YES` +#enable-rtti = false + # Whether or not to specify `-DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=YES` #allow-old-toolchain = false diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 683cfc630e771..f73d445469a0d 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -105,6 +105,7 @@ pub struct Config { pub llvm_version_suffix: Option, pub llvm_use_linker: Option, pub llvm_allow_old_toolchain: bool, + pub llvm_enable_rtti: bool, pub llvm_polly: bool, pub llvm_clang: bool, pub llvm_from_ci: bool, @@ -474,6 +475,7 @@ derive_merge! { use_libcxx: Option, use_linker: Option, allow_old_toolchain: Option, + enable_rtti: Option, polly: Option, clang: Option, download_ci_llvm: Option, @@ -805,6 +807,7 @@ impl Config { set(&mut config.llvm_use_libcxx, llvm.use_libcxx); config.llvm_use_linker = llvm.use_linker.clone(); config.llvm_allow_old_toolchain = llvm.allow_old_toolchain.unwrap_or(false); + config.llvm_enable_rtti = llvm.enable_rtti.unwrap_or(false); config.llvm_polly = llvm.polly.unwrap_or(false); config.llvm_clang = llvm.clang.unwrap_or(false); config.llvm_from_ci = match llvm.download_ci_llvm { @@ -874,6 +877,7 @@ impl Config { check_ci_llvm!(llvm.use_libcxx); check_ci_llvm!(llvm.use_linker); check_ci_llvm!(llvm.allow_old_toolchain); + check_ci_llvm!(llvm.enable_rtti); check_ci_llvm!(llvm.polly); check_ci_llvm!(llvm.clang); check_ci_llvm!(llvm.plugins); diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 94424cb4548fa..0385cb94a6786 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -73,6 +73,7 @@ def v(*args): o("optimize", "rust.optimize", "build optimized rust code") o("optimize-llvm", "llvm.optimize", "build optimized LLVM") o("llvm-assertions", "llvm.assertions", "build LLVM with assertions") +o("llvm-enable-rtti", "llvm.enable-rtti", "build LLVM with using C++’s built in RTTI") o("llvm-plugins", "llvm.plugins", "build LLVM with plugin interface") o("debug-assertions", "rust.debug-assertions", "build with debugging assertions") o("debug-assertions-std", "rust.debug-assertions-std", "build the standard library with debugging assertions") diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 4a754e6da1209..ed802c74794dd 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -351,6 +351,10 @@ impl Step for Llvm { cfg.define("LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN", "YES"); } + if builder.config.llvm_enable_rtti { + cfg.define("LLVM_ENABLE_RTTI", "YES"); + } + configure_cmake(builder, target, &mut cfg, true); // FIXME: we don't actually need to build all LLVM tools and all LLVM