When libgpg-error is initialized, it has a module constructor to do initialization work, and sets up an atexit handler. Unfortunately, causes some problems. If libgpg-error gets dlclosed (either directly or via the dynamic linker closing it as part of cleaning up dependencies from another dlclosed library), it will remove libgpg-error from memory, but keep the atexit handler. This will cause a crash on exit when the handler gets called and jumps to nulls. The case I saw this happen was with PHP; it loads a gnupg extension that references libgpgme and thus libgpg-error, it calls dlclose on those extensions, the dynamic linker garbage collects modules that are no longer needed, and libgpg-error gets unloaded.
I think the correct solution is to use a module destructor for symmetry; this will get called on both exit and dlclose, and we don't have to worry about the operation of operations or if dlclose will trigger or not for the module (which is highly platform dependent or unpredictable). Since we're already relying on __attribute__(constructor), this seems to make sense to me.
I've created a patch (D605) to do so, and I've tested that it fixes the issue for me, at least on AIX where I was seeing this issues. It also contains more background; I've made this ticket mostly to provide a ticket associated with the diff.
Technically, this is a dupe of T1749, but the patch in that ticket was incorrect and it got closed because of that.