Page MenuHomeFreeBSD

libc: Fix dtor order in __cxa_thread_atexit
ClosedPublic

Authored by aokblast on Thu, Mar 12, 2:39 PM.

Details

Summary

The thread_local variable may creates another thread_local variable
inside its dtor. This new object is immediately be registered in
__cxa_thread_atexit() and need to be freed before processing another
variable.

This fixes the libcxx test thread_local_destruction_order.pass.cpp.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

lib/libc/stdlib/cxa_thread_atexit_impl.c
125

This is

dtor = LIST_FIRST(&dtors);

But usually it is written as

    while ((dtor = LIST_FIRST(&dtors)) != NULL) {
          LIST_REMOVE();
...
This revision is now accepted and ready to land.Thu, Mar 12, 3:02 PM

I think we need to refactor these stuff to dynamic array in the future. It makes no sense to use linked_list if we only need to push and pop from the top.

This revision was automatically updated to reflect the committed changes.