[llvm] [BOLT] Emit bolt-synthetic FILE symbol (PR #89794)
Amir Ayupov via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 23 09:50:59 PDT 2024
https://github.com/aaupov created https://github.com/llvm/llvm-project/pull/89794
Follow-up to https://github.com/llvm/llvm-project/pull/89648.
Emit a FILE symbol to distinguish BOLT-created local symbols for split
functions, to prevent polluting the namespace of the last file symbol.
Test Plan: Updated cdsplit-symbol-names.s
>From 6d621e9d0b51fe21d8c1fc2c953242d788452579 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Tue, 23 Apr 2024 09:48:12 -0700
Subject: [PATCH] [BOLT] Emit bolt-synthetic FILE symbol
Follow-up to https://github.com/llvm/llvm-project/pull/89648.
Emit a FILE symbol to distinguish BOLT-created local symbols for split
functions, to prevent polluting the namespace of the last file symbol.
Test Plan: Updated cdsplit-symbol-names.s
---
bolt/lib/Rewrite/RewriteInstance.cpp | 11 +++++++++++
bolt/test/X86/cdsplit-symbol-names.s | 1 +
2 files changed, 12 insertions(+)
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 4e0096cf988aed..edd2dacfb70e4a 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -4493,6 +4493,17 @@ void RewriteInstance::updateELFSymbolTable(
// Symbols for the new symbol table.
std::vector<ELFSymTy> Symbols;
+ // Prepend synthetic FILE symbol to prevent local cold fragments from
+ // colliding with existing symbols with the same name.
+ ELFSymTy FileSymbol;
+ FileSymbol.st_shndx =
+ BC->getUniqueSectionByName(BC->getColdCodeSectionName())->getIndex();
+ FileSymbol.st_name = AddToStrTab("bolt-synthetic");
+ FileSymbol.st_value = 0;
+ FileSymbol.st_size = 0;
+ FileSymbol.setBindingAndType(ELF::STB_LOCAL, ELF::STT_FILE);
+ Symbols.emplace_back(FileSymbol);
+
auto getNewSectionIndex = [&](uint32_t OldIndex) {
// For dynamic symbol table, the section index could be wrong on the input,
// and its value is ignored by the runtime if it's different from
diff --git a/bolt/test/X86/cdsplit-symbol-names.s b/bolt/test/X86/cdsplit-symbol-names.s
index e2259276e2554c..e6e686a381e14a 100644
--- a/bolt/test/X86/cdsplit-symbol-names.s
+++ b/bolt/test/X86/cdsplit-symbol-names.s
@@ -10,6 +10,7 @@
# RUN: --call-scale=2 --data=%t.fdata --reorder-blocks=ext-tsp
# RUN: llvm-objdump --syms %t.bolt | FileCheck %s --check-prefix=CHECK-SYMS-WARM
+# CHECK-SYMS-WARM: [[#%X,VALUE:0]] l df *ABS* [[#%X,SIZE:0]] bolt-synthetic
# CHECK-SYMS-WARM: .text.warm
# CHECK-SYMS-WARM-SAME: chain.warm
# CHECK-SYMS-WARM: .text.cold
More information about the llvm-commits
mailing list