diff --git a/components/cplusplus/crt_init.c b/components/cplusplus/crt_init.c index 0f89b35636..8641f93f40 100644 --- a/components/cplusplus/crt_init.c +++ b/components/cplusplus/crt_init.c @@ -22,6 +22,7 @@ * 2014-12-03 Bernard Add copyright header. * 2014-12-29 Bernard Add cplusplus initialization for ARMCC. * 2016-06-28 Bernard Add _init/_fini routines for GCC. +* 2016-10-02 Bernard Add WEAK for cplusplus_system_init routine. */ #include @@ -44,22 +45,18 @@ void _fini() } #endif +WEAK int cplusplus_system_init(void) { #if defined(__GNUC__) && !defined(__CC_ARM) - extern unsigned char __ctors_start__; - extern unsigned char __ctors_end__; - typedef void (*func)(void); + typedef void (*pfunc) (); + extern pfunc __ctors_start__[]; + extern pfunc __ctors_end__[]; + pfunc *p; - /* .ctors initalization */ - func *ctors_func; + for (p = __ctors_start__; p < __ctors_end__; p++) + (*p)(); - for (ctors_func = (func *)&__ctors_start__; - ctors_func < (func *)&__ctors_end__; - ctors_func ++) - { - (*ctors_func)(); - } #elif defined(__CC_ARM) /* If there is no SHT$$INIT_ARRAY, calling * $Super$$__cpp_initialize__aeabi_() will cause fault. At least until Keil5.12