Skip to content

Commit d979b57

Browse files
Upgrade to GCC 10.1 toolchain (#6294)
* Upgrade to GCC 9.1 toolchain * Rebuilt using pure GNU binutils and GCC Remove dependencies on earlier forked GNU utilities (gcc-xtensa, binutils-gdb-xtensa) and just use GCC sources, unmodified (except for patches in the esp-quick-toolchain directories). * Rebuild bearssl using new toolchain * Fix GDBstub linkage options GDB works with pure GNU GCC and pure GNU binutils now. Still warnings galore, but tested with the example sketch in the docs. * Fix digitalRead alias warning * Remove gdb stub warnings w/a pragma * Fix deprecated implicit copy ctors in IP code Fix some warnings present in GCC8/9 in the IPAddress code In AddressListIterator there was a copy constructor which simply copied the structure bit-for-bit. That's the default operation, so remove it to avoid the warning there. IPAddress, add a default copy constructor since the other copy constructors are simply parsing from one format into a native ip_addr_t. @d-a-v, can you give these a look over and see if they're good (since IP stuff is really your domain). * Fix AxTLS alias function defs to match real code * Fix WiFiClientSecure implicit default copy ctor These both use shared-ptrs to handle refcnts to allocated data, so using the default copy constructor is fine (and has been in use for a long time). * Dummy size for heap to avoid GCC 8/9 warnings Make GCC think _heap_start is large enough to avoid the basic (and incorrect) bounds-checking warnings it produces. The size chosen is arbitrary and does not affect the actual size of the heap in any way. * Make heap an undefined extend array Instead of a bogus size, use an indefinite size for the heap to avoid GCC warnings * Trivial tab to space fix * Update SDFat to remove FatFile warnings * Fix ticker function cast warnings in GCC 9 The callback function is defined to take a (void*) as parameter, but our templates let users use anything that fits inside sizeof(void*) to be passed in. Add pragmas to stop GCC warnings about this, since we already check the size of the type will fit in the allocated space. * Remove GCC support fcn that's in ROM Manually delete the divdi3.so from the libgcc.a library by running the updated EQT's 9.1-post script. * Make exceptions work again, get std::regex up Exceptions are broken on all builds (GCC4.8-9.1) due to the removal of the PROGMEM non-32b read exception handler (added in the unstable pre3.0.0). Build the exception code with -mforce-l32 and patch accordingly to avoid LoadStore errors. Apply patches to select portions of the regex lib which use _stype_ (which is now in flash). * Rebuild Bearssl using latest GCC push * Automate building of BearSSL and LWIP w/new toolchain * Workaround g++ template section problem for exception strings G++ seems to throw out the section attributes for templates. This means that the __EXCSTR(a synonym for "PSTR()") is ignored and exception.what strings are stored in RODATA, eating up RAM. Workaround by using the linker to place the strings keying off their name ("*__exception_what__*"). * Rebuild moving exception.what to unique names Exception.whats are now all in __exception_what__ and can be moved by the linker to flash. Works aroung G++ issue with segments being lost in templates. * Rebuild with new LWIP locking * Update to latest libs, save iram Move two GCC FP support routines out of iram since they are in ROM already, saving some add'l IRAM. Same list as gcc 4.8. * Update BearSSL to latest release * Fix umm_perf reference to ROM function * Fix "reinterpret_case is not a constexpr" error In GCC 9 (and 8 from what I read on SO), a cast of a const int to a function pointer (via explicit or implicit reinterpret_cast) is not a constexpr. ```` /home/earle/Arduino/hardware/esp8266com/esp8266/cores/esp8266/umm_malloc/umm_performance.cpp:45:36: error: a reinterpret_cast is not a constant expression 45 | int constexpr (*_rom_putc1)(int) = (int (*)(int))(void*)0x40001dcc; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ```` Remove the constexpr, potentially increasing heap usage by 4 bytes in debug mode. * Update libc.a to latest rev * Full rebuild of toolchain and libs * Upgrade to GCC 9.2, released in August 2019 Add builds for all 5 cross-compiles to pass CI * Move to --std=gnu++14 (C++14 + GNU extensions) * Fix Ticker merge conflict * Fix json merge conflict * One more merge diff fix * Reapply Ticker.h casting warning fixes for gcc9 * Update with fixes from Sming repo for PSTR and ASM * Upgrade to -gnu4 toolchain * Move to gnu5 build with add'l softFP from ROM * Move add'l softFP from IRAM to flash Per @mikee47, we miss sone add'l soft-FP routined in the linker which makes them end up in IRAM. Move them explicitly into flash, like a couple others we have already done this for. * Move to std=c++17/c17 in platform, remove abs/round Move to C++17 and C17 standards on the compiler options. Remove "register" from core since it is deprecated. Remove the #define abs() and #define round() which a) overwrote the C stdlib definitions, poorly, and b) broke the GCC core code which used "abs" as an internal function name. Now abs() returns an integer, and not whatever was being absoluted. fabs() etc. can be used if users need fload/double suport. round() returns a double now, which is basically what it was returning in the original case since adding/subtracting by a FP. * Use std::abs/round to replace the macro definitions Per discussion w/@devyte, preserve the abs() and round() functionality via the using statement. * Remove using std::abs which conflicted with C lib headers * Add 2nd arg (exception handler) to ets_isr_t Disassembly of the ROM shows there are 2 params to the ets_isr_t callback. The first is the arg passed in, the second is a pointer to an exception frame where you can get info about when the IRQ happened. * Move the gdbstub example to a subdir The Arduino IDE and the build CI don't build it without a subdir, so make one for gdbstub's example so it's visible and tested. * Fix ets_irq_arratch redefinition and core IRQ handlers Remove a duplicated, different declaration for ets_irq_attach from ets_sys.h. It never really even matched the other declaration in the same header. Update the core to IRQ handlers to fix the prototype and include the 2nd, unused frame parameter. * Actually rebuild the libc.a using GCC 9.2 * Fix SPISlave interrupt attach's 2nd parameter * Rebuild eboot.elf with GCC 9 * Update to latest SoftwareSerial for Delegate fix * Upgrade to GCC 9.3 * Rebuild all arch toolchains * Move to GCC 10.1 * Merge master and fix eboot build GCC10 now uses `-fno-common` so the eboot global variables were being placed in IRAM. Adjust the makefile and rebuild to fix. * Built complete toolchain for all archs * Pull in latest PSTR changes and fix GCC10.1 build Somehow the prior GCC build's -mforce32 patch wasn't applying correctly, but I was still able to get a binary. Fixed. Also pulled in latest PSTR changes in progmem.h * Update platform.io to platform C/C++ standards * Use PR's toolchain in platformio build * Fix several asm warnings in PIO build * Optional stack smash protection -fstack-protector Add a menu to enable GCC's built-in stack smash protection. When a subroutine goes past its end of stack, generate a crashdump on function exit like: ```` GCC detected stack overrun Stack corrupted, stack smash detected. >>>stack>>> ctx: cont sp: 3fffff20 end: 3fffffc0 offset: 0000 3fffff20: 40202955 00000001 0000001c 4020287e 3fffff30: feefeffe 000000fd 00000000 00000000 ... <<<stack<<< ```` Disabled by default because there is a small per-function code overhead (and CPU time if the function is called very frequently and is very small). BearSSL and LWIP are not built using stack smash detection, yet. * Fix duplicated stc=gnu99/c17 in build * Dump faulting function PC in stack overflow Report a fake exception to have the exception decoder print the actual faulting function. This won't tell you where in the function the issue happened, but it will tell you the function name first and foremost. * Rebuild with Platform.io JSON tag in release tgzs
1 parent 7b48b9d commit d979b57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+337
-144
lines changed

boards.txt

+137
Large diffs are not rendered by default.

bootloaders/eboot/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ INC += -I../../tools/sdk/include -I../../tools/sdk/uzlib/src
2323

2424
CFLAGS += -std=gnu99
2525

26-
CFLAGS += -Os -g -Wall -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mno-text-section-literals -ffunction-sections -fdata-sections
26+
CFLAGS += -Os -fcommon -g -Wall -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mno-text-section-literals -ffunction-sections -fdata-sections
2727

2828
CFLAGS += $(INC)
2929

bootloaders/eboot/eboot.elf

9.13 KB
Binary file not shown.

cores/esp8266/Arduino.h

+2-7
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,8 @@ void timer0_isr_init(void);
127127
void timer0_attachInterrupt(timercallback userFunc);
128128
void timer0_detachInterrupt(void);
129129

130-
// undefine stdlib's abs if encountered
131-
#ifdef abs
132-
#undef abs
133-
#endif
134-
135-
#define abs(x) ((x)>0?(x):-(x))
130+
// Use stdlib abs() and round() to avoid issues with the C++ libraries
136131
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
137-
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
138132
#define radians(deg) ((deg)*DEG_TO_RAD)
139133
#define degrees(rad) ((rad)*RAD_TO_DEG)
140134
#define sq(x) ((x)*(x))
@@ -249,6 +243,7 @@ const int TIM_DIV265 __attribute__((deprecated, weak)) = TIM_DIV256;
249243

250244
using std::min;
251245
using std::max;
246+
using std::round;
252247
using std::isinf;
253248
using std::isnan;
254249

cores/esp8266/StackThunk.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extern uint32_t stack_thunk_refcnt;
5151

5252
// Thunking macro
5353
#define make_stack_thunk(fcnToThunk) \
54-
__asm("\n\
54+
__asm__ ("\n\
5555
.text\n\
5656
.literal_position\n\
5757
.literal .LC_STACK_VALUE"#fcnToThunk", 0xdeadbeef\n\

cores/esp8266/core_esp8266_features.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ void precache(void *f, uint32_t bytes) {
3737
// page (ie 1 word in 8) for this to work.
3838
#define CACHE_PAGE_SIZE 32
3939

40-
register uint32_t a0 asm("a0");
41-
register uint32_t lines = (bytes/CACHE_PAGE_SIZE)+2;
40+
uint32_t a0;
41+
__asm__("mov.n %0, a0" : "=r"(a0));
42+
uint32_t lines = (bytes/CACHE_PAGE_SIZE)+2;
4243
volatile uint32_t *p = (uint32_t*)((f ? (uint32_t)f : a0) & ~0x03);
4344
uint32_t x;
4445
for (uint32_t i=0; i<lines; i++, p+=CACHE_PAGE_SIZE/sizeof(uint32_t)) x=*p;

cores/esp8266/core_esp8266_main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ extern "C" bool ets_post_rom(uint8 prio, ETSSignal sig, ETSParam par);
172172

173173
extern "C" bool IRAM_ATTR ets_post(uint8 prio, ETSSignal sig, ETSParam par) {
174174
uint32_t saved;
175-
asm volatile ("rsr %0,ps":"=a" (saved));
175+
__asm__ __volatile__ ("rsr %0,ps":"=a" (saved));
176176
bool rc=ets_post_rom(prio, sig, par);
177177
xt_wsr_ps(saved);
178178
return rc;

cores/esp8266/core_esp8266_postmortem.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ static const char* s_panic_what = 0;
4545
static bool s_abort_called = false;
4646
static const char* s_unhandled_exception = NULL;
4747

48+
static uint32_t s_stacksmash_addr = 0;
49+
4850
void abort() __attribute__((noreturn));
4951
static void uart_write_char_d(char c);
5052
static void uart0_write_char_d(char c);
@@ -54,6 +56,7 @@ static void print_stack(uint32_t start, uint32_t end);
5456
// using numbers different from "REASON_" in user_interface.h (=0..6)
5557
enum rst_reason_sw
5658
{
59+
REASON_USER_STACK_SMASH = 253,
5760
REASON_USER_SWEXCEPTION_RST = 254
5861
};
5962
static int s_user_reset_reason = REASON_DEFAULT_RST;
@@ -147,6 +150,11 @@ void __wrap_system_restart_local() {
147150
else if (rst_info.reason == REASON_SOFT_WDT_RST) {
148151
ets_printf_P(PSTR("\nSoft WDT reset\n"));
149152
}
153+
else if (rst_info.reason == REASON_USER_STACK_SMASH) {
154+
ets_printf_P(PSTR("\nStack overflow detected.\n"));
155+
ets_printf_P(PSTR("\nException (%d):\nepc1=0x%08x epc2=0x%08x epc3=0x%08x excvaddr=0x%08x depc=0x%08x\n"),
156+
5 /* Alloca exception, closest thing to stack fault*/, s_stacksmash_addr, 0, 0, 0, 0);
157+
}
150158
else {
151159
ets_printf_P(PSTR("\nGeneric Reset\n"));
152160
}
@@ -290,4 +298,20 @@ void __panic_func(const char* file, int line, const char* func) {
290298
raise_exception();
291299
}
292300

301+
uintptr_t __stack_chk_guard = 0x08675309 ^ RANDOM_REG32;
302+
void __stack_chk_fail(void) {
303+
s_user_reset_reason = REASON_USER_STACK_SMASH;
304+
ets_printf_P(PSTR("\nPANIC: Stack overrun"));
305+
306+
s_stacksmash_addr = (uint32_t)__builtin_return_address(0);
307+
308+
if (gdb_present())
309+
__asm__ __volatile__ ("syscall"); // triggers GDB when enabled
310+
311+
__wrap_system_restart_local();
312+
313+
while (1); // never reached, needed to satisfy "noreturn" attribute
314+
}
315+
316+
293317
};

cores/esp8266/core_esp8266_si2c.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void ICACHE_RAM_ATTR Twi::busywait(unsigned int v)
234234
unsigned int i;
235235
for (i = 0; i < v; i++) // loop time is 5 machine cycles: 31.25ns @ 160MHz, 62.5ns @ 80MHz
236236
{
237-
asm("nop"); // minimum element to keep GCC from optimizing this function out.
237+
__asm__ __volatile__("nop"); // minimum element to keep GCC from optimizing this function out.
238238
}
239239
}
240240

cores/esp8266/core_esp8266_timer.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ extern "C" {
3131

3232
static volatile timercallback timer1_user_cb = NULL;
3333

34-
void ICACHE_RAM_ATTR timer1_isr_handler(void *para){
34+
void ICACHE_RAM_ATTR timer1_isr_handler(void *para, void *frame) {
3535
(void) para;
36+
(void) frame;
3637
if ((T1C & ((1 << TCAR) | (1 << TCIT))) == 0) TEIE &= ~TEIE1;//edge int disable
3738
T1I = 0;
3839
if (timer1_user_cb) {
@@ -79,8 +80,9 @@ void ICACHE_RAM_ATTR timer1_disable(){
7980

8081
static volatile timercallback timer0_user_cb = NULL;
8182

82-
void ICACHE_RAM_ATTR timer0_isr_handler(void* para){
83+
void ICACHE_RAM_ATTR timer0_isr_handler(void *para, void *frame) {
8384
(void) para;
85+
(void) frame;
8486
if (timer0_user_cb) {
8587
// to make ISR compatible to Arduino AVR model where interrupts are disabled
8688
// we disable them before we call the client ISR

cores/esp8266/core_esp8266_wiring_digital.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ typedef struct {
130130
static interrupt_handler_t interrupt_handlers[16] = { {0, 0, 0, 0}, };
131131
static uint32_t interrupt_reg = 0;
132132

133-
void ICACHE_RAM_ATTR interrupt_handler(void*)
133+
void ICACHE_RAM_ATTR interrupt_handler(void *arg, void *frame)
134134
{
135+
(void) arg;
136+
(void) frame;
135137
uint32_t status = GPIE;
136138
GPIEC = status;//clear them interrupts
137139
uint32_t levels = GPI;

cores/esp8266/gdb_hooks.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ static bool ICACHE_RAM_ATTR __gdb_no_op()
3131
return false;
3232
}
3333

34+
// To save space, don't create a dummy no-op for each GCC, just point to the no-op
35+
// Need to turn off GCC's checking of parameter types or we'll get many warnings
36+
#pragma GCC diagnostic push
37+
#pragma GCC diagnostic ignored "-Wattribute-alias"
38+
#pragma GCC diagnostic ignored "-Wmissing-attributes"
3439
void gdb_init(void) __attribute__ ((weak, alias("__gdb_no_op")));
3540
void gdb_do_break(void) __attribute__ ((weak, alias("__gdb_no_op")));
3641
bool gdb_present(void) __attribute__ ((weak, alias("__gdb_no_op")));
@@ -40,5 +45,6 @@ bool gdbstub_has_uart_isr_control(void) __attribute__ ((weak, alias("__gdb_no_op
4045
void gdbstub_set_uart_isr_callback(void (*func)(void*, uint8_t), void* arg) __attribute__ ((weak, alias("__gdb_no_op")));
4146
void gdbstub_write_char(char c) __attribute__ ((weak, alias("__gdb_no_op")));
4247
void gdbstub_write(const char* buf, size_t size) __attribute__ ((weak, alias("__gdb_no_op")));
48+
#pragma GCC diagnostic pop
4349

4450
};

cores/esp8266/uart.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,9 @@ uart_get_rx_buffer_size(uart_t* uart)
371371

372372
// The default ISR handler called when GDB is not enabled
373373
void ICACHE_RAM_ATTR
374-
uart_isr(void * arg)
374+
uart_isr(void * arg, void * frame)
375375
{
376+
(void) frame;
376377
uart_t* uart = (uart_t*)arg;
377378
uint32_t usis = USIS(uart->uart_nr);
378379

libraries/GDBStub/src/internal/gdbstub.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ static inline int gdbHandleCommand() {
445445
writeByte(i, gdbGetHexVal(&data, 8));
446446
}
447447
//Make sure caches are up-to-date. Procedure according to Xtensa ISA document, ISYNC inst desc.
448-
asm volatile("ISYNC\nISYNC\n");
448+
__asm__ __volatile__ ("ISYNC\nISYNC\n");
449449
gdbSendPacketOK();
450450
} else {
451451
//Trying to do a software breakpoint on a flash proc, perhaps?

libraries/SPISlave/src/hspi_slave.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ static void (*_hspi_slave_rx_status_cb)(void * arg, uint32_t data) = NULL;
2828
static void (*_hspi_slave_tx_status_cb)(void * arg) = NULL;
2929
static uint8_t _hspi_slave_buffer[33];
3030

31-
void ICACHE_RAM_ATTR _hspi_slave_isr_handler(void *arg)
31+
void ICACHE_RAM_ATTR _hspi_slave_isr_handler(void *arg, void *frame)
3232
{
33+
(void) frame;
3334
uint32_t status;
3435
uint32_t istatus;
3536

libraries/Ticker/src/Ticker.h

+6
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,22 @@ class Ticker
7474
template<typename TArg>
7575
void attach(float seconds, void (*callback)(TArg), TArg arg)
7676
{
77+
#pragma GCC diagnostic push
78+
#pragma GCC diagnostic ignored "-Wcast-function-type"
7779
static_assert(sizeof(TArg) <= sizeof(void*), "attach() callback argument size must be <= sizeof(void*)");
7880
_attach_ms(1000UL * seconds, true, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<void*>(arg));
81+
#pragma GCC diagnostic pop
7982
}
8083

8184
// callback will be called in SYS ctx when ticker fires
8285
template<typename TArg>
8386
void attach_ms(uint32_t milliseconds, void (*callback)(TArg), TArg arg)
8487
{
88+
#pragma GCC diagnostic push
89+
#pragma GCC diagnostic ignored "-Wcast-function-type"
8590
static_assert(sizeof(TArg) <= sizeof(void*), "attach() callback argument size must be <= sizeof(void*)");
8691
_attach_ms(milliseconds, true, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<void*>(arg));
92+
#pragma GCC diagnostic pop
8793
}
8894

8995
// callback will be called at following loop() after ticker fires

0 commit comments

Comments
 (0)