cmake: llvm: use lld
Use lld linker instead of ld. Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
22c1c505c4
commit
1d949ee20f
3 changed files with 151 additions and 1 deletions
111
cmake/linker/lld/target.cmake
Normal file
111
cmake/linker/lld/target.cmake
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
find_program(CMAKE_LINKER ld.lld )
|
||||||
|
|
||||||
|
set_ifndef(LINKERFLAGPREFIX -Wl)
|
||||||
|
|
||||||
|
# Run $LINKER_SCRIPT file through the C preprocessor, producing ${linker_script_gen}
|
||||||
|
# NOTE: ${linker_script_gen} will be produced at build-time; not at configure-time
|
||||||
|
macro(configure_linker_script linker_script_gen linker_pass_define)
|
||||||
|
set(extra_dependencies ${ARGN})
|
||||||
|
|
||||||
|
# Different generators deal with depfiles differently.
|
||||||
|
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
|
||||||
|
# Note that the IMPLICIT_DEPENDS option is currently supported only
|
||||||
|
# for Makefile generators and will be ignored by other generators.
|
||||||
|
set(linker_script_dep IMPLICIT_DEPENDS C ${LINKER_SCRIPT})
|
||||||
|
elseif(CMAKE_GENERATOR STREQUAL "Ninja")
|
||||||
|
# Using DEPFILE with other generators than Ninja is an error.
|
||||||
|
set(linker_script_dep DEPFILE ${PROJECT_BINARY_DIR}/${linker_script_gen}.dep)
|
||||||
|
else()
|
||||||
|
# TODO: How would the linker script dependencies work for non-linker
|
||||||
|
# script generators.
|
||||||
|
message(STATUS "Warning; this generator is not well supported. The
|
||||||
|
Linker script may not be regenerated when it should.")
|
||||||
|
set(linker_script_dep "")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
zephyr_get_include_directories_for_lang(C current_includes)
|
||||||
|
get_filename_component(base_name ${CMAKE_CURRENT_BINARY_DIR} NAME)
|
||||||
|
get_property(current_defines GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES)
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${linker_script_gen}
|
||||||
|
DEPENDS
|
||||||
|
${LINKER_SCRIPT}
|
||||||
|
${extra_dependencies}
|
||||||
|
# NB: 'linker_script_dep' will use a keyword that ends 'DEPENDS'
|
||||||
|
${linker_script_dep}
|
||||||
|
COMMAND ${CMAKE_C_COMPILER}
|
||||||
|
-x assembler-with-cpp
|
||||||
|
${NOSYSDEF_CFLAG}
|
||||||
|
-MD -MF ${linker_script_gen}.dep -MT ${base_name}/${linker_script_gen}
|
||||||
|
-D_LINKER
|
||||||
|
-D_ASMLANGUAGE
|
||||||
|
${current_includes}
|
||||||
|
${current_defines}
|
||||||
|
${linker_pass_define}
|
||||||
|
-E ${LINKER_SCRIPT}
|
||||||
|
-P # Prevent generation of debug `#line' directives.
|
||||||
|
-o ${linker_script_gen}
|
||||||
|
VERBATIM
|
||||||
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||||
|
COMMAND_EXPAND_LISTS
|
||||||
|
)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
# Force symbols to be entered in the output file as undefined symbols
|
||||||
|
function(toolchain_ld_force_undefined_symbols)
|
||||||
|
foreach(symbol ${ARGN})
|
||||||
|
zephyr_link_libraries(${LINKERFLAGPREFIX},-u,${symbol})
|
||||||
|
endforeach()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# Link a target to given libraries with toolchain-specific argument order
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# toolchain_ld_link_elf(
|
||||||
|
# TARGET_ELF <target_elf>
|
||||||
|
# OUTPUT_MAP <output_map_file_of_target>
|
||||||
|
# LIBRARIES_PRE_SCRIPT [libraries_pre_script]
|
||||||
|
# LINKER_SCRIPT <linker_script>
|
||||||
|
# LIBRARIES_POST_SCRIPT [libraries_post_script]
|
||||||
|
# DEPENDENCIES [dependencies]
|
||||||
|
# )
|
||||||
|
function(toolchain_ld_link_elf)
|
||||||
|
cmake_parse_arguments(
|
||||||
|
TOOLCHAIN_LD_LINK_ELF # prefix of output variables
|
||||||
|
"" # list of names of the boolean arguments
|
||||||
|
"TARGET_ELF;OUTPUT_MAP;LINKER_SCRIPT" # list of names of scalar arguments
|
||||||
|
"LIBRARIES_PRE_SCRIPT;LIBRARIES_POST_SCRIPT;DEPENDENCIES" # list of names of list arguments
|
||||||
|
${ARGN} # input args to parse
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(
|
||||||
|
${TOOLCHAIN_LD_LINK_ELF_TARGET_ELF}
|
||||||
|
${TOOLCHAIN_LD_LINK_ELF_LIBRARIES_PRE_SCRIPT}
|
||||||
|
${TOPT}
|
||||||
|
${TOOLCHAIN_LD_LINK_ELF_LINKER_SCRIPT}
|
||||||
|
${TOOLCHAIN_LD_LINK_ELF_LIBRARIES_POST_SCRIPT}
|
||||||
|
|
||||||
|
${LINKERFLAGPREFIX},-Map=${TOOLCHAIN_LD_LINK_ELF_OUTPUT_MAP}
|
||||||
|
${LINKERFLAGPREFIX},--whole-archive
|
||||||
|
${ZEPHYR_LIBS_PROPERTY}
|
||||||
|
${LINKERFLAGPREFIX},--no-whole-archive
|
||||||
|
kernel
|
||||||
|
$<TARGET_OBJECTS:${OFFSETS_LIB}>
|
||||||
|
${LIB_INCLUDE_DIR}
|
||||||
|
-L${PROJECT_BINARY_DIR}
|
||||||
|
${TOOLCHAIN_LIBS}
|
||||||
|
|
||||||
|
${TOOLCHAIN_LD_LINK_ELF_DEPENDENCIES}
|
||||||
|
)
|
||||||
|
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_baremetal.cmake)
|
||||||
|
include(${ZEPHYR_BASE}/cmake/linker/ld/target_cpp.cmake)
|
||||||
|
include(${ZEPHYR_BASE}/cmake/linker/ld/target_relocation.cmake)
|
||||||
|
include(${ZEPHYR_BASE}/cmake/linker/ld/target_configure.cmake)
|
39
cmake/linker/lld/target_baremetal.cmake
Normal file
39
cmake/linker/lld/target_baremetal.cmake
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
# 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()
|
|
@ -9,7 +9,7 @@ endif()
|
||||||
set(LLVM_TOOLCHAIN_PATH ${CLANG_ROOT_DIR} CACHE PATH "clang install directory")
|
set(LLVM_TOOLCHAIN_PATH ${CLANG_ROOT_DIR} CACHE PATH "clang install directory")
|
||||||
|
|
||||||
set(COMPILER clang)
|
set(COMPILER clang)
|
||||||
set(LINKER ld) # TODO: Use lld eventually rather than GNU ld
|
set(LINKER lld)
|
||||||
set(BINTOOLS llvm)
|
set(BINTOOLS llvm)
|
||||||
|
|
||||||
if("${ARCH}" STREQUAL "arm")
|
if("${ARCH}" STREQUAL "arm")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue