From 65f02c04d5e0893f66010158de49303113c6ff76 Mon Sep 17 00:00:00 2001 From: Mark Ruvald Pedersen Date: Thu, 25 Apr 2019 16:31:30 +0200 Subject: [PATCH] cmake: Toolchain abstraction: introduce toolchain_ld_baremetal() The intent of toolchain_ld_baremetal() is to collect the flags belonging to non-hosted (i.e. POSIX-based) targets. No functional change expected. This is motivated by the wish to abstract Zephyr's usage of toolchains, permitting non-intrusive porting to other (commercial) toolchains. Signed-off-by: Mark Ruvald Pedersen --- CMakeLists.txt | 14 ++------------ cmake/linker/ld/target.cmake | 1 + cmake/linker/ld/target_baremetal.cmake | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 cmake/linker/ld/target_baremetal.cmake 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()