mirror of
https://github.com/intel/llvm.git
synced 2026-01-13 11:02:04 +08:00
[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:
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user