diff --git a/CMakeLists.txt b/CMakeLists.txt index d21d2a38ec..be10166d5d 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 5e19164a5e..a7739d04af 100644 --- a/Kconfig +++ b/Kconfig @@ -685,6 +685,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 45e4004bc4..7cd74d538b 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