kconfig: cmake: CMake linker script generator symbol added
A "Linker script" choice group has been added to the linker options menu. The existing HAVE_CUSTOM_LINKER_SCRIPT config has been relocated inside the linker script menu. Two new entries has been created: - LD template, for using the old ld template files together with the C pre-processor to create the final linker script. - CMake linker generator, used for ARMClang / armlink toolchain. The CMake linker generator is also supported for LD linker scripts for the ARM architecture. In CMake, the file cmake/linker/ld/target.cmake has been updated to support the CMake LD linker generator. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
parent
e9e47a45dd
commit
761eada9d3
2 changed files with 95 additions and 44 deletions
|
@ -132,8 +132,36 @@ config ROM_START_OFFSET
|
||||||
alignment requirements on most ARM targets, although some targets
|
alignment requirements on most ARM targets, although some targets
|
||||||
may require smaller or larger values.
|
may require smaller or larger values.
|
||||||
|
|
||||||
|
config LD_LINKER_SCRIPT_SUPPORTED
|
||||||
|
bool
|
||||||
|
default y
|
||||||
|
|
||||||
|
choice LINKER_SCRIPT
|
||||||
|
prompt "Linker script"
|
||||||
|
default LD_LINKER_TEMPLATE if LD_LINKER_SCRIPT_SUPPORTED
|
||||||
|
|
||||||
|
config LD_LINKER_TEMPLATE
|
||||||
|
bool "LD template"
|
||||||
|
depends on LD_LINKER_SCRIPT_SUPPORTED
|
||||||
|
help
|
||||||
|
Select this option to use the LD linker script templates.
|
||||||
|
The templates are pre-processed by the C pre-processor to create the
|
||||||
|
final LD linker script.
|
||||||
|
|
||||||
|
config CMAKE_LINKER_GENERATOR
|
||||||
|
bool "CMake generator"
|
||||||
|
depends on ARM
|
||||||
|
help
|
||||||
|
Select this option to use the Zephyr CMake linker script generator.
|
||||||
|
The linker configuration is written in CMake and the final linker
|
||||||
|
script will be generated by the toolchain specific linker generator.
|
||||||
|
For LD based linkers, this will be the ld generator, for ARMClang /
|
||||||
|
armlink based linkers it will be the scatter generator.
|
||||||
|
|
||||||
|
endchoice
|
||||||
|
|
||||||
config HAVE_CUSTOM_LINKER_SCRIPT
|
config HAVE_CUSTOM_LINKER_SCRIPT
|
||||||
bool "Custom linker scripts provided"
|
bool "Custom linker script provided"
|
||||||
help
|
help
|
||||||
Set this option if you have a custom linker script which needed to
|
Set this option if you have a custom linker script which needed to
|
||||||
be define in CUSTOM_LINKER_SCRIPT.
|
be define in CUSTOM_LINKER_SCRIPT.
|
||||||
|
|
|
@ -31,51 +31,74 @@ endif()
|
||||||
macro(configure_linker_script linker_script_gen linker_pass_define)
|
macro(configure_linker_script linker_script_gen linker_pass_define)
|
||||||
set(extra_dependencies ${ARGN})
|
set(extra_dependencies ${ARGN})
|
||||||
|
|
||||||
# Different generators deal with depfiles differently.
|
if(CONFIG_CMAKE_LINKER_GENERATOR)
|
||||||
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
|
if("${linker_pass_define}" STREQUAL "-DLINKER_ZEPHYR_PREBUILT")
|
||||||
# Note that the IMPLICIT_DEPENDS option is currently supported only
|
set(PASS 1)
|
||||||
# for Makefile generators and will be ignored by other generators.
|
elseif("${linker_pass_define}" STREQUAL "-DLINKER_ZEPHYR_FINAL;-DLINKER_PASS2")
|
||||||
set(linker_script_dep IMPLICIT_DEPENDS C ${LINKER_SCRIPT})
|
set(PASS 2)
|
||||||
elseif(CMAKE_GENERATOR STREQUAL "Ninja")
|
endif()
|
||||||
# Using DEPFILE with other generators than Ninja is an error.
|
|
||||||
set(linker_script_dep DEPFILE ${PROJECT_BINARY_DIR}/${linker_script_gen}.dep)
|
add_custom_command(
|
||||||
|
OUTPUT ${linker_script_gen}
|
||||||
|
COMMAND ${CMAKE_COMMAND}
|
||||||
|
-DPASS=${PASS}
|
||||||
|
-DFORMAT="$<TARGET_PROPERTY:linker,FORMAT>"
|
||||||
|
-DENTRY="$<TARGET_PROPERTY:linker,ENTRY>"
|
||||||
|
-DMEMORY_REGIONS="$<TARGET_PROPERTY:linker,MEMORY_REGIONS>"
|
||||||
|
-DGROUPS="$<TARGET_PROPERTY:linker,GROUPS>"
|
||||||
|
-DSECTIONS="$<TARGET_PROPERTY:linker,SECTIONS>"
|
||||||
|
-DSECTION_SETTINGS="$<TARGET_PROPERTY:linker,SECTION_SETTINGS>"
|
||||||
|
-DSYMBOLS="$<TARGET_PROPERTY:linker,SYMBOLS>"
|
||||||
|
-DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/${linker_script_gen}
|
||||||
|
-P ${ZEPHYR_BASE}/cmake/linker/ld/ld_script.cmake
|
||||||
|
)
|
||||||
else()
|
else()
|
||||||
# TODO: How would the linker script dependencies work for non-linker
|
# Different generators deal with depfiles differently.
|
||||||
# script generators.
|
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
|
||||||
message(STATUS "Warning; this generator is not well supported. The
|
# Note that the IMPLICIT_DEPENDS option is currently supported only
|
||||||
Linker script may not be regenerated when it should.")
|
# for Makefile generators and will be ignored by other generators.
|
||||||
set(linker_script_dep "")
|
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}
|
||||||
|
${AUTOCONF_H}
|
||||||
|
${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
|
||||||
|
-imacros ${AUTOCONF_H}
|
||||||
|
${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
|
||||||
|
)
|
||||||
endif()
|
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}
|
|
||||||
${AUTOCONF_H}
|
|
||||||
${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
|
|
||||||
-imacros ${AUTOCONF_H}
|
|
||||||
${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()
|
endmacro()
|
||||||
|
|
||||||
# Force symbols to be entered in the output file as undefined symbols
|
# Force symbols to be entered in the output file as undefined symbols
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue