Skip to content

Commit d017959

Browse files
committed
linker: ld: CMake linker script generator for ld scripts (-->rework)
This commit introduces ZEPHYR_LINKER_SCRIPT_GENERATOR CMake variable which enables the use of the new CMake based ld linker script generator instead of the old C preprocessor scripts. The use ZEPHYR_LINKER_SCRIPT_GENERATOR variable is a temporary solution for the draft PR until a proper Kconfig structure for linker handling has been implemented. This commit will be remorked before PR goes out of draft. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
1 parent 5bf4e11 commit d017959

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

cmake/linker/ld/target.cmake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ endif()
2929
macro(configure_linker_script linker_script_gen linker_pass_define)
3030
set(extra_dependencies ${ARGN})
3131

32+
if(ZEPHYR_LINKER_SCRIPT_GENERATOR)
33+
if("${linker_pass_define}" STREQUAL "-DLINKER_ZEPHYR_PREBUILT")
34+
set(PASS 1)
35+
elseif("${linker_pass_define}" STREQUAL "-DLINKER_ZEPHYR_FINAL;-DLINKER_PASS2")
36+
set(PASS 2)
37+
endif()
38+
39+
add_custom_command(
40+
OUTPUT ${linker_script_gen}
41+
${STEERING_FILE}
42+
${STEERING_C}
43+
COMMAND ${CMAKE_COMMAND}
44+
-DPASS=${PASS}
45+
-DFORMAT="$<TARGET_PROPERTY:linker,FORMAT>"
46+
-DMEMORY_REGIONS="$<TARGET_PROPERTY:linker,MEMORY_REGIONS>"
47+
-DSECTIONS="$<TARGET_PROPERTY:linker,SECTIONS>"
48+
-DSECTION_SETTINGS="$<TARGET_PROPERTY:linker,SECTION_SETTINGS>"
49+
-DSYMBOLS="$<TARGET_PROPERTY:linker,SYMBOLS>"
50+
-DOUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/${linker_script_gen}
51+
-P ${ZEPHYR_BASE}/cmake/linker/ld/ld_script.cmake
52+
)
53+
else()
3254
# Different generators deal with depfiles differently.
3355
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
3456
# Note that the IMPLICIT_DEPENDS option is currently supported only
@@ -72,6 +94,7 @@ macro(configure_linker_script linker_script_gen linker_pass_define)
7294
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
7395
COMMAND_EXPAND_LISTS
7496
)
97+
endif()
7598
endmacro()
7699

77100
# Force symbols to be entered in the output file as undefined symbols

0 commit comments

Comments
 (0)