Skip to content

Commit

Permalink
build: Fix disasmtool LTO
Browse files Browse the repository at this point in the history
  • Loading branch information
ianichitei committed Sep 16, 2024
1 parent d8f3046 commit f44ac0c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ option(BDD_USE_EXTERNAL_MEMSET "Expect nd_memset implementation from the integra
option(BDD_NO_MNEMONIC "Exclude mnemonics - this option involves setting the BDDISASM_NO_FORMAT flag" OFF)
option(BDD_ASAN "Build with ASAN" OFF)
option(BDD_UBSAN "Build with UBSAN" OFF)
option(BDD_LTO "Enable LTO" OFF)

set(BDD_VER_FILE ${CMAKE_CURRENT_LIST_DIR}/inc/bddisasm_version.h)

Expand Down Expand Up @@ -220,6 +221,15 @@ set_target_properties(

add_library(bddisasm::bdshemu ALIAS bdshemu)

if (BDD_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT USE_IPO)
if (USE_IPO)
set_target_properties(bddisasm PROPERTIES INTERPROCEDURAL_OPTIMIZATION True)
set_target_properties(bdshemu PROPERTIES INTERPROCEDURAL_OPTIMIZATION True)
endif ()
endif ()

# If this is the master project (and if the user requested it) add disasmtool.
if ((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) AND BDD_INCLUDE_TOOL)
add_subdirectory(disasmtool)
Expand Down
24 changes: 23 additions & 1 deletion disasmtool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
include(CheckIPOSupported)
check_ipo_supported(RESULT USE_IPO)
if (USE_IPO)
set_target_properties(bddisasm PROPERTIES INTERPROCEDURAL_OPTIMIZATION True)
set_target_properties(disasmtool PROPERTIES INTERPROCEDURAL_OPTIMIZATION True)
endif ()
endif ()

Expand Down Expand Up @@ -69,3 +69,25 @@ else ()
-Wduplicated-cond)
endif ()
endif ()

if (BDD_ASAN)
target_compile_options(disasmtool PUBLIC "-fsanitize=address")
target_link_libraries(disasmtool PUBLIC "-fsanitize=address")
endif ()

if (BDD_UBSAN)
target_compile_options(disasmtool PUBLIC
"-fsanitize=undefined"
"-fno-sanitize=alignment")
target_link_libraries(disasmtool PUBLIC
"-fsanitize=undefined"
"-fno-sanitize=alignment")
endif ()

if (BDD_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT USE_IPO)
if (USE_IPO)
set_target_properties(disasmtool PROPERTIES INTERPROCEDURAL_OPTIMIZATION True)
endif ()
endif ()

0 comments on commit f44ac0c

Please sign in to comment.