Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,17 @@ endif()

# @Intent: Set compiler flags to detect general stack overflows across all functions
if(CONFIG_STACK_CANARIES)
zephyr_compile_options($<TARGET_PROPERTY:compiler,security_canaries>)
zephyr_compile_options("$<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,security_canaries>>")
zephyr_compile_options("$<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,security_canaries>>")
elseif(CONFIG_STACK_CANARIES_STRONG)
zephyr_compile_options($<TARGET_PROPERTY:compiler,security_canaries_strong>)
zephyr_compile_options("$<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,security_canaries_strong>>")
zephyr_compile_options("$<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,security_canaries_strong>>")
elseif(CONFIG_STACK_CANARIES_ALL)
zephyr_compile_options($<TARGET_PROPERTY:compiler,security_canaries_all>)
zephyr_compile_options("$<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,security_canaries_all>>")
zephyr_compile_options("$<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,security_canaries_all>>")
elseif(CONFIG_STACK_CANARIES_EXPLICIT)
zephyr_compile_options($<TARGET_PROPERTY:compiler,security_canaries_explicit>)
zephyr_compile_options("$<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,security_canaries_explicit>>")
zephyr_compile_options("$<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,security_canaries_explitic>>")
endif()

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

# Apply the final optimization flag(s)
zephyr_compile_options(${OPTIMIZATION_FLAG})
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:${OPTIMIZATION_FLAG}>)
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:${OPTIMIZATION_FLAG}>)

if(CONFIG_LTO)
zephyr_compile_options($<TARGET_PROPERTY:compiler,optimization_lto>)
Expand Down Expand Up @@ -315,7 +320,9 @@ if(CONFIG_CODING_GUIDELINE_CHECK)
endif()

# @Intent: Set compiler specific macro inclusion of AUTOCONF_H
zephyr_compile_options("SHELL: $<TARGET_PROPERTY:compiler,imacros> ${AUTOCONF_H}")
zephyr_compile_options("SHELL: $<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,imacros> ${AUTOCONF_H}>")
zephyr_compile_options("SHELL: $<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,imacros> ${AUTOCONF_H}>")
zephyr_compile_options("SHELL: $<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:asm,imacros> ${AUTOCONF_H}>")

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

# Common toolchain-agnostic assembly flags
Expand Down
12 changes: 12 additions & 0 deletions MAINTAINERS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4481,6 +4481,18 @@ TDK Sensors:
labels:
- "area: Toolchains"

"Toolchain IAR":
status: maintained
maintainers:
- RobinKastberg
files:
- cmake/*/iar/
- include/zephyr/toolchain/iar.h
- include/zephyr/toolchain/iar/*
- lib/libc/iar/*
labels:
- "area: Toolchains"

"Toolchain oneApi":
status: maintained
maintainers:
Expand Down
5 changes: 4 additions & 1 deletion arch/arm/core/cortex_m/tz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

# '-mcmse' enables the generation of code for the Secure state of the ARMv8-M
# Security Extensions. This option is required when building a Secure firmware.
zephyr_compile_options_ifdef(CONFIG_ARM_SECURE_FIRMWARE -mcmse)

zephyr_compile_options_ifdef(CONFIG_ARM_SECURE_FIRMWARE $<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,cmse>>)
zephyr_compile_options_ifdef(CONFIG_ARM_SECURE_FIRMWARE $<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,cmse>>)
zephyr_compile_options_ifdef(CONFIG_ARM_SECURE_FIRMWARE $<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:asm,cmse>>)

if(CONFIG_ARM_FIRMWARE_HAS_SECURE_ENTRY_FUNCS)

Expand Down
2 changes: 2 additions & 0 deletions arch/arm/core/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ size_t arch_tls_stack_setup(struct k_thread *new_thread, char *stack_ptr)
stack_ptr -= z_tls_data_size();
z_tls_copy(stack_ptr);

#ifndef __IAR_SYSTEMS_ICC__
/* Skip two pointers due to toolchain */
stack_ptr -= sizeof(uintptr_t) * 2;
#endif

/*
* Set thread TLS pointer which is used in
Expand Down
21 changes: 15 additions & 6 deletions arch/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,21 @@ zephyr_linker_sources_ifdef(CONFIG_GEN_IRQ_VECTOR_TABLE
)

if(CONFIG_GEN_ISR_TABLES)
zephyr_linker_section(NAME .intList VMA IDT_LIST LMA IDT_LIST NOINPUT PASS NOT LINKER_ZEPHYR_FINAL)
zephyr_linker_section_configure(SECTION .intList KEEP INPUT ".irq_info" FIRST)
zephyr_linker_section_configure(SECTION .intList KEEP INPUT ".intList")

zephyr_linker_section_configure(SECTION /DISCARD/ KEEP INPUT ".irq_info" PASS LINKER_ZEPHYR_FINAL)
zephyr_linker_section_configure(SECTION /DISCARD/ KEEP INPUT ".intList" PASS LINKER_ZEPHYR_FINAL)
# IAR Toolchain is having problems with discarding .intList
# This will always keep .intList in a harmless location
# until we can implement a proper DISCARD.
if(ZEPHYR_TOOLCHAIN_VARIANT STREQUAL "iar")
Comment on lines +59 to +62
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted.

Making a comment to be able to back reference in future that this is a (temporary) exception because we generally want to avoid toolchain specific adjustments within the build system code itself and instead keep this in toolchain specific parts.

zephyr_linker_section(NAME .intList GROUP RODATA_REGION NOINPUT)
zephyr_linker_section_configure(SECTION .intList KEEP INPUT ".irq_info" FIRST)
zephyr_linker_section_configure(SECTION .intList KEEP INPUT ".intList")
else()
zephyr_linker_section(NAME .intList VMA IDT_LIST LMA IDT_LIST NOINPUT PASS NOT LINKER_ZEPHYR_FINAL)
zephyr_linker_section_configure(SECTION .intList KEEP INPUT ".irq_info" FIRST)
zephyr_linker_section_configure(SECTION .intList KEEP INPUT ".intList")

zephyr_linker_section_configure(SECTION /DISCARD/ KEEP INPUT ".irq_info" PASS LINKER_ZEPHYR_FINAL)
zephyr_linker_section_configure(SECTION /DISCARD/ KEEP INPUT ".intList" PASS LINKER_ZEPHYR_FINAL)
endif()
endif()

zephyr_linker_sources_ifdef(CONFIG_ARCH_HAS_RAMFUNC_SUPPORT
Expand Down
44 changes: 44 additions & 0 deletions cmake/bintools/iar/target.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright (c) 2025 IAR Systems AB
#
# SPDX-License-Identifier: Apache-2.0

# Configures binary tools as GNU binutils
include(extensions)

# Specifically choose arm-zephyr-eabi from the zephyr sdk for objcopy and friends

if("${IAR_TOOLCHAIN_VARIANT}" STREQUAL "iccarm")
set(IAR_ZEPHYR_HOME ${ZEPHYR_SDK_INSTALL_DIR}/arm-zephyr-eabi/bin)
set(IAR_GNU_PREFIX arm-zephyr-eabi-)
else()
message(ERROR "IAR_TOOLCHAIN_VARIANT not set")
endif()
find_program(CMAKE_OBJCOPY ${IAR_GNU_PREFIX}objcopy PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_OBJDUMP ${IAR_GNU_PREFIX}objdump PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_AS ${IAR_GNU_PREFIX}as PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_AR ${IAR_GNU_PREFIX}ar PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_RANLIB ${IAR_GNU_PREFIX}ranlib PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_READELF ${IAR_GNU_PREFIX}readelf PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_NM ${IAR_GNU_PREFIX}nm PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_STRIP ${IAR_GNU_PREFIX}strip PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)
find_program(CMAKE_GDB ${IAR_GNU_PREFIX}gdb-py PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)

if(CMAKE_GDB)
execute_process(
COMMAND ${CMAKE_GDB} --configuration
RESULTS_VARIABLE GDB_CFG_ERR
OUTPUT_QUIET
ERROR_QUIET
)
endif()

if(NOT CMAKE_GDB OR GDB_CFG_ERR)
find_program(CMAKE_GDB_NO_PY ${CROSS_COMPILE}gdb PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)

if(CMAKE_GDB_NO_PY)
set(CMAKE_GDB ${CMAKE_GDB_NO_PY} CACHE FILEPATH "Path to a program." FORCE)
endif()
endif()

# Include bin tool properties
include(${ZEPHYR_BASE}/cmake/bintools/iar/target_bintools.cmake)
135 changes: 135 additions & 0 deletions cmake/bintools/iar/target_bintools.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Copyright (c) 2025 IAR Systems AB
#
# SPDX-License-Identifier: Apache-2.0
#
# - elfconvert : Name of command for elf file conversion.
# In this implementation `objcopy` is used
# elfconvert_formats : Formats supported: ihex, srec, binary
# elfconvert_flag : empty
# elfconvert_flag_final : empty
# elfconvert_flag_strip_all : -S
# elfconvert_flag_strip_debug : -g
# elfconvert_flag_intarget : --input-target=
# elfconvert_flag_outtarget : --output-target=
# elfconvert_flag_section_remove: --remove-section=
# elfconvert_flag_section_only : --only-section=
# elfconvert_flag_section_rename: --rename-section;
# elfconvert_flag_gapfill : --gap-fill;
# Note: The ';' will be transformed into an
# empty space when executed
# elfconvert_flag_srec_len : --srec-len=
# elfconvert_flag_infile : empty, objcopy doesn't take arguments for filenames
# elfconvert_flag_outfile : empty, objcopy doesn't take arguments for filenames
#

# elfconvert to use for transforming an elf file into another format,
# such as intel hex, s-rec, binary, etc.
set_property(TARGET bintools PROPERTY elfconvert_command ${CMAKE_OBJCOPY})

# List of format the tool supports for converting, for example,
# GNU tools uses objectcopy, which supports the following: ihex, srec, binary
set_property(TARGET bintools PROPERTY elfconvert_formats ihex srec binary)

set_property(TARGET bintools PROPERTY elfconvert_flag "")
set_property(TARGET bintools PROPERTY elfconvert_flag_final "")

set_property(TARGET bintools PROPERTY elfconvert_flag_strip_all "-S")
set_property(TARGET bintools PROPERTY elfconvert_flag_strip_debug "-g")

set_property(TARGET bintools PROPERTY elfconvert_flag_intarget "--input-target=")
set_property(TARGET bintools PROPERTY elfconvert_flag_outtarget "--output-target=")

set_property(TARGET bintools PROPERTY elfconvert_flag_section_remove "--remove-section=")
set_property(TARGET bintools PROPERTY elfconvert_flag_section_only "--only-section=")
set_property(TARGET bintools PROPERTY elfconvert_flag_section_rename "--rename-section;")

set_property(TARGET bintools PROPERTY elfconvert_flag_lma_adjust "--change-section-lma;")

# Note, placing a ';' at the end results in the following param to be a list,
# and hence space separated.
# Thus the command line argument becomes:
# `--gap-file <value>` instead of `--gap-fill<value>` (The latter would result in an error)
set_property(TARGET bintools PROPERTY elfconvert_flag_gapfill "--gap-fill;")
set_property(TARGET bintools PROPERTY elfconvert_flag_srec_len "--srec-len=")

set_property(TARGET bintools PROPERTY elfconvert_flag_infile "")
set_property(TARGET bintools PROPERTY elfconvert_flag_outfile "")

#
# - disassembly : Name of command for disassembly of files
# In this implementation `objdump` is used
# disassembly_flag : -d
# disassembly_flag_final : empty
# disassembly_flag_inline_source : -S
# disassembly_flag_all : -SDz
# disassembly_flag_infile : empty, objdump doesn't take arguments for filenames
# disassembly_flag_outfile : '>', objdump doesn't take arguments for output file, but result is printed to standard out, and is redirected.

set_property(TARGET bintools PROPERTY disassembly_command ${CMAKE_OBJDUMP})
set_property(TARGET bintools PROPERTY disassembly_flag -d)
set_property(TARGET bintools PROPERTY disassembly_flag_final "")
set_property(TARGET bintools PROPERTY disassembly_flag_inline_source -S)
set_property(TARGET bintools PROPERTY disassembly_flag_all -SDz)

set_property(TARGET bintools PROPERTY disassembly_flag_infile "")
set_property(TARGET bintools PROPERTY disassembly_flag_outfile ">;" )

#
# - strip: Name of command for stripping symbols
# In this implementation `strip` is used
# strip_flag : empty
# strip_flag_final : empty
# strip_flag_all : --strip-all
# strip_flag_debug : --strip-debug
# strip_flag_dwo : --strip-dwo
# strip_flag_infile : empty, strip doesn't take arguments for input file
# strip_flag_outfile : -o

# This is using strip from bintools.
set_property(TARGET bintools PROPERTY strip_command ${CMAKE_STRIP})

# Any flag the strip command requires for processing
set_property(TARGET bintools PROPERTY strip_flag "")
set_property(TARGET bintools PROPERTY strip_flag_final "")

set_property(TARGET bintools PROPERTY strip_flag_all --strip-all)
set_property(TARGET bintools PROPERTY strip_flag_debug --strip-debug)
set_property(TARGET bintools PROPERTY strip_flag_dwo --strip-dwo)
set_property(TARGET bintools PROPERTY strip_flag_remove_section -R )

set_property(TARGET bintools PROPERTY strip_flag_infile "")
set_property(TARGET bintools PROPERTY strip_flag_outfile -o )

#
# - readelf : Name of command for reading elf files.
# In this implementation `readelf` is used
# readelf_flag : empty
# readelf_flag_final : empty
# readelf_flag_headers : -e
# readelf_flag_infile : empty, readelf doesn't take arguments for filenames
# readelf_flag_outfile : '>', readelf doesn't take arguments for output
# file, but result is printed to standard out, and
# is redirected.

# This is using readelf from bintools.
set_property(TARGET bintools PROPERTY readelf_command ${CMAKE_READELF})

set_property(TARGET bintools PROPERTY readelf_flag "")
set_property(TARGET bintools PROPERTY readelf_flag_final "")
set_property(TARGET bintools PROPERTY readelf_flag_headers -e)

set_property(TARGET bintools PROPERTY readelf_flag_infile "")
set_property(TARGET bintools PROPERTY readelf_flag_outfile ">;" )

# Example on how to support dwarfdump instead of readelf
#set_property(TARGET bintools PROPERTY readelf_command dwarfdump)
#set_property(TARGET bintools PROPERTY readelf_flag "")
#set_property(TARGET bintools PROPERTY readelf_flag_headers -E)
#set_property(TARGET bintools PROPERTY readelf_flag_infile "")
#set_property(TARGET bintools PROPERTY readelf_flag_outfile "-O file=" )

set_property(TARGET bintools PROPERTY symbols_command ${CMAKE_NM})
set_property(TARGET bintools PROPERTY symbols_flag "")
set_property(TARGET bintools PROPERTY symbols_final "")
set_property(TARGET bintools PROPERTY symbols_infile "")
set_property(TARGET bintools PROPERTY symbols_outfile ">;" )
8 changes: 8 additions & 0 deletions cmake/compiler/compiler_flags_template.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ set_property(TARGET compiler-cpp PROPERTY no_threadsafe_statics)
# Required ASM flags when compiling
set_property(TARGET asm PROPERTY required)

# GCC compiler flags for imacros. The specific header must be appended by user.
set_property(TARGET asm PROPERTY imacros)

# Compiler flag for disabling pointer arithmetic warnings
set_compiler_property(PROPERTY warning_no_pointer_arithmetic)

Expand All @@ -149,3 +152,8 @@ set_compiler_property(PROPERTY specs)

# Compiler flag for defining preinclude files.
set_compiler_property(PROPERTY include_file)

# Compiler flag for trustzone
set_compiler_property(PROPERTY cmse)

set_property(TARGET asm PROPERTY cmse)
7 changes: 7 additions & 0 deletions cmake/compiler/gcc/compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ set_property(TARGET compiler-cpp PROPERTY no_threadsafe_statics "-fno-threadsafe
# Required ASM flags when using gcc
set_property(TARGET asm PROPERTY required "-xassembler-with-cpp")

# GCC compiler flags for imacros. The specific header must be appended by user.
set_property(TARGET asm PROPERTY imacros "-imacros")

# gcc flag for colourful diagnostic messages
check_set_compiler_property(PROPERTY diagnostic -fdiagnostics-color=always)

Expand All @@ -253,3 +256,7 @@ set_compiler_property(PROPERTY no_builtin_malloc -fno-builtin-malloc)
set_compiler_property(PROPERTY specs -specs=)

set_compiler_property(PROPERTY include_file -include)

set_compiler_property(PROPERTY cmse -mcmse)

set_property(TARGET asm PROPERTY cmse -mcmse)
Loading
Loading