diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b049561b2..f28101eeb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,6 +175,14 @@ if(CMAKE_C_COMPILER_ID MATCHES "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATE list(APPEND c_compile_options "-fzero-init-padding-bits=all" "-fno-malloc-dce") endif() +if(CONFIG_COMPILER_CXX_GLIBCXX_CONSTEXPR_COLD_CONSTEXPR) + list(APPEND cxx_compile_options "-D_GLIBCXX20_CONSTEXPR=__attribute__((cold)) constexpr") + list(APPEND cxx_compile_options "-D_GLIBCXX23_CONSTEXPR=__attribute__((cold)) constexpr") +elseif(CONFIG_COMPILER_CXX_GLIBCXX_CONSTEXPR_COLD) + list(APPEND cxx_compile_options "-D_GLIBCXX20_CONSTEXPR=__attribute__((cold))") + list(APPEND cxx_compile_options "-D_GLIBCXX23_CONSTEXPR=__attribute__((cold))") +endif() + __generate_prefix_map(prefix_map_compile_options) list(APPEND compile_options ${prefix_map_compile_options}) diff --git a/Kconfig b/Kconfig index ad6dc33691..f5118f9365 100644 --- a/Kconfig +++ b/Kconfig @@ -682,6 +682,34 @@ mainmenu "Espressif IoT Development Framework Configuration" help Enable compiler static analyzer. This may produce false-positive results and increases compile time. + choice COMPILER_CXX_GLIBCXX_CONSTEXPR + prompt "Define _GLIBCXX_CONSTEXPR" + default COMPILER_CXX_GLIBCXX_CONSTEXPR_NO_CHANGE + depends on IDF_TOOLCHAIN_GCC && !IDF_TARGET_LINUX + help + Modify libstdc++ _GLIBCXX20_CONSTEXPR and _GLIBCXX23_CONSTEXPR definitions to provide size + optimizations. The total size optimization depends on the application's structure. + There is no robust way to determine which option would be better in a particular case. + Please try all available options to find the best size optimization. + + config COMPILER_CXX_GLIBCXX_CONSTEXPR_NO_CHANGE + bool "No change" + help + Use default _GLIBCXX20_CONSTEXPR and _GLIBCXX23_CONSTEXPR defined in libstdc++ + + config COMPILER_CXX_GLIBCXX_CONSTEXPR_COLD_CONSTEXPR + bool "_GLIBCXX2X_CONSTEXPR=__attribute__((cold)) constexpr" + help + Define _GLIBCXX20_CONSTEXPR=__attribute__((cold)) constexpr + Define _GLIBCXX23_CONSTEXPR=__attribute__((cold)) constexpr + + config COMPILER_CXX_GLIBCXX_CONSTEXPR_COLD + bool "_GLIBCXX2X_CONSTEXPR=__attribute__((cold))" + help + Define _GLIBCXX20_CONSTEXPR=__attribute__((cold)). + Define _GLIBCXX23_CONSTEXPR=__attribute__((cold)). + endchoice + endmenu # Compiler Options menu "Component config" diff --git a/docs/en/api-guides/performance/size.rst b/docs/en/api-guides/performance/size.rst index 3ac68e8867..23c0b1e196 100644 --- a/docs/en/api-guides/performance/size.rst +++ b/docs/en/api-guides/performance/size.rst @@ -194,6 +194,11 @@ Enabling "Nano" formatting reduces the stack usage of each function that calls ` .. _Newlib README file: https://sourceware.org/newlib/README +libstdc++ +@@@@@@@@@ + +- Enable :ref:`CONFIG_COMPILER_CXX_GLIBCXX_CONSTEXPR_COLD_CONSTEXPR` or :ref:`CONFIG_COMPILER_CXX_GLIBCXX_CONSTEXPR_COLD` to observe the impact on your application's binary size. + .. _minimizing_binary_mbedtls: MbedTLS Features diff --git a/docs/zh_CN/api-guides/performance/size.rst b/docs/zh_CN/api-guides/performance/size.rst index 3e19337145..b9a0048944 100644 --- a/docs/zh_CN/api-guides/performance/size.rst +++ b/docs/zh_CN/api-guides/performance/size.rst @@ -194,6 +194,11 @@ ESP-IDF 的 I/O 函数( ``printf()`` 和 ``scanf()`` 等)默认使用 Newlib .. _Newlib README 文件: https://sourceware.org/newlib/README +libstdc++ +@@@@@@@@@ + +- 启用 :ref:`CONFIG_COMPILER_CXX_GLIBCXX_CONSTEXPR_COLD_CONSTEXPR` 或 :ref:`CONFIG_COMPILER_CXX_GLIBCXX_CONSTEXPR_COLD` 观察对应用程序二进制大小的影响。 + .. _minimizing_binary_mbedtls: MbedTLS 功能