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

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 01:44:56 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-bolt

Author: Jinjie Huang  (Jinjie-Huang)

<details>
<summary>Changes</summary>

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(2GB), 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.

---
Full diff: https://github.com/llvm/llvm-project/pull/216654.diff


2 Files Affected:

- (modified) bolt/lib/Core/BinaryEmitter.cpp (+1-1) 
- (added) bolt/test/runtime/X86/lsda-absolute-udata4.test (+18) 


``````````diff
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/runtime/X86/lsda-absolute-udata4.test b/bolt/test/runtime/X86/lsda-absolute-udata4.test
new file mode 100644
index 0000000000000..9fd49411e95d8
--- /dev/null
+++ b/bolt/test/runtime/X86/lsda-absolute-udata4.test
@@ -0,0 +1,18 @@
+# REQUIRES: x86_64-linux
+
+## This test verifies that when emitting LSDA with absolute addresses allocated
+## above 0x7fffffff, the udata encoding is used, preventing
+## incorrect sign extension.
+
+# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-linux \
+# RUN:   %S/../../X86/split-all-lptrampoline.s -o %t.o
+# RUN: %clangxx -fuse-ld=lld -no-pie %t.o -o %t.exe -Wl,-q
+# RUN: llvm-bolt %t.exe --split-functions --split-strategy=all --split-eh \
+# RUN:   --custom-allocation-vma=0x80000000 -o %t.bolt -v=2 2>&1 | \
+# RUN:   FileCheck %s --check-prefix=CHECK-BOLT
+# RUN: llvm-readelf -x .gcc_except_table %t.bolt | \
+# RUN:   FileCheck %s --check-prefix=CHECK-LSDA
+# RUN: %t.bolt
+
+# CHECK-BOLT: falling back to generating absolute-address exception ranges for main
+# CHECK-LSDA: 03000000 00{{....}}03

``````````

</details>


https://github.com/llvm/llvm-project/pull/216654


More information about the llvm-commits mailing list