在尝试使用 esp-idf 工具链将 punyforth 从 esp8266 移植到 esp32 时,我遇到了一个让我很头疼的链接器问题。
如果不使用任何特殊的链接器标志,我会遇到如下错误:
.
.
.
/Users/k/.espressif/tools/xtensa-esp32-elf/esp-2020r1-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld: /Users/k/esp/esp-idf/examples/punyforth/arch/esp8266/rtos/user/main/punyforth.S:22:(.irom0.text+0x1237): dangerous relocation: l32r: literal placed after use: (.irom0.literal+0xc)
/Users/k/.espressif/tools/xtensa-esp32-elf/esp-2020r1-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld: /Users/k/esp/esp-idf/examples/punyforth/arch/esp8266/rtos/user/main/punyforth.S:24:(.irom0.text+0x123a): dangerous relocation: l32r: literal placed after use: (.irom0.literal+0x10)
/Users/k/.espressif/tools/xtensa-esp32-elf/esp-2020r1-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld: /Users/k/esp/esp-idf/examples/punyforth/arch/esp8266/rtos/user/main/punyforth.S:27:(.irom0.text+0x123f): dangerous relocation: l32r: literal placed after use: (.irom0.literal+0x14)
/Users/k/.espressif/tools/xtensa-esp32-elf/esp-2020r1-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld: /Users/k/esp/esp-idf/examples/punyforth/arch/esp8266/rtos/user/build/main/libmain.a(punyforth.o): in function `code_divmod':
/Users/k/esp/esp-idf/examples/punyforth/arch/esp8266/rtos/user/main/../../../primitives.S:121:(.irom0.text+0xcd): dangerous relocation: call0: call target out of range: forth_divmod
/Users/k/.espressif/tools/xtensa-esp32-elf/esp-2020r1-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld: /Users/k/esp/esp-idf/examples/punyforth/arch/esp8266/rtos/user/build/main/libmain.a(punyforth.o): in function `code_random':
/Users/k/esp/esp-idf/examples/punyforth/arch/esp8266/rtos/user/main/../../../ext.S:388:(.irom0.text+0xb75): dangerous relocation: call0: call target out of range: forth_random
/Users/k/.espressif/tools/xtensa-esp32-elf/esp-2020r1-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld: /Users/k/esp/esp-idf/examples/punyforth/arch/esp8266/rtos/user/build/main/libmain.a(punyforth.o): in function `code_usat':
/Users/k/esp/esp-idf/examples/punyforth/arch/esp8266/rtos/user/main/../../../ext.S:525:(.irom0.text+0xf85): dangerous relocation: call0: call target out of range: esp_timer_get_time
如果我设置(如在此处和其他地方推荐)
LDFLAGS += -mtext-section-literals
,那么我会得到 undefined main 像这样:
/Users/k/.espressif/tools/xtensa-esp32-elf/esp-2020r1-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld: /Users/k/.espressif/tools/xtensa-esp32-elf/esp-2020r1-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/lib/no-rtti/crt0.o:(.literal+0x0): undefined reference to `main'
关于 esp-idf 工具链,我是一个完全的菜鸟,所以我几乎被卡住了。关于如何解决这个问题的任何指示都会很棒。