diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ca8ab10891..91c369c4e01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -225,11 +225,8 @@ zephyr_compile_options( toolchain_ld_base() if(NOT CONFIG_NATIVE_APPLICATION) -zephyr_ld_options( - -nostdlib - -static - -no-pie -) + # @Intent: Set linker specific flags for bare metal target + toolchain_ld_baremetal() endif() if(CONFIG_LIB_CPLUSPLUS) @@ -379,13 +376,6 @@ if(CONFIG_USERSPACE) endif() endif() -if(NOT CONFIG_NATIVE_APPLICATION) -zephyr_ld_options( - ${LINKERFLAGPREFIX},-X - ${LINKERFLAGPREFIX},-N - ) -endif() - zephyr_ld_options( ${LINKERFLAGPREFIX},--gc-sections ${LINKERFLAGPREFIX},--build-id=none diff --git a/cmake/linker/ld/target.cmake b/cmake/linker/ld/target.cmake index a8b85fce838..ae5b2834448 100644 --- a/cmake/linker/ld/target.cmake +++ b/cmake/linker/ld/target.cmake @@ -6,3 +6,4 @@ set_ifndef(LINKERFLAGPREFIX -Wl) # Load toolchain_ld-family macros include(${ZEPHYR_BASE}/cmake/linker/${LINKER}/target_base.cmake) +include(${ZEPHYR_BASE}/cmake/linker/${LINKER}/target_baremetal.cmake) diff --git a/cmake/linker/ld/target_baremetal.cmake b/cmake/linker/ld/target_baremetal.cmake new file mode 100644 index 00000000000..96d337464df --- /dev/null +++ b/cmake/linker/ld/target_baremetal.cmake @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: Apache-2.0 + +# See root CMakeLists.txt for description and expectations of these macros + +macro(toolchain_ld_baremetal) + + zephyr_ld_options( + -nostdlib + -static + -no-pie + ${LINKERFLAGPREFIX},-X + ${LINKERFLAGPREFIX},-N + ) + +endmacro()