Skip to content

Commit e78aacd

Browse files
raffi-gcarlescufi
authored andcommitted
cmake: zephyr_linker_sources: Link each file only once
If an ld file is included multiple times using `zephyr_linker_sources`, only the last occurrence is actually used. Everything else is removed again from the generated snippet files. This allows to relocate certain blocks, e.g. the vector table, in an application-specific CMakeLists.txt (or for an arch or soc). Fixes: #66315 Signed-off-by: Greter Raffael <[email protected]>
1 parent 499edcd commit e78aacd

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

cmake/modules/extensions.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,8 @@ endfunction(zephyr_check_compiler_flag_hardcoded)
11591159
# copied/included verbatim into the given <location> in the global linker.ld.
11601160
# Preprocessor directives work inside <files>. Relative paths are resolved
11611161
# relative to the calling file, like zephyr_sources().
1162+
# Subsequent calls to zephyr_linker_sources with the same file(s) will remove
1163+
# these from the original location. Only the last call is considered.
11621164
# <location> is one of
11631165
# NOINIT Inside the noinit output section.
11641166
# RWDATA Inside the data output section.
@@ -1319,6 +1321,16 @@ function(zephyr_linker_sources location)
13191321
# Create strings to be written into the file
13201322
set (include_str "/* Sort key: \"${SORT_KEY}\" */#include \"${relpath}\"")
13211323

1324+
# Remove line from other snippet file, if already used
1325+
get_property(old_path GLOBAL PROPERTY "snippet_files_used_${relpath}")
1326+
if (DEFINED old_path)
1327+
file(STRINGS ${old_path} lines)
1328+
list(FILTER lines EXCLUDE REGEX ${relpath})
1329+
string(REPLACE ";" "\n;" lines "${lines}") # Add newline to each line.
1330+
file(WRITE ${old_path} ${lines} "\n")
1331+
endif()
1332+
set_property(GLOBAL PROPERTY "snippet_files_used_${relpath}" ${snippet_path})
1333+
13221334
# Add new line to existing lines, sort them, and write them back.
13231335
file(STRINGS ${snippet_path} lines) # Get current lines (without newlines).
13241336
list(APPEND lines ${include_str})

0 commit comments

Comments
 (0)