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

Jean-Sébastien Pédron jean-sebastien.pedron at dumbbell.fr
Mon Sep 7 02:16:22 PDT 2015


On 06.09.2015 23:40, Emil Velikov wrote:
> Hi Jean-Sébastien,

Hi!

> On 3 September 2015 at 19:07, Jean-Sébastien Pédron
> 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 ?

That's what I'm wondering too.

I didn't read the code thoroughly; my guess is that in the case of the
OpenCL ICD loader, the loader explicitely dlclose() the backend. This
must not be the case with OpenGL applications.

I can update the patch to change all uses of atexit(3) if you are ok
with it.

>> __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 ?

On one hand, my concern is this behavior is an extension to the standard
and it could break for someone else. On the other hand, I don't like the
standard behavior and would be glad to see FreeBSD implement this extension.

I still think relying on this atexit(3) extension is fragile and I don't
consider the use of the attribute a workaround.

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

You are right, I didn't think of the calling order of the destructors.

-- 
Jean-Sébastien Pédron

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 949 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150907/ab197aaf/attachment.sig>


More information about the mesa-dev mailing list