Skip to content

exception handling doesn't work with static executables #593

Closed

Description

@DanAlbert

Currently undiagnosed. Since it's a static executable, we don't get a stack trace in logcat.

Activity

  1. added this to the r18 milestone on Dec 8, 2017
  2. self-assigned this
    on Dec 8, 2017
  3. leebaok commented on Jan 24, 2018

    @leebaok

    So exceptions not work with libc++ static ?
    But for gnustl ? can exceptions work ?
    @DanAlbert

  4. jmgao commented on Jan 24, 2018

    @jmgao
    Contributor

    re: no stack traces in logcat, try gdbclient?

  5. modified the milestones: r18, r17 on Jan 25, 2018
  6. DanAlbert commented on Jan 25, 2018

    @DanAlbert
    ContributorAuthor

    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-hdr to the linker for static executables: https://android.googlesource.com/toolchain/clang/+/0659c9e0352a35af1ea86cf11b19618543702974/lib/Driver/ToolChains/Gnu.cpp#368

    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.

  7. added a commit that references this issue on Jan 25, 2018
    aeb5bc6
  8. eddielong commented on Feb 12, 2018

    @eddielong

    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?

  9. DanAlbert commented on Feb 12, 2018

    @DanAlbert
    ContributorAuthor

    The milestone is accurate. This is fixed in r17, but not necessarily in beta 1.

  10. DanAlbert commented on Feb 14, 2018

    @DanAlbert
    ContributorAuthor

    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.

  11. DanAlbert commented on Feb 14, 2018

    @DanAlbert
    ContributorAuthor
  12. changed the title [-]libc++ exception handling doesn't work with static executables[/-] [+]exception handling doesn't work with static executables[/+] on Feb 14, 2018
  13. DanAlbert commented on Feb 15, 2018

    @DanAlbert
    ContributorAuthor

    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.

  14. 9 remaining items

  15. FrankHB commented on Sep 7, 2019

    @FrankHB

    @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.

    Is this related to https://bugs.llvm.org/show_bug.cgi?id=21053?

  16. DanAlbert commented on Sep 9, 2019

    @DanAlbert
    ContributorAuthor

    It seems that the broken definition comes from the dynamically linked system libc .

    Then it sounds like you aren't using a static executable. Could you verify that?

  17. FrankHB commented on Sep 9, 2019

    @FrankHB

    @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.

  18. DanAlbert commented on Sep 10, 2019

    @DanAlbert
    ContributorAuthor

    Yeah, go ahead and open a new bug if you find something. It's almost always a broken dependency in this situation.

  19. FrankHB commented on Sep 11, 2019

    @FrankHB

    I find it a code generation issue, reported upstream.

  20. DanAlbert commented on Sep 11, 2019

    @DanAlbert
    ContributorAuthor

    Thanks! I filed #1079 to track that on our side.

  21. added 2 commits that reference this issue on Apr 22, 2024
    7fac86d
    0414f5b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions