Skip to content

Commit 6d621e9

Browse files
committed
[BOLT] Emit bolt-synthetic FILE symbol
Follow-up to llvm#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
1 parent 23d88a8 commit 6d621e9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4493,6 +4493,17 @@ void RewriteInstance::updateELFSymbolTable(
44934493
// Symbols for the new symbol table.
44944494
std::vector<ELFSymTy> Symbols;
44954495

4496+
// Prepend synthetic FILE symbol to prevent local cold fragments from
4497+
// colliding with existing symbols with the same name.
4498+
ELFSymTy FileSymbol;
4499+
FileSymbol.st_shndx =
4500+
BC->getUniqueSectionByName(BC->getColdCodeSectionName())->getIndex();
4501+
FileSymbol.st_name = AddToStrTab("bolt-synthetic");
4502+
FileSymbol.st_value = 0;
4503+
FileSymbol.st_size = 0;
4504+
FileSymbol.setBindingAndType(ELF::STB_LOCAL, ELF::STT_FILE);
4505+
Symbols.emplace_back(FileSymbol);
4506+
44964507
auto getNewSectionIndex = [&](uint32_t OldIndex) {
44974508
// For dynamic symbol table, the section index could be wrong on the input,
44984509
// and its value is ignored by the runtime if it's different from

bolt/test/X86/cdsplit-symbol-names.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# RUN: --call-scale=2 --data=%t.fdata --reorder-blocks=ext-tsp
1111
# RUN: llvm-objdump --syms %t.bolt | FileCheck %s --check-prefix=CHECK-SYMS-WARM
1212

13+
# CHECK-SYMS-WARM: [[#%X,VALUE:0]] l df *ABS* [[#%X,SIZE:0]] bolt-synthetic
1314
# CHECK-SYMS-WARM: .text.warm
1415
# CHECK-SYMS-WARM-SAME: chain.warm
1516
# CHECK-SYMS-WARM: .text.cold

0 commit comments

Comments
 (0)