From e54f5510aac99878cfc41b9b6c2a4ba228906e99 Mon Sep 17 00:00:00 2001 From: Nicolas Celik Date: Tue, 16 Dec 2025 21:33:36 +0200 Subject: [PATCH] Fix UBSan errors: vptr check failures due to lack of RTTI Fixes lots of "member call on address [...] which does not point to an object of type '[...]'" UBSan errors, e.g.: ``` .../source/compiler-core/slang-downstream-compiler-set.cpp:88:46: runtime error: member call on address 0x73ce982dc260 which does not point to an object of type 'Slang::IDownstreamCompiler' ``` UBSan's vptr/dynamic type checks require RTTI, as it assumes that a vtable is invalid if the vtable prefix points to a null type info pointer: https://github.com/llvm/llvm-project/blob/ea9addae8336e92222214036bbec821e6b29d8bc/compiler-rt/lib/ubsan/ubsan_type_hash_itanium.cpp#L215-L217 But as LLVM is built without RTTI by default, slang-llvm was being built without RTTI. Related to #9099. --- cmake/LLVM.cmake | 6 ------ external/build-llvm.sh | 3 +++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/cmake/LLVM.cmake b/cmake/LLVM.cmake index 9a9754684a8..3827a9b3e11 100644 --- a/cmake/LLVM.cmake +++ b/cmake/LLVM.cmake @@ -91,12 +91,6 @@ function(fetch_or_build_slang_llvm) target_compile_options(slang-llvm PRIVATE -wd4244 /Zc:preprocessor) endif() - if(NOT LLVM_ENABLE_RTTI) - # Make sure that we don't disable rtti if this library wasn't compiled with - # support - add_supported_cxx_flags(slang-llvm PRIVATE -fno-rtti /GR-) - endif() - # TODO: Put a check here that libslang-llvm.so doesn't have a 'NEEDED' # directive for libLLVM-21.so, it's almost certainly going to break at # runtime in surprising ways when linked alongside Mesa (or anything else diff --git a/external/build-llvm.sh b/external/build-llvm.sh index 91bc56560a7..571f00ae2b1 100755 --- a/external/build-llvm.sh +++ b/external/build-llvm.sh @@ -134,6 +134,9 @@ cmake_arguments_for_slang=( -DLLVM_ENABLE_PROJECTS=clang "-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64" -DLLVM_BUILD_TOOLS=0 + # slang-llvm is built with RTTI enabled to support UndefinedBehaviorSanitizer's vptr checks, so + # LLVM should be built with RTTI as well + -DLLVM_ENABLE_RTTI=1 # Get LLVM to use the static linked version of the msvc runtime "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$:Debug>" "-DLLVM_USE_CRT_RELEASE=MT"