Skip to content

[Linux] A Rust backtrace or panic crashes the app: libflutter_linux_gtk.so exports half of its unwinder #197043

Closed

Description

@Maksim-Nikolaev

Steps to reproduce

A Flutter Linux app that loads a Rust library through dart:ffi crashes when the Rust code captures a backtrace or panics. I ran into it through flutter_rust_bridge, which captures a backtrace for every Rust error, so the first error from Rust closed the app.

Repro: https://github.com/Maksim-Nikolaev/flutter-unwinder-repro

  1. flutter create --platforms=linux and add a tiny Rust cdylib (code below) that the app loads with dart:ffi at startup.
  2. Call capture_backtrace(), which runs std::backtrace::Backtrace::force_capture().
  3. Or call panic_and_catch(), which panics inside std::panic::catch_unwind.

The repro's ./check.sh builds the app and runs both cases on a private Xvfb.

Expected results

The backtrace is captured and the panic is caught. The app keeps running.

Actual results

The app crashes in both cases:

Engine library Rust backtrace Rust panic in catch_unwind
Flutter 3.50.0 stock crash, SIGSEGV crash, SIGABRT (failed to initiate panic, error 3)
stock + runner links libgcc_s first (workaround) works works
engine built with the fix below works works

Why: libflutter_linux_gtk.so links LLVM's libunwind statically and exports some of its _Unwind_* functions, but not _Unwind_Backtrace. Because the engine library is loaded before libgcc_s, a library loaded later ends up with two unwinders mixed together (diagram under "Screenshots or Video").

libgcc walks the stack and passes its own context to Rust; Rust reads it with the engine's _Unwind_GetIP, which expects LLVM's format, and crashes in unw_get_reg. A panic goes to the engine's _Unwind_RaiseException, which fails with _URC_FATAL_PHASE1_ERROR, so Rust aborts.

$ nm -D --defined-only bundle/lib/libflutter_linux_gtk.so | grep _Unwind_
_Unwind_DeleteException  _Unwind_ForcedUnwind  _Unwind_GetGR  _Unwind_GetIP
_Unwind_GetLanguageSpecificData  _Unwind_GetRegionStart  _Unwind_RaiseException
_Unwind_Resume  _Unwind_SetGR  _Unwind_SetIP

(plus the unw_* API, 31 unwinder symbols in total.)

Workaround

In the app's linux/runner/CMakeLists.txt, link libgcc_s before the engine so every _Unwind_* symbol comes from one unwinder:

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

Possible fix

Keep the statically linked 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",
+  ]

I built the 3.50.0 engine with this change: the library exports no _Unwind_* / unw_* symbols any more, the app starts with Impeller as usual, and both cases in the repro pass without the workaround. I only tested x86_64. Happy to send a PR if this approach is OK.

Code sample

Code sample

native/src/lib.rs (crate type cdylib, edition 2021, no dependencies):

use std::backtrace::Backtrace;
use std::panic;

#[no_mangle]
pub extern "C" fn capture_backtrace() -> usize {
    let backtrace = Backtrace::force_capture();

    backtrace.to_string().len()
}

#[no_mangle]
pub extern "C" fn panic_and_catch() -> i32 {
    panic::set_hook(Box::new(|_| {}));

    let result = panic::catch_unwind(|| {
        panic!("repro panic");
    });

    match result {
        Ok(()) => 0,
        Err(_) => 1,
    }
}

lib/main.dart:

import 'dart:ffi';
import 'dart:io';

import 'package:flutter/widgets.dart' hide Size;

typedef _CaptureBacktrace = Size Function();
typedef _CaptureBacktraceDart = int Function();
typedef _PanicAndCatch = Int32 Function();
typedef _PanicAndCatchDart = int Function();

void main() {
  runApp(const Center(child: Text('repro', textDirection: TextDirection.ltr)));

  final bundle = File(Platform.resolvedExecutable).parent.path;
  final library = DynamicLibrary.open('$bundle/lib/librepro_native.so');
  final captureBacktrace = library
      .lookupFunction<_CaptureBacktrace, _CaptureBacktraceDart>(
        'capture_backtrace',
      );
  final panicAndCatch = library
      .lookupFunction<_PanicAndCatch, _PanicAndCatchDart>('panic_and_catch');

  final mode = Platform.environment['REPRO_MODE'] ?? 'backtrace';

  if (mode == 'backtrace') {
    stderr.writeln('REPRO backtrace ok ${captureBacktrace()}');
  } else {
    stderr.writeln(
      panicAndCatch() == 1 ? 'REPRO panic caught' : 'REPRO panic not caught',
    );
  }

  exit(0);
}

Added to linux/CMakeLists.txt (after the FLUTTER_LIBRARY install):

set(REPRO_NATIVE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../native")
set(REPRO_NATIVE_LIBRARY "${REPRO_NATIVE_DIR}/target/release/librepro_native.so")
add_custom_target(repro_native ALL
  COMMAND cargo build --release --manifest-path "${REPRO_NATIVE_DIR}/Cargo.toml"
  BYPRODUCTS "${REPRO_NATIVE_LIBRARY}"
  USES_TERMINAL)
add_dependencies(${BINARY_NAME} repro_native)
install(FILES "${REPRO_NATIVE_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
  COMPONENT Runtime)

Screenshots or Video

Which unwinder each _Unwind_* call reaches
flowchart LR
    rust["Rust library<br/>(Backtrace::force_capture)"]
    rust -- "_Unwind_Backtrace" --> gcc["libgcc_s.so.1<br/>(GNU unwinder)"]
    rust -- "_Unwind_GetIP<br/>_Unwind_RaiseException<br/>+ 8 more" --> flutter["libflutter_linux_gtk.so<br/>(LLVM libunwind, exported by accident)"]
    gcc -. "walks the stack, hands<br/>its context to the callback" .-> rust
    flutter -. "reads that context<br/>in another format" .-> crash(("SIGSEGV"))
Loading

Logs

Logs

Exported unwinder symbols of the engine library:

$ nm -D --defined-only build/linux/x64/release/bundle/lib/libflutter_linux_gtk.so | rg -i '_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
0000000001037da0 W unw_iterate_dwarf_unwind_cache

Symbol bindings of the Rust library, stock runner (LD_DEBUG=bindings, paths shortened):

binding file bundle/lib/librepro_native.so [0] to bundle/lib/libflutter_linux_gtk.so [0]: normal symbol `_Unwind_DeleteException' [GCC_3.0]
binding file bundle/lib/librepro_native.so [0] to bundle/lib/libflutter_linux_gtk.so [0]: normal symbol `_Unwind_GetIP' [GCC_3.0]
binding file bundle/lib/librepro_native.so [0] to bundle/lib/libflutter_linux_gtk.so [0]: normal symbol `_Unwind_GetLanguageSpecificData' [GCC_3.0]
binding file bundle/lib/librepro_native.so [0] to bundle/lib/libflutter_linux_gtk.so [0]: normal symbol `_Unwind_GetRegionStart' [GCC_3.0]
binding file bundle/lib/librepro_native.so [0] to bundle/lib/libflutter_linux_gtk.so [0]: normal symbol `_Unwind_RaiseException' [GCC_3.0]
binding file bundle/lib/librepro_native.so [0] to bundle/lib/libflutter_linux_gtk.so [0]: normal symbol `_Unwind_Resume' [GCC_3.0]
binding file bundle/lib/librepro_native.so [0] to bundle/lib/libflutter_linux_gtk.so [0]: normal symbol `_Unwind_SetGR' [GCC_3.0]
binding file bundle/lib/librepro_native.so [0] to bundle/lib/libflutter_linux_gtk.so [0]: normal symbol `_Unwind_SetIP' [GCC_3.0]
binding file bundle/lib/librepro_native.so [0] to /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 [0]: normal symbol `_Unwind_Backtrace' [GCC_3.3]
binding file bundle/lib/librepro_native.so [0] to /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 [0]: normal symbol `_Unwind_FindEnclosingFunction' [GCC_3.3]
binding file bundle/lib/librepro_native.so [0] to /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 [0]: normal symbol `_Unwind_GetCFA' [GCC_3.3]
binding file bundle/lib/librepro_native.so [0] to /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 [0]: normal symbol `_Unwind_GetDataRelBase' [GCC_3.0]
binding file bundle/lib/librepro_native.so [0] to /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 [0]: normal symbol `_Unwind_GetIPInfo' [GCC_4.2.0]
binding file bundle/lib/librepro_native.so [0] to /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 [0]: normal symbol `_Unwind_GetTextRelBase' [GCC_3.0]

Crash stack, backtrace mode, stock runner (gdb -batch -ex run -ex bt):

Thread 1 "unwinder_repro" received signal SIGSEGV, Segmentation fault.
0x00007ffff7e37579 in unw_get_reg () from bundle/lib/libflutter_linux_gtk.so
#0  0x00007ffff7e37579 in unw_get_reg () at bundle/lib/libflutter_linux_gtk.so
#1  0x00007ffff7e37384 in _Unwind_GetIP () at bundle/lib/libflutter_linux_gtk.so
#2  0x00007fffd40386cc in <std::backtrace::Backtrace>::create::{closure#0} () at bundle/lib/librepro_native.so
#3  0x00007fffd404a3c2 in std::backtrace_rs::backtrace::libunwind::trace::trace_fn () at bundle/lib/librepro_native.so
#4  0x00007ffff7ee03bd in _Unwind_Backtrace () at /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
#5  0x00007fffd403ca3b in <std::backtrace::Backtrace>::create () at bundle/lib/librepro_native.so
#6  0x00007fffd403c985 in <std::backtrace::Backtrace>::force_capture () at bundle/lib/librepro_native.so
#7  0x00007fffd4023c84 in capture_backtrace () at bundle/lib/librepro_native.so
#8  0x00007fffcff25c61 in ??? ()

Environment: Ubuntu 26.04.1 LTS (x86_64, kernel 7.2.6), libgcc-s1 16-20260322-1ubuntu1, gcc 15.2.0, GNU ld 2.46, cmake 4.2.3, rustc 1.98.0 (88d9e12ae 2026-08-18). Only tested on x86_64; arm64 is unverified.

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.50.0, on Ubuntu 26.04.1 LTS 7.2.6-070206-generic, locale en_US.UTF-8) [29ms]
    • Flutter version 3.50.0 on channel stable at ~/flutter
    • Upstream repository [email protected]:flutter/flutter.git
    • Framework revision ab2912035e (11 days ago), 2026-11-09 08:50:21 -0800
    • Engine revision 371f77202a
    • Dart version 3.14.0
    • DevTools version 2.61.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration

[✓] Android toolchain - develop for Android devices (Android SDK version 37.0.0) [737ms]
    • Android SDK at ~/Android/Sdk
    • Emulator version 37.1.11.0 (build_id 15917651) (CL:N/A)
    • Platform android-37.0, build-tools 37.0.0
    • ANDROID_HOME = ~/Android/Sdk
    • ANDROID_SDK_ROOT = ~/Android/Sdk
    • Java binary at: /usr/lib/jvm/java-25-openjdk-amd64/bin/java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 25.0.5.1+2-1-26.04.1-Ubuntu)
    • All Android licenses accepted.

[✓] Chrome - develop for the web [5ms]
    • CHROME_EXECUTABLE = /snap/bin/chromium

[✓] Linux toolchain - develop for Linux desktop [221ms]
    • Ubuntu clang version 21.1.8 (6ubuntu1)
    • cmake version 4.2.3
    • ninja version 1.13.2
    • pkg-config version 2.5.1
    • OpenGL core renderer: AMD Radeon RX 9070 XT (radeonsi, gfx1201, ACO, DRM 3.64, 7.2.6-070206-generic)
    • OpenGL core version: 4.6 (Core Profile) Mesa 26.0.8-1ubuntu0.3
    • OpenGL core shading language version: 4.60
    • OpenGL ES renderer: AMD Radeon RX 9070 XT (radeonsi, gfx1201, ACO, DRM 3.64, 7.2.6-070206-generic)
    • OpenGL ES version: OpenGL ES 3.2 Mesa 26.0.8-1ubuntu0.3
    • OpenGL ES shading language version: OpenGL ES GLSL ES 3.20
    • GL_EXT_framebuffer_blit: yes
    • GL_EXT_texture_format_BGRA8888: yes

[✓] Connected device (3 available) [3.3s]
    • <android device> (mobile) • <serial> • android-arm64  • Android 16 (API 36)
    • Linux (desktop)  • linux    • linux-x64      • Ubuntu 26.04.1 LTS 7.2.6-070206-generic
    • Chrome (web)     • chrome   • web-javascript • Chromium 157.0.8103.50 snap

[✓] Network resources [608ms]
    • All expected network resources are available.

• No issues found!

Activity

  1. dcharkes commented on Nov 20, 2026

    @dcharkes
    Contributor

    Exporting half the symbols is definitely a bug.

    Going for option 1, including the full unwinder, could increase the size because the compiler can no longer tree-shake the parts of the unwinder not used by the Flutter engine itself. Could you check what the impact on the size is.

    Also, option 1 will require a flutter automigration for existing projects.

    Option 2 will work for sure. The fix is easier and doesn't require an auto migration. The size should be identical to today (broken state).

    So, I'd lean towards option 1.

    cc @loic-sharma for engine team opinion.

  2. added
    in triage
    on Nov 20, 2026
  3. suryaKommana2662 commented on Nov 20, 2026

    @suryaKommana2662
    Contributor

    @Maksim-Nikolaev TThanks for the report. This appears to have the same underlying cause as #196402. Both reports identify the unintended export of LLVM's _Unwind_* symbols from libflutter_linux_gtk.so, resulting in conflicts between the LLVM and GNU unwinders.

    Could you please review #196402 and confirm whether it describes the same issue you are experiencing? If so, we can close this issue as a duplicate. If you believe there are any differences, please let us know so we can investigate further.

  4. added
    waiting for response
    and removed
    in triage
    on Nov 20, 2026
  5. Maksim-Nikolaev commented on Nov 20, 2026

    @Maksim-Nikolaev
    Author

    Yes, I checked and it's basically the same root cause as #196402 but with C++ exceptions in plugins, and mine is with Rust backtraces and panics.

    Let's close this one as a duplicate, I wrote a comment in the #196402

  6. removed
    waiting for response
    on Nov 20, 2026
  7. added
    r: duplicate
    on Nov 20, 2026
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

    r: duplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions