Skip to content

Commit 8d63cba

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 756f2c6 + 3962937 commit 8d63cba

File tree

2 files changed

+41
-26
lines changed

2 files changed

+41
-26
lines changed

components/cplusplus/README.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,51 @@ This is the C++ component in RT-Thread RTOS. In order to support C++ language, t
44
implement a basic environment, such as new/delete operators.
55

66
Because RT-Thread RTOS is used in embedded system mostly, there are some rules for C++ applications:
7+
78
1. DOES NOT use exception.
89
2. DOES NOT use Run-Time Type Information (RTTI).
910
3. Template is discouraged and it easily causes code text large.
1011
4. Static class variables are discouraged. The time and place to call their constructor function could not be precisely controlled and make multi-threaded programming a nightmare.
1112
5. Multiple inheritance is strongly discouraged, as it can cause intolerable confusion.
1213

13-
*NOTE*: The libc must be enable.
14+
*NOTE*: The libc (RT_USING_LIBC in rtconfig.h) must be enable.
1415

1516
About GNU GCC compiler
1617

1718
please add following string in your ld link script:
18-
// in your .text section
19-
PROVIDE(__ctors_start__ = .);
20-
/* old GCC version uses .ctors */
21-
KEEP(*(SORT(.ctors.*)))
22-
KEEP(*(.ctors))
23-
/* new GCC version uses .init_array */
24-
KEEP (*(SORT(.init_array.*)))
25-
KEEP (*(.init_array))
26-
PROVIDE(__ctors_end__ = .);
27-
28-
. = ALIGN(4);
29-
30-
// as a standalone section if you use ARM target.
3119

20+
// in your .text section
21+
PROVIDE(__ctors_start__ = .);
22+
/* old GCC version uses .ctors */
23+
KEEP(*(SORT(.ctors.*)))
24+
KEEP(*(.ctors))
25+
/* new GCC version uses .init_array */
26+
KEEP (*(SORT(.init_array.*)))
27+
KEEP (*(.init_array))
28+
PROVIDE(__ctors_end__ = .);
29+
30+
. = ALIGN(4);
31+
32+
// as a standalone section if you use ARM target.
33+
3234
/* The .ARM.exidx section is used for C++ exception handling. */
3335
/* .ARM.exidx is sorted, so has to go in its own output section. */
3436
__exidx_start = .;
35-
.ARM.exidx :
37+
ARM.exidx :
3638
{
3739
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
3840

3941
/* This is used by the startup in order to initialize the .data secion */
4042
_sidata = .;
4143
} > CODE
4244
__exidx_end = .;
43-
45+
4446
/* .data section which is used for initialized data */
4547

46-
// in your .data section
47-
PROVIDE(__dtors_start__ = .);
48-
KEEP(*(SORT(.dtors.*)))
49-
KEEP(*(.dtors))
50-
PROVIDE(__dtors_end__ = .);
51-
52-
. = ALIGN(4);
53-
48+
// in your .data section
49+
PROVIDE(__dtors_start__ = .);
50+
KEEP(*(SORT(.dtors.*)))
51+
KEEP(*(.dtors))
52+
PROVIDE(__dtors_end__ = .);
53+
54+
. = ALIGN(4);

components/cplusplus/crt_init.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,22 @@ int cplusplus_system_init(void)
5151
(*ctors_func)();
5252
}
5353
#elif defined(__CC_ARM)
54-
/* call armcc lib to initialize cplusplus */
55-
$Super$$__cpp_initialize__aeabi_();
54+
/* If there is no SHT$$INIT_ARRAY, calling
55+
* $Super$$__cpp_initialize__aeabi_() will cause fault. At least until Keil5.12
56+
* the problem still exists. So we have to initialize the C++ runtime by ourself.
57+
*/
58+
typedef void PROC();
59+
extern const unsigned long SHT$$INIT_ARRAY$$Base[];
60+
extern const unsigned long SHT$$INIT_ARRAY$$Limit[];
61+
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+
}
5670
#endif
5771

5872
return 0;

0 commit comments

Comments
 (0)