Skip to content

Commit 99219ce

Browse files
Grommerinpennam
authored andcommitted
toolchain: gcc: iar: add ___in_section_unique()
Macros __in_section_unique() and __in_section_unique_named() use ___in_section with __FILE__ argument to create a unique section name. Since __FILE__ is a string, calling Z_STRINGIFY(__FILE__) in ___in_section() causes double quotes in __FILE__ value to be masked. This prevents ld from matching section names output by this script. For example, when using CONFIG_CODE_DATA_RELOCATION to relocate a noinit section, __in_section_unique() generates the following section name: KEEP(*file.c.obj(.noinit."WEST_TOPDIR/path/file.c".symbol)) Besides, __FILE__ is used to create unique sections in two macros, so why not unify this approach. This fix adds ___in_section_unique() macro, which substitutes __FILE__ string into section name without additional stringification. Thus, resulting section is correctly matched by ld. Signed-off-by: Nikita Divakov <grommerin@gmail.com>
1 parent e163da3 commit 99219ce

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

include/zephyr/toolchain/gcc.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,17 @@ do { \
200200
"." Z_STRINGIFY(c))))
201201
#define __in_section(a, b, c) ___in_section(a, b, c)
202202

203+
#define ___in_section_unique(a, b) \
204+
__attribute__((section("." Z_STRINGIFY(a) \
205+
"." __FILE__ \
206+
"." Z_STRINGIFY(b))))
207+
203208
#ifndef __in_section_unique
204-
#define __in_section_unique(seg) ___in_section(seg, __FILE__, __COUNTER__)
209+
#define __in_section_unique(seg) ___in_section_unique(seg, __COUNTER__)
205210
#endif
206211

207212
#ifndef __in_section_unique_named
208-
#define __in_section_unique_named(seg, name) \
209-
___in_section(seg, __FILE__, name)
213+
#define __in_section_unique_named(seg, name) ___in_section_unique(seg, name)
210214
#endif
211215

212216
/* When using XIP, using '__ramfunc' places a function into RAM instead

include/zephyr/toolchain/iar/iccarm.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,14 @@ do { \
121121
"." Z_STRINGIFY(c))))
122122
#define __in_section(a, b, c) ___in_section(a, b, c)
123123

124-
#define __in_section_unique(seg) ___in_section(seg, __FILE__, __COUNTER__)
124+
#define ___in_section_unique(a, b) \
125+
__attribute__((section("." Z_STRINGIFY(a) \
126+
"." __FILE__ \
127+
"." Z_STRINGIFY(b))))
125128

126-
#define __in_section_unique_named(seg, name) \
127-
___in_section(seg, __FILE__, name)
129+
#define __in_section_unique(seg) ___in_section_unique(seg, __COUNTER__)
130+
131+
#define __in_section_unique_named(seg, name) ___in_section_unique(seg, name)
128132

129133
/* When using XIP, using '__ramfunc' places a function into RAM instead
130134
* of FLASH. Make sure '__ramfunc' is defined only when

0 commit comments

Comments
 (0)