Skip to content

Commit 16ff73b

Browse files
committed
Merge pull request #362 from BernardXiong/master
[C++] fix GCC compiling issue.
2 parents e22264f + c319182 commit 16ff73b

File tree

12 files changed

+130
-31
lines changed

12 files changed

+130
-31
lines changed

bsp/lpc176x/SConstruct

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ TARGET = 'rtthread-lpc17xx.' + rtconfig.TARGET_EXT
1414
env = Environment(tools = ['mingw'],
1515
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
1616
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
17+
CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
1718
AR = rtconfig.AR, ARFLAGS = '-rc',
1819
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
1920

bsp/lpc176x/rtconfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@
9090
// </section>
9191

9292
// <section name="LIBC" description="C Runtime library setting" default="always" >
93-
// <bool name="RT_USING_NEWLIB" description="Using newlib library, only available under GNU GCC" default="true" />
94-
// #define RT_USING_NEWLIB
93+
// <bool name="RT_USING_LIBC" description="Using C library" default="true" />
94+
// #define RT_USING_LIBC
9595
// <bool name="RT_USING_PTHREADS" description="Using POSIX threads library" default="true" />
9696
// #define RT_USING_PTHREADS
9797
// </section>

bsp/lpc176x/rtconfig.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
if PLATFORM == 'gcc':
2727
# toolchains
2828
PREFIX = 'arm-none-eabi-'
29-
CC = PREFIX + 'gcc'
29+
CC = PREFIX + 'gcc'
30+
CXX = PREFIX + 'g++'
3031
AS = PREFIX + 'gcc'
3132
AR = PREFIX + 'ar'
3233
LINK = PREFIX + 'gcc'
@@ -37,6 +38,7 @@
3738

3839
DEVICE = ' -mcpu=cortex-m3 -mthumb'
3940
CFLAGS = DEVICE
41+
CXXFLAGS = CFLAGS
4042
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
4143
LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-lpc17xx.map,-cref,-u,Reset_Handler -T rtthread-lpc17xx.ld'
4244

@@ -54,6 +56,7 @@
5456
elif PLATFORM == 'armcc':
5557
# toolchains
5658
CC = 'armcc'
59+
CXX = 'armcc'
5760
AS = 'armasm'
5861
AR = 'armar'
5962
LINK = 'armlink'
@@ -65,6 +68,7 @@
6568
LFLAGS = DEVICE + ' --info sizes --info totals --info unused --info veneers --list rtthread-lpc17xx.map --scatter rtthread-lpc17xx.sct'
6669

6770
CFLAGS += ' -I' + EXEC_PATH + '/ARM/RV31/INC'
71+
CXXFLAGS = CFLAGS
6872
LFLAGS += ' --libpath ' + EXEC_PATH + '/ARM/RV31/LIB'
6973

7074
EXEC_PATH += '/arm/bin40/'

bsp/lpc408x/Libraries/Device/NXP/LPC407x_8x_177x_8x/Source/Templates/GCC/startup_LPC407x_8x_177x_8x.s

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,18 @@ __cs3_interrupt_vector_cortex_m:
102102
.long DMA_IRQHandler /* 42: General Purpose DMA */
103103
.long I2S_IRQHandler /* 43: I2S */
104104
.long ENET_IRQHandler /* 44: Ethernet */
105-
.long MCI_IRQHandler /* 45: SD/MMC Card */
105+
.long MCI_IRQHandler /* 45: SD/MMC Card */
106106
.long MCPWM_IRQHandler /* 46: Motor Control PWM */
107107
.long QEI_IRQHandler /* 47: Quadrature Encoder Interface */
108108
.long PLL1_IRQHandler /* 48: PLL1 Lock (USB PLL) */
109-
.long USBActivity_IRQHandler /* 49: USB Activity */
110-
.long CANActivity_IRQHandler /* 50: CAN Activity */
111-
.long UART4_IRQHandler /* 51: UART4 */
112-
.long SSP2_IRQHandler /* 52: SSP2 */
113-
.long LCD_IRQHandler /* 53: LCD */
114-
.long GPIO_IRQHandler /* 54: GPIO */
115-
.long PWM0_IRQHandler /* 55: PWM0 */
116-
.long EEPROM_IRQHandler /* 56: EEPROM */
109+
.long USBActivity_IRQHandler /* 49: USB Activity */
110+
.long CANActivity_IRQHandler /* 50: CAN Activity */
111+
.long UART4_IRQHandler /* 51: UART4 */
112+
.long SSP2_IRQHandler /* 52: SSP2 */
113+
.long LCD_IRQHandler /* 53: LCD */
114+
.long GPIO_IRQHandler /* 54: GPIO */
115+
.long PWM0_IRQHandler /* 55: PWM0 */
116+
.long EEPROM_IRQHandler /* 56: EEPROM */
117117

118118
.size __cs3_interrupt_vector_cortex_m, . - __cs3_interrupt_vector_cortex_m
119119

@@ -130,22 +130,24 @@ CRP_Value:
130130
.section .cs3.reset,"x",%progbits
131131
.thumb_func
132132
.globl __cs3_reset_cortex_m
133+
.globl Reset_Handler
133134
.type __cs3_reset_cortex_m, %function
134135
__cs3_reset_cortex_m:
136+
Reset_Handler:
135137
.fnstart
136138
.ifdef RAM_MODE
137139
/* Clear .bss section (Zero init) */
138-
MOV R0, #0
139-
LDR R1, =__bss_start__
140-
LDR R2, =__bss_end__
141-
CMP R1,R2
142-
BEQ BSSIsEmpty
140+
MOV R0, #0
141+
LDR R1, =__bss_start__
142+
LDR R2, =__bss_end__
143+
CMP R1,R2
144+
BEQ BSSIsEmpty
143145
LoopZI:
144-
CMP R1, R2
145-
BHS BSSIsEmpty
146-
STR R0, [R1]
147-
ADD R1, #4
148-
BLO LoopZI
146+
CMP R1, R2
147+
BHS BSSIsEmpty
148+
STR R0, [R1]
149+
ADD R1, #4
150+
BLO LoopZI
149151
BSSIsEmpty:
150152
LDR R0, =SystemInit
151153
BLX R0
@@ -154,7 +156,7 @@ BSSIsEmpty:
154156
.else
155157
LDR R0, =SystemInit
156158
BLX R0
157-
LDR R0,=_start
159+
LDR R0,=main
158160
BX R0
159161
.endif
160162
.pool

bsp/lpc408x/SConstruct

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ TARGET = 'rtthread-%s.%s' % (rtconfig.BOARD_NAME, rtconfig.TARGET_EXT)
1515
env = Environment(tools = ['mingw'],
1616
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
1717
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
18+
CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
1819
AR = rtconfig.AR, ARFLAGS = '-rc',
1920
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
2021
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)

bsp/lpc408x/rtconfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@
104104
// </section>
105105

106106
// <section name="LIBC" description="C Runtime library setting" default="always" >
107-
// <bool name="RT_USING_NEWLIB" description="Using newlib library, only available under GNU GCC" default="true" />
108-
// #define RT_USING_NEWLIB
107+
// <bool name="RT_USING_LIBC" description="Using C library" default="true" />
108+
// #define RT_USING_LIBC
109109
// <bool name="RT_USING_PTHREADS" description="Using POSIX threads library" default="true" />
110110
#define RT_USING_PTHREADS
111111
// </section>

bsp/lpc408x/rtconfig.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@
2929
if PLATFORM == 'gcc':
3030
# toolchains
3131
PREFIX = 'arm-none-eabi-'
32-
CC = PREFIX + 'gcc'
32+
CC = PREFIX + 'gcc'
33+
CXX = PREFIX + 'g++'
3334
AS = PREFIX + 'gcc'
3435
AR = PREFIX + 'ar'
35-
LINK = PREFIX + 'gcc'
36+
LINK = PREFIX + 'g++'
3637
TARGET_EXT = 'elf'
3738
SIZE = PREFIX + 'size'
3839
OBJDUMP = PREFIX + 'objdump'
@@ -52,11 +53,14 @@
5253
else:
5354
CFLAGS += ' -O2'
5455

56+
CXXFLAGS = CFLAGS
57+
5558
POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n'
5659

5760
elif PLATFORM == 'armcc':
5861
# toolchains
5962
CC = 'armcc'
63+
CXX = 'armcc'
6064
AS = 'armasm'
6165
AR = 'armar'
6266
LINK = 'armlink'
@@ -70,6 +74,7 @@
7074

7175
CFLAGS += ' -I' + EXEC_PATH + '/ARM/RV31/INC'
7276
LFLAGS += ' --libpath ' + EXEC_PATH + '/ARM/RV31/LIB'
77+
CXXFLAGS = CFLAGS
7378

7479
EXEC_PATH += '/arm/bin40/'
7580

bsp/lpc408x/rtthread-lpc408x.ld

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,25 @@ SECTIONS
3838
__vsymtab_end = .;
3939
. = ALIGN(4);
4040

41+
PROVIDE(__ctors_start__ = .);
42+
/* old GCC version uses .ctors */
43+
KEEP(*(SORT(.ctors.*)))
44+
KEEP(*(.ctors))
45+
/* new GCC version uses .init_array */
46+
KEEP (*(SORT(.init_array.*)))
47+
KEEP (*(.init_array))
48+
PROVIDE(__ctors_end__ = .);
49+
4150
. = ALIGN(4);
4251
_etext = .;
4352
} > CODE = 0
4453

54+
.ARM.extab :
55+
{
56+
*(.ARM.extab*)
57+
} > CODE
58+
59+
/* The .ARM.exidx section is used for C++ exception handling. */
4560
/* .ARM.exidx is sorted, so has to go in its own output section. */
4661
__exidx_start = .;
4762
.ARM.exidx :
@@ -57,6 +72,12 @@ SECTIONS
5772

5873
.data : AT (_sidata)
5974
{
75+
. = ALIGN(4);
76+
PROVIDE(__dtors_start__ = .);
77+
KEEP(*(SORT(.dtors.*)))
78+
KEEP(*(.dtors))
79+
PROVIDE(__dtors_end__ = .);
80+
6081
. = ALIGN(4);
6182
/* This is used by the startup in order to initialize the .data secion */
6283
_sdata = . ;
@@ -68,7 +89,7 @@ SECTIONS
6889
. = ALIGN(4);
6990
/* This is used by the startup in order to initialize the .data secion */
7091
_edata = . ;
71-
} >DATA
92+
} > DATA
7293

7394
.stack :
7495
{

components/cplusplus/README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,44 @@ Because RT-Thread RTOS is used in embedded system mostly, there are some rules f
1010
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.
1111
5. Multiple inheritance is strongly discouraged, as it can cause intolerable confusion.
1212

13-
*NOTE*: For armcc compiler, the libc must be enable.
13+
*NOTE*: The libc must be enable.
14+
15+
About GNU GCC compiler
16+
17+
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.
31+
32+
/* The .ARM.exidx section is used for C++ exception handling. */
33+
/* .ARM.exidx is sorted, so has to go in its own output section. */
34+
__exidx_start = .;
35+
.ARM.exidx :
36+
{
37+
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
38+
39+
/* This is used by the startup in order to initialize the .data secion */
40+
_sidata = .;
41+
} > CODE
42+
__exidx_end = .;
43+
44+
/* .data section which is used for initialized data */
45+
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+

components/cplusplus/SConscript

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from building import *
44

55
cwd = GetCurrentDir()
6-
src = Glob('*.cpp')
6+
src = Glob('*.cpp') + Glob('*.c')
77
CPPPATH = [cwd]
88

9-
group = DefineGroup('CPlusPlus', src, depend = ['RT_USING_CPLUSPLUS'], CPPPATH = CPPPATH)
9+
group = DefineGroup('CPlusPlus', src, depend = ['RT_USING_CPLUSPLUS', 'RT_USING_LIBC'], CPPPATH = CPPPATH)
1010

1111
Return('group')

0 commit comments

Comments
 (0)