How to prevent linking ALL libraries in ESP-IDF for ESP32-S2?

User avatar
MickPF
Posts: 45
Joined: Tue Apr 03, 2018 8:47 pm

How to prevent linking ALL libraries in ESP-IDF for ESP32-S2?

Postby MickPF » Thu Jul 08, 2021 8:02 am

Hello,

my code contains "large" data and I get a problem when linking the binary:

Code: Select all

section `.dram0.data' will not fit in region `dram0_0_seg'
Is there any way to prevent linking libraries I never use?

For few of them it's posssible to uncheck them in "menuconfig", but for most of them it's not possible!

I use the cmake "way" for compiling.

Thanks in advance,
Michael
Nobody is perfect!
My name is NOT Nobody...


Nobody lives forever to correct his mistakes someday in the future, if not right now!
Covid-19 is not responsible for any human failures!

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: How to prevent linking ALL libraries in ESP-IDF for ESP32-S2?

Postby ESP_igrr » Thu Jul 08, 2021 10:24 am

Hi Michael,

Although ESP-IDF build system builds and links all libraries, unused modules will generally not be included into the final binary. There are a few mechanisms used to ensure this:

1. The linker will not include object files that aren't required to satisfy some reference from another object file. This means that if functions of some library are never called from the application or other libraries, the object files of this library will not be included by the linker.

2. ESP-IDF build system enables -ffunction-sections, -fdata-sections flags for the compiler and --gc-sections flag of the linker. With these flags, each function and static/global variable are placed into separate section. The linker can then gargbage-collect all the unused sections. As a result, if you are using some library, but only calling a few functions from it, other unused functions can be removed from the application during the linking process.

Regarding the issue you are facing, the overflow happens for the data segment. On the ESP32, reducing the amount of program code (located in Flash) does not make space for more data, since the code flash memory and data memory are not interchangeable. So excluding some of the libraries from your program will only free up as much space as they are using for static data. In ESP-IDF, most libraries prefer dynamic memory allocation, so there isn't a lot of space to reclaim this way.

If you have several large arrays, you may be hitting the 160kB limit of statically allocated data on the ESP32 in ESP-IDF: https://github.com/espressif/esp-idf/issues/3497. The workaround for this issue is to make these arrays dynamically allocated, please see https://github.com/espressif/esp-idf/is ... -493879020.

Edit: the limit mentioned above applies to the ESP32; I just noticed you were asking about ESP32-S2. What is the total size of large arrays you are allocating, by your estimate? Can you make the application link succeed by reducing the size of the arrays, and then use 'idf.py size' command to check static memory allocation? See more about 'idf.py size' here: https://docs.espressif.com/projects/esp ... atic-sizes

User avatar
MickPF
Posts: 45
Joined: Tue Apr 03, 2018 8:47 pm

Re: How to prevent linking ALL libraries in ESP-IDF for ESP32-S2?

Postby MickPF » Thu Jul 08, 2021 1:39 pm

I understand...

I had this problem already on the ESP32 with some large static data and solved it by using a fatfs partition on the flash and loading/copying this data first from a SD card to the flash if it is inserted. I pass through these data from the flash to an EVE display via SPI. All things worked fine.

Few days ago I "moved" the display interface from VSPI to HSPI because the SD card slot uses (hard-wired) the VSPI and I'd like to have "clean" division. Since this time NOTHING works on the SPI buses and I don't know why! The logic analyzer displays dead lines! I rolled back the changes (it's only a definition and some precompiler conditionals) but they stay DEAD! Only a LED blinks fast hard-wired to GPIO5, but I don't use this GPIO in my code!

I'm very, very angry because I don't understand what "killed" my code. And that's why I "threw" ESP32 in the trash.

Now I try the same thing with a Saola board as my first step/attempt with ESP32-S2.
Nobody is perfect!
My name is NOT Nobody...


Nobody lives forever to correct his mistakes someday in the future, if not right now!
Covid-19 is not responsible for any human failures!

User avatar
MickPF
Posts: 45
Joined: Tue Apr 03, 2018 8:47 pm

Re: How to prevent linking ALL libraries in ESP-IDF for ESP32-S2?

Postby MickPF » Thu Jul 08, 2021 1:48 pm

By the way:

Thank you for your answer!

I didn't know anything about this limit before, but I already figured it out.

Thanks
Nobody is perfect!
My name is NOT Nobody...


Nobody lives forever to correct his mistakes someday in the future, if not right now!
Covid-19 is not responsible for any human failures!

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 143 guests