dladdr shim for gmodule; try to enable crash reporter on AIX (#15808)
* Introduce new dladdr wrapper in glib, AIX reimpl, and convert usage
Provides a wrapper around dladdr that should be platform-neutral.
Also provided is a reimplementation for AIX, which should enable
that platform to get some previously dladdr-specific functions like
the crash reporter. It is somewhat flawed in that it only gets info
for symbols in .text, returns non-constant allocated strings, and
allocates heap memory for buffers.
Then convert usages (except a macOS specific one) of dladdr to the
new eglib function. It has a different signature, which should
simplify intent and reduce structiness. Also free memory on AIX due
to limitations of its reimplmenetation.
* Enable (and fix build of) crash reporter on AIX
So far crashes don't seem any different, but the code for it is
built.
* typo fix (guess this isn't compiled on aix)
* attempt to fix macOS and win32 builds
* Implement more of g_module_address on Win32
Implements the filename stuff. Untested; don't have Windows.
* Look for backtrace_symbols in an IBM compat library for i
Enables i to natively dump a stack trace. (AIX "works" too if you
copy the compat lib's code and hack it in - it probably needs to be
in EGlib.) Unfortunately, it's not perfect. The backchain from the
signal handler is empty on i, and AIX sometimes mangles the stack
frame in a way that severely confuses the backtrace code, causing
it to dereference invalid memory by interpreting instructions as a
pointer. (I have seen somewhat similar for the sigaltstack case,
where the native memory dump attempts to read something it should
not.) Perhaps mincore could be used, but that feels like a sloppy
workaround, especially in the "AIX making an invalid stack frame"
case.
* If the file isn't an archive, don't format its name like one
* Fix up search for backtrace_symbols to look in libexecinfo
FreeBSD ships it in base and Haiku has a package; likely others too.
* Win32 suffers in g_module_address as well
* That should habe been guarded with AIX due to limitations
Otherwise seems to free things that shouldn't be freed
* Casting for win32
* Fix up Win32 impl of module address
* Free HMODULE to lower reference count after using it
* Change dladdr based impl to always dup for impl consistency
Means freeing afterwards shouldn't be ifdefable.
* probably shouldn't strdup NULL
Likely why macOS has failures.
* Don't dup/return const strs, but copy to caller-provided buffers
...which can be on the stack. This makes it far less risky to use
in a crash reporter scenario, because malloc can be hosed then.
Also fix profiler up better to work with this new reality.