Bug 91869

Summary: [PATCH] ralloc: atexit(3) handlers used in dlopened libraries
Product: Mesa Reporter: Jean-Sébastien Pédron <dumbbell>
Component: OtherAssignee: mesa-dev
Status: RESOLVED FIXED QA Contact: mesa-dev
Severity: normal    
Priority: medium    
Version: 10.6   
Hardware: Other   
OS: FreeBSD   
Whiteboard:
i915 platform: i915 features:
Attachments: Patch to use __attribute__((destructor)) in ralloc.c
Patch to use __attribute__((destructor)) in ralloc.c

Description Jean-Sébastien Pédron 2015-09-03 18:24:00 UTC
Created attachment 118072 [details]
Patch to use __attribute__((destructor)) in ralloc.c

Hi!

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.

__attribute__((destructor)) fixes the problem because such handlers are called when a library is unloaded and when the program exits.
Comment 1 Jean-Sébastien Pédron 2015-09-07 09:00:14 UTC
Created attachment 118120 [details] [review]
Patch to use __attribute__((destructor)) in ralloc.c

This new patch adds a test for __attribute__((destructor)) in the configure script and hides this attribute behind a "DESTRUCTOR" macro in src/util/macros.h.

This is requested by Matt Turner on the mesa-dev@ mailing-list.
Comment 2 Vedran Miletić 2017-03-22 16:32:23 UTC
atexit() no longer exists in src/util/ralloc.{c,h}

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.