Skip to content

Commit a3df2f1

Browse files
committed
Templates ignore section attributes so requires entries in linker script for IRAM code.
In the source code you'll see quite a bit of `__forceinline` as well as `IRAM_ATTR`, which is mainly for safety and to indicate functions/methods may be used from interrupt context. Unfortunately, marking templated code with `IRAM_ATTR` is not sufficient to get it into IRAM: https://stackoverflow.com/questions/36279162/section-attribute-of-a-function-template-is-silently-ignored-in-gcc So the linker script needs to be updated to catch all such instances. To do this requires splitting the `.text` output segment into two parts, called `.text` and `.text1`. The rBoot script also needs to know about both segments so they both end up in the ROM image it creates. Using `CallbackTimer` as an example, most of the code gets inlined anyway and as it's called from task context this actually uses very little IRAM. More details here: esp8266/Arduino#5922
1 parent 27a769a commit a3df2f1

File tree

2 files changed

+54
-32
lines changed

2 files changed

+54
-32
lines changed

Sming/Arch/Esp8266/Compiler/ld/common.ld

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,55 @@ SECTIONS
8282
_data_end = ABSOLUTE(.);
8383
} >dram0_0_seg :dram0_0_phdr
8484

85+
86+
/*
87+
IRAM is split into .text and .text1 to allow for moving specific
88+
functions into IRAM that would be matched by the irom0.text matcher
89+
*/
90+
.text : ALIGN(4)
91+
{
92+
_stext = .;
93+
_text_start = ABSOLUTE(.);
94+
*(.UserEnter.text)
95+
. = ALIGN(16);
96+
*(.DebugExceptionVector.text)
97+
. = ALIGN(16);
98+
*(.NMIExceptionVector.text)
99+
. = ALIGN(16);
100+
*(.KernelExceptionVector.text)
101+
LONG(0)
102+
LONG(0)
103+
LONG(0)
104+
LONG(0)
105+
. = ALIGN(16);
106+
*(.UserExceptionVector.text)
107+
LONG(0)
108+
LONG(0)
109+
LONG(0)
110+
LONG(0)
111+
. = ALIGN(16);
112+
*(.DoubleExceptionVector.text)
113+
LONG(0)
114+
LONG(0)
115+
LONG(0)
116+
LONG(0)
117+
. = ALIGN (16);
118+
*(.entry.text)
119+
*(.init.literal)
120+
*(.init)
121+
122+
*(.iram.literal .iram.text.literal .iram.text .iram.text.*)
123+
124+
/*
125+
GCC silently ignores section attributes on templated code.
126+
The only practical workaround is enforcing sections in the linker script.
127+
*/
128+
*(.literal._ZN13CallbackTimer*)
129+
*(.text._ZN13CallbackTimer*)
130+
*(.text._ZNKSt8functionIF*EE*) /* std::function<any(...)>::operator()() const */
131+
132+
} >iram1_0_seg :iram1_0_phdr
133+
85134
.irom0.text : ALIGN(4)
86135
{
87136
_irom0_text_start = ABSOLUTE(.);
@@ -128,39 +177,12 @@ SECTIONS
128177
_flash_code_end = ABSOLUTE(.);
129178
} >irom0_0_seg :irom0_0_phdr
130179

131-
.text : ALIGN(4)
180+
181+
/* Pick up any remaining IRAM objects and close the text segment */
182+
.text1 : ALIGN(4)
132183
{
133-
_stext = .;
134-
_text_start = ABSOLUTE(.);
135-
*(.UserEnter.text)
136-
. = ALIGN(16);
137-
*(.DebugExceptionVector.text)
138-
. = ALIGN(16);
139-
*(.NMIExceptionVector.text)
140-
. = ALIGN(16);
141-
*(.KernelExceptionVector.text)
142-
LONG(0)
143-
LONG(0)
144-
LONG(0)
145-
LONG(0)
146-
. = ALIGN(16);
147-
*(.UserExceptionVector.text)
148-
LONG(0)
149-
LONG(0)
150-
LONG(0)
151-
LONG(0)
152-
. = ALIGN(16);
153-
*(.DoubleExceptionVector.text)
154-
LONG(0)
155-
LONG(0)
156-
LONG(0)
157-
LONG(0)
158-
. = ALIGN (16);
159-
*(.entry.text)
160-
*(.init.literal)
161-
*(.init)
162184
*(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
163-
*(.iram.literal .iram.text.literal .iram.text .iram.text.*)
185+
164186
*(.fini.literal)
165187
*(.fini)
166188
*(.gnu.version)

Sming/Components/rboot/component.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ APP_CFLAGS += -DRBOOT_SPIFFS_1=$(RBOOT_SPIFFS_1)
6464
ROM_0_ADDR := 0x002000
6565

6666
# filenames and options for generating rBoot rom images with esptool2
67-
RBOOT_E2_SECTS ?= .text .data .rodata
67+
RBOOT_E2_SECTS ?= .text .text1 .data .rodata
6868
RBOOT_E2_USER_ARGS ?= -quiet -bin -boot2
6969

7070
RBOOT_ROM_0_BIN := $(FW_BASE)/$(RBOOT_ROM_0).bin

0 commit comments

Comments
 (0)