From d86ec0f3678f2147438b73462a063eaa18a35299 Mon Sep 17 00:00:00 2001 From: Anton Maklakov Date: Thu, 31 Oct 2019 10:12:16 +0700 Subject: [PATCH 1/2] Revert "C++: add provisions for optional RTTI support" This reverts commit 499d087c91141834bc41a282a592ba1d61f7b2c8. --- CMakeLists.txt | 6 ------ Kconfig | 9 --------- components/esp32/CMakeLists.txt | 5 ----- components/esp32/component.mk | 21 ++++++++------------- components/esp32/ld/esp32.discard-rtti.ld | 11 ----------- components/esp32/ld/esp32.ld | 5 ----- make/project.mk | 7 +------ tools/cmake/build.cmake | 3 ++- 8 files changed, 11 insertions(+), 56 deletions(-) delete mode 100644 components/esp32/ld/esp32.discard-rtti.ld diff --git a/CMakeLists.txt b/CMakeLists.txt index 55c9109f9..4dae14c8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,12 +27,6 @@ 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" diff --git a/Kconfig b/Kconfig index c93e3eb63..c0856669f 100644 --- a/Kconfig +++ b/Kconfig @@ -244,15 +244,6 @@ 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 diff --git a/components/esp32/CMakeLists.txt b/components/esp32/CMakeLists.txt index 06cc8f9c6..9371f570b 100644 --- a/components/esp32/CMakeLists.txt +++ b/components/esp32/CMakeLists.txt @@ -62,11 +62,6 @@ else() target_linker_script(${COMPONENT_LIB} INTERFACE "ld/esp32.extram.bss.ld") 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 # final binary target_linker_script(${COMPONENT_LIB} INTERFACE "${CMAKE_CURRENT_LIST_DIR}/ld/esp32.project.ld.in" diff --git a/components/esp32/component.mk b/components/esp32/component.mk index 836f242e2..8f999b26d 100644 --- a/components/esp32/component.mk +++ b/components/esp32/component.mk @@ -5,23 +5,18 @@ COMPONENT_SRCDIRS := . ifdef CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY - # This linker script must come before esp32.project.ld - LINKER_SCRIPTS += esp32.extram.bss.ld + # This linker script must come before esp32.project.ld + LINKER_SCRIPTS += esp32.extram.bss.ld 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. -# Warning: These linker scripts are only used when the normal app is compiled; the bootloader -# specifies its own scripts. +#Linker scripts used to link the final application. +#Warning: These linker scripts are only used when the normal app is compiled; the bootloader +#specifies its own scripts. LINKER_SCRIPTS += $(COMPONENT_BUILD_DIR)/esp32.project.ld esp32.peripherals.ld -# ld_include_panic_highint_hdl is added as an undefined symbol because otherwise the -# linker will ignore panic_highint_hdl.S as it has no other files depending on any -# symbols in it. +#ld_include_panic_highint_hdl is added as an undefined symbol because otherwise the +#linker will ignore panic_highint_hdl.S as it has no other files depending on any +#symbols in it. COMPONENT_ADD_LDFLAGS += -L $(COMPONENT_PATH)/ld \ -T esp32_out.ld \ -u ld_include_panic_highint_hdl \ diff --git a/components/esp32/ld/esp32.discard-rtti.ld b/components/esp32/ld/esp32.discard-rtti.ld deleted file mode 100644 index f9fdff994..000000000 --- a/components/esp32/ld/esp32.discard-rtti.ld +++ /dev/null @@ -1,11 +0,0 @@ -/* 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 -} diff --git a/components/esp32/ld/esp32.ld b/components/esp32/ld/esp32.ld index 167404ed3..7ecc94830 100644 --- a/components/esp32/ld/esp32.ld +++ b/components/esp32/ld/esp32.ld @@ -100,11 +100,6 @@ MEMORY /* external memory ,including data and text */ extern_ram_seg(RWX) : org = 0x3F800000, 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) diff --git a/make/project.mk b/make/project.mk index 61e80ac06..a8ec59f40 100644 --- a/make/project.mk +++ b/make/project.mk @@ -468,6 +468,7 @@ CXXFLAGS ?= EXTRA_CXXFLAGS ?= CXXFLAGS := $(strip \ -std=gnu++11 \ + -fno-rtti \ $(OPTIMIZATION_FLAGS) $(DEBUG_FLAGS) \ $(COMMON_FLAGS) \ $(COMMON_WARNING_FLAGS) \ @@ -480,12 +481,6 @@ else CXXFLAGS += -fno-exceptions endif -ifdef CONFIG_COMPILER_CXX_RTTI -CXXFLAGS += -frtti -else -CXXFLAGS += -fno-rtti -endif - ARFLAGS := cru export CFLAGS CPPFLAGS CXXFLAGS ARFLAGS diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index c3bbdeaff..f495ed8fa 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -114,7 +114,8 @@ 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") + list(APPEND cxx_compile_options "-std=gnu++11" + "-fno-rtti") idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND) idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND) From c45fdf754f51405509ce47b386d564f53f085886 Mon Sep 17 00:00:00 2001 From: Anton Maklakov Date: Thu, 31 Oct 2019 10:15:54 +0700 Subject: [PATCH 2/2] 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. --- CMakeLists.txt | 6 ++++++ Kconfig | 9 +++++++++ components/cxx/CMakeLists.txt | 4 ++++ make/project.mk | 8 +++++++- tools/cmake/build.cmake | 3 +-- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4dae14c8c..55c9109f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,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" diff --git a/Kconfig b/Kconfig index c0856669f..c93e3eb63 100644 --- a/Kconfig +++ b/Kconfig @@ -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 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 diff --git a/components/cxx/CMakeLists.txt b/components/cxx/CMakeLists.txt index ff2d0e438..852c4c884 100644 --- a/components/cxx/CMakeLists.txt +++ b/components/cxx/CMakeLists.txt @@ -15,3 +15,7 @@ target_link_libraries(${COMPONENT_LIB} PUBLIC stdcpp_pthread) 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() diff --git a/make/project.mk b/make/project.mk index a8ec59f40..93ed7a38f 100644 --- a/make/project.mk +++ b/make/project.mk @@ -468,7 +468,6 @@ CXXFLAGS ?= EXTRA_CXXFLAGS ?= CXXFLAGS := $(strip \ -std=gnu++11 \ - -fno-rtti \ $(OPTIMIZATION_FLAGS) $(DEBUG_FLAGS) \ $(COMMON_FLAGS) \ $(COMMON_WARNING_FLAGS) \ @@ -481,6 +480,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 diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index f495ed8fa..c3bbdeaff 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -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)