You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
exception handling doesn't work with static executables #593
This actually isn't unique to libc++. Exceptions don't work for any STL with static executables because of this.
I'm trying to dig into why Clang doesn't do that and get it fixed, but that will require a clang update. Until then, you can use exceptions in static executables by adding -Wl,--eh-frame-hdr to your ldflags.
I'm encountering this problem too (using zxing which heavily uses exceptions for not detecting barcodes, yuck), looking at that link above, do you know when or in what NDK the fix will be released?
The arm32 fix is now in r17 (will be in beta 1 since we're respinning that for a gradle workaround). The --eh-frame-hdr issue has a patch up for clang (https://reviews.llvm.org/D43203), but that won't land in the NDK until at least r18. We can still do a bit more work for r17 to add -Wl,--eh-frame-hdr to the default ldflags for CMake and ndk-build, but that won't be in beta 1.
changed the title [-]libc++ exception handling doesn't work with static executables[/-][+]exception handling doesn't work with static executables[/+]on Feb 14, 2018
r17 beta 1 is being respun again, so this will be in after all. I'll leave the bug open to track the clang fix, but I'm moving this off the r17 milestone since we've done as much as we can for this release.
@DanAlbert This is not fully fixed, at least for old platforms (tested with NDK r20, target platform v21), because the definition of __gnu_Unwind_Find_exidx actually used by libc++ is still broken. It seems that the broken definition comes from the dynamically linked system libc .
Since statically linked libc is problematic, I have to backport this and pass -Wl,--wrap=__gnu_Unwind_Find_exidx to the linker command with explicitly specified crtbegin_so/crtend_so stuff to allow the object file containing the wrapper after -lc++, and it worksbut this still terminates at __cxxabiv1::failed_throw for an exception that should have been caught.
I've tested it in a real machine running Android 9.0 and it fails at __cxxabiv1::failed_throw with a different exception failed to catch.
_Unwind_RaiseException returns _URC_FAILURE in __cxa_throw. Not sure why.
@DanAlbert My fault. I was testing the standalone toolchain with different project configurations and occasionally got confused by makefiles having different linker flags (-shared/-static/-static -static-libstdc++/nothing).
The previously mentioned problem still exists in the configuration with a single .so linked with -static-libstdc++ loaded by NativeActivity. This should be indeed another topic, but let me summarize a little here. AFAIK the failure is due to a call to an unexpected personality routine in the unwinding phase 1, which should not happen after following the document. The failure only occur within some specific position of my code. (Not sure if this and this are related.) Since the original case is not easy to reduce, I'm still investigating the exact condition to reproduce the problem. I'd open an issue then. Sorry for the misreport.
Activity
leebaok commentedon Jan 24, 2018
So exceptions not work with libc++ static ?
But for gnustl ? can exceptions work ?
@DanAlbert
jmgao commentedon Jan 24, 2018
re: no stack traces in logcat, try gdbclient?
DanAlbert commentedon Jan 25, 2018
https://android-review.googlesource.com/c/platform/bionic/+/600854
DanAlbert commentedon Jan 25, 2018
The patch above fixes arm32. The other architectures (arm64 at least, I haven't gotten to testing the Intel arches yet, but the fix is likely the same) are broken because Clang doesn't automatically pass
--eh-frame-hdrto the linker for static executables: https://android.googlesource.com/toolchain/clang/+/0659c9e0352a35af1ea86cf11b19618543702974/lib/Driver/ToolChains/Gnu.cpp#368This actually isn't unique to libc++. Exceptions don't work for any STL with static executables because of this.
I'm trying to dig into why Clang doesn't do that and get it fixed, but that will require a clang update. Until then, you can use exceptions in static executables by adding
-Wl,--eh-frame-hdrto your ldflags.Fix __gnu_Unwind_Find_exidx for static executables.
eddielong commentedon Feb 12, 2018
I'm encountering this problem too (using zxing which heavily uses exceptions for not detecting barcodes, yuck), looking at that link above, do you know when or in what NDK the fix will be released?
DanAlbert commentedon Feb 12, 2018
The milestone is accurate. This is fixed in r17, but not necessarily in beta 1.
DanAlbert commentedon Feb 14, 2018
The arm32 fix is now in r17 (will be in beta 1 since we're respinning that for a gradle workaround). The --eh-frame-hdr issue has a patch up for clang (https://reviews.llvm.org/D43203), but that won't land in the NDK until at least r18. We can still do a bit more work for r17 to add
-Wl,--eh-frame-hdrto the default ldflags for CMake and ndk-build, but that won't be in beta 1.DanAlbert commentedon Feb 14, 2018
https://android-review.googlesource.com/c/platform/ndk/+/618577 hoists this into the build systems until we get a clang with the fix.
[-]libc++ exception handling doesn't work with static executables[/-][+]exception handling doesn't work with static executables[/+]DanAlbert commentedon Feb 15, 2018
r17 beta 1 is being respun again, so this will be in after all. I'll leave the bug open to track the clang fix, but I'm moving this off the r17 milestone since we've done as much as we can for this release.
9 remaining items
Work around Clang not passing --eh-frame-hdr.
Test fixes for modern static libraries.
Hoist --eh-frame-hdr into the build systems.
Update Clang to build 4630689.
Update NDK platform prebuilts to build 4567395.
FrankHB commentedon Sep 7, 2019
@DanAlbert This is not fully fixed, at least for old platforms (tested with NDK r20, target platform v21), because the definition of
__gnu_Unwind_Find_exidxactually used by libc++ is still broken. It seems that the broken definition comes from the dynamically linked system libc .Since statically linked libc is problematic, I have to backport this and pass
-Wl,--wrap=__gnu_Unwind_Find_exidxto the linker command with explicitly specifiedcrtbegin_so/crtend_sostuff to allow the object file containing the wrapper after-lc++,and it worksbut this still terminates at__cxxabiv1::failed_throwfor an exception that should have been caught.I've tested it in a real machine running Android 9.0 and it fails at
__cxxabiv1::failed_throwwith a different exception failed to catch._Unwind_RaiseExceptionreturns_URC_FAILUREin__cxa_throw. Not sure why.Is this related to https://bugs.llvm.org/show_bug.cgi?id=21053?
DanAlbert commentedon Sep 9, 2019
Then it sounds like you aren't using a static executable. Could you verify that?
FrankHB commentedon Sep 9, 2019
@DanAlbert My fault. I was testing the standalone toolchain with different project configurations and occasionally got confused by makefiles having different linker flags (
-shared/-static/-static -static-libstdc++/nothing).The previously mentioned problem still exists in the configuration with a single
.solinked with-static-libstdc++loaded byNativeActivity. This should be indeed another topic, but let me summarize a little here. AFAIK the failure is due to a call to an unexpected personality routine in the unwinding phase 1, which should not happen after following the document. The failure only occur within some specific position of my code. (Not sure if this and this are related.) Since the original case is not easy to reduce, I'm still investigating the exact condition to reproduce the problem. I'd open an issue then. Sorry for the misreport.DanAlbert commentedon Sep 10, 2019
Yeah, go ahead and open a new bug if you find something. It's almost always a broken dependency in this situation.
FrankHB commentedon Sep 11, 2019
I find it a code generation issue, reported upstream.
DanAlbert commentedon Sep 11, 2019
Thanks! I filed #1079 to track that on our side.
Fix __gnu_Unwind_Find_exidx for static executables.
Fix __gnu_Unwind_Find_exidx for static executables.
Update NDK platform prebuilts to build 4567395.