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
This commit is contained in:
parent
eed94b87e2
commit
b354c11db7
|
@ -72,21 +72,21 @@ else()
|
||||||
target_linker_script(${COMPONENT_TARGET} "${CMAKE_CURRENT_BINARY_DIR}/esp32_out.ld")
|
target_linker_script(${COMPONENT_TARGET} "${CMAKE_CURRENT_BINARY_DIR}/esp32_out.ld")
|
||||||
|
|
||||||
if(CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY)
|
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")
|
target_linker_script(${COMPONENT_TARGET} "ld/esp32.extram.bss.ld")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(IDF_PROJECT_EXECUTABLE)
|
if(IDF_PROJECT_EXECUTABLE)
|
||||||
# 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
|
||||||
set(esp32_common_script "${CMAKE_CURRENT_BINARY_DIR}/esp32.common.ld")
|
set(esp32_project_script "${CMAKE_CURRENT_BINARY_DIR}/esp32.project.ld")
|
||||||
set(esp32_common_template "${CMAKE_CURRENT_LIST_DIR}/ld/esp32.common.ld.in")
|
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}")
|
target_link_libraries(${COMPONENT_TARGET} "-T ${esp32_project_script}")
|
||||||
|
|
||||||
set_property(TARGET ${IDF_PROJECT_EXECUTABLE} APPEND PROPERTY LINK_DEPENDS ${esp32_common_script})
|
set_property(TARGET ${IDF_PROJECT_EXECUTABLE} APPEND PROPERTY LINK_DEPENDS ${esp32_project_script})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_linker_script(${COMPONENT_TARGET}
|
target_linker_script(${COMPONENT_TARGET}
|
||||||
|
|
|
@ -42,9 +42,9 @@ endif
|
||||||
ifneq ("$(filter esp32,$(TEST_COMPONENTS_LIST))","")
|
ifneq ("$(filter esp32,$(TEST_COMPONENTS_LIST))","")
|
||||||
CPPFLAGS += -DESP_TIMER_DYNAMIC_OVERFLOW_VAL
|
CPPFLAGS += -DESP_TIMER_DYNAMIC_OVERFLOW_VAL
|
||||||
endif
|
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)
|
ESP32_LINKER_SCRIPT_OUTPUT_DIR := $(abspath $(BUILD_DIR_BASE)/esp32)
|
||||||
|
|
||||||
# Target to generate linker script generator from fragments presented by each of
|
# Target to generate linker script generator from fragments presented by each of
|
||||||
# the components
|
# 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))
|
||||||
|
|
|
@ -9,14 +9,14 @@ LIBS += core rtc net80211 pp wpa smartconfig coexist wps wpa2 espnow phy mesh
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
|
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
|
LINKER_SCRIPTS += esp32.extram.bss.ld
|
||||||
endif
|
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.
|
||||||
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
|
#Force pure functions from libgcc.a to be linked from ROM
|
||||||
LINKER_SCRIPTS += esp32.rom.libgcc.ld
|
LINKER_SCRIPTS += esp32.rom.libgcc.ld
|
||||||
|
@ -55,8 +55,8 @@ COMPONENT_SUBMODULES += lib
|
||||||
# final linking of project ELF depends on all binary libraries, and
|
# final linking of project ELF depends on all binary libraries, and
|
||||||
# all linker scripts (except esp32_out.ld, as this is code generated here.)
|
# all linker scripts (except esp32_out.ld, as this is code generated here.)
|
||||||
COMPONENT_ADD_LINKER_DEPS := $(ALL_LIB_FILES) \
|
COMPONENT_ADD_LINKER_DEPS := $(ALL_LIB_FILES) \
|
||||||
$(addprefix ld/, $(filter-out $(COMPONENT_BUILD_DIR)/esp32.common.ld, $(LINKER_SCRIPTS))) \
|
$(addprefix ld/, $(filter-out $(COMPONENT_BUILD_DIR)/esp32.project.ld, $(LINKER_SCRIPTS))) \
|
||||||
$(COMPONENT_BUILD_DIR)/esp32.common.ld
|
$(COMPONENT_BUILD_DIR)/esp32.project.ld
|
||||||
|
|
||||||
# Preprocess esp32.ld linker script into esp32_out.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
|
esp32_out.ld: $(COMPONENT_PATH)/ld/esp32.ld ../include/sdkconfig.h
|
||||||
$(CC) -I ../include -C -P -x c -E $< -o $@
|
$(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
|
# disable stack protection in files which are involved in initialization of that feature
|
||||||
stack_check.o: CFLAGS := $(filter-out -fstack-protector%, $(CFLAGS))
|
stack_check.o: CFLAGS := $(filter-out -fstack-protector%, $(CFLAGS))
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
This file describes the memory layout (memory blocks) as virtual
|
This file describes the memory layout (memory blocks) as virtual
|
||||||
memory addresses.
|
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.
|
into these memory blocks.
|
||||||
|
|
||||||
***
|
***
|
||||||
|
|
|
@ -539,7 +539,7 @@ lives under ``$(IDF_PATH)/tools/ldgen``.
|
||||||
|
|
||||||
Linker Script Template
|
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.
|
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
|
Linker Fragment File
|
||||||
|
|
|
@ -491,7 +491,7 @@ mapping 片段的映射条目共有三种类型,分别为:
|
||||||
|
|
||||||
链接脚本模板
|
链接脚本模板
|
||||||
^^^^^^^^^^^^
|
^^^^^^^^^^^^
|
||||||
目前使用的链接脚本模板是 :component:`esp32/ld/esp32.common.ld.in`,仅用于应用程序的构建,生成的链接脚本文件将放在同一组件的构建目录下。值得注意的是,修改此链接描述文件模板会触发应用程序的二进制文件的重新链接。
|
目前使用的链接脚本模板是 :component:`esp32/ld/esp32.project.ld.in`,仅用于应用程序的构建,生成的链接脚本文件将放在同一组件的构建目录下。值得注意的是,修改此链接描述文件模板会触发应用程序的二进制文件的重新链接。
|
||||||
|
|
||||||
链接片段文件
|
链接片段文件
|
||||||
^^^^^^^^^^^^
|
^^^^^^^^^^^^
|
||||||
|
|
|
@ -159,7 +159,7 @@ function run_tests()
|
||||||
|
|
||||||
print_status "Touching app-only template ld file should only re-link app"
|
print_status "Touching app-only template ld file should only re-link app"
|
||||||
take_build_snapshot
|
take_build_snapshot
|
||||||
touch ${IDF_PATH}/components/esp32/ld/esp32.common.ld.in
|
touch ${IDF_PATH}/components/esp32/ld/esp32.project.ld.in
|
||||||
make
|
make
|
||||||
assert_rebuilt ${APP_BINS}
|
assert_rebuilt ${APP_BINS}
|
||||||
assert_not_rebuilt ${BOOTLOADER_BINS}
|
assert_not_rebuilt ${BOOTLOADER_BINS}
|
||||||
|
|
|
@ -178,13 +178,13 @@ function run_tests()
|
||||||
|
|
||||||
print_status "Updating app-only ld file should only re-link app"
|
print_status "Updating app-only ld file should only re-link app"
|
||||||
take_build_snapshot
|
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
|
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"
|
idf.py build || failure "Failed to rebuild with modified linker script"
|
||||||
assert_rebuilt ${APP_BINS}
|
assert_rebuilt ${APP_BINS}
|
||||||
assert_not_rebuilt ${BOOTLOADER_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
|
print_status "Updating fragment file should only re-link app" # only app linker script is generated by tool for now
|
||||||
take_build_snapshot
|
take_build_snapshot
|
||||||
|
|
Loading…
Reference in a new issue