Skip to content

[Linux] libflutter_linux_gtk.so exports _Unwind_* since 3.50.0, C++ exceptions caught inside plugins abort the app #196402

Closed

Description

@patrickweh

Steps to reproduce

  1. flutter create --template=plugin --platforms=linux unwind_probe
  2. in linux/unwind_probe_plugin.cc add #include <stdexcept> and put this at the top of unwind_probe_plugin_register_with_registrar:
  try {
    throw std::runtime_error("thrown inside the plugin");
  } catch (const std::exception& e) {
    g_print("unwind_probe: caught: %s\n", e.what());
  }
  1. cd example && flutter build linux --release (same with --debug)
  2. run build/linux/x64/release/bundle/unwind_probe_example

done with the official tarballs flutter_linux_3.47.9-stable.tar.xz and flutter_linux_3.50.0-stable.tar.xz on a clean Ubuntu 24.04 x64, each project created by its own sdk, two runs each

Expected results

the exception is caught inside the plugin, like on 3.47.9:

unwind_probe: caught: thrown inside the plugin

Actual results

on 3.50.0 the app aborts (SIGABRT, debug and release):

terminate called after throwing an instance of 'std::runtime_error'
terminate called recursively

real world case: flutter_secure_storage_linux throws LibsecretError when there is no unlocked keyring and catches it in its method call handler, so on 3.50.0 the app dies at start on any machine without one instead of getting a PlatformException

libflutter_linux_gtk.so exports an unwinder since 3.50.0:

$ nm -D --defined-only 3.47.9/flutter/bin/cache/artifacts/engine/linux-x64-release/libflutter_linux_gtk.so | grep -c _Unwind_
0
$ nm -D --defined-only 3.50.0/flutter/bin/cache/artifacts/engine/linux-x64-release/libflutter_linux_gtk.so | grep _Unwind_
0000000001037250 T _Unwind_DeleteException
00000000010370b0 T _Unwind_ForcedUnwind
00000000010372b0 T _Unwind_GetGR
0000000001037370 T _Unwind_GetIP
0000000001037140 T _Unwind_GetLanguageSpecificData
00000000010371e0 T _Unwind_GetRegionStart
0000000001036610 T _Unwind_RaiseException
0000000001036cd0 T _Unwind_Resume
0000000001037310 T _Unwind_SetGR
00000000010373d0 T _Unwind_SetIP

same 10 symbols in linux-x64 and linux-x64-profile, 0 in all three on 3.47.9

LD_DEBUG=bindings on the 3.50.0 release build shows libstdc++ and even libgcc_s throwing through the engines copy:

binding file /lib/x86_64-linux-gnu/libstdc++.so.6 [0] to .../bundle/lib/libflutter_linux_gtk.so [0]: normal symbol `_Unwind_RaiseException' [GCC_3.0]
binding file /lib/x86_64-linux-gnu/libgcc_s.so.1 [0] to .../bundle/lib/libflutter_linux_gtk.so [0]: normal symbol `_Unwind_RaiseException' [GCC_3.0]

so the plugin is compiled against libstdc++/libgcc but unwinds with the llvm libunwind inside the engine, and the handler is never found

looks like it comes from #192607 (2553f89), engine/src/build/config/compiler/BUILD.gn at 3.50.0, lines 640 to 646:

    ldflags += [ "-nostdlib++" ]

    if (is_linux) {
      # Our custom libcxx doesn't include the unwinder, which is included in
      # libc++.a. Link the libunwind directly.
      ldflags += [ "--unwindlib=libunwind" ]
    }

on 3.47.9 linux was excluded there (if (!is_linux) { ldflags += [ "-nostdlib++" ] }). nothing hides the static libunwind, so its symbols end up in the dynamic symbol table. i guess -Wl,--exclude-libs,libunwind.a (or a version script) for the linux shared library would fix it, didnt build the engine to verify that. testing/symbols/verify_exported.dart only checks libflutter_engine.so on linux, not libflutter_linux_gtk.so, probably why it wasnt caught

workaround for apps: link libgcc_s first in linux/runner/CMakeLists.txt, then its unwinder wins the lookup again and the probe catches on 3.50.0 (debug and release, two runs each):

target_link_options(${BINARY_NAME} PRIVATE
  "LINKER:--push-state,--no-as-needed,-lgcc_s,--pop-state")

maybe related to #188877, same area (static runtime of the engine colliding with the host process) but a different symptom

Code sample

Code sample

linux/unwind_probe_plugin.cc of a fresh flutter create --template=plugin --platforms=linux unwind_probe, only change:

#include <stdexcept>

void unwind_probe_plugin_register_with_registrar(FlPluginRegistrar* registrar) {
  try {
    throw std::runtime_error("thrown inside the plugin");
  } catch (const std::exception& e) {
    g_print("unwind_probe: caught: %s\n", e.what());
  }
  // ... generated code unchanged
}

Flutter Doctor output

Doctor output
[!] Flutter (Channel stable, 3.50.0, on Ubuntu 24.04.5 LTS 7.2.12-orbstack-00394-gbecdd6130068, locale en_US.UTF-8)
    • Flutter version 3.50.0 on channel stable
    • Framework revision ab2912035e (2 days ago), 2026-11-09 08:50:21 -0800
    • Engine revision 371f77202a
    • Dart version 3.14.0
    • DevTools version 2.61.0
[✓] Linux toolchain - develop for Linux desktop
    • Ubuntu clang version 18.1.3 (1ubuntu1)
    • cmake version 3.28.3
    • ninja version 1.11.1
    • pkg-config version 1.8.1

works on 3.47.9 (framework c197ca5, engine 89c39ed, Dart 3.13.7), same machine and toolchain. the [!] is only "flutter not on PATH"

Activity

  1. added
    in triage
    on Nov 12, 2026
  2. suryaKommana2662 commented on Nov 12, 2026

    @suryaKommana2662
    Contributor

    @patrickweh Thanks for report. Routing to the team-linux for further investigation.

  3. added
    engine
    platform-linux
    team-linux
    and removed
    in triage
    on Nov 12, 2026
  4. added
    P2
    triaged-linux
    on Nov 18, 2026
  5. Maksim-Nikolaev commented on Nov 20, 2026

    @Maksim-Nikolaev

    Same root cause also breaks Rust libraries loaded through dart:ffi (reported in #197043, closing as a duplicate of this one). std::backtrace::Backtrace::force_capture() crashes with SIGSEGV and a panic inside catch_unwind aborts with failed to initiate panic, error 3. flutter_rust_bridge captures a backtrace for every Rust error, so the first error closes the app. The engine exports 10 _Unwind_* functions but not _Unwind_Backtrace, so Rust walks the stack with libgcc and reads the context with the engine's _Unwind_GetIP.

    Repro: https://github.com/Maksim-Nikolaev/flutter-unwinder-repro (./check.sh runs both cases)

    Tested fix: keep the static unwinder private in engine/src/flutter/shell/platform/linux/BUILD.gn:

     shared_library("flutter_linux_gtk") {
       deps = [ ":flutter_linux" ]
    
    -  ldflags = [ "-Wl,-rpath,\$ORIGIN" ]
    +  ldflags = [
    +    "-Wl,-rpath,\$ORIGIN",
    +    "-Wl,--exclude-libs,libunwind.a",
    +  ]

    With a 3.50.0 engine built this way the library exports no _Unwind_* / unw_* symbols and Impeller starts as usual. Results, two runs each, x86_64 only:

    Case 3.50.0 3.50.0 + fix
    C++ plugin repro from this issue terminate called after throwing an instance of 'std::runtime_error', exit 134 unwind_probe: caught: thrown inside the plugin
    Rust Backtrace::force_capture() SIGSEGV works
    Rust panic in catch_unwind SIGABRT caught

    Workaround until a release has the fix, in linux/runner/CMakeLists.txt:

    target_link_options(${BINARY_NAME} PRIVATE "LINKER:--no-as-needed" "-lgcc_s" "LINKER:--as-needed")

    @dcharkes compared two options in #197043 (comment): exporting the full unwinder (possible size increase, needs an automigration) versus hiding it as above (no migration, same size as today). The diff above is the second one. Happy to send a PR for it.

  6. added a commit that references this issue on Nov 20, 2026
    203c0c4
  7. h4rm00n commented on Nov 24, 2026

    @h4rm00n

    One more affected category that neither C++ plugins nor Rust cover: libmpv built against LuaJIT — the default for system mpv on Arch/Debian/Ubuntu/Fedora. This one dies with SIGSEGV rather than abort, and it hits audio-only apps.

    YesPlayMusic (CI pins FLUTTER_VERSION: "3.50.0") plays audio via media_kit, which dlopen()s the system libmpv.so. On Arch (mpv 1:0.42.0-3, luajit 2.1.1795119671+96f7b29-1), mpv's builtin Lua scripts abort JIT trace recording routinely (lj_trace_err → lj_err_throw → _Unwind_RaiseException); normally this unwinds silently inside LuaJIT. With the 3.50 engine exporting its unwinder, LuaJIT's GOT ends up mixed — read back from core dumps of the running app:

    • _Unwind_RaiseException / _Unwind_GetIP / _Unwind_SetIP / _Unwind_SetGR / _Unwind_DeleteException → libflutter_linux_gtk.so
    • _Unwind_GetCFA (not exported by the engine) → libgcc_s.so.1

    So _Unwind_RaiseException builds an LLVM-libunwind context, then LuaJIT's personality routine reads that context with libgcc's _Unwind_GetCFA; the two struct _Unwind_Context layouts differ, so libgcc returns garbage and LuaJIT's err_unwind dereferences it — SIGSEGV, si_code=SI_KERNEL. The trigger is stochastic (JIT hot-spot counters), so it presents as a random crash; in our logs it most often fires when a track ends and playback switches to the next file, but one of five captured cores crashed during mpv_initialize.

    Reproduced without the GUI app: a trivial C program linked against libflutter_linux_gtk.so that dlopen("libmpv.so")s and plays short audio files to EOF reliably segfaults; the same program with LD_PRELOAD=libgcc_s.so.1 runs indefinitely. On the real app, the -lgcc_s link-order workaround suggested in this issue fixes it as well (A/B on one machine: 4/4 runs crash unpatched, 4/4 survive patched, ~10 end-of-track transitions per run).

    Looking forward to #196451 landing in a stable release — it would fix this whole class of failures for Linux apps that embed native libraries.

  8. Kataglyphis commented on Nov 27, 2026

    @Kataglyphis

    3.50.1 still ships the exported unwinder, so this still aborts apps on stable. #196451 is on master only: its merge commit 203c0c42 is on neither flutter-3.50-candidate.0 (stable) nor flutter-3.51-candidate.0 (beta), and 3.51.0-0.2.pre does not have it either.

    Could someone with triage rights add cp: stable and cp: beta to #196451? Its merge commit already carries cp-trigger.yml.

    What 3.50.1 exports (linux-x64-release and linux-x64-debug from storage.googleapis.com/flutter_infra_release/flutter/<engine>/):

    $ nm -D --defined-only libflutter_linux_gtk.so | grep -E -c '_Unwind_|unw_|register_frame'
    0     # 3.47.9, engine 89c39edfdfae2949f6806e4a315c0c08522238b7
    31    # 3.50.1, engine 4d35714800b9266b6693a58e1225ecd7e9e45ed7

    The 31 are ten _Unwind_* functions (_Unwind_DeleteException, _Unwind_ForcedUnwind, _Unwind_GetGR, _Unwind_GetIP, _Unwind_GetLanguageSpecificData, _Unwind_GetRegionStart, _Unwind_RaiseException, _Unwind_Resume, _Unwind_SetGR, _Unwind_SetIP), four __unw_* (__unw_add_dynamic_eh_frame_section, __unw_add_dynamic_fde and their two remove twins) and seventeen unw_*. _Unwind_GetIPInfo and _Unwind_Backtrace are not exported, so they still come from libgcc_s.

    Smallest reproduction, no Flutter project needed (repro.cc):

    #include <cstdio>
    #include <stdexcept>
    
    int main() {
      try {
        throw std::runtime_error("caught");
      } catch (const std::exception &e) {
        std::puts(e.what());
      }
    }
    ENGINE=<dir with libflutter_linux_gtk.so>
    # The engine first in NEEDED, as in a Flutter runner:
    g++ -o flutter-first repro.cc -Wl,--no-as-needed -L"$ENGINE" -lflutter_linux_gtk -Wl,-rpath,"$ENGINE"
    # libgcc_s first:
    g++ -o gcc-first repro.cc -Wl,--no-as-needed -lgcc_s -L"$ENGINE" -lflutter_linux_gtk -Wl,-rpath,"$ENGINE"
    Engine flutter-first gcc-first
    3.50.1 release terminate called after throwing an instance of 'std::runtime_error', terminate called recursively, SIGABRT (134) prints caught
    3.50.1 debug the same abort prints caught
    3.47.9 release prints caught prints caught

    Ubuntu, GCC 15.2, x86_64. In a real app the core's stack is __cxa_throw → _Unwind_RaiseException (libflutter_linux_gtk.so) → __gxx_personality_v0 → __cxa_call_terminate, for an exception the throwing library catches itself.

    The workaround every Linux app needs until a release carries the fix, in linux/CMakeLists.txt before the runner links flutter:

    target_link_libraries(${BINARY_NAME} PRIVATE "-Wl,--push-state,--no-as-needed" gcc_s "-Wl,--pop-state")
    target_link_libraries(${BINARY_NAME} PRIVATE flutter)

    Expected: the engine exports none of libunwind's symbols. #196451 does that with -Wl,--exclude-libs,libunwind.a; hidden visibility for the statically linked libunwind would do the same.

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

    P2engineplatform-linuxteam-linuxtriaged-linux

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions