diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt index 2c52788de56af..47672a7328397 100644 --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -363,8 +363,11 @@ append_list_if(COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SANIT if(NOT COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG) append_list_if(COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG -fvisibility-inlines-hidden SANITIZER_COMMON_CFLAGS) endif() -append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SANITIZER_COMMON_CFLAGS) - +if(NOT COMPILER_RT_ENABLE_LTO) + append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SANITIZER_COMMON_CFLAGS) + append_list_if(COMPILER_RT_HAS_FNO_WPD_FLAG -fno-whole-program-vtables SANITIZER_COMMON_CFLAGS) + append_list_if(COMPILER_RT_HAS_FNO_VFE_FLAG -fno-virtual-function-elimination SANITIZER_COMMON_CFLAGS) +endif() # By default do not instrument or use profdata for compiler-rt. if(NOT COMPILER_RT_ENABLE_PGO) if(LLVM_PROFDATA_FILE AND COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG) diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake index c3e734f72392f..f4a5c612aaa4e 100644 --- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake +++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake @@ -178,8 +178,14 @@ function(add_compiler_rt_runtime name type) # Until we support this some other way, build compiler-rt runtime without LTO # to allow non-LTO projects to link with it. GPU targets can currently only be # distributed as LLVM-IR and ignore this. - if(COMPILER_RT_HAS_FNO_LTO_FLAG AND NOT COMPILER_RT_GPU_BUILD) + if(COMPILER_RT_HAS_FNO_LTO_FLAG AND NOT COMPILER_RT_GPU_BUILD OR NOT COMPILER_RT_ENABLE_LTO) set(NO_LTO_FLAGS "-fno-lto") + if(COMPILER_RT_HAS_FNO_WPD_FLAG) + list(APPEND NO_LTO_FLAGS "-fno-whole-program-vtables") + endif() + if(COMPILER_RT_HAS_FNO_VFE_FLAG) + list(APPEND NO_LTO_FLAGS "-fno-virtual-function-elimination") + endif() else() set(NO_LTO_FLAGS "") endif() diff --git a/compiler-rt/cmake/Modules/CheckSectionExists.cmake b/compiler-rt/cmake/Modules/CheckSectionExists.cmake index cb32276b5aee1..e53aaf7ce5b7a 100644 --- a/compiler-rt/cmake/Modules/CheckSectionExists.cmake +++ b/compiler-rt/cmake/Modules/CheckSectionExists.cmake @@ -17,7 +17,11 @@ function(check_section_exists section output) if(CMAKE_C_COMPILER_ID MATCHES Clang AND CMAKE_C_COMPILER_TARGET) list(APPEND try_compile_flags "-target ${CMAKE_C_COMPILER_TARGET}") endif() - append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto try_compile_flags) + if(NOT COMPILER_RT_ENABLE_LTO) + append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto try_compile_flags) + append_list_if(COMPILER_RT_HAS_FNO_WPD_FLAG -fno-whole-program-vtables try_compile_flags) + append_list_if(COMPILER_RT_HAS_FNO_VFE_FLAG -fno-virtual-function-elimination try_compile_flags) + endif() if(NOT COMPILER_RT_ENABLE_PGO) if(LLVM_PROFDATA_FILE AND COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG) list(APPEND try_compile_flags "-fno-profile-instr-use") diff --git a/compiler-rt/cmake/builtin-config-ix.cmake b/compiler-rt/cmake/builtin-config-ix.cmake index b1bde47ec8555..48b956ae86418 100644 --- a/compiler-rt/cmake/builtin-config-ix.cmake +++ b/compiler-rt/cmake/builtin-config-ix.cmake @@ -15,6 +15,8 @@ builtin_check_c_compiler_flag(-fomit-frame-pointer COMPILER_RT_HAS_OMIT_FRAME_P builtin_check_c_compiler_flag(-ffreestanding COMPILER_RT_HAS_FFREESTANDING_FLAG) builtin_check_c_compiler_flag(-fxray-instrument COMPILER_RT_HAS_XRAY_COMPILER_FLAG) builtin_check_c_compiler_flag(-fno-lto COMPILER_RT_HAS_FNO_LTO_FLAG) +builtin_check_c_compiler_flag(-fno-whole-program-vtables COMPILER_RT_HAS_FNO_WPD_FLAG) +builtin_check_c_compiler_flag(-fno-virtual-function-elimination COMPILER_RT_HAS_FNO_VFE_FLAG) builtin_check_c_compiler_flag(-fno-profile-generate COMPILER_RT_HAS_FNO_PROFILE_GENERATE_FLAG) builtin_check_c_compiler_flag(-fno-profile-instr-generate COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG) builtin_check_c_compiler_flag(-fno-profile-instr-use COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG) diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index cf729c3adb1f5..83a65c99b580e 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -105,6 +105,8 @@ check_cxx_compiler_flag(-fno-rtti COMPILER_RT_HAS_FNO_RTTI_FLAG) check_cxx_compiler_flag("-Werror -fno-function-sections" COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG) check_cxx_compiler_flag(-ftls-model=initial-exec COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC) check_cxx_compiler_flag(-fno-lto COMPILER_RT_HAS_FNO_LTO_FLAG) +check_cxx_compiler_flag(-fno-whole-program-vtables COMPILER_RT_HAS_FNO_WPD_FLAG) +check_cxx_compiler_flag(-fno-virtual-function-elimination COMPILER_RT_HAS_FNO_VFE_FLAG) check_cxx_compiler_flag(-fno-profile-generate COMPILER_RT_HAS_FNO_PROFILE_GENERATE_FLAG) check_cxx_compiler_flag(-fno-profile-instr-generate COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG) check_cxx_compiler_flag(-fno-profile-instr-use COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG) diff --git a/compiler-rt/cmake/crt-config-ix.cmake b/compiler-rt/cmake/crt-config-ix.cmake index ebc7d671e74ee..e688bcad8eb88 100644 --- a/compiler-rt/cmake/crt-config-ix.cmake +++ b/compiler-rt/cmake/crt-config-ix.cmake @@ -8,6 +8,8 @@ builtin_check_c_compiler_flag(-fPIC COMPILER_RT_HAS_FPIC_FLAG) builtin_check_c_compiler_flag(-std=c11 COMPILER_RT_HAS_STD_C11_FLAG) builtin_check_c_compiler_flag(-Wno-pedantic COMPILER_RT_HAS_WNO_PEDANTIC) builtin_check_c_compiler_flag(-fno-lto COMPILER_RT_HAS_FNO_LTO_FLAG) +builtin_check_c_compiler_flag(-fno-whole-program-vtables COMPILER_RT_HAS_FNO_WPD_FLAG) +builtin_check_c_compiler_flag(-fno-virtual-function-elimination COMPILER_RT_HAS_FNO_VFE_FLAG) builtin_check_c_compiler_flag(-fno-profile-generate COMPILER_RT_HAS_FNO_PROFILE_GENERATE_FLAG) builtin_check_c_compiler_flag(-fno-profile-instr-generate COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG) builtin_check_c_compiler_flag(-fno-profile-instr-use COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG) diff --git a/compiler-rt/lib/scudo/standalone/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/CMakeLists.txt index 3f9ae866a7553..d97d26dafd05e 100644 --- a/compiler-rt/lib/scudo/standalone/CMakeLists.txt +++ b/compiler-rt/lib/scudo/standalone/CMakeLists.txt @@ -23,6 +23,8 @@ append_list_if(COMPILER_RT_HAS_WNO_PEDANTIC -Wno-pedantic SCUDO_CFLAGS) # FIXME: find cleaner way to agree with GWPAsan flags append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SCUDO_CFLAGS) +append_list_if(COMPILER_RT_HAS_FNO_WPD_FLAG -fno-whole-program-vtables SCUDO_CFLAGS) +append_list_if(COMPILER_RT_HAS_FNO_VFE_FLAG -fno-virtual-function-elimination SCUDO_CFLAGS) if(COMPILER_RT_DEBUG) list(APPEND SCUDO_CFLAGS -O0 -DSCUDO_DEBUG=1 -DSCUDO_ENABLE_HOOKS=1)