dladdr shim for gmodule; try to enable crash reporter on AIX (#15808)
commit01dd63c440d0ad09542b8d3b9301658a6e8a0d30
authorCalvin Buckley <calvin@cmpct.info>
Mon, 7 Oct 2019 22:19:28 +0000 (7 19:19 -0300)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Mon, 7 Oct 2019 22:19:28 +0000 (8 00:19 +0200)
tree053a4aea0bc9f74455bea1d0c2626cb6c472ba72
parentc7f8e5bdb7dddd8ad437343f8715f6d36cdcbf7d
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.
configure.ac
mono/eglib/Makefile.am
mono/eglib/gmodule-aix.c [new file with mode: 0644]
mono/eglib/gmodule-unix.c
mono/eglib/gmodule-win32.c
mono/eglib/gmodule.h
mono/mini/mini-exceptions.c
mono/mini/mini-posix.c
mono/profiler/log.c