[llvm] [BOLT] Refactor undefined symbols handling. NFCI (PR #167075)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 7 18:45:00 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-bolt
Author: Maksim Panchenko (maksfb)
<details>
<summary>Changes</summary>
Remove internal undefined symbol tracking and instead rely on the emission state of `MCSymbol` while processing data-to-code relocations.
Note that `CleanMCState` pass resets the state of all `MCSymbol`s prior to code emission.
---
Full diff: https://github.com/llvm/llvm-project/pull/167075.diff
3 Files Affected:
- (modified) bolt/include/bolt/Core/BinaryContext.h (-3)
- (modified) bolt/lib/Core/BinaryFunction.cpp (-18)
- (modified) bolt/lib/Core/BinarySection.cpp (+4-2)
``````````diff
diff --git a/bolt/include/bolt/Core/BinaryContext.h b/bolt/include/bolt/Core/BinaryContext.h
index 085c0265de3ed..57d4515bf8325 100644
--- a/bolt/include/bolt/Core/BinaryContext.h
+++ b/bolt/include/bolt/Core/BinaryContext.h
@@ -354,9 +354,6 @@ class BinaryContext {
/// Newly created segments.
std::vector<SegmentInfo> NewSegments;
- /// Symbols that are expected to be undefined in MCContext during emission.
- std::unordered_set<MCSymbol *> UndefinedSymbols;
-
/// [name] -> [BinaryData*] map used for global symbol resolution.
using SymbolMapType = StringMap<BinaryData *>;
SymbolMapType GlobalSymbols;
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index ddaad6eef6140..2fd1ab13008b7 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -1896,16 +1896,6 @@ bool BinaryFunction::scanExternalRefs() {
}
}
- // Inform BinaryContext that this function symbols will not be defined and
- // relocations should not be created against them.
- if (BC.HasRelocations) {
- for (std::pair<const uint32_t, MCSymbol *> &LI : Labels)
- BC.UndefinedSymbols.insert(LI.second);
- for (MCSymbol *const EndLabel : FunctionEndLabels)
- if (EndLabel)
- BC.UndefinedSymbols.insert(EndLabel);
- }
-
clearList(Relocations);
clearList(ExternallyReferencedOffsets);
@@ -3234,14 +3224,6 @@ void BinaryFunction::clearDisasmState() {
clearList(Instructions);
clearList(IgnoredBranches);
clearList(TakenBranches);
-
- if (BC.HasRelocations) {
- for (std::pair<const uint32_t, MCSymbol *> &LI : Labels)
- BC.UndefinedSymbols.insert(LI.second);
- for (MCSymbol *const EndLabel : FunctionEndLabels)
- if (EndLabel)
- BC.UndefinedSymbols.insert(EndLabel);
- }
}
void BinaryFunction::setTrapOnEntry() {
diff --git a/bolt/lib/Core/BinarySection.cpp b/bolt/lib/Core/BinarySection.cpp
index 6f07017c26060..e803d17021f8b 100644
--- a/bolt/lib/Core/BinarySection.cpp
+++ b/bolt/lib/Core/BinarySection.cpp
@@ -112,8 +112,10 @@ void BinarySection::emitAsData(MCStreamer &Streamer,
RI = ROE;
// Skip undefined symbols.
- auto HasUndefSym = [this](const auto &Relocation) {
- return BC.UndefinedSymbols.count(Relocation.Symbol);
+ auto HasUndefSym = [](const auto &Relocation) {
+ return Relocation.Symbol && Relocation.Symbol->isTemporary() &&
+ Relocation.Symbol->isUndefined() &&
+ !Relocation.Symbol->isRegistered();
};
if (std::any_of(ROI, ROE, HasUndefSym))
``````````
</details>
https://github.com/llvm/llvm-project/pull/167075
More information about the llvm-commits
mailing list