1# SPDX-License-Identifier: Apache-2.0
2
3# See root CMakeLists.txt for description and expectations of these macros
4
5macro(toolchain_ld_baremetal)
6
7  # LINKERFLAGPREFIX comes from linker/ld/target.cmake
8  zephyr_ld_options(
9    -nostdlib
10    -static
11    ${LINKERFLAGPREFIX},-X
12    ${LINKERFLAGPREFIX},-N
13  )
14
15  # Funny thing is if this is set to =error, some architectures will
16  # skip this flag even though the compiler flag check passes
17  # (e.g. ARC and Xtensa). So warning should be the default for now.
18  #
19  # Skip this for native application as Zephyr only provides
20  # additions to the host toolchain linker script. The relocation
21  # sections (.rel*) requires us to override those provided
22  # by host toolchain. As we can't account for all possible
23  # combination of compiler and linker on all machines used
24  # for development, it is better to turn this off.
25  #
26  # CONFIG_LINKER_ORPHAN_SECTION_PLACE is to place the orphan sections
27  # without any warnings or errors, which is the default behavior.
28  # So there is no need to explicitly set a linker flag.
29  if(CONFIG_LINKER_ORPHAN_SECTION_WARN)
30    zephyr_ld_options(
31      ${LINKERFLAGPREFIX},--orphan-handling=warn
32    )
33  elseif(CONFIG_LINKER_ORPHAN_SECTION_ERROR)
34    zephyr_ld_options(
35      ${LINKERFLAGPREFIX},--orphan-handling=error
36    )
37  endif()
38
39endmacro()
40