Open andylinpersonal opened 1 month ago
@andylinpersonal Thanks for pointing this out! We'll take a look at this.
We need to find and discuss some implementation (of __cxa_thread_atexit_impl
, etc.), and it appears to me that we would also need to change the toolchain, so solving this problem might take a while. But we'll keep you updated here.
@andylinpersonal , for now, you can workaround it with these steps:
-fuse-cxa-atexit
into your CMakeLists.txt:
target_compile_options(${COMPONENT_LIB} PRIVATE -fuse-cxa-atexit)
extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
void *__dso_handle = 0;
After these steps I have the output:
I (285) main_task: Calling app_main()
TestTLS
foo
I (285) main_task: Returned from app_main()
~TestTLS
Done
I also tested it with multiple tasks created with xTaskCreate(test, "test", 2048, NULL, 10, NULL);
and seems all works fine.
@andylinpersonal , could you please test this fix and leave feedback?
Ok, it works now! Thanks for your suggestion @Lapshin!
IDF version.
v5.2, master
Espressif SoC revision.
ESP32-C3, ESP32-C6, ESP32-S3
Operating System used.
Linux
How did you build your project?
Command line with idf.py
Development Kit.
esp32-c6 devkit-c
What is the expected behavior?
TLS finalizers of C++
thread_local
variables seems to be missing from the current implementation of toolchain.MWE on other platform (linux,x64): https://godbolt.org/z/vfWWdh7qe
The TLS wrapper function registered the destructor of
thread_local
object to__cxa_thread_atexit
and get called aftermain
returned. But there are no such ABI function found in ESP-IDF.What is the actual behavior?
Destructor of thread local variables are not called after the task died.
Logging messages excerpted from my C6
Steps to reproduce.
More Information.
Relevant crosstool-NG config files here: RISC-V: https://github.com/espressif/crosstool-NG/blob/esp-13.2.0_20240530/samples/riscv32-esp-elf/crosstool.config ESP32-S3: https://github.com/espressif/crosstool-NG/blob/esp-13.2.0_20240530/samples/xtensa-esp32s3-elf/crosstool.config TLS finalizers in libsupc++: https://github.com/espressif/gcc/blob/esp-13.2.0_20240530/libstdc%2B%2B-v3/libsupc%2B%2B/atexit_thread.cc