Commit 5badbfe2 authored by Torsten Rasmussen's avatar Torsten Rasmussen Committed by Carles Cufi
Browse files

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: default avatarTorsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
parent 9a9e252d
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -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)
+32 −0
Original line number Diff line number Diff line
@@ -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)

+0 −45
Original line number Diff line number Diff line
@@ -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
+15 −0
Original line number Diff line number Diff line
@@ -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.
+0 −33
Original line number Diff line number Diff line
@@ -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()
Loading