Skip to content

Commit

Permalink
C++: prepare RTTI support
Browse files Browse the repository at this point in the history
Ref. #1684

Also, for full RTTI support, libstdc++.a in the toolchain should be built
in both with RTTI and w/o RTTI options. Multilib with -fno-rtti
flag is used for that.

Note that this commit does not actually enable RTTI support.
The respective Kconfig option is hidden, and will be made visible when
the toolchain is updated.
  • Loading branch information
antmak committed Oct 31, 2019
1 parent 4f297ed commit fae64f7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Expand Up @@ -22,6 +22,12 @@ else()
list(APPEND cxx_compile_options "-fno-exceptions")
endif()

if(CONFIG_COMPILER_CXX_RTTI)
list(APPEND cxx_compile_options "-frtti")
else()
list(APPEND cxx_compile_options "-fno-rtti")
endif()

if(CONFIG_COMPILER_DISABLE_GCC8_WARNINGS)
list(APPEND compile_options "-Wno-parentheses"
"-Wno-sizeof-pointer-memaccess"
Expand Down
9 changes: 9 additions & 0 deletions Kconfig
Expand Up @@ -149,6 +149,15 @@ mainmenu "Espressif IoT Development Framework Configuration"
Size (in bytes) of the emergency memory pool for C++ exceptions. This pool will be used to allocate
memory for thrown exceptions when there is not enough memory on the heap.

config COMPILER_CXX_RTTI
# Invisible option, until the toolchain with RTTI support is released.
# Use prompt "Enable C++ run-time type info (RTTI)" when updating.
bool
help
Enabling this option compiles all C++ files with RTTI support enabled.
This increases binary size (typically by tens of kB) but allows using
dynamic_cast conversion and typeid operator.

choice COMPILER_STACK_CHECK_MODE
prompt "Stack smashing protection mode"
default COMPILER_STACK_CHECK_MODE_NONE
Expand Down
4 changes: 4 additions & 0 deletions components/cxx/CMakeLists.txt
Expand Up @@ -7,3 +7,7 @@ target_link_libraries(${COMPONENT_LIB} INTERFACE "-u __cxa_guard_dummy")
if(NOT CONFIG_COMPILER_CXX_EXCEPTIONS)
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u __cxx_fatal_exception")
endif()

if(NOT CONFIG_COMPILER_CXX_RTTI)
target_link_libraries(${COMPONENT_LIB} PUBLIC -fno-rtti)
endif()
8 changes: 7 additions & 1 deletion make/project.mk
Expand Up @@ -452,7 +452,6 @@ CXXFLAGS ?=
EXTRA_CXXFLAGS ?=
CXXFLAGS := $(strip \
-std=gnu++11 \
-fno-rtti \
$(OPTIMIZATION_FLAGS) $(DEBUG_FLAGS) \
$(COMMON_FLAGS) \
$(COMMON_WARNING_FLAGS) \
Expand All @@ -465,6 +464,13 @@ else
CXXFLAGS += -fno-exceptions
endif

ifdef CONFIG_COMPILER_CXX_RTTI
CXXFLAGS += -frtti
else
CXXFLAGS += -fno-rtti
LDFLAGS += -fno-rtti
endif

ARFLAGS := cru

export CFLAGS CPPFLAGS CXXFLAGS ARFLAGS
Expand Down
3 changes: 1 addition & 2 deletions tools/cmake/build.cmake
Expand Up @@ -114,8 +114,7 @@ function(__build_set_default_build_specifications)
list(APPEND c_compile_options "-std=gnu99"
"-Wno-old-style-declaration")

list(APPEND cxx_compile_options "-std=gnu++11"
"-fno-rtti")
list(APPEND cxx_compile_options "-std=gnu++11")

idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND)
idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND)
Expand Down

0 comments on commit fae64f7

Please sign in to comment.