Skip to content

Commit ce89e7e

Browse files
committed
Launch libc initialization after hardware setup
This pachs allows C++ global constructors to run after hardware initialization. This helps some libraries that setups hardware in class constructor to work properly. See also arduino#169
1 parent 8737fd8 commit ce89e7e

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

cores/arduino/cortex_handlers.c

-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ __attribute__ ((section(".isr_vector"))) const DeviceVectors exception_table =
134134
};
135135

136136
extern int main(void);
137-
extern void __libc_init_array(void);
138137

139138
/* This is called on processor reset to initialize the device and call main() */
140139
void Reset_Handler(void)
@@ -156,9 +155,6 @@ void Reset_Handler(void)
156155
*pDest = 0;
157156
}
158157

159-
/* Initialize the C library */
160-
__libc_init_array();
161-
162158
SystemInit();
163159

164160
main();

cores/arduino/main.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@
2424
void initVariant() __attribute__((weak));
2525
void initVariant() { }
2626

27+
// Initialize C library
28+
extern "C" void __libc_init_array(void);
29+
2730
/*
2831
* \brief Main entry point of Arduino application
2932
*/
3033
int main( void )
3134
{
3235
init();
3336

37+
__libc_init_array();
38+
3439
initVariant();
3540

3641
delay(1);

0 commit comments

Comments
 (0)