espressif / esp-mdf

Espressif Mesh Development Framework, limited maintain, recommend to use https://github.com/espressif/esp-mesh-lite
Other
774 stars 253 forks source link

Building fails with certain optimization levels #190

Open DeeFuse opened 3 years ago

DeeFuse commented 3 years ago

Environment

Problem Description

Setting Optimization Level to -Os or -O0 results in linker not finding certain mdf functions (See Log)

Expected Behavior

Compilation + Linking should work as with -Og

Actual Behavior

Linking fails with undefined references

Steps to repropduce

  1. go to esp-mdf/examples/get-started
  2. idf.py menuconfig > Compiler Options > Optimization Level
  3. set to -Os and save
  4. build with idf.py build
...
-- Build files have been written to: C:/Code/ESP/esp-mdf/examples/get-started/build/bootloader
[9/13] Linking CXX executable get_started.elf
FAILED: get_started.elf
cmd.exe /C "cd . && C:\Users\admin\.espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe  -mlongcalls -Wno-frame-address   @CMakeFiles\get_started.elf.rsp  -o get_started.elf  && cd ."
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(get_started.c.obj):(.literal.root_task+0x20): undefined reference to `mdf_heap_malloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(get_started.c.obj): in function `root_task':
c:\code\esp\esp-mdf\examples\get-started\build/../main/get_started.c:25: undefined reference to `mdf_heap_malloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(get_started.c.obj): in function `node_read_task':
c:\code\esp\esp-mdf\examples\get-started\build/../main/get_started.c:47: undefined reference to `mdf_heap_malloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(get_started.c.obj): in function `node_write_task':
c:\code\esp\esp-mdf\examples\get-started\build/../main/get_started.c:76: undefined reference to `mdf_heap_malloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/mwifi/libmwifi.a(mwifi.c.obj):(.literal.mwifi_init+0x34): undefined reference to `mdf_heap_calloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/mwifi/libmwifi.a(mwifi.c.obj):(.literal.mwifi_transmit_write+0x18): undefined reference to `mdf_heap_realloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/mwifi/libmwifi.a(mwifi.c.obj): in function `mwifi_init':
C:/Code/ESP/esp-mdf/components/mwifi/mwifi.c:297: undefined reference to `mdf_heap_calloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:/Code/ESP/esp-mdf/components/mwifi/mwifi.c:301: undefined reference to `mdf_heap_calloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/mwifi/libmwifi.a(mwifi.c.obj): in function `mwifi_transmit_write':
C:/Code/ESP/esp-mdf/components/mwifi/mwifi.c:739: undefined reference to `mdf_heap_realloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:/Code/ESP/esp-mdf/components/mwifi/mwifi.c:745: undefined reference to `mdf_heap_realloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/mwifi/libmwifi.a(mwifi.c.obj): in function `mwifi_write':
C:/Code/ESP/esp-mdf/components/mwifi/mwifi.c:887: undefined reference to `mdf_heap_malloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:/Code/ESP/esp-mdf/components/mwifi/mwifi.c:907: undefined reference to `mdf_heap_malloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/mwifi/libmwifi.a(mwifi.c.obj): in function `__mwifi_read':
C:/Code/ESP/esp-mdf/components/mwifi/mwifi.c:978: undefined reference to `mdf_heap_realloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:/Code/ESP/esp-mdf/components/mwifi/mwifi.c:1034: undefined reference to `mdf_heap_realloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:/Code/ESP/esp-mdf/components/mwifi/mwifi.c:1098: undefined reference to `mdf_heap_realloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:/Code/ESP/esp-mdf/components/mwifi/mwifi.c:1118: undefined reference to `mdf_heap_realloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/mwifi/libmwifi.a(mwifi.c.obj): in function `mwifi_root_write':
C:/Code/ESP/esp-mdf/components/mwifi/mwifi.c:1185: undefined reference to `mdf_heap_malloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:/Code/ESP/esp-mdf/components/mwifi/mwifi.c:1220: undefined reference to `mdf_heap_malloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:/Code/ESP/esp-mdf/components/mwifi/mwifi.c:1247: undefined reference to `mdf_heap_malloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/mwifi/libmwifi.a(mwifi.c.obj): in function `__mwifi_root_read':
C:/Code/ESP/esp-mdf/components/mwifi/mwifi.c:1298: undefined reference to `mdf_heap_realloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:/Code/ESP/esp-mdf/components/mwifi/mwifi.c:1349: undefined reference to `mdf_heap_realloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:/Code/ESP/esp-mdf/components/mwifi/mwifi.c:1360: undefined reference to `mdf_heap_realloc'
c:/users/admin/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:/Code/ESP/esp-mdf/components/mwifi/mwifi.c:1378: undefined reference to `mdf_heap_realloc'
collect2.exe: error: ld returned 1 exit status
EspHuifeng commented 3 years ago

Hi @Dee-Fuse. You can use O2 level optimization rather than Os. I found that the inline function defined in the header file will be optimized by the compiler(v8.2.0 or v8.4.0).