[components/cplusplus]修正cplusplus_system_init在arm V6下的问题

This commit is contained in:
liruncong 2019-01-12 12:05:55 +08:00
parent e5522d6292
commit d0239b43a0

View File

@ -13,10 +13,10 @@
#include <rtthread.h> #include <rtthread.h>
#ifdef __CC_ARM #if defined(__CC_ARM) || defined(__CLANG_ARM)
extern void $Super$$__cpp_initialize__aeabi_(void); extern void $Super$$__cpp_initialize__aeabi_(void);
/* we need to change the cpp_initialize order */ /* we need to change the cpp_initialize order */
void $Sub$$__cpp_initialize__aeabi_(void) RT_WEAK void $Sub$$__cpp_initialize__aeabi_(void)
{ {
/* empty */ /* empty */
} }
@ -34,19 +34,9 @@ RT_WEAK void *__dso_handle = 0;
#endif #endif
RT_WEAK RT_WEAK int cplusplus_system_init(void)
int cplusplus_system_init(void)
{ {
#if defined(__GNUC__) && !defined(__CC_ARM) #if defined(__CC_ARM) || defined(__CLANG_ARM)
typedef void (*pfunc) ();
extern pfunc __ctors_start__[];
extern pfunc __ctors_end__[];
pfunc *p;
for (p = __ctors_start__; p < __ctors_end__; p++)
(*p)();
#elif defined(__CC_ARM)
/* If there is no SHT$$INIT_ARRAY, calling /* If there is no SHT$$INIT_ARRAY, calling
* $Super$$__cpp_initialize__aeabi_() will cause fault. At least until Keil5.12 * $Super$$__cpp_initialize__aeabi_() will cause fault. At least until Keil5.12
* the problem still exists. So we have to initialize the C++ runtime by ourself. * the problem still exists. So we have to initialize the C++ runtime by ourself.
@ -63,9 +53,16 @@ int cplusplus_system_init(void)
PROC *proc = (PROC*)((const char*)base + *base); PROC *proc = (PROC*)((const char*)base + *base);
(*proc)(); (*proc)();
} }
#elif defined(__GNUC__)
typedef void(*pfunc) ();
extern pfunc __ctors_start__[];
extern pfunc __ctors_end__[];
pfunc *p;
for (p = __ctors_start__; p < __ctors_end__; p++)
(*p)();
#endif #endif
return 0; return 0;
} }
INIT_COMPONENT_EXPORT(cplusplus_system_init); INIT_COMPONENT_EXPORT(cplusplus_system_init);