Skip to content

Commit 20904ea

Browse files
committed
[compiler-rt] Disable WPD/VFE if LTO is disabled
WPD/VFE requires LTO, so if LTO is disabled, we should also disable WPD/VFE to avoid build failure
1 parent 3496e96 commit 20904ea

File tree

7 files changed

+25
-4
lines changed

7 files changed

+25
-4
lines changed

compiler-rt/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,11 @@ append_list_if(COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SANIT
363363
if(NOT COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG)
364364
append_list_if(COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG -fvisibility-inlines-hidden SANITIZER_COMMON_CFLAGS)
365365
endif()
366-
append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SANITIZER_COMMON_CFLAGS)
367-
366+
if(NOT COMPILER_RT_ENABLE_LTO)
367+
append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SANITIZER_COMMON_CFLAGS)
368+
append_list_if(COMPILER_RT_HAS_FNO_WPD_FLAG -fno-whole-program-vtables SANITIZER_COMMON_CFLAGS)
369+
append_list_if(COMPILER_RT_HAS_FNO_VFE_FLAG -fno-virtual-function-elimination SANITIZER_COMMON_CFLAGS)
370+
endif()
368371
# By default do not instrument or use profdata for compiler-rt.
369372
if(NOT COMPILER_RT_ENABLE_PGO)
370373
if(LLVM_PROFDATA_FILE AND COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG)

compiler-rt/cmake/Modules/AddCompilerRT.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,14 @@ function(add_compiler_rt_runtime name type)
178178
# Until we support this some other way, build compiler-rt runtime without LTO
179179
# to allow non-LTO projects to link with it. GPU targets can currently only be
180180
# distributed as LLVM-IR and ignore this.
181-
if(COMPILER_RT_HAS_FNO_LTO_FLAG AND NOT COMPILER_RT_GPU_BUILD)
181+
if(COMPILER_RT_HAS_FNO_LTO_FLAG AND NOT COMPILER_RT_GPU_BUILD OR NOT COMPILER_RT_ENABLE_LTO)
182182
set(NO_LTO_FLAGS "-fno-lto")
183+
if(COMPILER_RT_HAS_FNO_WPD_FLAG)
184+
list(APPEND NO_LTO_FLAGS "-fno-whole-program-vtables")
185+
endif()
186+
if(COMPILER_RT_HAS_FNO_VFE_FLAG)
187+
list(APPEND NO_LTO_FLAGS "-fno-virtual-function-elimination")
188+
endif()
183189
else()
184190
set(NO_LTO_FLAGS "")
185191
endif()

compiler-rt/cmake/Modules/CheckSectionExists.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ function(check_section_exists section output)
1717
if(CMAKE_C_COMPILER_ID MATCHES Clang AND CMAKE_C_COMPILER_TARGET)
1818
list(APPEND try_compile_flags "-target ${CMAKE_C_COMPILER_TARGET}")
1919
endif()
20-
append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto try_compile_flags)
20+
if(NOT COMPILER_RT_ENABLE_LTO)
21+
append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto try_compile_flags)
22+
append_list_if(COMPILER_RT_HAS_FNO_WPD_FLAG -fno-whole-program-vtables try_compile_flags)
23+
append_list_if(COMPILER_RT_HAS_FNO_VFE_FLAG -fno-virtual-function-elimination try_compile_flags)
24+
endif()
2125
if(NOT COMPILER_RT_ENABLE_PGO)
2226
if(LLVM_PROFDATA_FILE AND COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG)
2327
list(APPEND try_compile_flags "-fno-profile-instr-use")

compiler-rt/cmake/builtin-config-ix.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ builtin_check_c_compiler_flag(-fomit-frame-pointer COMPILER_RT_HAS_OMIT_FRAME_P
1515
builtin_check_c_compiler_flag(-ffreestanding COMPILER_RT_HAS_FFREESTANDING_FLAG)
1616
builtin_check_c_compiler_flag(-fxray-instrument COMPILER_RT_HAS_XRAY_COMPILER_FLAG)
1717
builtin_check_c_compiler_flag(-fno-lto COMPILER_RT_HAS_FNO_LTO_FLAG)
18+
builtin_check_c_compiler_flag(-fno-whole-program-vtables COMPILER_RT_HAS_FNO_WPD_FLAG)
19+
builtin_check_c_compiler_flag(-fno-virtual-function-elimination COMPILER_RT_HAS_FNO_VFE_FLAG)
1820
builtin_check_c_compiler_flag(-fno-profile-generate COMPILER_RT_HAS_FNO_PROFILE_GENERATE_FLAG)
1921
builtin_check_c_compiler_flag(-fno-profile-instr-generate COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG)
2022
builtin_check_c_compiler_flag(-fno-profile-instr-use COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG)

compiler-rt/cmake/config-ix.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ check_cxx_compiler_flag(-fno-rtti COMPILER_RT_HAS_FNO_RTTI_FLAG)
105105
check_cxx_compiler_flag("-Werror -fno-function-sections" COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG)
106106
check_cxx_compiler_flag(-ftls-model=initial-exec COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC)
107107
check_cxx_compiler_flag(-fno-lto COMPILER_RT_HAS_FNO_LTO_FLAG)
108+
check_cxx_compiler_flag(-fno-whole-program-vtables COMPILER_RT_HAS_FNO_WPD_FLAG)
109+
check_cxx_compiler_flag(-fno-virtual-function-elimination COMPILER_RT_HAS_FNO_VFE_FLAG)
108110
check_cxx_compiler_flag(-fno-profile-generate COMPILER_RT_HAS_FNO_PROFILE_GENERATE_FLAG)
109111
check_cxx_compiler_flag(-fno-profile-instr-generate COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG)
110112
check_cxx_compiler_flag(-fno-profile-instr-use COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG)

compiler-rt/cmake/crt-config-ix.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ builtin_check_c_compiler_flag(-fPIC COMPILER_RT_HAS_FPIC_FLAG)
88
builtin_check_c_compiler_flag(-std=c11 COMPILER_RT_HAS_STD_C11_FLAG)
99
builtin_check_c_compiler_flag(-Wno-pedantic COMPILER_RT_HAS_WNO_PEDANTIC)
1010
builtin_check_c_compiler_flag(-fno-lto COMPILER_RT_HAS_FNO_LTO_FLAG)
11+
builtin_check_c_compiler_flag(-fno-whole-program-vtables COMPILER_RT_HAS_FNO_WPD_FLAG)
12+
builtin_check_c_compiler_flag(-fno-virtual-function-elimination COMPILER_RT_HAS_FNO_VFE_FLAG)
1113
builtin_check_c_compiler_flag(-fno-profile-generate COMPILER_RT_HAS_FNO_PROFILE_GENERATE_FLAG)
1214
builtin_check_c_compiler_flag(-fno-profile-instr-generate COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG)
1315
builtin_check_c_compiler_flag(-fno-profile-instr-use COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG)

compiler-rt/lib/scudo/standalone/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ append_list_if(COMPILER_RT_HAS_WNO_PEDANTIC -Wno-pedantic SCUDO_CFLAGS)
2323

2424
# FIXME: find cleaner way to agree with GWPAsan flags
2525
append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SCUDO_CFLAGS)
26+
append_list_if(COMPILER_RT_HAS_FNO_WPD_FLAG -fno-whole-program-vtables SCUDO_CFLAGS)
27+
append_list_if(COMPILER_RT_HAS_FNO_VFE_FLAG -fno-virtual-function-elimination SCUDO_CFLAGS)
2628

2729
if(COMPILER_RT_DEBUG)
2830
list(APPEND SCUDO_CFLAGS -O0 -DSCUDO_DEBUG=1 -DSCUDO_ENABLE_HOOKS=1)

0 commit comments

Comments
 (0)