Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 23 Jan 2022 21:37:41 +0100
From: Florian Weimer <>
To: Sebastian Huber <>
Subject: Re: Constructors/destructors for thread-local objects?

* Sebastian Huber:

> I would like to add something similar to the .init_array and
> .fini_array at least for Newlib.  Would .tls_init_array and
> .tls_fini_array good names?

You need to allocate ELF section types and dynamic tags, too.  This
probably should make it to the ELF generic ABI.  The names only matter
for static linking (which is probably the case you are interested in).

> extern void (*__tls_init_array_start []) (void);
> extern void (*__tls_init_array_end []) (void);
> extern void (*__tls_fini_array_start []) (void);
> extern void (*__tls_fini_array_end []) (void);
> Do we need .tls_preinit_array?

I thought a bit about this, and the semantics of per-thread initializers
are really fuzzy when it comes to dlopen: What do you do for the
existing other threads in that case?  I really do not see there is a
clean way to support per-thread initializers in the presence of dlopen.

Destructors do not have this issue.

> It is unlikely that another C library will use this, but anyway, I
> would like to use some names which could be used elsewhere as well.

I'm interested in this for glibc as well (well, the destructor part).
__cxa_thread_atexit has to allocate, but has no way to report allocation
failure, so it just crashes the process.  Registration for global
destructors has the same problem, but presumably dlopen is a bit rarer
than thread creation.

The destructors should probably take an iteration count as argument, and
a return value that's non-zero if any action was taken by the
destructor.  I think this is needed because it is not always possible to
destruct per-thread resources in a single pass.  For example, a logger
handle could be brought back to life if another destructor needs to log
something.  The C library would keep running all destructors until all
of them signal that no work was left to do anymore.


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.