Skip to content

Commit b7eec0f

Browse files
Fymytehenrikbrixandersen
authored andcommitted
cmake: linker: separate toolchain_ld_options() calls for grouped flags
Fixes #91045 Adding NO_SPLIT in the TOOLCHAIN_LD_FLAGS list caused every flags in the list to be checked together by the linker. This caused issues where incompatible flags was passed together, and the result was that none was propagated to the linker. By using separate variables, we can achieve the initial goal of NO_SPLIT to only group a sub-set of flags. Signed-off-by: Pierrick Guillaume <[email protected]>
1 parent 5ad9494 commit b7eec0f

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,16 @@ if(DEFINED TOOLCHAIN_LD_FLAGS)
474474
zephyr_ld_options(${TOOLCHAIN_LD_FLAGS})
475475
endif()
476476

477+
foreach(GROUPED_FLAGS IN LISTS TOOLCHAIN_GROUPED_LD_FLAGS)
478+
if(DEFINED ${GROUPED_FLAGS})
479+
zephyr_ld_options(NO_SPLIT ${${GROUPED_FLAGS}})
480+
else()
481+
message(FATAL_ERROR "Variable '${GROUPED_FLAGS}' is not defined, "
482+
"please ensure the variable is defined and points to valid linker flags. "
483+
"If '${GROUPED_FLAGS}' is a linker flags itself, then it must be placed in a list")
484+
endif()
485+
endforeach()
486+
477487
zephyr_link_libraries(PROPERTY base)
478488

479489
zephyr_link_libraries_ifndef(CONFIG_LINKER_USE_RELAX PROPERTY no_relax)

cmake/compiler/clang/target_arm.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ if(CONFIG_FP16)
3939
endif()
4040
endif()
4141
list(APPEND TOOLCHAIN_C_FLAGS ${ARM_C_FLAGS})
42-
list(APPEND TOOLCHAIN_LD_FLAGS NO_SPLIT ${ARM_C_FLAGS})
42+
list(APPEND TOOLCHAIN_GROUPED_LD_FLAGS ARM_C_FLAGS)

cmake/compiler/gcc/target_arm.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ if(CONFIG_THREAD_LOCAL_STORAGE)
4545
endif()
4646

4747
list(APPEND TOOLCHAIN_C_FLAGS ${ARM_C_FLAGS})
48-
list(APPEND TOOLCHAIN_LD_FLAGS NO_SPLIT ${ARM_C_FLAGS})
48+
list(APPEND TOOLCHAIN_GROUPED_LD_FLAGS ARM_C_FLAGS)
4949

5050
# Flags not supported by llext linker
5151
# (regexps are supported and match whole word)

cmake/compiler/gcc/target_riscv.cmake

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,13 @@ if(NOT CONFIG_RISCV_ISA_EXT_M AND
129129
string(CONCAT riscv_march ${riscv_march} "_zmmul")
130130
endif()
131131

132-
list(APPEND TOOLCHAIN_C_FLAGS
133-
-mabi=${riscv_mabi}
134-
-march=${riscv_march}
135-
-mcmodel=${riscv_mcmodel}
136-
)
137-
138-
list(APPEND TOOLCHAIN_LD_FLAGS NO_SPLIT
132+
list(APPEND RISCV_C_FLAGS
139133
-mabi=${riscv_mabi}
140134
-march=${riscv_march}
141135
-mcmodel=${riscv_mcmodel}
142136
)
137+
list(APPEND TOOLCHAIN_C_FLAGS ${RISCV_C_FLAGS})
138+
list(APPEND TOOLCHAIN_GROUPED_LD_FLAGS RISCV_C_FLAGS)
143139

144140
# Flags not supported by llext linker
145141
# (regexps are supported and match whole word)

0 commit comments

Comments
 (0)