cmake: move toolchain_ld_baremetal to linker properties.

Move linker flag setting from toolchain_ld_baremetal() to linker flag
properties as to follow the principle used in previos commits and from
PR#24851.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2024-09-02 13:14:43 +02:00 committed by Carles Cufí
commit 5badbfe2a2
9 changed files with 96 additions and 118 deletions

View file

@ -385,6 +385,28 @@ toolchain_ld_force_undefined_symbols(
if(NOT CONFIG_NATIVE_BUILD)
# @Intent: Set linker specific flags for bare metal target
toolchain_ld_baremetal()
zephyr_link_libraries(PROPERTY baremetal)
# Note that some architectures will skip this flag if set to error, even
# though the compiler flag check passes (e.g. ARC and Xtensa). So warning
# should be the default for now.
#
# Skip this for native application as Zephyr only provides
# additions to the host toolchain linker script. The relocation
# sections (.rel*) requires us to override those provided
# by host toolchain. As we can't account for all possible
# combination of compiler and linker on all machines used
# for development, it is better to turn this off.
#
# CONFIG_LINKER_ORPHAN_SECTION_PLACE is to place the orphan sections
# without any warnings or errors, which is the default behavior.
# So there is no need to explicitly set a linker flag.
if(CONFIG_LINKER_ORPHAN_SECTION_WARN)
zephyr_link_libraries(PROPERTY orphan_warning)
elseif(CONFIG_LINKER_ORPHAN_SECTION_ERROR)
zephyr_link_libraries(PROPERTY orphan_error)
endif()
endif()
if(CONFIG_CPP)

View file

@ -4,6 +4,38 @@
set_property(TARGET linker PROPERTY cpp_base -Hcplus)
check_set_linker_property(TARGET linker PROPERTY baremetal
-Hlld
-Hnosdata
-Xtimer0 # to suppress the warning message
-Hnoxcheck_obj
-Hnocplus
-Hhostlib=
-Hheap=0
-Hnoivt
-Hnocrt
)
# There are two options:
# - We have full MWDT libc support and we link MWDT libc - this is default
# behavior and we don't need to do something for that.
# - We use minimal libc provided by Zephyr itself. In that case we must not
# link MWDT libc, but we still need to link libmw
if(CONFIG_MINIMAL_LIBC)
check_set_linker_property(TARGET linker APPEND PROPERTY baremetal
-Hnolib
-Hldopt=-lmw
)
endif()
check_set_linker_property(TARGET linker PROPERTY orphan_warning
${LINKERFLAGPREFIX},--orphan-handling=warn
)
check_set_linker_property(TARGET linker PROPERTY orphan_error
${LINKERFLAGPREFIX},--orphan-handling=error
)
# Extra warnings options for twister run
set_property(TARGET linker PROPERTY warnings_as_errors -Wl,--fatal-warnings)

View file

@ -110,51 +110,6 @@ endfunction(toolchain_ld_link_elf)
# linker options of temporary linkage for code generation
macro(toolchain_ld_baremetal)
zephyr_ld_options(
-Hlld
-Hnosdata
-Xtimer0 # to suppress the warning message
-Hnoxcheck_obj
-Hnocplus
-Hhostlib=
-Hheap=0
-Hnoivt
-Hnocrt
)
# There are two options:
# - We have full MWDT libc support and we link MWDT libc - this is default
# behavior and we don't need to do something for that.
# - We use minimal libc provided by Zephyr itself. In that case we must not
# link MWDT libc, but we still need to link libmw
if(CONFIG_MINIMAL_LIBC)
zephyr_ld_options(
-Hnolib
-Hldopt=-lmw
)
endif()
# Funny thing is if this is set to =error, some architectures will
# skip this flag even though the compiler flag check passes
# (e.g. ARC and Xtensa). So warning should be the default for now.
#
# Skip this for native application as Zephyr only provides
# additions to the host toolchain linker script. The relocation
# sections (.rel*) requires us to override those provided
# by host toolchain. As we can't account for all possible
# combination of compiler and linker on all machines used
# for development, it is better to turn this off.
#
# CONFIG_LINKER_ORPHAN_SECTION_PLACE is to place the orphan sections
# without any warnings or errors, which is the default behavior.
# So there is no need to explicitly set a linker flag.
if(CONFIG_LINKER_ORPHAN_SECTION_WARN)
message(WARNING "MWDT toolchain does not support
CONFIG_LINKER_ORPHAN_SECTION_WARN")
elseif(CONFIG_LINKER_ORPHAN_SECTION_ERROR)
zephyr_ld_options(
${LINKERFLAGPREFIX}--orphan-handling=error)
endif()
endmacro()
# base linker options

View file

@ -11,6 +11,21 @@ if(NOT CONFIG_MINIMAL_LIBCPP AND NOT CONFIG_NATIVE_LIBRARY AND NOT CONFIG_EXTERN
set_property(TARGET linker PROPERTY cpp_base -lstdc++)
endif()
check_set_linker_property(TARGET linker PROPERTY baremetal
-nostdlib
-static
${LINKERFLAGPREFIX},-X
${LINKERFLAGPREFIX},-N
)
check_set_linker_property(TARGET linker PROPERTY orphan_warning
${LINKERFLAGPREFIX},--orphan-handling=warn
)
check_set_linker_property(TARGET linker PROPERTY orphan_error
${LINKERFLAGPREFIX},--orphan-handling=error
)
check_set_linker_property(TARGET linker PROPERTY memusage "${LINKERFLAGPREFIX},--print-memory-usage")
# -no-pie is not supported until binutils 2.37.

View file

@ -3,37 +3,4 @@
# See root CMakeLists.txt for description and expectations of these macros
macro(toolchain_ld_baremetal)
# LINKERFLAGPREFIX comes from linker/ld/target.cmake
zephyr_ld_options(
-nostdlib
-static
${LINKERFLAGPREFIX},-X
${LINKERFLAGPREFIX},-N
)
# Funny thing is if this is set to =error, some architectures will
# skip this flag even though the compiler flag check passes
# (e.g. ARC and Xtensa). So warning should be the default for now.
#
# Skip this for native application as Zephyr only provides
# additions to the host toolchain linker script. The relocation
# sections (.rel*) requires us to override those provided
# by host toolchain. As we can't account for all possible
# combination of compiler and linker on all machines used
# for development, it is better to turn this off.
#
# CONFIG_LINKER_ORPHAN_SECTION_PLACE is to place the orphan sections
# without any warnings or errors, which is the default behavior.
# So there is no need to explicitly set a linker flag.
if(CONFIG_LINKER_ORPHAN_SECTION_WARN)
zephyr_ld_options(
${LINKERFLAGPREFIX},--orphan-handling=warn
)
elseif(CONFIG_LINKER_ORPHAN_SECTION_ERROR)
zephyr_ld_options(
${LINKERFLAGPREFIX},--orphan-handling=error
)
endif()
endmacro()

View file

@ -11,6 +11,13 @@ set_property(TARGET linker PROPERTY base)
# using C++.
set_property(TARGET linker PROPERTY cpp_base)
# Base properties when building Zephyr for an embedded target (baremetal).
set_property(TARGET linker PROPERTY baremetal)
# Property for controlling linker reporting / handling when placing orphaned sections.
set_property(TARGET linker PROPERTY orphan_warning)
set_property(TARGET linker PROPERTY orphan_error)
# coverage is a property holding the linker flag required for coverage support on the toolchain.
# For example, on ld/gcc this would be: -lgcov
# Set the property for the corresponding flags of the given toolchain.

View file

@ -9,6 +9,11 @@ if(NOT CONFIG_MINIMAL_LIBCPP AND NOT CONFIG_NATIVE_LIBRARY AND NOT CONFIG_EXTERN
set_property(TARGET linker PROPERTY cpp_base -lc++ ${LINKERFLAGPREFIX},-z,norelro)
endif()
# Force LLVM to use built-in lld linker
if(NOT CONFIG_LLVM_USE_LD)
check_set_linker_property(TARGET linker APPEND PROPERTY baremetal -fuse-ld=lld)
endif()
set_property(TARGET linker PROPERTY no_position_independent "${LINKERFLAGPREFIX},--no-pie")
set_property(TARGET linker PROPERTY lto_arguments)

View file

@ -3,44 +3,4 @@
# See root CMakeLists.txt for description and expectations of these macros
macro(toolchain_ld_baremetal)
# LINKERFLAGPREFIX comes from linker/lld/target.cmake
zephyr_ld_options(
-nostdlib
-static
${LINKERFLAGPREFIX},-X
${LINKERFLAGPREFIX},-N
)
# Force LLVM to use built-in lld linker
if(NOT CONFIG_LLVM_USE_LD)
zephyr_ld_options(
-fuse-ld=lld
)
endif()
# Funny thing is if this is set to =error, some architectures will
# skip this flag even though the compiler flag check passes
# (e.g. ARC and Xtensa). So warning should be the default for now.
#
# Skip this for native application as Zephyr only provides
# additions to the host toolchain linker script. The relocation
# sections (.rel*) requires us to override those provided
# by host toolchain. As we can't account for all possible
# combination of compiler and linker on all machines used
# for development, it is better to turn this off.
#
# CONFIG_LINKER_ORPHAN_SECTION_PLACE is to place the orphan sections
# without any warnings or errors, which is the default behavior.
# So there is no need to explicitly set a linker flag.
if(CONFIG_LINKER_ORPHAN_SECTION_WARN)
zephyr_ld_options(
${LINKERFLAGPREFIX},--orphan-handling=warn
)
elseif(CONFIG_LINKER_ORPHAN_SECTION_ERROR)
zephyr_ld_options(
${LINKERFLAGPREFIX},--orphan-handling=error
)
endif()
endmacro()

View file

@ -11,6 +11,21 @@ if(NOT CONFIG_MINIMAL_LIBCPP AND NOT CONFIG_NATIVE_LIBRARY AND NOT CONFIG_EXTERN
set_property(TARGET linker PROPERTY cpp_base -lstdc++)
endif()
check_set_linker_property(TARGET linker PROPERTY baremetal
-nostdlib
-static
${LINKERFLAGPREFIX},-X
${LINKERFLAGPREFIX},-N
)
check_set_linker_property(TARGET linker PROPERTY orphan_warning
${LINKERFLAGPREFIX},--orphan-handling=warn
)
check_set_linker_property(TARGET linker PROPERTY orphan_error
${LINKERFLAGPREFIX},--orphan-handling=error
)
set_property(TARGET linker PROPERTY partial_linking "-r")
check_set_linker_property(TARGET linker PROPERTY no_relax ${LINKERFLAGPREFIX},--no-relax)