LLVM: add built-in lld linker support for x86.

add support to use LLVM built-in lld linker to build
zephyr applications for x86 platforms.

Signed-off-by: Chen Peng1 <peng1.chen@intel.com>
This commit is contained in:
Chen Peng1 2022-02-25 16:21:27 +08:00 committed by Carles Cufí
commit d8fa857b19
7 changed files with 90 additions and 3 deletions

View file

@ -107,7 +107,7 @@ endfunction(toolchain_ld_link_elf)
# Load toolchain_ld-family macros
include(${ZEPHYR_BASE}/cmake/linker/ld/target_base.cmake)
include(${ZEPHYR_BASE}/cmake/linker/${LINKER}/target_base.cmake)
include(${ZEPHYR_BASE}/cmake/linker/${LINKER}/target_baremetal.cmake)
include(${ZEPHYR_BASE}/cmake/linker/ld/target_cpp.cmake)
include(${ZEPHYR_BASE}/cmake/linker/ld/target_relocation.cmake)

View file

@ -4,7 +4,7 @@
macro(toolchain_ld_baremetal)
# LINKERFLAGPREFIX comes from linker/ld/target.cmake
# LINKERFLAGPREFIX comes from linker/lld/target.cmake
zephyr_ld_options(
-nostdlib
-static
@ -12,6 +12,13 @@ macro(toolchain_ld_baremetal)
${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.

View file

@ -0,0 +1,28 @@
# SPDX-License-Identifier: Apache-2.0
# See root CMakeLists.txt for description and expectations of these macros
macro(toolchain_ld_base)
if(NOT PROPERTY_LINKER_SCRIPT_DEFINES)
set_property(GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES -D__GCC_LINKER_CMD__)
endif()
# 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
)
endmacro()