Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C personality function crashes on ARM EHABI #26386

Closed
llvmbot opened this issue Jan 4, 2016 · 2 comments
Closed

C personality function crashes on ARM EHABI #26386

llvmbot opened this issue Jan 4, 2016 · 2 comments
Labels
bugzilla Issues migrated from bugzilla compiler-rt

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 4, 2016

Bugzilla Link 26012
Resolution FIXED
Resolved on Mar 13, 2016 17:12
Version unspecified
OS Linux
Attachments A function with cleanup attribute., Functions to throw/catch exception., Build script.
Reporter LLVM Bugzilla Contributor

Extended Description

If a C function contains a cleanup attribute and the source code is compiled with -fexceptions, then __gcc_personality_v0() will be called by the unwinder.

However, our __gcc_personality_v0() implementation in compiler-rt is not compatible with ARM EHABI. Consequently, the mismatch of the function signature will cause a segmentation fault.

$ cat cleanup.c
extern void my_throw();

int i = 0;

void callback(int *p) {
i = 1;
}

void test_cleanup() {
int a attribute((cleanup(callback))) = 1;
my_throw();
}

$ gdb ./bad.out
... skipped ...
Program received signal SIGSEGV, Segmentation fault.
0xb6f6e910 in unw_get_proc_info () from /opt/llvm/lib/libunwind.so.1
(gdb) bt
#​0 0xb6f6e910 in unw_get_proc_info () from /opt/llvm/lib/libunwind.so.1
#​1 0xb6f73c70 in _Unwind_GetLanguageSpecificData ()
from /opt/llvm/lib/libunwind.so.1
#​2 0x000108fc in __gcc_personality_v0 ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)

NOTE: There is a patch (written by Timon Van Overveldt) in the review process that can fix the problem:
http://reviews.llvm.org/D15781

@llvmbot
Copy link
Collaborator Author

llvmbot commented Feb 29, 2016

I've spent much of today (thanks to poor Android native debugging) tracking down a crash on Android that seems to be this. If libc.so's _Unwind_Backtrace() gets called, I get the same crash:

#​00 pc 00097122 libc++_shared.so (unw_get_proc_info+93)
#​01 pc 000992ab libc++_shared.so (_Unwind_GetLanguageSpecificData+10)
#​02 pc 00094c0f libc++_shared.so (__gxx_personality_v0+46)
#​03 pc 0003c630 /system/lib/libc.so (__gnu_Unwind_Backtrace+152)
#​04 pc 0003cb44 /system/lib/libc.so (_Unwind_Backtrace+20)

This happens due to system libraries that only link to libc.so calling _Unwind_Backtrace.

I haven't found any workaround for this, so I'll revert back to gnuc++ for now (and jump some other hoops for a library that doesn't work with that gnuc++, which was the reason I was trying to use this in the first place). This is the repro I isolated, FWIW:

#include <unwind.h>
#include <dlfcn.h>

static _Unwind_Reason_Code test(struct _Unwind_Context *c, void *p) { return _URC_NO_REASON; }

void go()
{
void *libc = dlopen("libc.so", RTLD_LAZY);
void *_Unwind_Backtrace = dlsym(libc, "_Unwind_Backtrace");

typedef _Unwind_Reason_Code (*p_Unwind_Backtrace)(_Unwind_Trace_Fn, void *);
((p_Unwind_Backtrace) _Unwind_Backtrace)(test, NULL);

try {
	throw runtime_error("");
} catch(runtime_error &e) {
}

}

@llvmbot
Copy link
Collaborator Author

llvmbot commented Mar 14, 2016

This should be fixed now that http://reviews.llvm.org/rL262178 and http://reviews.llvm.org/rL263010 have landed. Please try it out!

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla compiler-rt
Projects
None yet
Development

No branches or pull requests

1 participant