Skip to content

Destructors of C++11 thread_local object are not called after task returned (IDFGH-13456) #14360

@andylinpersonal

Description

@andylinpersonal

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

TestTLS
foo
~TestTLS

The TLS wrapper function registered the destructor of thread_local object to __cxa_thread_atexit and get called after main 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

I (80) sleep: Configure to isolate all GPIO pins in sleep state
I (81) sleep: Enable automatic switching of GPIO sleep configuration
I (81) coexist: coex firmware version: 8da3f50af
I (82) coexist: coexist rom version 5b8dcfa
I (82) main_task: Started on CPU0
I (82) main_task: Calling app_main()
TestTLS
test
I (82) main_task: Returned from app_main()

Steps to reproduce.

  1. Build the aforementioned code https://godbolt.org/z/vfWWdh7qe.
  2. See the output and disassembled code.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions