feat(build): add CONFIG_COMPILER_CXX_GLIBCXX_CONSTEXPR choise option

Allow to disable implicit inlining of constexpr functions from libstdc++.
This is a known GCC issue https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93008
that may affect C++ application size depending on its structure.
This commit is contained in:
Alexey Lapshin
2024-11-21 17:37:16 +07:00
parent 4c8833b6b6
commit 6d1d5ccb1c
3 changed files with 41 additions and 0 deletions

View File

@@ -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") list(APPEND c_compile_options "-fzero-init-padding-bits=all" "-fno-malloc-dce")
endif() 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) __generate_prefix_map(prefix_map_compile_options)
list(APPEND compile_options ${prefix_map_compile_options}) list(APPEND compile_options ${prefix_map_compile_options})

28
Kconfig
View File

@@ -685,6 +685,34 @@ mainmenu "Espressif IoT Development Framework Configuration"
help help
Enable compiler static analyzer. This may produce false-positive results and increases compile time. 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 endmenu # Compiler Options
menu "Component config" menu "Component config"

View File

@@ -194,6 +194,11 @@ Enabling "Nano" formatting reduces the stack usage of each function that calls `
.. _Newlib README file: https://sourceware.org/newlib/README .. _Newlib README file: https://sourceware.org/newlib/README
libstdc++
@@@@@@@@@
- Enable :ref:`CONFIG_COMPILER_CXX_GLIBCXX_CONSTEXPR_COLD_CONSTEXPR<CONFIG_COMPILER_CXX_GLIBCXX_CONSTEXPR_COLD_CONSTEXPR>` or :ref:`CONFIG_COMPILER_CXX_GLIBCXX_CONSTEXPR_COLD<CONFIG_COMPILER_CXX_GLIBCXX_CONSTEXPR_COLD>` to observe the impact on your application's binary size.
.. _minimizing_binary_mbedtls: .. _minimizing_binary_mbedtls:
MbedTLS Features MbedTLS Features