-
Notifications
You must be signed in to change notification settings - Fork 258
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
SIGSEGV in libc++_shared while _Unwind_Backtrace #816
Comments
The main thing to look for is whether or not the unwinder was linked properly in each of your libraries (third-party dependencies too; check every .so in your application). This can be diagnosed easily with $ readelf -sW lib1.so | grep Unwind If the library was correctly, you'll see something like reported in #785. Every unwind symbol (with the exception of https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#Unwinding details the general requirements for linking the STL correctly. It's somewhat ahead of time (libgcc is not a linker script until r19, which is not even in beta yet), but the concepts are correct. CMake builds your libraries correctly as long as their dependencies are not also broken. For a standalone toolchain you need to manually set up the If none of those things help, we'll need a test case to dig into this (one that repros with r18). Our tests don't show any issues in this area and there's not enough information to know what went wrong. I strongly suspect that the information in #379 will turn something up though. |
@DanAlbert, Could you please help me understand "Why unwinder has to be linked properly in each of libraries". If unwinder is not linked with the library, wont it work for unwinding function calls from those libraries?? |
I don't understand your question. How's it going to unwind without an unwinder? |
"I don't understand your question. How's it going to unwind without an unwinder?" However, I have run readelf with my libs and following is the output. ####################readelf from lib1.so################################## ####################readelf from lib2.so################################## ####################readelf from lib3.so################################## readelf & grep unwind on lib1.so and lib3.so are giving same outputs. So I am assuming there is no problem with linking unwinder. you said "WEAK DEFAULT or any other form that is not some variation of private is a problem.". But in lib3.so, __gnu_Unwind_Find_exidx is WEAK DEFAULT and unwind is working for lib3.so |
Other way around. Those are all built incorrectly. |
The output is same even when I used gnustl and with gnustl the same setup is working fine. However, I take your suggestion. I will get those symbols to LOCAL HIDDEN and will try running. If you have time, could you please tell me why these symbols has to be LOCAL HIDDEN. What is the dependency? why cant they be GLOBAL DEFAULT? |
@DanAlbert, Could you please provide some readouts for Local and Global references you are talking about? I think we both are out of sync on this issue. |
gnustl is different. What I said above remains true for libc++.
readelf on libc++ itself shows them:
|
@DanAlbert , I am still struggling to understand and resolve this problem. Could you please help me understand the following You are saying _Unwind* symbols has to be present in all the three libs and all of them has to be "LOCAL HIDDEN" except those you pointed out. As mentioned earlier,
Please help me understand. |
To ensure that the unwinder invoked from any given callsite is the same unwinder throughout the unwind. An unwinder is linked into every binary. Different unwinders have different implementations but the same API. When not hidden, it's possible for the loader to resolve some of the symbols from one unwinder and some from the other. The two implementations then call into each other during the same unwind. This is bad.
If they didn't do any unwinding they wouldn't have references to unwind symbols. You can disassemble the binaries to see where that's coming from if you want. |
Interestingly, the same code base is working on android x86 emulator. But crashing on actual physical phones i.e. arm android phones. |
Yes, ARM and x86 use different unwinders on Android. |
Finally, we got it working. Until now, we haven't linked our libs with cxx-stl\llvm-libc++\libs\armeabi-v7a\libunwind.a. When we started linking, it started working. @DanAlbert, Also could you please help me understand why there is no libunwind.a present under cxx-stl\llvm-libc++\libs\x86? |
The doc I linked above explains it. |
specifically https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#Unwinding which says "To avoid this problem, libraries should always be built with |
@enh Shouldn't that actually be |
@falken42 yes, good catch. The other places it was used in that doc were correct, at least: https://android-review.googlesource.com/c/platform/ndk/+/929717 |
I have an application which internally uses three .so files. From Java, I am calling function in lib1.so via JNI which internally call function in lib2.so. lib2.so make a call to lib3.so whose functionality
is to print the back trace. This is set up is working fine when I am using libgnustl_shared.so. But after switching to libc++_shared.so, the application is crashing. After hours of analysis, I observed
that _Unwind_Backtrace is successfully calling the callback provided for number of times same as the number of function calls in lib2.so and lib3.so together. Now while _Unwind_Backtrace is calling
the callback for the functions in the lib1.so, it is crashing with SEGV
To be clear following is my call flow.
Java -> lib1.so (func1 -> func2) -> lib2.so (func3 -> func4 -> func5) -> lib3.so(func 6 -> func 7 -> _Unwind_Backtrace)
_Unwind_Backtrace is calling the callback provided to it successfully for 5 times ( 2 functions in lib3.so and 3 functions in lib2.so) and then crashing with following error statement
10-11 04:17:28.956 16882 16904 F libc : Fatal signal 11 (SIGSEGV), code 1, fault addr 0x1f in tid 16904
10-11 04:17:29.043 16905 16905 F DEBUG : #00 pc 0007d84e /data/app/com.myapp/lib/arm/libc++_shared.so
10-11 04:17:29.044 16905 16905 F DEBUG : #1 pc 0007d67b /data/app/com.myapp/lib/arm/libc++_shared.so
10-11 04:17:29.044 16905 16905 F DEBUG : #2 pc 00079bf5 /data/app/com.myapp/lib/arm/libc++_shared.so
10-11 04:17:29.044 16905 16905 F DEBUG : #3 pc 00079b97 /data/app/com.myapp/lib/arm/libc++_shared.so (__gxx_personality_v0+270)
This is happening very consistently. So this could not be memory corruption.
Even after hours of thinking, I could not understand what is going wrong. If anybody has any idea, kindly help.
Environment Details
The text was updated successfully, but these errors were encountered: