Skip to content

Commit 9e31fd5

Browse files
Move all PROGMEM to their own section
According to the GCC man page, __section__ attributes should only be used for global variables. However, the PROGMEM and ICACHE_RODATA macros use this variable decorator even for local variables. Most of the time it works, but when a static or inlined function tries to use a PROGMEM/PSTR/etc. variable the compiler can throw an error like: error: XXX causes a section type conflict with YYY Change the PROGMEM macro to emit a section name that is unique (a combo of the file, line, and counter variables to ensure uniqueness). The standard linker script will place them properly in .IROM without any changes. Fixes #5036 and others.
1 parent adde93b commit 9e31fd5

File tree

7 files changed

+26
-12
lines changed

7 files changed

+26
-12
lines changed

cores/esp8266/Print.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
size_t Print::write(const uint8_t *buffer, size_t size) {
3636

3737
#ifdef DEBUG_ESP_CORE
38-
static char not_the_best_way [] ICACHE_RODATA_ATTR STORE_ATTR = "Print::write(data,len) should be overridden for better efficiency\r\n";
38+
static char not_the_best_way [] PROGMEM STORE_ATTR = "Print::write(data,len) should be overridden for better efficiency\r\n";
3939
static bool once = false;
4040
if (!once) {
4141
once = true;

cores/esp8266/heap.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ void* ICACHE_RAM_ATTR pvPortZalloc(size_t size, const char* file, int line)
8484
#undef calloc
8585
#undef realloc
8686

87-
static const char oom_fmt[] ICACHE_RODATA_ATTR STORE_ATTR = ":oom(%d)@?\n";
88-
static const char oom_fmt_1[] ICACHE_RODATA_ATTR STORE_ATTR = ":oom(%d)@";
89-
static const char oom_fmt_2[] ICACHE_RODATA_ATTR STORE_ATTR = ":%d\n";
87+
static const char oom_fmt[] PROGMEM STORE_ATTR = ":oom(%d)@?\n";
88+
static const char oom_fmt_1[] PROGMEM STORE_ATTR = ":oom(%d)@";
89+
static const char oom_fmt_2[] PROGMEM STORE_ATTR = ":%d\n";
9090

9191
void* malloc (size_t s)
9292
{

cores/esp8266/pgmspace.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,19 @@
1010
#include "ets_sys.h"
1111
#include "osapi.h"
1212

13-
#define PROGMEM ICACHE_RODATA_ATTR
13+
// Since __section__ is supposed to be only use for global variables,
14+
// there could be conflicts when a static/inlined function has them in the
15+
// same file as a non-static PROGMEM object.
16+
// Ref: https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Variable-Attributes.html
17+
// Place each progmem object into its own named section, avoiding conflicts
18+
19+
// The following two macros cause a parameter to be enclosed in quotes
20+
// by the preopressor (i.e. for concatenating ints to strings)
21+
#define __STRINGIZE_NX(A) #A
22+
#define __STRINGIZE(A) __STRINGIZE_NX(A)
23+
24+
#define PROGMEM __attribute__((section( ".irom.text." __FILE__ "." __STRINGIZE(__LINE__) "." __STRINGIZE(__COUNTER__))))
25+
1426
#define PGM_P const char *
1527
#define PGM_VOID_P const void *
1628
#define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))

cores/esp8266/uart.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@
4141
*
4242
*/
4343
#include "Arduino.h"
44+
#include <pgmspace.h>
4445
#include "uart.h"
4546
#include "esp8266_peri.h"
4647
#include "user_interface.h"
4748
#include "uart_register.h"
4849

49-
const char overrun_str [] ICACHE_RODATA_ATTR STORE_ATTR = "uart input full!\r\n";
50+
const char overrun_str [] PROGMEM STORE_ATTR = "uart input full!\r\n";
5051
static int s_uart_debug_nr = UART0;
5152

5253

cores/esp8266/umm_malloc/umm_malloc_cfg.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ extern char _heap_start;
178178
// this must be outside from "#ifndef _UMM_MALLOC_CFG_H"
179179
// because Arduino.h's <cstdlib> does #undef *alloc
180180
// Arduino.h recall us to redefine them
181-
#define malloc(s) ({ static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; malloc_loc(s, mem_debug_file, __LINE__); })
182-
#define calloc(n,s) ({ static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; calloc_loc(n, s, mem_debug_file, __LINE__); })
183-
#define realloc(p,s) ({ static const char mem_debug_file[] ICACHE_RODATA_ATTR STORE_ATTR = __FILE__; realloc_loc(p, s, mem_debug_file, __LINE__); })
181+
#include <pgmspace.h>
182+
#define malloc(s) ({ static const char mem_debug_file[] PROGMEM STORE_ATTR = __FILE__; malloc_loc(s, mem_debug_file, __LINE__); })
183+
#define calloc(n,s) ({ static const char mem_debug_file[] PROGMEM STORE_ATTR = __FILE__; calloc_loc(n, s, mem_debug_file, __LINE__); })
184+
#define realloc(p,s) ({ static const char mem_debug_file[] PROGMEM STORE_ATTR = __FILE__; realloc_loc(p, s, mem_debug_file, __LINE__); })
184185
#endif /* DEBUG_ESP_OOM */

libraries/ESP8266WebServer/src/detail/mimetable.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace mime
55
{
66

77
// Table of extension->MIME strings stored in PROGMEM, needs to be global due to GCC section typing rules
8-
const Entry mimeTable[maxType] ICACHE_RODATA_ATTR =
8+
const Entry mimeTable[maxType] PROGMEM =
99
{
1010
{ ".html", "text/html" },
1111
{ ".htm", "text/html" },

libraries/ESP8266WiFi/examples/WiFiHTTPSServer/make-self-signed-cert.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# Replace your-name-here with somethine appropriate before running and use
55
# the generated .H files in your code as follows:
66
#
7-
# static const uint8_t rsakey[] ICACHE_RODATA_ATTR = {
7+
# static const uint8_t rsakey[] PROGMEM = {
88
# #include "key.h"
99
# };
1010
#
11-
# static const uint8_t x509[] ICACHE_RODATA_ATTR = {
11+
# static const uint8_t x509[] PROGMEM = {
1212
# #include "x509.h"
1313
# };
1414
#

0 commit comments

Comments
 (0)