[llvm] [BOLT] Exclude BOLT injected functions from AssignSections. NFCI (PR #171579)

Maksim Panchenko via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 10 00:29:32 PST 2025


https://github.com/maksfb created https://github.com/llvm/llvm-project/pull/171579

Assign output sections for injected functions explicitly, and don't reassign in AssignSections pass.

This change is a prerequisite for further PRs where veneer functions are created as injected functions and their code section depends on their placement.

>From 7517a14ed0e927064625eb8c0e33a96e1d588cf1 Mon Sep 17 00:00:00 2001
From: Maksim Panchenko <maks at fb.com>
Date: Tue, 9 Dec 2025 21:04:38 -0800
Subject: [PATCH] [BOLT] Exclude BOLT injected functions from AssignSections.
 NFCI

Assign output sections for injected functions explicitly, and don't
reassign in AssignSections pass.

This change is a prerequisite for further PRs where veneer functions are
created as injected functions and their code section depends on their
placement.
---
 bolt/include/bolt/Core/BinaryFunction.h | 7 ++++---
 bolt/lib/Core/BinaryContext.cpp         | 4 ++++
 bolt/lib/Passes/BinaryPasses.cpp        | 7 -------
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h
index 5b147b23eccf4..4493d0c5f7872 100644
--- a/bolt/include/bolt/Core/BinaryFunction.h
+++ b/bolt/include/bolt/Core/BinaryFunction.h
@@ -735,11 +735,12 @@ class BinaryFunction {
     Symbols.push_back(BC.Ctx->getOrCreateSymbol(Name));
   }
 
-  /// This constructor is used to create an injected function
+  /// This constructor is used to create an injected function, i.e. a function
+  /// that didn't originate in the input file.
   BinaryFunction(const std::string &Name, BinaryContext &BC, bool IsSimple)
       : Address(0), Size(0), BC(BC), IsSimple(IsSimple),
-        CodeSectionName(buildCodeSectionName(Name, BC)),
-        ColdCodeSectionName(buildColdCodeSectionName(Name, BC)),
+        CodeSectionName(BC.getInjectedCodeSectionName()),
+        ColdCodeSectionName(BC.getInjectedColdCodeSectionName()),
         FunctionNumber(++Count) {
     Symbols.push_back(BC.Ctx->getOrCreateSymbol(Name));
     IsInjected = true;
diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp
index b06eee2f415a7..a980ef7b99c3f 100644
--- a/bolt/lib/Core/BinaryContext.cpp
+++ b/bolt/lib/Core/BinaryContext.cpp
@@ -2598,6 +2598,10 @@ BinaryContext::createInstructionPatch(uint64_t Address,
   PBF->addBasicBlock()->addInstructions(Instructions);
   PBF->setIsPatch(true);
 
+  // Patch functions have to be emitted each into their unique section.
+  PBF->setCodeSectionName(
+      BinaryFunction::buildCodeSectionName(PBF->getOneName(), *this));
+
   // Don't create symbol table entry if the name wasn't specified.
   if (Name.str().empty())
     PBF->setAnonymous(true);
diff --git a/bolt/lib/Passes/BinaryPasses.cpp b/bolt/lib/Passes/BinaryPasses.cpp
index 1d187de11c35e..144cbc573ed00 100644
--- a/bolt/lib/Passes/BinaryPasses.cpp
+++ b/bolt/lib/Passes/BinaryPasses.cpp
@@ -1276,13 +1276,6 @@ Error SimplifyRODataLoads::runOnFunctions(BinaryContext &BC) {
 }
 
 Error AssignSections::runOnFunctions(BinaryContext &BC) {
-  for (BinaryFunction *Function : BC.getInjectedBinaryFunctions()) {
-    if (!Function->isPatch()) {
-      Function->setCodeSectionName(BC.getInjectedCodeSectionName());
-      Function->setColdCodeSectionName(BC.getInjectedColdCodeSectionName());
-    }
-  }
-
   // In non-relocation mode functions have pre-assigned section names.
   if (!BC.HasRelocations)
     return Error::success();



More information about the llvm-commits mailing list