Merge branch 'feature/cxx_rtti_preparation_v2' into 'master'

C++: add provisions for optional RTTI support (v2)

See merge request espressif/esp-idf!6341
This commit is contained in:
Ivan Grokhotkov 2019-10-17 16:22:06 +08:00
commit e8af0f264c
8 changed files with 56 additions and 11 deletions

View file

@ -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"

View file

@ -237,6 +237,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

View file

@ -56,6 +56,11 @@ else()
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.extram.bss.ld") target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.extram.bss.ld")
endif() endif()
if(NOT CONFIG_COMPILER_CXX_RTTI)
# This has to be linked before esp32.project.ld
target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.discard-rtti.ld")
endif()
# Process the template file through the linker script generation mechanism, and use the output for linking the # Process the template file through the linker script generation mechanism, and use the output for linking the
# final binary # final binary
target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_LIST_DIR}/ld/esp32.project.ld.in" target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_LIST_DIR}/ld/esp32.project.ld.in"

View file

@ -9,6 +9,11 @@ ifdef CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
LINKER_SCRIPTS += esp32.extram.bss.ld LINKER_SCRIPTS += esp32.extram.bss.ld
endif endif
ifndef CONFIG_COMPILER_CXX_RTTI
# This linker script must come before esp32.project.ld
LINKER_SCRIPTS += esp32.discard-rtti.ld
endif
# Linker scripts used to link the final application. # Linker scripts used to link the final application.
# Warning: These linker scripts are only used when the normal app is compiled; the bootloader # Warning: These linker scripts are only used when the normal app is compiled; the bootloader
# specifies its own scripts. # specifies its own scripts.

View file

@ -0,0 +1,11 @@
/* This is only included if CONFIG_COMPILER_CXX_RTTI is not set, to
* move RTTI sections of libstdc++ to an unused non-loadable memory region.
*/
SECTIONS
{
.rodata.discard-rtti (NOLOAD):
{
*libstdc++.a:(.rodata._ZTI* .rodata._ZTS*)
} > discard_seg
}

View file

@ -98,6 +98,11 @@ MEMORY
/* external memory ,including data and text */ /* external memory ,including data and text */
extern_ram_seg(RWX) : org = 0x3F800000, extern_ram_seg(RWX) : org = 0x3F800000,
len = 0x400000 len = 0x400000
/* This is not a memory range which can really be accessed; we use it as a "bitbucket"
where non-loadable sections, which aren't used at run time, can be discarded.
*/
discard_seg (R) : org = 0x00000000, len = 0x10000000
} }
#if defined(CONFIG_ESP32_USE_FIXED_STATIC_RAM_SIZE) #if defined(CONFIG_ESP32_USE_FIXED_STATIC_RAM_SIZE)

View file

@ -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,12 @@ else
CXXFLAGS += -fno-exceptions CXXFLAGS += -fno-exceptions
endif endif
ifdef CONFIG_COMPILER_CXX_RTTI
CXXFLAGS += -frtti
else
CXXFLAGS += -fno-rtti
endif
ARFLAGS := cru ARFLAGS := cru
export CFLAGS CPPFLAGS CXXFLAGS ARFLAGS export CFLAGS CPPFLAGS CXXFLAGS ARFLAGS

View file

@ -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)