[Mesa-stable] [PATCH] ralloc: Use __attribute__((destructor)) instead of atexit(3)

Emil Velikov emil.l.velikov at gmail.com
Sun Sep 6 14:40:08 PDT 2015


Hi Jean-Sébastien,

On 3 September 2015 at 19:07, Jean-Sébastien Pédron
<jean-sebastien.pedron at dumbbell.fr> wrote:
> ... to free the ralloc context at program exit.
>
> On Linux, atexit(3) handlers are called when the program exits but also
> when a library is unloaded. The latter behavior is a Glibc extension.
>
> On systems where this extension is not supported, this causes an
> application to crash when, for instance, a library using ralloc is
> dlclosed: at program exit, the registered function is no longer in
> memory. For example, this happens with OpenCL applications using an ICD
> loader on FreeBSD.
>
We have 4(5) users of atexit() - EGL, gallium trace driver, core mesa
and util/ralloc. The latter of which is used almost everywhere in
mesa. So a bit I'm confused how you hit this only with OpenCL :-\
Perhaps the others should be updated as well ?

> __attribute__((destructor)) fixes the problem because such handlers are
> called when a library is unloaded and when the program exits.
Considering that atexit() (reportedly) works for Linux/Glibc, Solaris,
Android and Windows perhaps we should consider this as a workaround
for FreeBSD (and other *BSD) systems ?

Considering the multiple users (mentioned above) should one set
priority for the destructors ?

Cheers,
Emil


More information about the mesa-stable mailing list