From f44ac0ce39ea19a08f1784e2ce6ac0bbdc8a7585 Mon Sep 17 00:00:00 2001 From: Anichitei Ionel-Cristinel Date: Mon, 16 Sep 2024 12:50:52 +0300 Subject: [PATCH] build: Fix disasmtool LTO --- CMakeLists.txt | 10 ++++++++++ disasmtool/CMakeLists.txt | 24 +++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cc5dcf..1e5c2c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) diff --git a/disasmtool/CMakeLists.txt b/disasmtool/CMakeLists.txt index 80f7c64..f98ec45 100644 --- a/disasmtool/CMakeLists.txt +++ b/disasmtool/CMakeLists.txt @@ -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 () @@ -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 ()