diff --git a/Kconfig.zephyr b/Kconfig.zephyr index edb9a79593..1b12e5955a 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -508,7 +508,6 @@ endchoice config LTO bool "Link Time Optimization [EXPERIMENTAL]" depends on !(GEN_ISR_TABLES || GEN_IRQ_VECTOR_TABLE) || ISR_TABLES_LOCAL_DECLARATION - depends on !NATIVE_LIBRARY depends on !CODE_DATA_RELOCATION select EXPERIMENTAL help diff --git a/arch/posix/CMakeLists.txt b/arch/posix/CMakeLists.txt index 1e57132865..907fb5dd9e 100644 --- a/arch/posix/CMakeLists.txt +++ b/arch/posix/CMakeLists.txt @@ -159,13 +159,17 @@ endif() # (supported by current gcc's as well) # if(CONFIG_CFI) - zephyr_compile_options(-flto -fvisibility=hidden -fno-sanitize-trap=cfi -fsanitize-ignorelist=/home/patrick/repos/uni/idp/zephyrtest/zephyr/ignore_list.txt) - target_link_options(native_simulator INTERFACE "-flto -fvisibility=hidden -fno-sanitize-trap=cfi -fsanitize-ignorelist=/home/patrick/repos/uni/idp/zephyrtest/zephyr/ignore_list.txt") - target_compile_options(native_simulator INTERFACE "-flto -fvisibility=hidden -fno-sanitize-trap=cfi -fsanitize-ignorelist=/home/patrick/repos/uni/idp/zephyrtest/zephyr/ignore_list.txt") - zephyr_link_libraries("-flto") + zephyr_compile_options(-fvisibility=hidden -fno-sanitize-trap=cfi -fsanitize-ignorelist=/home/patrick/repos/uni/idp/zephyrtest/zephyr/ignore_list.txt) + target_link_options(native_simulator INTERFACE "-fvisibility=hidden -fno-sanitize-trap=cfi -fsanitize-ignorelist=/home/patrick/repos/uni/idp/zephyrtest/zephyr/ignore_list.txt") + target_compile_options(native_simulator INTERFACE "-fvisibility=hidden -fno-sanitize-trap=cfi -fsanitize-ignorelist=/home/patrick/repos/uni/idp/zephyrtest/zephyr/ignore_list.txt") list(APPEND LLVM_SANITIZERS "cfi") endif() +if(CONFIG_LTO) + target_compile_options(native_simulator INTERFACE "-flto") + target_link_options(native_simulator INTERFACE "-flto") +endif() + if(CONFIG_ASAN) list(APPEND LLVM_SANITIZERS "address") endif() diff --git a/cmake/linker/ld/target.cmake b/cmake/linker/ld/target.cmake index 5b6cb7a23d..2d60e8ea63 100644 --- a/cmake/linker/ld/target.cmake +++ b/cmake/linker/ld/target.cmake @@ -131,7 +131,6 @@ function(toolchain_ld_link_elf) ${TOPT} ${TOOLCHAIN_LD_LINK_ELF_LINKER_SCRIPT} ${TOOLCHAIN_LD_LINK_ELF_LIBRARIES_POST_SCRIPT} - -flto ${LINKERFLAGPREFIX},-Map=${TOOLCHAIN_LD_LINK_ELF_OUTPUT_MAP} ${LINKERFLAGPREFIX},--whole-archive diff --git a/ignore_list.txt b/ignore_list.txt index a61e6ff8fd..aab45b8740 100644 --- a/ignore_list.txt +++ b/ignore_list.txt @@ -1 +1,2 @@ src:*/native_simulator/* +fun:z_cbvprintf_impl diff --git a/samples/basic/blinky/prj.conf b/samples/basic/blinky/prj.conf index 2d7d146afb..836d4e21f4 100644 --- a/samples/basic/blinky/prj.conf +++ b/samples/basic/blinky/prj.conf @@ -2,6 +2,7 @@ CONFIG_GPIO=y #CONFIG_ASAN=y CONFIG_CFI=y CONFIG_LLVM_USE_LLD=y +CONFIG_LTO=y #CONFIG_DEBUG=y #CONFIG_DEBUG_INFO=y diff --git a/scripts/pylib/twister/twisterlib/testinstance.py b/scripts/pylib/twister/twisterlib/testinstance.py index 5be57e1deb..36b4fc8109 100644 --- a/scripts/pylib/twister/twisterlib/testinstance.py +++ b/scripts/pylib/twister/twisterlib/testinstance.py @@ -285,6 +285,7 @@ class TestInstance: content = content + "\nCONFIG_COVERAGE=y" content = content + "\nCONFIG_COVERAGE_DUMP=y" + content = content + "\nCONFIG_CFI=y\nCONFIG_LTO=y\nCONFIG_LLVM_USE_LLD=y" if enable_asan: if platform.type == "native": content = content + "\nCONFIG_ASAN=y" diff --git a/subsys/debug/Kconfig b/subsys/debug/Kconfig index 89eac0940c..3ef79c1d65 100644 --- a/subsys/debug/Kconfig +++ b/subsys/debug/Kconfig @@ -110,6 +110,8 @@ config GPROF config CFI bool "Build with control flow integrity sanitizer" + depends on LTO + depends on LLVM_USE_LLD help Builds Zephyr with Address Sanitizer enabled. This is currently only supported by boards based on the posix architecture, and requires a