From afeed3cc6f79c167aae52f5903bc8ceebced5f06 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 20 Nov 2019 14:18:28 +0100 Subject: [PATCH 1/2] build system: explicitly disable LTO plugin ... to reduce the number of simultaneously open files at link time. When plugin support is enabled in the linker, BFD's (and the corresponding file handles) are cached for the plugin to use. This results in quite a large number of simultaneously open files, which hits the default limit on macOS (256 files). Since we aren't using LTO now, disable it explicitly when invoking the linker. Closes IDF-923 Closes IDFGH-1764 Closes https://github.com/espressif/esp-idf/issues/3989 --- CMakeLists.txt | 3 +++ tools/cmake/build.cmake | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b7022c17..e47cf5f81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ unset(compile_options) unset(c_compile_options) unset(cxx_compile_options) unset(compile_definitions) +unset(link_options) # Add the following build specifications here, since these seem to be dependent # on config values on the root Kconfig. @@ -60,11 +61,13 @@ elseif(CONFIG_COMPILER_STACK_CHECK_MODE_ALL) list(APPEND compile_options "-fstack-protector-all") endif() +list(APPEND link_options "-fno-lto") idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND) idf_build_set_property(C_COMPILE_OPTIONS "${c_compile_options}" APPEND) idf_build_set_property(CXX_COMPILE_OPTIONS "${cxx_compile_options}" APPEND) idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND) +idf_build_set_property(LINK_OPTIONS "${link_options}" APPEND) idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS) diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index c3bbdeaff..bbd4d16fe 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -469,6 +469,11 @@ endmacro() # files used for linking, targets which should execute before creating the specified executable, # generating additional binary files, generating files related to flashing, etc.) function(idf_build_executable elf) + # Set additional link flags for the executable + idf_build_get_property(link_options LINK_OPTIONS) + # Using LINK_LIBRARIES here instead of LINK_OPTIONS, as the latter is not in CMake 3.5. + set_property(TARGET ${elf} APPEND PROPERTY LINK_LIBRARIES "${link_options}") + # Propagate link dependencies from component library targets to the executable idf_build_get_property(link_depends __LINK_DEPENDS) set_property(TARGET ${elf} APPEND PROPERTY LINK_DEPENDS "${link_depends}") From 14f1a30e389a42ae11480ab4278b19d01e63f9ab Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Thu, 21 Nov 2019 10:41:34 +0100 Subject: [PATCH 2/2] build system: move -fno-rtti link option next to the compile option Previous commit has added `link_options` to the root CMakeLists.txt, can use it to collect such global link options now. --- CMakeLists.txt | 1 + components/cxx/CMakeLists.txt | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e47cf5f81..f87020b52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ if(CONFIG_COMPILER_CXX_RTTI) list(APPEND cxx_compile_options "-frtti") else() list(APPEND cxx_compile_options "-fno-rtti") + list(APPEND link_options "-fno-rtti") # used to invoke correct multilib variant (no-rtti) during linking endif() if(CONFIG_COMPILER_DISABLE_GCC8_WARNINGS) diff --git a/components/cxx/CMakeLists.txt b/components/cxx/CMakeLists.txt index 852c4c884..ff2d0e438 100644 --- a/components/cxx/CMakeLists.txt +++ b/components/cxx/CMakeLists.txt @@ -15,7 +15,3 @@ 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()