C++: prepare RTTI support

Ref. https://github.com/espressif/esp-idf/issues/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.
pull/4345/head
Anton Maklakov 2019-10-31 10:15:54 +07:00
rodzic d86ec0f367
commit c45fdf754f
5 zmienionych plików z 27 dodań i 3 usunięć

Wyświetl plik

@ -27,6 +27,12 @@ else()
list(APPEND cxx_compile_options "-fno-exceptions") list(APPEND cxx_compile_options "-fno-exceptions")
endif() 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) if(CONFIG_COMPILER_DISABLE_GCC8_WARNINGS)
list(APPEND compile_options "-Wno-parentheses" list(APPEND compile_options "-Wno-parentheses"
"-Wno-sizeof-pointer-memaccess" "-Wno-sizeof-pointer-memaccess"

Wyświetl plik

@ -244,6 +244,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 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. 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 choice COMPILER_STACK_CHECK_MODE
prompt "Stack smashing protection mode" prompt "Stack smashing protection mode"
default COMPILER_STACK_CHECK_MODE_NONE default COMPILER_STACK_CHECK_MODE_NONE

Wyświetl plik

@ -15,3 +15,7 @@ target_link_libraries(${COMPONENT_LIB} PUBLIC stdcpp_pthread)
if(NOT CONFIG_COMPILER_CXX_EXCEPTIONS) if(NOT CONFIG_COMPILER_CXX_EXCEPTIONS)
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u __cxx_fatal_exception") target_link_libraries(${COMPONENT_LIB} INTERFACE "-u __cxx_fatal_exception")
endif() endif()
if(NOT CONFIG_COMPILER_CXX_RTTI)
target_link_libraries(${COMPONENT_LIB} PUBLIC -fno-rtti)
endif()

Wyświetl plik

@ -468,7 +468,6 @@ CXXFLAGS ?=
EXTRA_CXXFLAGS ?= EXTRA_CXXFLAGS ?=
CXXFLAGS := $(strip \ CXXFLAGS := $(strip \
-std=gnu++11 \ -std=gnu++11 \
-fno-rtti \
$(OPTIMIZATION_FLAGS) $(DEBUG_FLAGS) \ $(OPTIMIZATION_FLAGS) $(DEBUG_FLAGS) \
$(COMMON_FLAGS) \ $(COMMON_FLAGS) \
$(COMMON_WARNING_FLAGS) \ $(COMMON_WARNING_FLAGS) \
@ -481,6 +480,13 @@ else
CXXFLAGS += -fno-exceptions CXXFLAGS += -fno-exceptions
endif endif
ifdef CONFIG_COMPILER_CXX_RTTI
CXXFLAGS += -frtti
else
CXXFLAGS += -fno-rtti
LDFLAGS += -fno-rtti
endif
ARFLAGS := cru ARFLAGS := cru
export CFLAGS CPPFLAGS CXXFLAGS ARFLAGS export CFLAGS CPPFLAGS CXXFLAGS ARFLAGS

Wyświetl plik

@ -114,8 +114,7 @@ function(__build_set_default_build_specifications)
list(APPEND c_compile_options "-std=gnu99" list(APPEND c_compile_options "-std=gnu99"
"-Wno-old-style-declaration") "-Wno-old-style-declaration")
list(APPEND cxx_compile_options "-std=gnu++11" list(APPEND cxx_compile_options "-std=gnu++11")
"-fno-rtti")
idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND) idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND)
idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND) idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND)