-
Notifications
You must be signed in to change notification settings - Fork 257
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
libc++ is linked improperly when using cmake or standalone toolchains #379
Comments
Or a list of known cases that generate invalid results? |
Do you have a bug report? We have no open bugs about exception handling in libc++ that I see. |
It is said so on https://developer.android.com/ndk/guides/cpp-support.html#ic (scroll up a bit)
On a project we noticed strange crashes after exceptions. I assumed this to be the cause. I think I could make a small proof of concept for it. |
Oh, that bullet point is way out of date. That was a KI in r11 or something. libc++ is in much better shape than it was back then, but it's still not quite to the point that I'm comfortable recommending it. For a timeline on that, see our roadmap.
Please do. I can't fix bugs that don't get reported. |
(doc is fixed now, btw, sorry for the confusion) |
I went a bit deeper into this, now I know that When nm libjansson.so | grep 'gnu'
00008038 T __gnu_Unwind_Backtrace
00000000 w __gnu_Unwind_Find_exidx
00007f36 T __gnu_Unwind_ForcedUnwind
00007ed4 T __gnu_Unwind_RaiseException
00008570 T __gnu_Unwind_Restore_VFP
00008580 T __gnu_Unwind_Restore_VFP_D
00008590 T __gnu_Unwind_Restore_VFP_D_16_to_31
00008628 T __gnu_Unwind_Restore_WMMXC
000085a0 T __gnu_Unwind_Restore_WMMXD
00007f4a T __gnu_Unwind_Resume
00007f8c T __gnu_Unwind_Resume_or_Rethrow
00008578 T __gnu_Unwind_Save_VFP
00008588 T __gnu_Unwind_Save_VFP_D
00008598 T __gnu_Unwind_Save_VFP_D_16_to_31
0000863c T __gnu_Unwind_Save_WMMXC
000085e4 T __gnu_Unwind_Save_WMMXD
00007dd2 t __gnu_unwind_24bit.isra.1
0000874a T __gnu_unwind_execute
000089c0 T __gnu_unwind_frame
00007ca6 t __gnu_unwind_get_pr_addr
000080b2 t __gnu_unwind_pr_common I'm assuming I'm doing something wrong, causing this. But I don't know what. |
This is probably the problem. Could you share how |
Eh, just the same as native-lib. Nothing fancy there.
Op wo 3 mei 2017 om 21:35 schreef Dan Albert <notifications@github.com>
… For some reason, the externalproject_add library gets linked with a lot of
gnu functions, while the other doesn't.
This is probably the problem. Could you share how second-lib is built?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#379 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAtBQ_R9OTQbQ--Y849_go8xx2dRcf9Cks5r2NccgaJpZM4NODnm>
.
|
Hmm. We need to rethink how we link STLs in cmake, and also in standalone toolchains. Looking at the
In order:
If we look at the output for roughly the same project in ndk-build:
ndk-build gets this right. All static libraries must precede libgcc, which must preceded all shared libraries. I think I can at least fix cmake by just not using the linker script, but I'm not sure what to do about standalone toolchains... |
Fyi, this is the real-world dependency-building project we (attempt to) use: https://github.com/marijnvdwerf/openrct2-dependencies-android. |
I don't think this can be truly fixed without patching CMake itself: https://github.com/Kitware/CMake/blob/master/Source/cmLinkLineComputer.cxx#L182 The standard libraries are always the last libraries to be linked. Even if we were to try to add the libraries in some way other than This works in the typical CMake build because CMake usually isn't in the business of deciding how to link your stdlib, it just leaves that to the compiler. These sorts of issues can affect libraries beyond the stdlib too, it's just much less likely (DLL hell for static libraries, essentially). There might be some things we can do to mitigate this problem. Could you try applying this patch to your cmake toolchain file and rebuilding? I've done this locally and can confirm that the unwind symbols in libjansson do get hidden. I believe this should alleviate the problems, even if it isn't a perfect solution. Longer term we're going to be replacing both unwinders (libgcc and libunwind) with one that we've written from scratch. Having that should also help things. |
How can I download the patch file? |
Excellent question. I'm not sure, so here: https://gist.github.com/DanAlbert/e8593db1f22e3014463da02a54471927 |
(there's the download drop-down in the top right corner that lets you download something you'll have to base64 decode or a zip file, or you can click on the individual file and there's a download icon next to where it says "Patch set 1" over the right hand pane.) |
This does fix the example project, and the real-world subprojects we use |
The standalone toolchain case is a bit more haphazard, but I think we can do it by wrapping the linker in a script that would autoappend those flags (this is already how we add the I can go ahead and submit the CMake fix (I'll extend it to cover ndk-build too) and work on the standalone toolchain case separately. |
https://android-review.googlesource.com/389852 has a fix for standalone toolchains, but it occurs to me that we might not be able to use this. iirc this will break I can verify this later when I have a Windows machine available. If I'm right, maybe we should teach the Clang driver to do this by default for Android. @stephenhines: thoughts? We should also get the |
Yeah, confirmed that. Fixing standalone toolchains with the patch above will make things messy on Windows. We're not going to be able to tackle those in r15. I'll give it some more thought. |
I'm having the same issue, however the provided patch doesn't help in my case. Now when an exception is thrown in one of these libraries and caught in the scankit, I get the same SIGABRT as above.
|
BTW, can anybody explain me what's the difference between libc++.so and libc++_shared.so in this case? Because my log states that I'm using libc++.so and the other logs show libc++_shared.so is being linked instead. |
libc++_shared.so is the real library, libc++.so is a linker script that makes it less of a hassle to use standalone toolchains. |
See android/ndk#379 Fixes #1163 Fixes issues with gdb segfaulting on arm on an unrecognized command.
Hi Dan. I'm using NDK r15c (15.2.4203891) and cmake 3.6.4111459 (I'm experiencing the very same results on r12b and r14b and the previous version of cmake). I've checked cmake scripts as well as build.ninja file. It seems that However, I've got the issue similar to one described here. When I statically link to libc++, I've got the following crash:
when I dynamically link to libc++, I've got a crash here:
Please, note that for some reason crash with dynamically inked libc++ happens when the exception is thrown, but call stack shows Note: it seems that Unwind* functions were linked from liblog.so instead of being statically linked from libunwind.a. Following the ndk-build's linking order we re-sorted all libraries in CMakeList.txt and manually added libc++ between static and dynamic libraries. Now we've got only __gnu_Unwind_Find_exidx being unresolved. Not quite sure what piece of code/library introduced it. However, we don't see crashes because of exceptions anymore. |
We ran into the same issue here. We use a custom script to call clang instead of using NDK build or Andoid Studio or anything else. Sometime between setting up our build system and the latest NDK, the NDK build added a unwind.a (I think NDK r15?) to it linking process. We added that and did some reordering of the args we pass into the linker (based on the verbose output from the NDK build args) and we were able to resolve our issue. |
It seems we can't guarantee the link order of our libraries (objects, then static libraries, then shared libraries) in cmake, which prevents us from ensuring that libunwind is used with libc++ in the event that some other library is exporting an unwinder. The best we can do without patching cmake (and until the new unwinder is available) is hide libgcc in any new libraries we build. This can't protect us from libraries built without this patch (or with build systems we don't control), but it will at least protect us from ourselves. Patch this in both ndk-build and cmake. ndk-build doesn't have the same problems that cmake does, but libraries built by ndk-build can cause problems for cmake. Standalone toolchains are also affected by this. I'll fix them in a follow up patch. Test: Built the test cast attached to the bug, libgcc is hidden. Bug: android/ndk#379 Change-Id: I3406c7e49f7194231bfe1e5f921a3e51d875dc84
Doing this here causes libgcc to be linked ahead of the STL, which breaks unwinding and therefore exception handling. Test: ./run_tests.py Bug: android/ndk#379 Change-Id: I63cbbdc125fdc3231a21f3354c1b1cfb129ac12b
A breakdown of the current status here:
Since the issue with broken prebuilts can only be fixed by the build system, the NDK cannot do any more to solve that problem. ndk-build does not have this problem. NDK r19 turns libgcc.a into a linker script to ensure that libunwind.a is linked before libgcc.a, which clears up most of the issues. This cannot make the symbols hidden, so it may not behave properly in the presence of broken dependencies, but the toolchain itself produces correct output. The remaining work here is to lift Anything beyond that is something that each build system will have to deal with individually. |
I should also mention that the correct build process is documented here: https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#Unwinding |
Is there a roadmap on providing stable exception support on ARM-devices when compiled using
c++_shared
?The text was updated successfully, but these errors were encountered: