From b354c11db78403a68990ad653902edebf1587263 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 14 Mar 2019 09:59:31 +1100 Subject: [PATCH] esp32: Rename esp32.common.ld to esp32.project.ld to avoid build errors when downgrading Linker script generator produces build/esp32/esp32.common.ld from components/esp32/ld/esp32.common.ld.in This works fine until IDF is downgraded to V3.1 which uses components/esp32/ld/esp32.common.ld and doesn't track build/esp32/esp32.common.ld at all. At this point, the linker runs in the build/esp32 directory and "-T esp32.common.ld" picks up the linker script generated .ld file, which causes mis-builds. As reported on forums: https://esp32.com/viewtopic.php?f=13&t=9684&p=40105 --- components/esp32/CMakeLists.txt | 14 +++++++------- components/esp32/Makefile.projbuild | 4 ++-- components/esp32/component.mk | 10 +++++----- components/esp32/ld/esp32.ld | 2 +- .../ld/{esp32.common.ld.in => esp32.project.ld.in} | 0 docs/en/api-guides/linker-script-generation.rst | 2 +- docs/zh_CN/api-guides/linker-script-generation.rst | 2 +- tools/ci/test_build_system.sh | 2 +- tools/ci/test_build_system_cmake.sh | 6 +++--- 9 files changed, 21 insertions(+), 21 deletions(-) rename components/esp32/ld/{esp32.common.ld.in => esp32.project.ld.in} (100%) diff --git a/components/esp32/CMakeLists.txt b/components/esp32/CMakeLists.txt index 4e9740a40..dbacc35a7 100644 --- a/components/esp32/CMakeLists.txt +++ b/components/esp32/CMakeLists.txt @@ -72,21 +72,21 @@ else() target_linker_script(${COMPONENT_TARGET} "${CMAKE_CURRENT_BINARY_DIR}/esp32_out.ld") if(CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY) - # This has to be linked before esp32.common.ld + # This has to be linked before esp32.project.ld target_linker_script(${COMPONENT_TARGET} "ld/esp32.extram.bss.ld") endif() if(IDF_PROJECT_EXECUTABLE) # Process the template file through the linker script generation mechanism, and use the output for linking the # final binary - set(esp32_common_script "${CMAKE_CURRENT_BINARY_DIR}/esp32.common.ld") - set(esp32_common_template "${CMAKE_CURRENT_LIST_DIR}/ld/esp32.common.ld.in") + set(esp32_project_script "${CMAKE_CURRENT_BINARY_DIR}/esp32.project.ld") + set(esp32_project_template "${CMAKE_CURRENT_LIST_DIR}/ld/esp32.project.ld.in") - ldgen_process_template(${esp32_common_template} ${esp32_common_script}) + ldgen_process_template(${esp32_project_template} ${esp32_project_script}) - target_link_libraries(${COMPONENT_TARGET} "-T ${esp32_common_script}") - - set_property(TARGET ${IDF_PROJECT_EXECUTABLE} APPEND PROPERTY LINK_DEPENDS ${esp32_common_script}) + target_link_libraries(${COMPONENT_TARGET} "-T ${esp32_project_script}") + + set_property(TARGET ${IDF_PROJECT_EXECUTABLE} APPEND PROPERTY LINK_DEPENDS ${esp32_project_script}) endif() target_linker_script(${COMPONENT_TARGET} diff --git a/components/esp32/Makefile.projbuild b/components/esp32/Makefile.projbuild index 5f819ae8a..b99415538 100644 --- a/components/esp32/Makefile.projbuild +++ b/components/esp32/Makefile.projbuild @@ -42,9 +42,9 @@ endif ifneq ("$(filter esp32,$(TEST_COMPONENTS_LIST))","") CPPFLAGS += -DESP_TIMER_DYNAMIC_OVERFLOW_VAL endif -ESP32_LINKER_SCRIPT_TEMPLATE := $(COMPONENT_PATH)/ld/esp32.common.ld.in +ESP32_LINKER_SCRIPT_TEMPLATE := $(COMPONENT_PATH)/ld/esp32.project.ld.in ESP32_LINKER_SCRIPT_OUTPUT_DIR := $(abspath $(BUILD_DIR_BASE)/esp32) # Target to generate linker script generator from fragments presented by each of # the components -$(eval $(call ldgen_process_template, $(ESP32_LINKER_SCRIPT_TEMPLATE), $(ESP32_LINKER_SCRIPT_OUTPUT_DIR)/esp32.common.ld)) +$(eval $(call ldgen_process_template, $(ESP32_LINKER_SCRIPT_TEMPLATE), $(ESP32_LINKER_SCRIPT_OUTPUT_DIR)/esp32.project.ld)) diff --git a/components/esp32/component.mk b/components/esp32/component.mk index 54d4a2a5c..21d8ce6bc 100644 --- a/components/esp32/component.mk +++ b/components/esp32/component.mk @@ -9,14 +9,14 @@ LIBS += core rtc net80211 pp wpa smartconfig coexist wps wpa2 espnow phy mesh endif ifdef CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY - # This linker script must come before esp32.common.ld + # This linker script must come before esp32.project.ld LINKER_SCRIPTS += esp32.extram.bss.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 += $(COMPONENT_BUILD_DIR)/esp32.common.ld esp32.rom.ld esp32.peripherals.ld +LINKER_SCRIPTS += $(COMPONENT_BUILD_DIR)/esp32.project.ld esp32.rom.ld esp32.peripherals.ld #Force pure functions from libgcc.a to be linked from ROM LINKER_SCRIPTS += esp32.rom.libgcc.ld @@ -55,8 +55,8 @@ COMPONENT_SUBMODULES += lib # final linking of project ELF depends on all binary libraries, and # all linker scripts (except esp32_out.ld, as this is code generated here.) COMPONENT_ADD_LINKER_DEPS := $(ALL_LIB_FILES) \ - $(addprefix ld/, $(filter-out $(COMPONENT_BUILD_DIR)/esp32.common.ld, $(LINKER_SCRIPTS))) \ - $(COMPONENT_BUILD_DIR)/esp32.common.ld + $(addprefix ld/, $(filter-out $(COMPONENT_BUILD_DIR)/esp32.project.ld, $(LINKER_SCRIPTS))) \ + $(COMPONENT_BUILD_DIR)/esp32.project.ld # Preprocess esp32.ld linker script into esp32_out.ld # @@ -67,7 +67,7 @@ $(COMPONENT_LIBRARY): esp32_out.ld esp32_out.ld: $(COMPONENT_PATH)/ld/esp32.ld ../include/sdkconfig.h $(CC) -I ../include -C -P -x c -E $< -o $@ -COMPONENT_EXTRA_CLEAN := esp32_out.ld $(COMPONENT_BUILD_DIR)/esp32.common.ld +COMPONENT_EXTRA_CLEAN := esp32_out.ld $(COMPONENT_BUILD_DIR)/esp32.project.ld # disable stack protection in files which are involved in initialization of that feature stack_check.o: CFLAGS := $(filter-out -fstack-protector%, $(CFLAGS)) diff --git a/components/esp32/ld/esp32.ld b/components/esp32/ld/esp32.ld index fd02e0d21..11873b9d3 100644 --- a/components/esp32/ld/esp32.ld +++ b/components/esp32/ld/esp32.ld @@ -3,7 +3,7 @@ This file describes the memory layout (memory blocks) as virtual memory addresses. - esp32.common.ld contains output sections to link compiler output + esp32.project.ld contains output sections to link compiler output into these memory blocks. *** diff --git a/components/esp32/ld/esp32.common.ld.in b/components/esp32/ld/esp32.project.ld.in similarity index 100% rename from components/esp32/ld/esp32.common.ld.in rename to components/esp32/ld/esp32.project.ld.in diff --git a/docs/en/api-guides/linker-script-generation.rst b/docs/en/api-guides/linker-script-generation.rst index aa2407791..4c0347036 100644 --- a/docs/en/api-guides/linker-script-generation.rst +++ b/docs/en/api-guides/linker-script-generation.rst @@ -539,7 +539,7 @@ lives under ``$(IDF_PATH)/tools/ldgen``. Linker Script Template ^^^^^^^^^^^^^^^^^^^^^^ -Currently, the linker script template used is :component:`esp32/ld/esp32.common.ld.in`, and is used only for the app build. The generated output script is +Currently, the linker script template used is :component:`esp32/ld/esp32.project.ld.in`, and is used only for the app build. The generated output script is put under the build directory of the same component. Modifying this linker script template triggers a re-link of the app binary. Linker Fragment File diff --git a/docs/zh_CN/api-guides/linker-script-generation.rst b/docs/zh_CN/api-guides/linker-script-generation.rst index 33a3527d5..9e47f7044 100644 --- a/docs/zh_CN/api-guides/linker-script-generation.rst +++ b/docs/zh_CN/api-guides/linker-script-generation.rst @@ -491,7 +491,7 @@ mapping 片段的映射条目共有三种类型,分别为: 链接脚本模板 ^^^^^^^^^^^^ -目前使用的链接脚本模板是 :component:`esp32/ld/esp32.common.ld.in`,仅用于应用程序的构建,生成的链接脚本文件将放在同一组件的构建目录下。值得注意的是,修改此链接描述文件模板会触发应用程序的二进制文件的重新链接。 +目前使用的链接脚本模板是 :component:`esp32/ld/esp32.project.ld.in`,仅用于应用程序的构建,生成的链接脚本文件将放在同一组件的构建目录下。值得注意的是,修改此链接描述文件模板会触发应用程序的二进制文件的重新链接。 链接片段文件 ^^^^^^^^^^^^ diff --git a/tools/ci/test_build_system.sh b/tools/ci/test_build_system.sh index 0915f2376..ee8e70bd5 100755 --- a/tools/ci/test_build_system.sh +++ b/tools/ci/test_build_system.sh @@ -159,7 +159,7 @@ function run_tests() print_status "Touching app-only template ld file should only re-link app" take_build_snapshot - touch ${IDF_PATH}/components/esp32/ld/esp32.common.ld.in + touch ${IDF_PATH}/components/esp32/ld/esp32.project.ld.in make assert_rebuilt ${APP_BINS} assert_not_rebuilt ${BOOTLOADER_BINS} diff --git a/tools/ci/test_build_system_cmake.sh b/tools/ci/test_build_system_cmake.sh index ae6bbd5ba..75fb523c4 100755 --- a/tools/ci/test_build_system_cmake.sh +++ b/tools/ci/test_build_system_cmake.sh @@ -178,13 +178,13 @@ function run_tests() print_status "Updating app-only ld file should only re-link app" take_build_snapshot - cp ${IDF_PATH}/components/esp32/ld/esp32.common.ld.in . + cp ${IDF_PATH}/components/esp32/ld/esp32.project.ld.in . sleep 1 # ninja may ignore if the timestamp delta is too low - echo "/* (Build test comment) */" >> ${IDF_PATH}/components/esp32/ld/esp32.common.ld.in + echo "/* (Build test comment) */" >> ${IDF_PATH}/components/esp32/ld/esp32.project.ld.in idf.py build || failure "Failed to rebuild with modified linker script" assert_rebuilt ${APP_BINS} assert_not_rebuilt ${BOOTLOADER_BINS} - mv esp32.common.ld.in ${IDF_PATH}/components/esp32/ld/ + mv esp32.project.ld.in ${IDF_PATH}/components/esp32/ld/ print_status "Updating fragment file should only re-link app" # only app linker script is generated by tool for now take_build_snapshot