Dangerous relocation and link errors when build type is debug


I am moving from the Arduino IDE to make use of the debugger. My project builds OK if I do not have “build_type = debug” in platformio.ini. However if I do build for debugging, I get the following and get no elf file. I will also paste a copy of my platformio.ini after the error messages.

I just installed platformio and vscode so these are up to date.

Maybe there is a linker option to make it more efficient with the debug info?


Linking .pio\build\esp32dev\firmware.elf
.pio\build\esp32dev\src\DCCAnalyzer-LA.cpp.o: In function `EventTimerClass::processInterrupt()':
E:\AllDev\Trains-Arduino\DCCLogicAnalyzerWorkspace\Projects\DCC_LogicAnalyzer/src/DCCAnalyzer-LA.cpp:811:(.iram1.22[EventTimerClass::processInterrupt()]+0x1b): dangerous 
relocation: l32r: literal placed after use: .literal._ZN15EventTimerClass16processInterruptEv
E:\AllDev\Trains-Arduino\DCCLogicAnalyzerWorkspace\Projects\DCC_LogicAnalyzer/src/DCCAnalyzer-LA.cpp:811:(.iram1.22[EventTimerClass::processInterrupt()]+0x33): dangerous 
relocation: l32r: literal placed after use: .literal._ZN15EventTimerClass16processInterruptEv
E:\AllDev\Trains-Arduino\DCCLogicAnalyzerWorkspace\Projects\DCC_LogicAnalyzer/src/DCCAnalyzer-LA.cpp:811:(.iram1.22[EventTimerClass::processInterrupt()]+0x3c): dangerous 
relocation: l32r: literal placed after use: (.literal._ZN15EventTimerClass16processInterruptEv+0x4)
E:\AllDev\Trains-Arduino\DCCLogicAnalyzerWorkspace\Projects\DCC_LogicAnalyzer/src/DCCAnalyzer-LA.cpp:811:(.iram1.22[EventTimerClass::processInterrupt()]+0x4b): dangerous 
relocation: l32r: literal placed after use: .literal._ZN15EventTimerClass16processInterruptEv
E:\AllDev\Trains-Arduino\DCCLogicAnalyzerWorkspace\Projects\DCC_LogicAnalyzer/src/DCCAnalyzer-LA.cpp:811:(.iram1.22[EventTimerClass::processInterrupt()]+0x66): dangerous 
relocation: l32r: literal placed after use: .literal._ZN15EventTimerClass16processInterruptEv
E:\AllDev\Trains-Arduino\DCCLogicAnalyzerWorkspace\Projects\DCC_LogicAnalyzer/src/DCCAnalyzer-LA.cpp:811:(.iram1.22[EventTimerClass::processInterrupt()]+0x6f): dangerous 
relocation: l32r: literal placed after use: (.literal._ZN15EventTimerClass16processInterruptEv+0x8)
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\esp32dev\firmware.elf] Error 1
============================ [FAILED]


platform = espressif32
board = nodemcu-32s
debug_build_flags = -O0 -ggdb3 -g3
build_type = debug
debug_tool = esp-prog
;debug_init = break tbreak setup
framework = arduino
monitor_speed = 115200
upload_port = COM5
lib_extra_dirs = ~/Documents/Arduino/libraries

build_flags = -IC:/Users/tbvin/Documents/ArduinoData/packages/esp32/hardware/esp32/1.0.6/tools/sdk/include/soc/

It’s not good that you include your Arduino IDE’s system headers within a PlatformIO project. PlatformIO has its own Arduino-ESP32 package. You can very easily get a mismatch in versions this way. Does your project not compile without these?

Also, see https://www.reddit.com/r/esp32/comments/h7czjx/dangerous_relocation_from_xtensa_linker/fuo2svu/?utm_source=reddit&utm_medium=web2x&context=3.

Hi maxgerhatdt, Thanks for the quick response.

The code was originally written to work with the Espressif SDK which was available on the Arduino. I did not find the SDK on Platformio so I built using the ones I had. Figured that was OK since I am still using the Arduino framework. I’ll go back and make it work with the proper platformio Arduino-ESP32 package.

And after that I will move the code from the header file into a cpp and see what that does,

Thanks again, Tony

oops sorry about the misspelling in your name…

Does it work if you do -Os optimization instead of -O0? The O0 code might be so unoptimized big that you’re running in this relocation issue.

Yes it does! YAY!

Concerning those build flags, I commented them all out and it still builds. The functions that I thought needed them now point back to an Espressive file under the .platformio packages directory. During the migration there were so many things to correct that I guess I confused myself.

Thanks for the help.