managarm / mlibc

Portable C standard library
Other
827 stars 126 forks source link

options/rtld: Call fini functions on exit #1092

Open Qwinci opened 2 months ago

Qwinci commented 2 months ago

This is needed to support functions marked with attribute gnu::destructor. ~The way I implemented it it destructs the objects in reverse order that they were initialized in and first runs functions registered with __cxa_atexit for the object and after that the fini functions for that object, I am not sure if that's completely correct but to me it seems reasonable enough so in case of an object that doesn't have any circular dependencies both the atexit functions and destructor functions are run after the object can't be used by anything anymore.~ It turned out that there is an autogenerated call to __cxa_finalize that should call the functions registered for that dso, so I implemented that.