[llvm] [BOLT] Correctly handle entry point at FDE boundaries (PR #176173)

Elvina Yakubova via llvm-commits llvm-commits at lists.llvm.org
Fri May 29 04:19:43 PDT 2026


https://github.com/ElvinaYakubova updated https://github.com/llvm/llvm-project/pull/176173

>From 425f1523506e270bb688085a7f27def7e45a02b0 Mon Sep 17 00:00:00 2001
From: Elvina Yakubova <eyakubova at nvidia.com>
Date: Thu, 15 Jan 2026 22:11:53 +0530
Subject: [PATCH 1/4] [BOLT] Correctly handle entry point at FDE boundaries

Fix a bug where getOrCreateLocalLabel() would return getFunctionEndLabel() when a secondary entry point is located exactly at an FDE end.

This occurs when:
An FDE covers code with no symbol
Inlined code follows immediately after the FDE
An external branch targets exactly the FDE end address
---
 bolt/include/bolt/Core/BinaryFunction.h       |  2 +-
 bolt/lib/Core/BinaryFunction.cpp              |  7 +-
 .../AArch64/entry-point-at-function-end.s     | 97 +++++++++++++++++++
 3 files changed, 102 insertions(+), 4 deletions(-)
 create mode 100644 bolt/test/AArch64/entry-point-at-function-end.s

diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h
index 0fdfcc5d76597..870e06d83740f 100644
--- a/bolt/include/bolt/Core/BinaryFunction.h
+++ b/bolt/include/bolt/Core/BinaryFunction.h
@@ -637,7 +637,7 @@ class BinaryFunction {
   ///
   /// NOTE: the function always returns a local (temp) symbol, even if there's
   ///       a global symbol that corresponds to an entry at this address.
-  MCSymbol *getOrCreateLocalLabel(uint64_t Address);
+  MCSymbol *getOrCreateLocalLabel(uint64_t Address, bool IsEntryPoint = false);
 
   /// Register an data entry at a given \p Offset into the function.
   void markDataAtOffset(uint64_t Offset) {
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index b9d4a1f4f52fa..49d02e5798590 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -1034,7 +1034,8 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, unsigned Size,
   return BranchType;
 }
 
-MCSymbol *BinaryFunction::getOrCreateLocalLabel(uint64_t Address) {
+MCSymbol *BinaryFunction::getOrCreateLocalLabel(uint64_t Address,
+                                                bool IsEntryPoint) {
   const uint64_t Offset = Address - getAddress();
 
   auto LI = Labels.find(Offset);
@@ -1049,7 +1050,7 @@ MCSymbol *BinaryFunction::getOrCreateLocalLabel(uint64_t Address) {
     }
   }
 
-  if (Offset == getSize())
+  if (Offset == getSize() && !IsEntryPoint)
     return getFunctionEndLabel();
 
   MCSymbol *Label = BC.Ctx->createNamedTempSymbol();
@@ -3824,7 +3825,7 @@ MCSymbol *BinaryFunction::addEntryPointAtOffset(uint64_t Offset) {
   const uint64_t EntryPointAddress = getAddress() + Offset;
   assert(!isInConstantIsland(EntryPointAddress) &&
          "cannot add entry point that points to constant data");
-  MCSymbol *LocalSymbol = getOrCreateLocalLabel(EntryPointAddress);
+  MCSymbol *LocalSymbol = getOrCreateLocalLabel(EntryPointAddress, true);
 
   MCSymbol *EntrySymbol = getSecondaryEntryPointSymbol(LocalSymbol);
   if (EntrySymbol)
diff --git a/bolt/test/AArch64/entry-point-at-function-end.s b/bolt/test/AArch64/entry-point-at-function-end.s
new file mode 100644
index 0000000000000..d5a370f4846cc
--- /dev/null
+++ b/bolt/test/AArch64/entry-point-at-function-end.s
@@ -0,0 +1,97 @@
+## Test that BOLT correctly handles entry points at exact FDE boundaries.
+##
+## This test simulates a real-world scenario where:
+## 1. A large function (big_func) contains an FDE with no symbol
+## 2. The FDE covers a sub-function within big_func [fde_start, fde_end)
+## 3. Inlined code follows immediately after the FDE (no symbol, no FDE)
+## 4. .init branches to exactly the FDE end address via section relocation
+##
+## Without the fix, getOrCreateLocalLabel() would return getFunctionEndLabel()
+## when offset == FDE size. The fix ensures a proper entry point label is created.
+##
+
+# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
+# RUN: %clang %cflags %t.o -pie -Wl,-q -Wl,--init=_init -o %t.exe
+# RUN: llvm-bolt %t.exe -o %t.bolt --print-disasm -v=1 2>&1 | FileCheck %s
+
+## The FDE-only function should get an entry point for the inlined code
+# CHECK: BOLT-WARNING: FDE {{.*}} has no corresponding symbol table entry
+# CHECK: Binary Function "{{.*}}__BOLT_FDE_FUNC{{.*}}" after disassembly
+# CHECK: Size        : 0x1c
+# CHECK: MaxSize     : 0x30
+# CHECK: IsMultiEntry: 1
+
+## _init function in .init section
+	.section .init,"ax", at progbits
+	.globl	_init
+	.type	_init, %function
+_init:
+	.cfi_startproc
+	stp	x29, x30, [sp, #-16]!
+	mov	x29, sp
+	## Branch to inlined code that's right after FDE end
+	## Linker converts this to: R_AARCH64_CALL26 .text + offset
+	bl	.Linlined_code
+	ldp	x29, x30, [sp], #16
+	ret
+	.cfi_endproc
+	.size	_init, .-_init
+
+## Main code in .text section
+	.text
+
+## Large function that contains the FDE and inlined code
+	.globl	big_func
+	.type	big_func, %function
+big_func:
+	.cfi_startproc
+	stp	x29, x30, [sp, #-16]!
+	mov	x29, sp
+	mov	w0, #1
+	add	w0, w0, #1
+	ldp	x29, x30, [sp], #16
+	ret
+	.cfi_endproc
+	.size	big_func, .-big_func
+
+## FDE-covered code WITHOUT a symbol - simulates sub-function within big_func
+## This has its own FDE but no symbol in the symbol table
+.Lfde_start:
+	.cfi_startproc
+	stp	x29, x30, [sp, #-16]!
+	mov	x29, sp
+	adrp	x0, .Lsome_data
+	add	x0, x0, :lo12:.Lsome_data
+	ldr	x0, [x0]
+	ldp	x29, x30, [sp], #16
+	ret
+	.cfi_endproc
+## FDE ends here - inlined code follows immediately
+
+## Inlined code at exactly FDE end (offset == FDE size)
+## _init branches here - this is what triggers the bug without the fix
+.Linlined_code:
+	adrp	x0, .Lsome_data
+	ldr	x0, [x0, :lo12:.Lsome_data]
+	cbz	x0, .Linlined_ret
+	mov	w0, #1
+.Linlined_ret:
+	ret
+
+	.globl	_start
+	.type	_start, %function
+_start:
+	.cfi_startproc
+	stp	x29, x30, [sp, #-16]!
+	mov	x29, sp
+	bl	_init
+	bl	big_func
+	ldp	x29, x30, [sp], #16
+	mov	w0, #0
+	ret
+	.cfi_endproc
+	.size	_start, .-_start
+
+	.data
+.Lsome_data:
+	.xword	0

>From a3e366b254576b34ff03a17d40aa7c626fe4ddfb Mon Sep 17 00:00:00 2001
From: Elvina Yakubova <eyakubova at nvidia.com>
Date: Wed, 28 Jan 2026 04:08:26 -0800
Subject: [PATCH 2/4] Simplify the test

---
 .../test/AArch64/entry-point-at-function-end.s | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/bolt/test/AArch64/entry-point-at-function-end.s b/bolt/test/AArch64/entry-point-at-function-end.s
index d5a370f4846cc..f657e9e522036 100644
--- a/bolt/test/AArch64/entry-point-at-function-end.s
+++ b/bolt/test/AArch64/entry-point-at-function-end.s
@@ -17,8 +17,8 @@
 ## The FDE-only function should get an entry point for the inlined code
 # CHECK: BOLT-WARNING: FDE {{.*}} has no corresponding symbol table entry
 # CHECK: Binary Function "{{.*}}__BOLT_FDE_FUNC{{.*}}" after disassembly
-# CHECK: Size        : 0x1c
-# CHECK: MaxSize     : 0x30
+# CHECK: Size        : 0x14
+# CHECK: MaxSize     : 0x1c
 # CHECK: IsMultiEntry: 1
 
 ## _init function in .init section
@@ -60,9 +60,7 @@ big_func:
 	.cfi_startproc
 	stp	x29, x30, [sp, #-16]!
 	mov	x29, sp
-	adrp	x0, .Lsome_data
-	add	x0, x0, :lo12:.Lsome_data
-	ldr	x0, [x0]
+	mov	w0, #42
 	ldp	x29, x30, [sp], #16
 	ret
 	.cfi_endproc
@@ -71,11 +69,7 @@ big_func:
 ## Inlined code at exactly FDE end (offset == FDE size)
 ## _init branches here - this is what triggers the bug without the fix
 .Linlined_code:
-	adrp	x0, .Lsome_data
-	ldr	x0, [x0, :lo12:.Lsome_data]
-	cbz	x0, .Linlined_ret
-	mov	w0, #1
-.Linlined_ret:
+	nop
 	ret
 
 	.globl	_start
@@ -91,7 +85,3 @@ _start:
 	ret
 	.cfi_endproc
 	.size	_start, .-_start
-
-	.data
-.Lsome_data:
-	.xword	0

>From b7599cf797c1e36f8c70878b6600b097eb3d9731 Mon Sep 17 00:00:00 2001
From: Elvina Yakubova <eyakubova at nvidia.com>
Date: Wed, 27 May 2026 08:28:42 -0700
Subject: [PATCH 3/4] [BOLT][AArch64] Split unmarked tail code after
 CFI-bounded functions into separate functions

Detect trailing unmarked code after CFI-bounded predecessors
(__BOLT_FDE_FUNC* or symbols whose FDE address range equals their size)
and promote it into separate BinaryFunction objects named
__BOLT_UNMARKED_TAILat<addr>.
---
 bolt/include/bolt/Core/BinaryFunction.h       |   2 +-
 bolt/include/bolt/Rewrite/RewriteInstance.h   |   6 +
 bolt/lib/Core/BinaryFunction.cpp              |   7 +-
 bolt/lib/Rewrite/RewriteInstance.cpp          | 127 ++++++++++++++++++
 .../AArch64/entry-point-at-function-end.s     |  95 ++++++-------
 5 files changed, 180 insertions(+), 57 deletions(-)

diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h
index 870e06d83740f..0fdfcc5d76597 100644
--- a/bolt/include/bolt/Core/BinaryFunction.h
+++ b/bolt/include/bolt/Core/BinaryFunction.h
@@ -637,7 +637,7 @@ class BinaryFunction {
   ///
   /// NOTE: the function always returns a local (temp) symbol, even if there's
   ///       a global symbol that corresponds to an entry at this address.
-  MCSymbol *getOrCreateLocalLabel(uint64_t Address, bool IsEntryPoint = false);
+  MCSymbol *getOrCreateLocalLabel(uint64_t Address);
 
   /// Register an data entry at a given \p Offset into the function.
   void markDataAtOffset(uint64_t Offset) {
diff --git a/bolt/include/bolt/Rewrite/RewriteInstance.h b/bolt/include/bolt/Rewrite/RewriteInstance.h
index 166336cbb8fcf..6586e4320c7d9 100644
--- a/bolt/include/bolt/Rewrite/RewriteInstance.h
+++ b/bolt/include/bolt/Rewrite/RewriteInstance.h
@@ -270,6 +270,12 @@ class RewriteInstance {
   /// symbol table has been processed.
   void adjustFunctionBoundaries(DenseMap<uint64_t, MarkerSymType> &MarkerSyms);
 
+  /// Promote unmarked executable regions after CFI-bounded functions into
+  /// separate BinaryFunction objects (__BOLT_FDE_FUNC* or named symbols
+  /// whose FDE range matches their size).
+  void splitUnmarkedTailFunctions(
+      DenseMap<uint64_t, MarkerSymType> &MarkerSyms);
+
   /// Make .eh_frame section relocatable.
   void relocateEHFrameSection();
 
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 49d02e5798590..b9d4a1f4f52fa 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -1034,8 +1034,7 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, unsigned Size,
   return BranchType;
 }
 
-MCSymbol *BinaryFunction::getOrCreateLocalLabel(uint64_t Address,
-                                                bool IsEntryPoint) {
+MCSymbol *BinaryFunction::getOrCreateLocalLabel(uint64_t Address) {
   const uint64_t Offset = Address - getAddress();
 
   auto LI = Labels.find(Offset);
@@ -1050,7 +1049,7 @@ MCSymbol *BinaryFunction::getOrCreateLocalLabel(uint64_t Address,
     }
   }
 
-  if (Offset == getSize() && !IsEntryPoint)
+  if (Offset == getSize())
     return getFunctionEndLabel();
 
   MCSymbol *Label = BC.Ctx->createNamedTempSymbol();
@@ -3825,7 +3824,7 @@ MCSymbol *BinaryFunction::addEntryPointAtOffset(uint64_t Offset) {
   const uint64_t EntryPointAddress = getAddress() + Offset;
   assert(!isInConstantIsland(EntryPointAddress) &&
          "cannot add entry point that points to constant data");
-  MCSymbol *LocalSymbol = getOrCreateLocalLabel(EntryPointAddress, true);
+  MCSymbol *LocalSymbol = getOrCreateLocalLabel(EntryPointAddress);
 
   MCSymbol *EntrySymbol = getSecondaryEntryPointSymbol(LocalSymbol);
   if (EntrySymbol)
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 4a2d83cbf8706..21fcb2a0e0d9a 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1367,6 +1367,7 @@ void RewriteInstance::discoverFileObjects() {
 
   // Now that all the functions were created - adjust their boundaries.
   adjustFunctionBoundaries(MarkerSymbols);
+  splitUnmarkedTailFunctions(MarkerSymbols);
 
   // Annotate functions with code/data markers in AArch64
   for (auto &[Address, Type] : MarkerSymbols) {
@@ -2067,6 +2068,125 @@ void RewriteInstance::disassemblePLT() {
   }
 }
 
+namespace {
+
+/// True when the predecessor body ends at its FDE boundary, so trailing bytes
+/// are outside both symtab size and unwind info:
+///   (1) __BOLT_FDE_FUNC* (FDE with no symtab entry), or
+///   (2) a normal symbol whose size equals its FDE address range.
+bool isCFIBoundedTailPredecessor(const BinaryFunction &BF,
+                                 const CFIReaderWriter &CFI) {
+  if (BF.getOneName().starts_with("__BOLT_FDE_FUNC"))
+    return true;
+  auto FDEI = CFI.getFDEs().find(BF.getAddress());
+  if (FDEI == CFI.getFDEs().end())
+    return false;
+  return FDEI->second->getAddressRange() == BF.getSize();
+}
+
+bool hasDataMarkerAt(DenseMap<uint64_t, MarkerSymType> &MarkerSyms,
+                     uint64_t Address) {
+  auto It = MarkerSyms.find(Address);
+  return It != MarkerSyms.end() && It->second == MarkerSymType::DATA;
+}
+
+/// Disassemble a prefix of [TailStart, TailStart + TrailingExtent) and return
+/// its length. Any remaining bytes in the range must be zero padding.
+/// Returns 0 if the region is not valid unmarked code.
+static uint64_t measureAArch64UnmarkedTail(BinaryContext &BC,
+                                             const BinaryFunction &Pred,
+                                             DenseMap<uint64_t, MarkerSymType>
+                                                 &MarkerSyms,
+                                             uint64_t TailStart,
+                                             uint64_t TrailingExtent) {
+  // Pred was registered from an executable section during symbol/FDE discovery.
+  BinarySection &Section = *Pred.getOriginSection();
+
+  // adjustFunctionBoundaries() set Pred->MaxSize so [Pred, Pred+MaxSize) fits
+  // in the section and stops at the next symbol/function.
+  if (!Section.containsRange(TailStart, TrailingExtent))
+    return 0;
+
+  StringRef Contents = Section.getContents();
+  const uint64_t SectionOffset = TailStart - Section.getAddress();
+  const uint8_t *Bytes =
+      reinterpret_cast<const uint8_t *>(Contents.data()) + SectionOffset;
+
+  uint64_t CodeLen = 0;
+  while (CodeLen < TrailingExtent) {
+    if (hasDataMarkerAt(MarkerSyms, TailStart + CodeLen))
+      return 0;
+    if (Pred.isInConstantIsland(TailStart + CodeLen))
+      return 0;
+
+    MCInst Inst;
+    uint64_t Size = 0;
+    ArrayRef<uint8_t> Slice(Bytes + CodeLen, TrailingExtent - CodeLen);
+    if (!BC.SymbolicDisAsm->getInstruction(Inst, Size, Slice, TailStart + CodeLen,
+                                           nulls()) ||
+        !Size)
+      break;
+    CodeLen += Size;
+  }
+
+  if (!CodeLen)
+    return 0;
+
+  for (uint64_t I = CodeLen; I < TrailingExtent; ++I) {
+    if (Bytes[I] != 0)
+      return 0;
+  }
+
+  return CodeLen;
+}
+
+} // namespace
+
+void RewriteInstance::splitUnmarkedTailFunctions(
+    DenseMap<uint64_t, MarkerSymType> &MarkerSyms) {
+  if (!BC->isAArch64())
+    return;
+
+  std::vector<BinaryFunction *> Worklist;
+  for (BinaryFunction &BF : llvm::make_second_range(BC->getBinaryFunctions())) {
+    if (BF.isPseudo() || BF.isFragment())
+      continue;
+    if (BF.getMaxSize() == BF.getSize())
+      continue;
+    if (!isCFIBoundedTailPredecessor(BF, *CFIRdWrt))
+      continue;
+    Worklist.push_back(&BF);
+  }
+
+  for (BinaryFunction *Pred : Worklist) {
+    const uint64_t TailStart = Pred->getAddress() + Pred->getSize();
+    const uint64_t TrailingExtent = Pred->getMaxSize() - Pred->getSize();
+
+    if (BC->getBinaryFunctionAtAddress(TailStart))
+      continue;
+
+    const uint64_t CodeLen = measureAArch64UnmarkedTail(
+        *BC, *Pred, MarkerSyms, TailStart, TrailingExtent);
+    if (!CodeLen)
+      continue;
+
+    BinarySection &Section = *Pred->getOriginSection();
+
+    Pred->setMaxSize(Pred->getSize());
+
+    std::string TailName =
+        "__BOLT_UNMARKED_TAILat" + Twine::utohexstr(TailStart).str();
+    if (opts::Verbosity >= 1)
+      BC->outs() << "BOLT-INFO: creating unmarked tail function " << TailName
+                 << " after " << *Pred << '\n';
+
+    // Inherit [TailStart, TailStart + TrailingExtent) from Pred's old extent.
+    BinaryFunction *TailBF = BC->createBinaryFunction(
+        TailName, Section, TailStart, CodeLen, CodeLen);
+    TailBF->setMaxSize(TrailingExtent);
+  }
+}
+
 void RewriteInstance::adjustFunctionBoundaries(
     DenseMap<uint64_t, MarkerSymType> &MarkerSyms) {
   for (auto BFI = BC->getBinaryFunctions().begin(),
@@ -2110,6 +2230,13 @@ void RewriteInstance::adjustFunctionBoundaries(
       if (It == MarkerSyms.end() || It->second != MarkerSymType::DATA) {
         // This is potentially another entry point into the function.
         uint64_t EntryOffset = NextSymRefI->first - Function.getAddress();
+        // At the FDE/symbol end, unmarked tail code may follow; split will
+        // promote it to __BOLT_UNMARKED_TAIL instead of a secondary entry.
+        if (BC->isAArch64() && EntryOffset == Function.getSize() &&
+            isCFIBoundedTailPredecessor(Function, *CFIRdWrt)) {
+          ++NextSymRefI;
+          continue;
+        }
         LLVM_DEBUG(dbgs() << "BOLT-DEBUG: adding entry point to function "
                           << Function << " at offset 0x"
                           << Twine::utohexstr(EntryOffset) << '\n');
diff --git a/bolt/test/AArch64/entry-point-at-function-end.s b/bolt/test/AArch64/entry-point-at-function-end.s
index f657e9e522036..5dbaf0bff1ec4 100644
--- a/bolt/test/AArch64/entry-point-at-function-end.s
+++ b/bolt/test/AArch64/entry-point-at-function-end.s
@@ -1,85 +1,76 @@
-## Test that BOLT correctly handles entry points at exact FDE boundaries.
-##
-## This test simulates a real-world scenario where:
-## 1. A large function (big_func) contains an FDE with no symbol
-## 2. The FDE covers a sub-function within big_func [fde_start, fde_end)
-## 3. Inlined code follows immediately after the FDE (no symbol, no FDE)
-## 4. .init branches to exactly the FDE end address via section relocation
-##
-## Without the fix, getOrCreateLocalLabel() would return getFunctionEndLabel()
-## when offset == FDE size. The fix ensures a proper entry point label is created.
-##
+## Promote unmarked code after a CFI-bounded predecessor into __BOLT_UNMARKED_TAIL.
+## Covers:
+##   1) FDE-only region (no symtab entry; BOLT names it __BOLT_FDE_FUNC* or .text/N)
+##   2) Named function (FDE range == symbol size) -> named_sub + tail
+## Caller is in a separate section; -Wl,-q keeps PC-relative relocs on the bl.
 
 # RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
-# RUN: %clang %cflags %t.o -pie -Wl,-q -Wl,--init=_init -o %t.exe
+# RUN: %clang %cflags %t.o -pie -Wl,-q -o %t.exe
 # RUN: llvm-bolt %t.exe -o %t.bolt --print-disasm -v=1 2>&1 | FileCheck %s
 
-## The FDE-only function should get an entry point for the inlined code
-# CHECK: BOLT-WARNING: FDE {{.*}} has no corresponding symbol table entry
-# CHECK: Binary Function "{{.*}}__BOLT_FDE_FUNC{{.*}}" after disassembly
+# CHECK: Binary Function "{{(__BOLT_FDE_FUNC.*|\.text/[0-9]+)}}" after disassembly
 # CHECK: Size        : 0x14
-# CHECK: MaxSize     : 0x1c
-# CHECK: IsMultiEntry: 1
+# CHECK: MaxSize     : 0x14
+# CHECK: Binary Function "{{.*}}__BOLT_UNMARKED_TAIL{{.*}}" after disassembly
+# CHECK: Size        : 0x8
+# CHECK: MaxSize     : 0x8
 
-## _init function in .init section
-	.section .init,"ax", at progbits
-	.globl	_init
-	.type	_init, %function
-_init:
-	.cfi_startproc
-	stp	x29, x30, [sp, #-16]!
-	mov	x29, sp
-	## Branch to inlined code that's right after FDE end
-	## Linker converts this to: R_AARCH64_CALL26 .text + offset
-	bl	.Linlined_code
-	ldp	x29, x30, [sp], #16
-	ret
-	.cfi_endproc
-	.size	_init, .-_init
+# CHECK: Binary Function "named_sub" after disassembly
+# CHECK: Size        : 0x14
+# CHECK: MaxSize     : 0x14
+# CHECK: Binary Function "{{.*}}__BOLT_UNMARKED_TAIL{{.*}}" after disassembly
+# CHECK: Size        : 0x10
+# CHECK: MaxSize     : 0x10
+
+# CHECK-COUNT-2: bl	__BOLT_UNMARKED_TAILat{{.*}}
 
-## Main code in .text section
-	.text
+	.section	.text.fdeonly,"ax", at progbits
 
-## Large function that contains the FDE and inlined code
-	.globl	big_func
-	.type	big_func, %function
-big_func:
+## Scenario 1: FDE-only predecessor (no symbol table entry).
+.Lfde_sub:
 	.cfi_startproc
 	stp	x29, x30, [sp, #-16]!
 	mov	x29, sp
-	mov	w0, #1
-	add	w0, w0, #1
+	mov	w0, #42
 	ldp	x29, x30, [sp], #16
 	ret
 	.cfi_endproc
-	.size	big_func, .-big_func
 
-## FDE-covered code WITHOUT a symbol - simulates sub-function within big_func
-## This has its own FDE but no symbol in the symbol table
-.Lfde_start:
+.Ltail_after_fde:
+	nop
+	ret
+
+	.section	.text.named,"ax", at progbits
+
+## Scenario 2: named predecessor (FDE address range matches .size).
+	.globl	named_sub
+	.type	named_sub, %function
+named_sub:
 	.cfi_startproc
 	stp	x29, x30, [sp, #-16]!
 	mov	x29, sp
-	mov	w0, #42
+	mov	w0, #7
 	ldp	x29, x30, [sp], #16
 	ret
 	.cfi_endproc
-## FDE ends here - inlined code follows immediately
+	.size	named_sub, .-named_sub
 
-## Inlined code at exactly FDE end (offset == FDE size)
-## _init branches here - this is what triggers the bug without the fix
-.Linlined_code:
-	nop
+.Ltail_after_named:
+	mov	x0, x0
+	mov	w1, #7
+	add	w0, w0, w1
 	ret
 
+	.section	.text.entry,"ax", at progbits
+
 	.globl	_start
 	.type	_start, %function
 _start:
 	.cfi_startproc
 	stp	x29, x30, [sp, #-16]!
 	mov	x29, sp
-	bl	_init
-	bl	big_func
+	bl	.Ltail_after_fde
+	bl	.Ltail_after_named
 	ldp	x29, x30, [sp], #16
 	mov	w0, #0
 	ret

>From fabea67812d145675d624103b27776990c4221b2 Mon Sep 17 00:00:00 2001
From: Elvina Yakubova <eyakubova at nvidia.com>
Date: Fri, 29 May 2026 16:47:31 +0530
Subject: [PATCH 4/4] clang format

---
 bolt/include/bolt/Rewrite/RewriteInstance.h |  4 ++--
 bolt/lib/Rewrite/RewriteInstance.cpp        | 14 ++++++--------
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/bolt/include/bolt/Rewrite/RewriteInstance.h b/bolt/include/bolt/Rewrite/RewriteInstance.h
index 6586e4320c7d9..0922315afc790 100644
--- a/bolt/include/bolt/Rewrite/RewriteInstance.h
+++ b/bolt/include/bolt/Rewrite/RewriteInstance.h
@@ -273,8 +273,8 @@ class RewriteInstance {
   /// Promote unmarked executable regions after CFI-bounded functions into
   /// separate BinaryFunction objects (__BOLT_FDE_FUNC* or named symbols
   /// whose FDE range matches their size).
-  void splitUnmarkedTailFunctions(
-      DenseMap<uint64_t, MarkerSymType> &MarkerSyms);
+  void
+  splitUnmarkedTailFunctions(DenseMap<uint64_t, MarkerSymType> &MarkerSyms);
 
   /// Make .eh_frame section relocatable.
   void relocateEHFrameSection();
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 21fcb2a0e0d9a..40dd96d14e3ae 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -2093,12 +2093,10 @@ bool hasDataMarkerAt(DenseMap<uint64_t, MarkerSymType> &MarkerSyms,
 /// Disassemble a prefix of [TailStart, TailStart + TrailingExtent) and return
 /// its length. Any remaining bytes in the range must be zero padding.
 /// Returns 0 if the region is not valid unmarked code.
-static uint64_t measureAArch64UnmarkedTail(BinaryContext &BC,
-                                             const BinaryFunction &Pred,
-                                             DenseMap<uint64_t, MarkerSymType>
-                                                 &MarkerSyms,
-                                             uint64_t TailStart,
-                                             uint64_t TrailingExtent) {
+static uint64_t
+measureAArch64UnmarkedTail(BinaryContext &BC, const BinaryFunction &Pred,
+                           DenseMap<uint64_t, MarkerSymType> &MarkerSyms,
+                           uint64_t TailStart, uint64_t TrailingExtent) {
   // Pred was registered from an executable section during symbol/FDE discovery.
   BinarySection &Section = *Pred.getOriginSection();
 
@@ -2122,8 +2120,8 @@ static uint64_t measureAArch64UnmarkedTail(BinaryContext &BC,
     MCInst Inst;
     uint64_t Size = 0;
     ArrayRef<uint8_t> Slice(Bytes + CodeLen, TrailingExtent - CodeLen);
-    if (!BC.SymbolicDisAsm->getInstruction(Inst, Size, Slice, TailStart + CodeLen,
-                                           nulls()) ||
+    if (!BC.SymbolicDisAsm->getInstruction(Inst, Size, Slice,
+                                           TailStart + CodeLen, nulls()) ||
         !Size)
       break;
     CodeLen += Size;



More information about the llvm-commits mailing list