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