Hello.
ESP32 IDF gcc linker remove "static" symbols in module, even if have "constructor" attribute.
(use "Master" branch).
I.E. , i'm built sources in project :
------------ main.c ----------------------
#include <stdio.h>
void f(void) { printf ("test\n"); }
void app_main() {}
//void main() { app_main(); }
------------------------------------------
------------ test.c ----------------------
void f(void);
static void __attribute__ ((constructor (101))) test (void) { f(); }
-------------------------------------------
methods 'f()' and 'test()' do not called.
I'm checked it at xtensa - (ESP32) and risc-v - (ESP32-C3) projects.
How to fix it?
If build this on other platforms (Windows-, linux-, arm-linux- , none-eabi- gcc ), static constructors are called.
ESP-IDF gcc static constructor
-
- Posts: 9729
- Joined: Thu Nov 26, 2015 4:08 am
Re: ESP-IDF gcc static constructor
You need to make sure the linker doesn't discard the object these functions are in; it normally does this if the objects do not contains any unresolved symbols. You can do this by defining a dummy function ('void dummy_for_inclusion() {}') in the source file, then modifying the CMakeLists.txt file like described here to mark that dummy function as an unresolved symbol.
Re: ESP-IDF gcc static constructor
Thanks.
This is strange behavior of linker.
We are need to use in this project some dozens sources from our repository.
Need to put "dummy" function with different names in each source.
This is strange behavior of linker.
We are need to use in this project some dozens sources from our repository.
Need to put "dummy" function with different names in each source.
Re: ESP-IDF gcc static constructor
If you are using the master branch, you can take advantage of the new feature in IDF build system, which instructs the linker to take the whole content of the static library without discarding unused files. Please search https://docs.espressif.com/projects/esp ... ystem.html for WHOLE_ARCHIVE for details.
There is also an example demonstrating this feature at https://github.com/espressif/esp-idf/tr ... executable
There is also an example demonstrating this feature at https://github.com/espressif/esp-idf/tr ... executable
Who is online
Users browsing this forum: No registered users and 69 guests