[BOLT] Refactor undefined symbols handling. NFCI (#167075)

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.
This commit is contained in:
Maksim Panchenko
2025-11-07 19:42:05 -08:00
committed by GitHub
parent ad7488a941
commit 7af2b56dd5
3 changed files with 4 additions and 23 deletions

View File

@@ -354,9 +354,6 @@ public:
/// 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;

View File

@@ -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() {

View File

@@ -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))