Wrap ARM abort() to improve stack trace.

The code generated for Thumb and Thumb2 targets has different handling
for abort().  Because abort() is "noreturn", it doesn't need to preserve
the callee-save registers.  The Thumb2 version trashes LR and makes it
impossible to figure out who called abort().

This inserts a trivial stub function; net effect is stack traces are
reasonable after an abort().

For bug 2191452.

Eclair branch Dr. No approved by: hiroshi
This commit is contained in:
Andy McFadden 2009-10-15 16:07:43 -07:00
parent 7e7d6c48a0
commit 96bbbe2177

View File

@ -39,8 +39,13 @@
#define debug_log(format, ...) \
__libc_android_log_print(ANDROID_LOG_DEBUG, "libc-abort", (format), ##__VA_ARGS__ )
#ifdef __arm__
void
__libc_android_abort(void)
#else
void
abort(void)
#endif
{
struct atexit *p = __atexit;
static int cleanup_called = 0;
@ -97,3 +102,29 @@ abort(void)
(void)kill(getpid(), SIGABRT);
_exit(1);
}
#ifdef __arm__
/*
* abort() does not return, which gcc interprets to mean that it doesn't
* need to preserve any of the callee-save registers. Unfortunately this
* includes the link register, so if LR is used there is no way to determine
* which function called abort().
*
* We work around this by inserting a trivial stub that doesn't alter
* any of the "interesting" registers and thus doesn't need to save them.
* We can't just call __libc_android_abort from C because gcc uses "bl"
* without first saving LR, so we use an asm statement. This also has
* the side-effect of replacing abort() with __libc_android_abort() in
* the stack trace.
*
* Ideally __libc_android_abort would be static, but I haven't figured out
* how to tell gcc to call a static function from an asm statement.
*/
void
abort(void)
{
asm ("b __libc_android_abort");
_exit(1); /* suppress gcc noreturn warnings */
}
#endif