From 328813ce121bcd5a2744e165a21fa54940b1adc0 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Wed, 21 Aug 2019 16:31:06 +0200 Subject: [PATCH] cpu/esp32: fix of ctor and newlib initialization Module `newlib` is now used by default. Therefore, the separation of initialization of ctors and the newlibc is not needed any longer. Instead of calling `do_global_ctors` and `_init` separately, `__libc_init_array` is called. Explicit function `do_global_ctors` is removed. --- cpu/esp32/startup.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/cpu/esp32/startup.c b/cpu/esp32/startup.c index 1b85a1e041..875ff84c47 100644 --- a/cpu/esp32/startup.c +++ b/cpu/esp32/startup.c @@ -93,7 +93,6 @@ extern void bootloader_clock_configure(void); /* forward declarations */ static void system_init(void); -static void do_global_ctors(void); static void intr_matrix_clear(void); typedef int32_t esp_err_t; @@ -279,8 +278,12 @@ static NORETURN void IRAM system_init (void) /* Disable the hold flag of all RTC GPIO pins */ RTCCNTL.hold_force.val = 0; - /* execute constructors */ - do_global_ctors(); + /* + * initialization of newlib, includes the ctors initialization and + * and the execution of stdio_init in _init of newlib_syscalls_default + */ + extern void __libc_init_array(void); + __libc_init_array(); /* init watchdogs */ system_wdt_init(); @@ -288,13 +291,6 @@ static NORETURN void IRAM system_init (void) /* init random number generator */ srand(hwrand()); - /* - * initialization as it should be called from newlibc (includes the - * execution of stdio_init) - */ - extern void _init(void); - _init(); - /* add SPI RAM to heap if enabled */ #if CONFIG_SPIRAM_SUPPORT && CONFIG_SPIRAM_BOOT_INIT spi_ram_heap_init(); @@ -345,18 +341,6 @@ static NORETURN void IRAM system_init (void) UNREACHABLE(); } -static void do_global_ctors(void) -{ - #if 0 /* TODO when real ctors are used exist */ - extern uint32_t* __init_array_start; - extern uint32_t* __init_array_end; - for (uint32_t* up = __init_array_end - 1; up >= __init_array_start; --up) { - void (*fp)(void) = (void (*)(void))up; - fp(); - } - #endif -} - static void intr_matrix_clear(void) { /* attach all peripheral interrupt sources (Technical Reference, Table 7) */