Skip to content

Commit 65471a6

Browse files
RobinKastbergfabiobaltieri
authored andcommitted
toolchain: stop C flags from leaking to the assembler
Currently the compiler and assembler shares many properties. This can be problematic for non-GNU toolchains that takes different parameters to the assembler and compiler. Signed-off-by: Robin Kastberg <[email protected]>
1 parent e9a0d14 commit 65471a6

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

CMakeLists.txt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,17 @@ endif()
174174

175175
# @Intent: Set compiler flags to detect general stack overflows across all functions
176176
if(CONFIG_STACK_CANARIES)
177-
zephyr_compile_options($<TARGET_PROPERTY:compiler,security_canaries>)
177+
zephyr_compile_options("$<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,security_canaries>>")
178+
zephyr_compile_options("$<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,security_canaries>>")
178179
elseif(CONFIG_STACK_CANARIES_STRONG)
179-
zephyr_compile_options($<TARGET_PROPERTY:compiler,security_canaries_strong>)
180+
zephyr_compile_options("$<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,security_canaries_strong>>")
181+
zephyr_compile_options("$<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,security_canaries_strong>>")
180182
elseif(CONFIG_STACK_CANARIES_ALL)
181-
zephyr_compile_options($<TARGET_PROPERTY:compiler,security_canaries_all>)
183+
zephyr_compile_options("$<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,security_canaries_all>>")
184+
zephyr_compile_options("$<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,security_canaries_all>>")
182185
elseif(CONFIG_STACK_CANARIES_EXPLICIT)
183-
zephyr_compile_options($<TARGET_PROPERTY:compiler,security_canaries_explicit>)
186+
zephyr_compile_options("$<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,security_canaries_explicit>>")
187+
zephyr_compile_options("$<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,security_canaries_explitic>>")
184188
endif()
185189

186190
# @Intent: Obtain compiler optimizations flags and store in variables
@@ -227,7 +231,8 @@ SOC_* symbol.")
227231
endif()
228232

229233
# Apply the final optimization flag(s)
230-
zephyr_compile_options(${OPTIMIZATION_FLAG})
234+
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:${OPTIMIZATION_FLAG}>)
235+
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:${OPTIMIZATION_FLAG}>)
231236

232237
if(CONFIG_LTO)
233238
zephyr_compile_options($<TARGET_PROPERTY:compiler,optimization_lto>)
@@ -315,7 +320,9 @@ if(CONFIG_CODING_GUIDELINE_CHECK)
315320
endif()
316321

317322
# @Intent: Set compiler specific macro inclusion of AUTOCONF_H
318-
zephyr_compile_options("SHELL: $<TARGET_PROPERTY:compiler,imacros> ${AUTOCONF_H}")
323+
zephyr_compile_options("SHELL: $<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,imacros> ${AUTOCONF_H}>")
324+
zephyr_compile_options("SHELL: $<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,imacros> ${AUTOCONF_H}>")
325+
zephyr_compile_options("SHELL: $<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:asm,imacros> ${AUTOCONF_H}>")
319326

320327
if(CONFIG_COMPILER_FREESTANDING)
321328
# @Intent: Set compiler specific flag for bare metal freestanding option
@@ -360,7 +367,9 @@ zephyr_compile_options($<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:asm,required>
360367
# @Intent: Enforce standard integer type correspondence to match Zephyr usage.
361368
# (must be after compiler specific flags)
362369
if(CONFIG_ENFORCE_ZEPHYR_STDINT)
363-
zephyr_compile_options("SHELL: $<TARGET_PROPERTY:compiler,imacros> ${ZEPHYR_BASE}/include/zephyr/toolchain/zephyr_stdint.h")
370+
zephyr_compile_options("SHELL:$<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,imacros> ${ZEPHYR_BASE}/include/zephyr/toolchain/zephyr_stdint.h>")
371+
zephyr_compile_options("SHELL:$<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,imacros> ${ZEPHYR_BASE}/include/zephyr/toolchain/zephyr_stdint.h>")
372+
zephyr_compile_options("SHELL:$<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:asm,imacros> ${ZEPHYR_BASE}/include/zephyr/toolchain/zephyr_stdint.h>")
364373
endif()
365374

366375
# Common toolchain-agnostic assembly flags

0 commit comments

Comments
 (0)