[llvm] [Bazel] Add opt-in libunwind EH frame registration (PR #226148)

Corentin Kerisit via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 05:47:49 PDT 2026


https://github.com/cerisier created https://github.com/llvm/llvm-project/pull/226148

LLVM libunwind expects `__register_frame` to receive one FDE, while non-Apple Bazel builds pass the whole `.eh_frame` section by default. This can produce `FDE is really a CIE` when linking against LLVM libunwind (see #43419).

Add `-- at llvm-project//llvm:use_libunwind_for_eh_frame_registration=true` to set `HAVE_UNW_ADD_DYNAMIC_FDE` locally on `ExecutionEngine` and `OrcTargetProcess`. Defaults and runtime linkage stay unchanged.

This follows the existing [`enable_abi_breaking_checks` setting](https://github.com/llvm/llvm-project/blob/a8705c33dda2bb831ee6d6e0500b2d20bb902d0c/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel#L29-L41). CMake already probes `__unw_add_dynamic_fde` for the same purpose.

Checked Linux and macOS compile actions, define scope, and Linux JIT frame registration/teardown.


>From 136e724812ed5260b10924f9e690ae0681e520a2 Mon Sep 17 00:00:00 2001
From: Corentin Kerisit <corentin.kerisit at gmail.com>
Date: Thu, 24 Sep 2026 14:41:53 +0200
Subject: [PATCH] [Bazel] Add opt-in libunwind EH frame registration

---
 .../llvm-project-overlay/llvm/BUILD.bazel     | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
index b683f86ca3863..f58420c5f7d7e 100644
--- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -40,6 +40,18 @@ config_setting(
     },
 )
 
+# Use LLVM libunwind's per-FDE registration API. This does not link libunwind.
+# Usage: -- at llvm-project//llvm:use_libunwind_for_eh_frame_registration=true
+bool_flag(
+    name = "use_libunwind_for_eh_frame_registration",
+    build_setting_default = False,
+)
+
+config_setting(
+    name = "libunwind_eh_frame_registration_enabled",
+    flag_values = {":use_libunwind_for_eh_frame_registration": "true"},
+)
+
 exports_files([
     "LICENSE.TXT",
     "cmake/modules/llvm-driver-template.cpp.in",
@@ -4366,6 +4378,10 @@ cc_library(
     ) + ["include/llvm-c/ExecutionEngine.h"],
     copts = llvm_copts,
     features = ["-parse_headers"],
+    local_defines = select({
+        ":libunwind_eh_frame_registration_enabled": ["HAVE_UNW_ADD_DYNAMIC_FDE=1"],
+        "//conditions:default": [],
+    }),
     deps = [
         ":BinaryFormat",
         ":CodeGen",
@@ -4585,6 +4601,10 @@ cc_library(
             "-lrt",
         ],
     }),
+    local_defines = select({
+        ":libunwind_eh_frame_registration_enabled": ["HAVE_UNW_ADD_DYNAMIC_FDE=1"],
+        "//conditions:default": [],
+    }),
     deps = [
         ":BinaryFormat",
         ":CodeGen",



More information about the llvm-commits mailing list