[libc-commits] [libc] [libc] Provide empty definitions for `teardown_main_tls` symbols (PR #173412)

Roland McGrath via libc-commits libc-commits at lists.llvm.org
Tue Dec 23 12:38:05 PST 2025


================
@@ -16,7 +16,7 @@ namespace LIBC_NAMESPACE_DECL {
 
 constinit ExitCallbackList atexit_callbacks;
 Mutex handler_list_mtx(false, false, false, false);
-[[gnu::weak]] extern void teardown_main_tls();
+[[gnu::weak]] void teardown_main_tls() {}
----------------
frobtech wrote:

This (and any use of `weak`) merits a clear comment about what's going on here.  
It should explain that the weak no-op is in the same TU with its caller for the case
where the real definition is not linked in.  In particular, why it's OK to omit what it does when that specific TU is not linked in for other reasons, and what reasons would cause it to be linked in and thus have its strong definition take precedence.  In this case it's also important to note in both `atexit.cpp` and `quick_exit.cpp` that each is doing its own weak no-op definition and why.

Since this is the first to set the example, we should also have a clear comment about the choice of weak no-op definition vs weak undefined with check.  That's probably something we should write more formally into the libc style guide as a generic rule and rationale.

It's not entirely clear to me what the intended weak no-op scenario is for this particular one.  The symbol is defined in libc's startup code, which will always be present in the statically-linked executable scenarios that I think are the only cases actually supported today.

https://github.com/llvm/llvm-project/pull/173412


More information about the libc-commits mailing list