From 4f5ba63c7c94b37515c2b3f3c4ae423585795d0c Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 14 Jun 2023 00:03:38 -0400 Subject: [PATCH] [cpp] attach CXXFLAGS to reduce the resource consumptions --- bsp/k210/drivers/SConscript | 2 +- components/libc/cplusplus/Kconfig | 4 ++++ components/libc/cplusplus/SConscript | 7 ++++++- components/libc/cplusplus/cpp11/gcc/__utils.h | 4 +--- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bsp/k210/drivers/SConscript b/bsp/k210/drivers/SConscript index 9d10702655..a118be7270 100644 --- a/bsp/k210/drivers/SConscript +++ b/bsp/k210/drivers/SConscript @@ -38,7 +38,7 @@ if GetDepend('RT_USING_PWM'): if GetDepend('RT_USING_WDT'): src += ['drv_wdt.c'] -group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH) +group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=['NNCASE_NO_EXCEPTIONS']) objs = [group] diff --git a/components/libc/cplusplus/Kconfig b/components/libc/cplusplus/Kconfig index e049f65629..1dcc6f389c 100644 --- a/components/libc/cplusplus/Kconfig +++ b/components/libc/cplusplus/Kconfig @@ -16,4 +16,8 @@ if RT_USING_CPLUSPLUS bool "Enable RT-Thread APIs C++ wrapper" default n + config RT_USING_CPP_EXCEPTIONS + bool "Enable C++ exceptions (will increase overhead)" + default n + endif diff --git a/components/libc/cplusplus/SConscript b/components/libc/cplusplus/SConscript index a7829cea6d..2f280892f4 100644 --- a/components/libc/cplusplus/SConscript +++ b/components/libc/cplusplus/SConscript @@ -5,8 +5,13 @@ Import('rtconfig') cwd = GetCurrentDir() src = ['cxx_crt_init.c', 'cxx_crt.cpp'] CPPPATH = [cwd] +CXXFLAGS = '' -group = DefineGroup('CPP', src, depend=['RT_USING_CPLUSPLUS'], CPPPATH=CPPPATH) + +if rtconfig.PLATFORM in ['gcc', 'armclang', 'llvm-arm'] and not GetDepend('RT_USING_CPP_EXCEPTIONS'): + CXXFLAGS += ' -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -Wl,--gc-sections' # reduce resource consumptions + +group = DefineGroup('CPP', src, depend=['RT_USING_CPLUSPLUS'], CPPPATH=CPPPATH, CXXFLAGS=CXXFLAGS) list = os.listdir(cwd) for d in list: diff --git a/components/libc/cplusplus/cpp11/gcc/__utils.h b/components/libc/cplusplus/cpp11/gcc/__utils.h index f9a3c93796..304d789ab5 100644 --- a/components/libc/cplusplus/cpp11/gcc/__utils.h +++ b/components/libc/cplusplus/cpp11/gcc/__utils.h @@ -17,11 +17,9 @@ #include -#define RT_USING_CPP_EXCEPTION - inline void throw_system_error(int err, const char *what_msg) { -#ifdef RT_USING_CPP_EXCEPTION +#ifdef RT_USING_CPP_EXCEPTIONS throw std::system_error(std::error_code(err, std::system_category()), what_msg); #else (void)err;