[llvm] [BOLT] Fix overflow issue when using absolute addressing in LSDA (PR #216654)

Jinjie Huang via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 00:59:57 PDT 2026


https://github.com/Jinjie-Huang created https://github.com/llvm/llvm-project/pull/216654

Currently, in the emitLSDA() flow, signed data is used when using absolute addresses to update the LSDA. But when the PC is higher than 0x7fffffff, this will be sign-extended into an invalid 64-bit address. Especially when the output binary is large, silent errors can easily occur (we have met this problem in real scenarios).

So this patch changes the signed data to unsigned data, thereby fixing the incorrect address extension.

>From c9235922ba9b13f2e15ac08d600df06a56642e95 Mon Sep 17 00:00:00 2001
From: huangjinjie <huangjinjie at bytedance.com>
Date: Mon, 17 Aug 2026 15:59:14 +0800
Subject: [PATCH] fix bolt lsda overflow

---
 bolt/lib/Core/BinaryEmitter.cpp        |  2 +-
 bolt/test/X86/split-all-lptrampoline.s | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/bolt/lib/Core/BinaryEmitter.cpp b/bolt/lib/Core/BinaryEmitter.cpp
index 9243b6701b918..29dbcab7945ec 100644
--- a/bolt/lib/Core/BinaryEmitter.cpp
+++ b/bolt/lib/Core/BinaryEmitter.cpp
@@ -1037,7 +1037,7 @@ void BinaryEmitter::emitLSDA(BinaryFunction &BF, const FunctionFragment &FF) {
   // Emit encoding of entries in the call site table. The format is used for the
   // call site start, length, and corresponding landing pad.
   if (!LPStartSymbol)
-    Streamer.emitIntValue(dwarf::DW_EH_PE_sdata4, 1);
+    Streamer.emitIntValue(dwarf::DW_EH_PE_udata4, 1);
   else
     Streamer.emitIntValue(dwarf::DW_EH_PE_uleb128, 1);
 
diff --git a/bolt/test/X86/split-all-lptrampoline.s b/bolt/test/X86/split-all-lptrampoline.s
index df50a7fbe0305..9a957ef7d6095 100644
--- a/bolt/test/X86/split-all-lptrampoline.s
+++ b/bolt/test/X86/split-all-lptrampoline.s
@@ -7,6 +7,17 @@
 # RUN: llvm-bolt %t.exe --split-functions --split-strategy=all --split-eh \
 # RUN:         -o %t.bolt --print-split --print-only=main 2>&1 | FileCheck %s
 
+# RUN: %clangxx -fuse-ld=lld -no-pie %t.o -o %t.nopie.exe -Wl,-q
+# RUN: llvm-bolt %t.nopie.exe --split-functions --split-strategy=all --split-eh \
+# RUN:   --custom-allocation-vma=0x80000000 -o %t.nopie.bolt -v=2 2>&1 | \
+# RUN:   FileCheck %s --check-prefix=CHECK-ABS
+# RUN: llvm-readelf -x .gcc_except_table %t.nopie.bolt | \
+# RUN:   FileCheck %s --check-prefix=CHECK-ABS-LSDA
+# RUN: %t.nopie.bolt
+
+# CHECK-ABS: falling back to generating absolute-address exception ranges for main
+# CHECK-ABS-LSDA: 03000000 00{{....}}03
+
 # CHECK: -------   HOT-COLD SPLIT POINT   -------
 # CHECK: .LFT0
 # CHECK: Landing Pads: .LBB0



More information about the llvm-commits mailing list