Page MenuHomeFreeBSD

cxa_thread_call_dtors(): restore limit on the number of destructors called
Needs ReviewPublic

Authored by kib on Mar 23 2026, 6:53 PM.
Tags
None
Referenced Files
F153761337: D56053.id174405.diff
Thu, Apr 23, 12:32 PM
Unknown Object (File)
Sun, Apr 19, 10:00 PM
Unknown Object (File)
Sun, Apr 19, 9:34 AM
Unknown Object (File)
Sun, Apr 19, 9:34 AM
Unknown Object (File)
Tue, Apr 14, 3:38 AM
Unknown Object (File)
Sat, Apr 11, 8:04 PM
Unknown Object (File)
Sat, Apr 11, 1:30 PM
Unknown Object (File)
Fri, Apr 10, 12:41 AM
Subscribers

Details

Summary
If the exiting thread has a destructor registered that keeps
re-registering itself, the function loops forever. Implement
approximation for the number of passes over the desctructor list as it
was done before 9d26b82826d99.  Maintain the count of destructors
registered, and break out of the loop if we called more destructors then
the memoized count times CXA_DTORS_ITERATIONS.

__cxa_thread_call_dtors(3): bump number of iterations

This allows more breezing room for somewhat weird code that registers
thread-local destructors at destruction time.  At the same time, we
still limit the amount of iterations, making this aspect of the thread
termination time-bound.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

kib edited the summary of this revision. (Show Details)
kib added reviewers: markj, emaste, aokblast.

Bump the iteration limit. Request review.

Seems ok, but I'm not sure if it's sufficient for the LLVM test case that @aokblast was looking at.

lib/libc/stdlib/cxa_thread_atexit_impl.c
129

cnt is uninitialized.

kib marked an inline comment as done.

Initialize cnt

Seems ok, but I'm not sure if it's sufficient for the LLVM test case that @aokblast was looking at.

It works on my test but a problem comes from my previous comment in D56022

ignore my incomplete comment

lib/libc/stdlib/cxa_thread_atexit_impl.c
126

Can we just