2022-02-25 16:21:27 +08:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
# See root CMakeLists.txt for description and expectations of these macros
|
|
|
|
|
|
|
|
macro(toolchain_ld_base)
|
|
|
|
# TOOLCHAIN_LD_FLAGS comes from compiler/clang/target.cmake
|
|
|
|
# LINKERFLAGPREFIX comes from linker/lld/target.cmake
|
|
|
|
zephyr_ld_options(
|
|
|
|
${TOOLCHAIN_LD_FLAGS}
|
|
|
|
)
|
|
|
|
|
|
|
|
zephyr_ld_options(
|
|
|
|
${LINKERFLAGPREFIX},--gc-sections
|
|
|
|
${LINKERFLAGPREFIX},--build-id=none
|
|
|
|
)
|
|
|
|
|
|
|
|
# Sort each input section by alignment.
|
|
|
|
zephyr_ld_option_ifdef(
|
|
|
|
CONFIG_LINKER_SORT_BY_ALIGNMENT
|
|
|
|
${LINKERFLAGPREFIX},--sort-section=alignment
|
|
|
|
)
|
|
|
|
|
2022-12-20 10:36:34 -08:00
|
|
|
if (NOT CONFIG_LINKER_USE_RELAX)
|
|
|
|
zephyr_ld_options(
|
|
|
|
${LINKERFLAGPREFIX},--no-relax
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2024-03-18 13:04:17 -07:00
|
|
|
# Global pointer relaxation is off by default in lld. Explicitly enable it if
|
|
|
|
# linker relaxations and gp usage are both allowed.
|
|
|
|
if (CONFIG_LINKER_USE_RELAX AND CONFIG_RISCV_GP)
|
|
|
|
zephyr_ld_options(
|
|
|
|
${LINKERFLAGPREFIX},--relax-gp
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2023-02-25 16:08:55 -08:00
|
|
|
if(CONFIG_CPP)
|
|
|
|
# LLVM lld complains:
|
|
|
|
# error: section: init_array is not contiguous with other relro sections
|
|
|
|
#
|
|
|
|
# So do not create RELRO program header.
|
|
|
|
zephyr_link_libraries(
|
|
|
|
-Wl,-z,norelro
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2023-08-01 14:39:34 +02:00
|
|
|
if(CONFIG_LIBGCC_RTLIB)
|
|
|
|
set(runtime_lib "libgcc")
|
|
|
|
elseif(CONFIG_COMPILER_RT_RTLIB)
|
|
|
|
set(runtime_lib "compiler_rt")
|
|
|
|
endif()
|
|
|
|
|
2023-02-13 13:34:23 -08:00
|
|
|
zephyr_link_libraries(
|
2023-08-01 14:39:34 +02:00
|
|
|
--config ${ZEPHYR_BASE}/cmake/toolchain/llvm/clang_${runtime_lib}.cfg
|
2023-02-13 13:34:23 -08:00
|
|
|
)
|
2022-02-25 16:21:27 +08:00
|
|
|
endmacro()
|