[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 01:35:12 PDT 2026


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

>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 1/2] 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

>From 87b0fe1b25bfa4bf001039ee6f25d99e5a9a5336 Mon Sep 17 00:00:00 2001
From: huangjinjie <huangjinjie at bytedance.com>
Date: Mon, 17 Aug 2026 16:34:53 +0800
Subject: [PATCH 2/2] add test

---
 bolt/test/X86/split-all-lptrampoline.s         | 11 -----------
 .../test/runtime/X86/lsda-absolute-udata4.test | 18 ++++++++++++++++++
 2 files changed, 18 insertions(+), 11 deletions(-)
 create mode 100644 bolt/test/runtime/X86/lsda-absolute-udata4.test

diff --git a/bolt/test/X86/split-all-lptrampoline.s b/bolt/test/X86/split-all-lptrampoline.s
index 9a957ef7d6095..df50a7fbe0305 100644
--- a/bolt/test/X86/split-all-lptrampoline.s
+++ b/bolt/test/X86/split-all-lptrampoline.s
@@ -7,17 +7,6 @@
 # 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
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



More information about the llvm-commits mailing list