Skip to content

Commit 9ab06ec

Browse files
RobinKastbergfabiobaltieri
authored andcommitted
toolchain: iar: Add experimental IAR support
This adds experimental support for the IAR toolchain. Signed-off-by: Robin Kastberg <[email protected]>
1 parent d41da75 commit 9ab06ec

34 files changed

+2848
-9
lines changed

Diff for: arch/common/CMakeLists.txt

+15-6
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,21 @@ zephyr_linker_sources_ifdef(CONFIG_GEN_IRQ_VECTOR_TABLE
5656
)
5757

5858
if(CONFIG_GEN_ISR_TABLES)
59-
zephyr_linker_section(NAME .intList VMA IDT_LIST LMA IDT_LIST NOINPUT PASS NOT LINKER_ZEPHYR_FINAL)
60-
zephyr_linker_section_configure(SECTION .intList KEEP INPUT ".irq_info" FIRST)
61-
zephyr_linker_section_configure(SECTION .intList KEEP INPUT ".intList")
62-
63-
zephyr_linker_section_configure(SECTION /DISCARD/ KEEP INPUT ".irq_info" PASS LINKER_ZEPHYR_FINAL)
64-
zephyr_linker_section_configure(SECTION /DISCARD/ KEEP INPUT ".intList" PASS LINKER_ZEPHYR_FINAL)
59+
# IAR Toolchain is having problems with discarding .intList
60+
# This will always keep .intList in a harmless location
61+
# until we can implement a proper DISCARD.
62+
if(ZEPHYR_TOOLCHAIN_VARIANT STREQUAL "iar")
63+
zephyr_linker_section(NAME .intList GROUP RODATA_REGION NOINPUT)
64+
zephyr_linker_section_configure(SECTION .intList KEEP INPUT ".irq_info" FIRST)
65+
zephyr_linker_section_configure(SECTION .intList KEEP INPUT ".intList")
66+
else()
67+
zephyr_linker_section(NAME .intList VMA IDT_LIST LMA IDT_LIST NOINPUT PASS NOT LINKER_ZEPHYR_FINAL)
68+
zephyr_linker_section_configure(SECTION .intList KEEP INPUT ".irq_info" FIRST)
69+
zephyr_linker_section_configure(SECTION .intList KEEP INPUT ".intList")
70+
71+
zephyr_linker_section_configure(SECTION /DISCARD/ KEEP INPUT ".irq_info" PASS LINKER_ZEPHYR_FINAL)
72+
zephyr_linker_section_configure(SECTION /DISCARD/ KEEP INPUT ".intList" PASS LINKER_ZEPHYR_FINAL)
73+
endif()
6574
endif()
6675

6776
zephyr_linker_sources_ifdef(CONFIG_ARCH_HAS_RAMFUNC_SUPPORT

Diff for: cmake/bintools/iar/target.cmake

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright (c) 2025 IAR Systems AB
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# Configures binary tools as GNU binutils
6+
include(extensions)
7+
8+
# Specifically choose arm-zephyr-eabi from the zephyr sdk for objcopy and friends
9+
10+
if("${IAR_TOOLCHAIN_VARIANT}" STREQUAL "iccarm")
11+
set(IAR_ZEPHYR_HOME ${ZEPHYR_SDK_INSTALL_DIR}/arm-zephyr-eabi/bin)
12+
set(IAR_GNU_PREFIX arm-zephyr-eabi-)
13+
else()
14+
message(ERROR "IAR_TOOLCHAIN_VARIANT not set")
15+
endif()
16+
find_program(CMAKE_OBJCOPY ${IAR_GNU_PREFIX}objcopy PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)
17+
find_program(CMAKE_OBJDUMP ${IAR_GNU_PREFIX}objdump PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)
18+
find_program(CMAKE_AS ${IAR_GNU_PREFIX}as PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)
19+
find_program(CMAKE_AR ${IAR_GNU_PREFIX}ar PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)
20+
find_program(CMAKE_RANLIB ${IAR_GNU_PREFIX}ranlib PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)
21+
find_program(CMAKE_READELF ${IAR_GNU_PREFIX}readelf PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)
22+
find_program(CMAKE_NM ${IAR_GNU_PREFIX}nm PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)
23+
find_program(CMAKE_STRIP ${IAR_GNU_PREFIX}strip PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)
24+
find_program(CMAKE_GDB ${IAR_GNU_PREFIX}gdb-py PATHS ${IAR_ZEPHYR_HOME} NO_DEFAULT_PATH)
25+
26+
if(CMAKE_GDB)
27+
execute_process(
28+
COMMAND ${CMAKE_GDB} --configuration
29+
RESULTS_VARIABLE GDB_CFG_ERR
30+
OUTPUT_QUIET
31+
ERROR_QUIET
32+
)
33+
endif()
34+
35+
if(NOT CMAKE_GDB OR GDB_CFG_ERR)
36+
find_program(CMAKE_GDB_NO_PY ${CROSS_COMPILE}gdb PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
37+
38+
if(CMAKE_GDB_NO_PY)
39+
set(CMAKE_GDB ${CMAKE_GDB_NO_PY} CACHE FILEPATH "Path to a program." FORCE)
40+
endif()
41+
endif()
42+
43+
# Include bin tool properties
44+
include(${ZEPHYR_BASE}/cmake/bintools/iar/target_bintools.cmake)

Diff for: cmake/bintools/iar/target_bintools.cmake

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Copyright (c) 2025 IAR Systems AB
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# - elfconvert : Name of command for elf file conversion.
6+
# In this implementation `objcopy` is used
7+
# elfconvert_formats : Formats supported: ihex, srec, binary
8+
# elfconvert_flag : empty
9+
# elfconvert_flag_final : empty
10+
# elfconvert_flag_strip_all : -S
11+
# elfconvert_flag_strip_debug : -g
12+
# elfconvert_flag_intarget : --input-target=
13+
# elfconvert_flag_outtarget : --output-target=
14+
# elfconvert_flag_section_remove: --remove-section=
15+
# elfconvert_flag_section_only : --only-section=
16+
# elfconvert_flag_section_rename: --rename-section;
17+
# elfconvert_flag_gapfill : --gap-fill;
18+
# Note: The ';' will be transformed into an
19+
# empty space when executed
20+
# elfconvert_flag_srec_len : --srec-len=
21+
# elfconvert_flag_infile : empty, objcopy doesn't take arguments for filenames
22+
# elfconvert_flag_outfile : empty, objcopy doesn't take arguments for filenames
23+
#
24+
25+
# elfconvert to use for transforming an elf file into another format,
26+
# such as intel hex, s-rec, binary, etc.
27+
set_property(TARGET bintools PROPERTY elfconvert_command ${CMAKE_OBJCOPY})
28+
29+
# List of format the tool supports for converting, for example,
30+
# GNU tools uses objectcopy, which supports the following: ihex, srec, binary
31+
set_property(TARGET bintools PROPERTY elfconvert_formats ihex srec binary)
32+
33+
set_property(TARGET bintools PROPERTY elfconvert_flag "")
34+
set_property(TARGET bintools PROPERTY elfconvert_flag_final "")
35+
36+
set_property(TARGET bintools PROPERTY elfconvert_flag_strip_all "-S")
37+
set_property(TARGET bintools PROPERTY elfconvert_flag_strip_debug "-g")
38+
39+
set_property(TARGET bintools PROPERTY elfconvert_flag_intarget "--input-target=")
40+
set_property(TARGET bintools PROPERTY elfconvert_flag_outtarget "--output-target=")
41+
42+
set_property(TARGET bintools PROPERTY elfconvert_flag_section_remove "--remove-section=")
43+
set_property(TARGET bintools PROPERTY elfconvert_flag_section_only "--only-section=")
44+
set_property(TARGET bintools PROPERTY elfconvert_flag_section_rename "--rename-section;")
45+
46+
set_property(TARGET bintools PROPERTY elfconvert_flag_lma_adjust "--change-section-lma;")
47+
48+
# Note, placing a ';' at the end results in the following param to be a list,
49+
# and hence space separated.
50+
# Thus the command line argument becomes:
51+
# `--gap-file <value>` instead of `--gap-fill<value>` (The latter would result in an error)
52+
set_property(TARGET bintools PROPERTY elfconvert_flag_gapfill "--gap-fill;")
53+
set_property(TARGET bintools PROPERTY elfconvert_flag_srec_len "--srec-len=")
54+
55+
set_property(TARGET bintools PROPERTY elfconvert_flag_infile "")
56+
set_property(TARGET bintools PROPERTY elfconvert_flag_outfile "")
57+
58+
#
59+
# - disassembly : Name of command for disassembly of files
60+
# In this implementation `objdump` is used
61+
# disassembly_flag : -d
62+
# disassembly_flag_final : empty
63+
# disassembly_flag_inline_source : -S
64+
# disassembly_flag_all : -SDz
65+
# disassembly_flag_infile : empty, objdump doesn't take arguments for filenames
66+
# disassembly_flag_outfile : '>', objdump doesn't take arguments for output file, but result is printed to standard out, and is redirected.
67+
68+
set_property(TARGET bintools PROPERTY disassembly_command ${CMAKE_OBJDUMP})
69+
set_property(TARGET bintools PROPERTY disassembly_flag -d)
70+
set_property(TARGET bintools PROPERTY disassembly_flag_final "")
71+
set_property(TARGET bintools PROPERTY disassembly_flag_inline_source -S)
72+
set_property(TARGET bintools PROPERTY disassembly_flag_all -SDz)
73+
74+
set_property(TARGET bintools PROPERTY disassembly_flag_infile "")
75+
set_property(TARGET bintools PROPERTY disassembly_flag_outfile ">;" )
76+
77+
#
78+
# - strip: Name of command for stripping symbols
79+
# In this implementation `strip` is used
80+
# strip_flag : empty
81+
# strip_flag_final : empty
82+
# strip_flag_all : --strip-all
83+
# strip_flag_debug : --strip-debug
84+
# strip_flag_dwo : --strip-dwo
85+
# strip_flag_infile : empty, strip doesn't take arguments for input file
86+
# strip_flag_outfile : -o
87+
88+
# This is using strip from bintools.
89+
set_property(TARGET bintools PROPERTY strip_command ${CMAKE_STRIP})
90+
91+
# Any flag the strip command requires for processing
92+
set_property(TARGET bintools PROPERTY strip_flag "")
93+
set_property(TARGET bintools PROPERTY strip_flag_final "")
94+
95+
set_property(TARGET bintools PROPERTY strip_flag_all --strip-all)
96+
set_property(TARGET bintools PROPERTY strip_flag_debug --strip-debug)
97+
set_property(TARGET bintools PROPERTY strip_flag_dwo --strip-dwo)
98+
set_property(TARGET bintools PROPERTY strip_flag_remove_section -R )
99+
100+
set_property(TARGET bintools PROPERTY strip_flag_infile "")
101+
set_property(TARGET bintools PROPERTY strip_flag_outfile -o )
102+
103+
#
104+
# - readelf : Name of command for reading elf files.
105+
# In this implementation `readelf` is used
106+
# readelf_flag : empty
107+
# readelf_flag_final : empty
108+
# readelf_flag_headers : -e
109+
# readelf_flag_infile : empty, readelf doesn't take arguments for filenames
110+
# readelf_flag_outfile : '>', readelf doesn't take arguments for output
111+
# file, but result is printed to standard out, and
112+
# is redirected.
113+
114+
# This is using readelf from bintools.
115+
set_property(TARGET bintools PROPERTY readelf_command ${CMAKE_READELF})
116+
117+
set_property(TARGET bintools PROPERTY readelf_flag "")
118+
set_property(TARGET bintools PROPERTY readelf_flag_final "")
119+
set_property(TARGET bintools PROPERTY readelf_flag_headers -e)
120+
121+
set_property(TARGET bintools PROPERTY readelf_flag_infile "")
122+
set_property(TARGET bintools PROPERTY readelf_flag_outfile ">;" )
123+
124+
# Example on how to support dwarfdump instead of readelf
125+
#set_property(TARGET bintools PROPERTY readelf_command dwarfdump)
126+
#set_property(TARGET bintools PROPERTY readelf_flag "")
127+
#set_property(TARGET bintools PROPERTY readelf_flag_headers -E)
128+
#set_property(TARGET bintools PROPERTY readelf_flag_infile "")
129+
#set_property(TARGET bintools PROPERTY readelf_flag_outfile "-O file=" )
130+
131+
set_property(TARGET bintools PROPERTY symbols_command ${CMAKE_NM})
132+
set_property(TARGET bintools PROPERTY symbols_flag "")
133+
set_property(TARGET bintools PROPERTY symbols_final "")
134+
set_property(TARGET bintools PROPERTY symbols_infile "")
135+
set_property(TARGET bintools PROPERTY symbols_outfile ">;" )

Diff for: cmake/compiler/iar/compiler_flags.cmake

+178
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# Copyright (c) 2025 IAR Systems AB
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# Compiler options for the IAR C/C++ Compiler for Arm
6+
7+
#####################################################
8+
# This section covers flags related to optimization #
9+
#####################################################
10+
set_compiler_property(PROPERTY no_optimization -On)
11+
12+
set_compiler_property(PROPERTY optimization_debug -Ol)
13+
14+
set_compiler_property(PROPERTY optimization_speed -Ohs)
15+
16+
set_compiler_property(PROPERTY optimization_size -Ohz)
17+
18+
set_compiler_property(PROPERTY optimization_size_aggressive -Ohz)
19+
20+
#######################################################
21+
# This section covers flags related to warning levels #
22+
#######################################################
23+
24+
# Property for standard warning base in Zephyr, this will always be set when
25+
# compiling.
26+
set_compiler_property(PROPERTY warning_base
27+
--diag_error=Pe223 # function "xxx" declared implicitly
28+
--diag_warning=Pe054 # too few arguments in invocation of macro
29+
--diag_warning=Pe144 # a value of type "void *" cannot be used to initialize an entity of type [...] "void (*)(struct onoff_manager *, int)"
30+
--diag_warning=Pe167 # argument of type "void *" is incompatible with [...] "void (*)(void *, void *, void *)"
31+
--diag_suppress=Pe1675 # unrecognized GCC pragma
32+
--diag_suppress=Pe111 # statement is unreachable
33+
--diag_suppress=Pe1143 # arithmetic on pointer to void or function type
34+
--diag_suppress=Pe068) # integer conversion resulted in a change of sign)
35+
36+
37+
set(IAR_WARNING_DW_1
38+
--diag_suppress=Pe188 # enumerated type mixed with another type
39+
--diag_suppress=Pe128 # loop is not reachable
40+
--diag_suppress=Pe550 # variable "res" was set but never used
41+
--diag_suppress=Pe546 # transfer of control bypasses initialization
42+
--diag_suppress=Pe186) # pointless comparison of unsigned integer with zero
43+
44+
set(IAR_WARNING_DW2
45+
--diag_suppress=Pe1097 # unknown attribute
46+
--diag_suppress=Pe381 # extra ";" ignored
47+
--diag_suppress=Pa082 # undefined behavior: the order of volatile accesses is undefined
48+
--diag_suppress=Pa084 # pointless integer comparison, the result is always false
49+
--diag_suppress=Pe185 # dynamic initialization in unreachable code )
50+
--diag_suppress=Pe167 # argument of type "onoff_notify_fn" is incompatible with...
51+
--diag_suppress=Pe144 # a value of type "void *" cannot be used to initialize...
52+
--diag_suppress=Pe177 # function "xxx" was declared but never referenced
53+
--diag_suppress=Pe513) # a value of type "void *" cannot be assigned to an entity of type "int (*)(int)"
54+
55+
set(IAR_WARNING_DW3)
56+
57+
set_compiler_property(PROPERTY warning_dw_1
58+
${IAR_WARNING_DW_3}
59+
${IAR_WARNING_DW_2}
60+
${IAR_WARNING_DW_1})
61+
62+
set_compiler_property(PROPERTY warning_dw_2
63+
${IAR_WARNING_DW3}
64+
${IAR_WARNING_DW2})
65+
66+
# no suppressions
67+
set_compiler_property(PROPERTY warning_dw_3 ${IAR_WARNING_DW3})
68+
69+
# Extended warning set supported by the compiler
70+
set_compiler_property(PROPERTY warning_extended)
71+
72+
# Compiler property that will issue error if a declaration does not specify a type
73+
set_compiler_property(PROPERTY warning_error_implicit_int)
74+
75+
# Compiler flags to use when compiling according to MISRA
76+
set_compiler_property(PROPERTY warning_error_misra_sane)
77+
78+
set_property(TARGET compiler PROPERTY warnings_as_errors --warnings_are_errors)
79+
80+
###########################################################################
81+
# This section covers flags related to C or C++ standards / standard libs #
82+
###########################################################################
83+
84+
# Compiler flags for C standard. The specific standard must be appended by user.
85+
# For example, gcc specifies this as: set_compiler_property(PROPERTY cstd -std=)
86+
# TC-WG: the `cstd99` is used regardless of this flag being useful for iccarm
87+
# This flag will make it a symbol. Works for C,CXX,ASM
88+
# Since ICCARM does not use C standard flags, we just make them a defined symbol
89+
# instead
90+
set_compiler_property(PROPERTY cstd -D__IAR_CSTD_)
91+
92+
# Compiler flags for disabling C standard include and instead specify include
93+
# dirs in nostdinc_include to use.
94+
set_compiler_property(PROPERTY nostdinc)
95+
set_compiler_property(PROPERTY nostdinc_include)
96+
97+
# Compiler flags for disabling C++ standard include.
98+
set_compiler_property(TARGET compiler-cpp PROPERTY nostdincxx)
99+
100+
# Required C++ flags when compiling C++ code
101+
set_property(TARGET compiler-cpp PROPERTY required --c++)
102+
103+
# Compiler flags to use for specific C++ dialects
104+
set_property(TARGET compiler-cpp PROPERTY dialect_cpp98)
105+
set_property(TARGET compiler-cpp PROPERTY dialect_cpp11)
106+
set_property(TARGET compiler-cpp PROPERTY dialect_cpp14)
107+
set_property(TARGET compiler-cpp PROPERTY dialect_cpp17 --libc++)
108+
set_property(TARGET compiler-cpp PROPERTY dialect_cpp2a --libc++)
109+
set_property(TARGET compiler-cpp PROPERTY dialect_cpp20 --libc++)
110+
set_property(TARGET compiler-cpp PROPERTY dialect_cpp2b --libc++)
111+
112+
# Flag for disabling strict aliasing rule in C and C++
113+
set_compiler_property(PROPERTY no_strict_aliasing)
114+
115+
# Flag for disabling exceptions in C++
116+
set_property(TARGET compiler-cpp PROPERTY no_exceptions --no_exceptions)
117+
118+
# Flag for disabling rtti in C++
119+
set_property(TARGET compiler-cpp PROPERTY no_rtti --no_rtti)
120+
121+
###################################################
122+
# This section covers all remaining C / C++ flags #
123+
###################################################
124+
125+
# Flags for coverage generation
126+
set_compiler_property(PROPERTY coverage)
127+
128+
# Security canaries flags.
129+
set_compiler_property(PROPERTY security_canaries --stack_protection)
130+
set_compiler_property(PROPERTY security_canaries_strong --stack_protection)
131+
set_compiler_property(PROPERTY security_canaries_all --security_canaries_all_is_not_supported)
132+
set_compiler_property(PROPERTY security_canaries_explicit --security_canaries_explicit_is_not_supported)
133+
134+
if(CONFIG_STACK_CANARIES_TLS)
135+
check_set_compiler_property(APPEND PROPERTY security_canaries --stack_protector_guard=tls)
136+
check_set_compiler_property(APPEND PROPERTY security_canaries_strong --stack_protector_guard=tls)
137+
check_set_compiler_property(APPEND PROPERTY security_canaries_all --stack_protector_guard=tls)
138+
check_set_compiler_property(APPEND PROPERTY security_canaries_explicit --stack_protector_guard=tls)
139+
endif()
140+
141+
set_compiler_property(PROPERTY security_fortify)
142+
143+
# Flag for a hosted (no-freestanding) application
144+
set_compiler_property(PROPERTY hosted)
145+
146+
# gcc flag for a freestanding application
147+
set_compiler_property(PROPERTY freestanding)
148+
149+
# Flag to include debugging symbol in compilation
150+
set_property(TARGET compiler PROPERTY debug --debug)
151+
set_property(TARGET compiler-cpp PROPERTY debug --debug)
152+
set_property(TARGET asm PROPERTY debug -gdwarf-4)
153+
154+
set_compiler_property(PROPERTY no_common)
155+
156+
# Flags for imacros. The specific header must be appended by user.
157+
set_property(TARGET compiler PROPERTY imacros --preinclude)
158+
set_property(TARGET compiler-cpp PROPERTY imacros --preinclude)
159+
set_property(TARGET asm PROPERTY imacros -imacros)
160+
161+
# Compiler flag for turning off thread-safe initialization of local statics
162+
set_property(TARGET compiler-cpp PROPERTY no_threadsafe_statics)
163+
164+
# Required ASM flags when compiling
165+
set_property(TARGET asm PROPERTY required)
166+
167+
# Compiler flag for disabling pointer arithmetic warnings
168+
set_compiler_property(PROPERTY warning_no_pointer_arithmetic)
169+
170+
# Compiler flags for disabling position independent code / executable
171+
set_compiler_property(PROPERTY no_position_independent)
172+
173+
# Compiler flag for defining preinclude files.
174+
set_compiler_property(PROPERTY include_file --preinclude)
175+
176+
set_compiler_property(PROPERTY cmse --cmse)
177+
178+
set_property(TARGET asm PROPERTY cmse -mcmse)

0 commit comments

Comments
 (0)