Skip to content

Commit 01ab0c1

Browse files
committed
crt_init: fix hardfault in Keil toolchain when there is no cpp object
If there is no SHT$$INIT_ARRAY, calling $Super$$__cpp_initialize__aeabi_() will fault. At least until Keil5.12 the problem still exists. So we have to initialize the C++ runtime our own.
1 parent 2475568 commit 01ab0c1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

components/cplusplus/crt_init.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,26 @@ int cplusplus_system_init(void)
5151
(*ctors_func)();
5252
}
5353
#elif defined(__CC_ARM)
54+
# if 1
55+
/* If there is no SHT$$INIT_ARRAY, calling
56+
* $Super$$__cpp_initialize__aeabi_() will fault. At least until Keil5.12
57+
* the problem still exists. So we have to initialize the C++ runtime our
58+
* own. */
59+
typedef void PROC();
60+
extern const unsigned long SHT$$INIT_ARRAY$$Base[];
61+
extern const unsigned long SHT$$INIT_ARRAY$$Limit[];
62+
const unsigned long *base = SHT$$INIT_ARRAY$$Base;
63+
const unsigned long *lim = SHT$$INIT_ARRAY$$Limit;
64+
65+
for (; base != lim; base++)
66+
{
67+
PROC *proc = (PROC*)((const char*)base + *base);
68+
(*proc)();
69+
}
70+
# else
5471
/* call armcc lib to initialize cplusplus */
5572
$Super$$__cpp_initialize__aeabi_();
73+
# endif
5674
#endif
5775

5876
return 0;

0 commit comments

Comments
 (0)