Skip to content

[compiler-rt] Disable WPD/VFE if LTO is disabled #120735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler-rt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion compiler-rt/cmake/Modules/AddCompilerRT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion compiler-rt/cmake/Modules/CheckSectionExists.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/cmake/builtin-config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/cmake/crt-config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/scudo/standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading