Skip to content

Commit f620175

Browse files
committed
[cpp] attach CXXFLAGS to reduce the resource consumptions
1 parent 593d794 commit f620175

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

components/libc/cplusplus/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ if RT_USING_CPLUSPLUS
1616
bool "Enable RT-Thread APIs C++ wrapper"
1717
default n
1818

19+
config RT_USING_CPP_REDUCE_OVERHEAD
20+
bool "Disable exceptions to reduce overhead"
21+
default n
22+
1923
endif

components/libc/cplusplus/SConscript

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ Import('rtconfig')
55
cwd = GetCurrentDir()
66
src = ['cxx_crt_init.c', 'cxx_crt.cpp']
77
CPPPATH = [cwd]
8+
CXXFLAGS = ''
89

9-
group = DefineGroup('CPP', src, depend=['RT_USING_CPLUSPLUS'], CPPPATH=CPPPATH)
10+
11+
12+
if GetDepend('RT_USING_CPP_REDUCE_OVERHEAD') and rtconfig.PLATFORM in ['gcc', 'armclang', 'llvm-arm']:
13+
CXXFLAGS += ' -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -Wl,--gc-sections' # reduce resource consumptions
14+
15+
group = DefineGroup('CPP', src, depend=['RT_USING_CPLUSPLUS'], CPPPATH=CPPPATH, CXXFLAGS=CXXFLAGS)
1016

1117
list = os.listdir(cwd)
1218
for d in list:

components/libc/cplusplus/cpp11/gcc/__utils.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717

1818
#include <rtthread.h>
1919

20-
#define RT_USING_CPP_EXCEPTION
21-
2220
inline void throw_system_error(int err, const char *what_msg)
2321
{
24-
#ifdef RT_USING_CPP_EXCEPTION
22+
#ifndef RT_USING_CPP_REDUCE_OVERHEAD
2523
throw std::system_error(std::error_code(err, std::system_category()), what_msg);
2624
#else
2725
(void)err;

0 commit comments

Comments
 (0)