Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions / symbols defined in sketch may override framework .a #8710

Open
mcspr opened this issue Nov 6, 2022 · 2 comments
Open

Functions / symbols defined in sketch may override framework .a #8710

mcspr opened this issue Nov 6, 2022 · 2 comments
Labels
component: core help wanted Help needed from the community

Comments

@mcspr
Copy link
Collaborator

mcspr commented Nov 6, 2022

I tested the MCVE and OTA works again perfectly fine. I found the problem in my full sketch. I had a global object called crc32! The same name as the function name with problem. Sorry for bothering you and thank you @earlephilhower for your help. Closing this issue...

Originally posted by @kamran00f in #7651 (comment)

@mcspr
Copy link
Collaborator Author

mcspr commented Nov 6, 2022

Linking happens like this right now

xtensa-lx106-elf-g++ -o .pio/build/d1_mini/firmware.elf -T eagle.flash.4m1m.ld -Os -nostdlib -Wl,--no-check-sections -Wl,-static -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read -u app_entry -u _printf_float -u _scanf_float -u _DebugExceptionVector -u _DoubleExceptionVector -u _KernelExceptionVector -u _NMIExceptionVector -u _UserExceptionVector .pio/build/d1_mini/src/main.cpp.o -L.pio/build/d1_mini -L.pio/build/d1_mini/ld -L/home/runner/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/tools/sdk/lib -L/home/runner/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/tools/sdk/ld -L/home/runner/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/tools/sdk/lib/NONOSDK22x_190703 -Wl,--start-group .pio/build/d1_mini/lib2ea/libESP8266WiFi.a .pio/build/d1_mini/libb9e/libESP8266mDNS.a .pio/build/d1_mini/libc61/libArduinoOTA.a .pio/build/d1_mini/libFrameworkArduinoVariant.a .pio/build/d1_mini/libFrameworkArduino.a -lhal -lphy -lpp -lnet80211 -llwip2-536-feat -lwpa -lcrypto -lmain -lwps -lbearssl -lespnow -lsmartconfig -lairkiss -lwpa2 -lstdc++ -lm -lc -lgcc -Wl,--end-group

With a sketch c/p from the issue, lets add our own crc32 func

uint32_t crc32 (const void* data, size_t length, uint32_t crc /*= 0xffffffff*/) {
    return 0;
}

Resulting .elf has our function and not the original one, crc32 returning 0.

> xtensa-lx106-elf-gdb --batch --ex "disassemble crc32" .pio/build/d1_mini/firmware.elf
Dump of assembler code for function crc32(void const*, size_t, uint32_t):
   0x4020d0f0 <+0>:     movi.n  a2, 0
   0x4020d0f2 <+2>:     ret.n
End of assembler dump.

Moving main .o to the back of the 'library group' seems to help

/home/runner/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld: .pio/build/d1_mini/src/main.cpp.o: in function `crc32':
/home/runner/dev/arduino7651/src/main.cpp:8: multiple definition of `crc32'; .pio/build/d1_mini/libFrameworkArduino.a(crc32.cpp.o):/home/runner/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/cores/esp8266/crc32.cpp:39: first defined here
collect2: error: ld returned 1 exit status

Not sure if that has any more side-effects, or whether this feature is used by any sketches.
(iirc tasmota might override wificlient this way)

@mcspr mcspr added help wanted Help needed from the community component: core labels Nov 6, 2022
@TD-er
Copy link
Contributor

TD-er commented Nov 15, 2022

Is it possible to add a warning when a (global) function is redefined? Maybe even better to stop further compilation. I rather would have a build to fail compared to nearly impossible to find issues which may appear and disappear nearly random on new builds.
We've seen enough of those the last few years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: core help wanted Help needed from the community
Projects
None yet
Development

No branches or pull requests

2 participants