dfhack icon indicating copy to clipboard operation
dfhack copied to clipboard

calls to `dlclose`/`FreeLibrary` are unchecked

Open ab9rf opened this issue 2 years ago • 0 comments

dlclose (on Linux) or FreeLibrary (on Windows) can fail under certain circumstances, but our plugin routines (in PlugLoad-posix.cpp and PlugLoad-windows.cpp) do not check the return value of dlclose/FreeLibrary.

The known circumstance in which dlclose will fail on Linux is if the DLL contains any symbols marked STB_GNU_UNIQUE; if a segment contains any such symbol, that segment is marked NODELETE by the loader, which prevents the dll from being unloaded. g++ will emit symbols with this flag for, among possibly other things, templated statics and statics inside of inline functions.

In order to prevent user surprise, then, we should detect whether DLL unload fails, and when it does issue an appropriate diagnostic, and mark the plugin as "broken" instead of as "unloaded".

Relevant Discord discussion

ab9rf avatar Feb 25 '24 18:02 ab9rf