dangerous relocation: l32r: literal target out of range (try using text-section-literals)

User avatar
rudi ;-)
Posts: 1729
Joined: Fri Nov 13, 2015 3:25 pm

Re: dangerous relocation: l32r: literal target out of range (try using text-section-literals)

Postby rudi ;-) » Sun Aug 11, 2019 11:45 pm

permal wrote:
Sun Aug 11, 2019 4:53 pm
Progress!

Apparently, target_link_options doesn't do what I expect, or I'm using it wrongly.

This doesn't work:

Code: Select all

target_link_options(${PROJECT_NAME} PUBLIC -mlongcalls -mtext-section-literals)
This, however, does:

Code: Select all

if(${ESP_PLATFORM})
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mlongcalls -mtext-section-literals")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mlongcalls -mtext-section-literals")
endif()
Both the C and C++ version has to be set. Note that this is only when building for Xtensa (if you are also compiling for Linux like I am).

Surely modern CMake scripts are not meant to use CMAKE_C_FLAGS directly and instead use target_link_libraries?!

yes it was a (8266)bug i think - not sure - usually this is not happend in ESP32 again, but read yours - perhabs in ESP32 again, still, (hope ) in progress. remember me in mongosse

Code: Select all


# Flags for other component builds, including SPIFFS, go here.
CFLAGS += -Wall -Werror -mtext-section-literals \
          -DCS_SPIFFS_ENABLE_VFS -I$(MGOS_PATH) \
          -DMBEDTLS_X509_CA_CHAIN_ON_DISK \
          -DSPIFFS_ON_PAGE_MOVE_HOOK=esp_spiffs_on_page_move_hook

but there was ".text.unlikely.*"

Code: Select all

/app/src//pcmutils_lib.cpp:706:(.text.unlikely._ZL21getChannelDescription20PCM_DMX_CHANNEL_MODEPA8_KhP18AUDIO_CHANNEL_TYPEPhS5_+0x54): dangerous relocation: l32r: literal target out of range (try using text-section-literals): .literal.unlikely._ZL21getChannelDescription20PCM_DMX_CHANNEL_MODEPA8_KhP18AUDIO_CHANNEL_TYPEPhS5_
please update your progress in this and how you can go on in this.

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: dangerous relocation: l32r: literal target out of range (try using text-section-literals)

Postby ESP_Angus » Mon Aug 12, 2019 12:16 am

Hi permal,

Is there a branch in your project repo that will reproduce this linker error if I build it?

Are you sure the source files with the errors are being compiled with the -mlongcalls -mtext-section-literal flags? These flags are needed at compile time, but the error will not appear until link time (when the linker finds out that a PC-relative "short" call can't reach the target address).

Angus

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: dangerous relocation: l32r: literal target out of range (try using text-section-literals)

Postby permal » Mon Aug 12, 2019 6:39 am

@ESP_Angus They are now (and it is working), since I added the compiler flags as per the earlier post. Are these settings enabled by default in ESP-IDF? If so they are probably not propagated to my code since I build IDF as a library and link against it.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: dangerous relocation: l32r: literal target out of range (try using text-section-literals)

Postby ESP_Angus » Mon Aug 12, 2019 7:47 am

permal wrote:
Mon Aug 12, 2019 6:39 am
@ESP_Angus They are now (and it is working), since I added the compiler flags as per the earlier post.
Ah, I missed this when skimming the thread. Great!
Are these settings enabled by default in ESP-IDF? If so they are probably not propagated to my code since I build IDF as a library and link against it.
"-mlongcalls" is part of ESP-IDF standard flags. This flag is set in the toolchain file so it should propagate to all C source files even when using IDF as a library. The IDF "examples/build_system/cmake/idf_as_lib" example correctly propagates it, on both v3.3-rc and current master branch.

We don't use "-mtext-section-literals" in ESP-IDF, you only need this if the linker script doesn't allow for input literal pool sections alongside .text sections. So you can either modify your project's linker script to include '.literal' sections alongside '.text' ones (see the IDF esp32.project.ld.in file for some examples), or add this flag when compiling. The former should result in slightly smaller binaries, I think.

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: dangerous relocation: l32r: literal target out of range (try using text-section-literals)

Postby permal » Mon Aug 12, 2019 5:28 pm

Thanks for the reply, Angus.

I had a look at esp32.project.ld.in ....it's like programming language in and of itself! I'll stick to -mtext-section-literals for now.

As to why -mlongcalls doesn't propagate I don't know, will have to investigate later.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: dangerous relocation: l32r: literal target out of range (try using text-section-literals)

Postby ESP_Angus » Tue Aug 13, 2019 2:28 am

permal wrote:
Mon Aug 12, 2019 5:28 pm
I had a look at esp32.project.ld.in ....it's like programming language in and of itself! I'll stick to -mtext-section-literals for now.
Yeah, there's a lot there as this is also a linker script generator input file!

Actually the change for "literals" is not too complex, it's just that anywhere you include something like ".text.*" in the linker script, you need to include a matching ".literal.*" so that the literals from the source file/library/etc are linked nearby. Linking them nearby means that they can be loaded by the code itself.

abansal22
Posts: 105
Joined: Wed Apr 22, 2020 8:24 am

Re: dangerous relocation: l32r: literal target out of range (try using text-section-literals)

Postby abansal22 » Thu Jun 17, 2021 3:23 pm

Hello guys,

I am compiling a very large program and getting the same error of dangerous relocation.
d:/iotcode/framework/toolchain4.0/.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: D:\IOTCode\archive\client_work\afibmodel_small\build/../main/main.cpp:159092:(.text.predict_multiclass+0x10f315): dangerous relocation: l32r: literal target out of range (try using text-section-literals): (.literal.predict_multiclass+0x5f060)

Please let me know where and how to add the compiler flags in the cmakelist.txt

Who is online

Users browsing this forum: Bing [Bot] and 102 guests