Skip to content

Commit 7af2b56

Browse files
authored
[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.
1 parent ad7488a commit 7af2b56

File tree

3 files changed

+4
-23
lines changed

3 files changed

+4
-23
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,6 @@ class BinaryContext {
354354
/// Newly created segments.
355355
std::vector<SegmentInfo> NewSegments;
356356

357-
/// Symbols that are expected to be undefined in MCContext during emission.
358-
std::unordered_set<MCSymbol *> UndefinedSymbols;
359-
360357
/// [name] -> [BinaryData*] map used for global symbol resolution.
361358
using SymbolMapType = StringMap<BinaryData *>;
362359
SymbolMapType GlobalSymbols;

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,16 +1896,6 @@ bool BinaryFunction::scanExternalRefs() {
18961896
}
18971897
}
18981898

1899-
// Inform BinaryContext that this function symbols will not be defined and
1900-
// relocations should not be created against them.
1901-
if (BC.HasRelocations) {
1902-
for (std::pair<const uint32_t, MCSymbol *> &LI : Labels)
1903-
BC.UndefinedSymbols.insert(LI.second);
1904-
for (MCSymbol *const EndLabel : FunctionEndLabels)
1905-
if (EndLabel)
1906-
BC.UndefinedSymbols.insert(EndLabel);
1907-
}
1908-
19091899
clearList(Relocations);
19101900
clearList(ExternallyReferencedOffsets);
19111901

@@ -3234,14 +3224,6 @@ void BinaryFunction::clearDisasmState() {
32343224
clearList(Instructions);
32353225
clearList(IgnoredBranches);
32363226
clearList(TakenBranches);
3237-
3238-
if (BC.HasRelocations) {
3239-
for (std::pair<const uint32_t, MCSymbol *> &LI : Labels)
3240-
BC.UndefinedSymbols.insert(LI.second);
3241-
for (MCSymbol *const EndLabel : FunctionEndLabels)
3242-
if (EndLabel)
3243-
BC.UndefinedSymbols.insert(EndLabel);
3244-
}
32453227
}
32463228

32473229
void BinaryFunction::setTrapOnEntry() {

bolt/lib/Core/BinarySection.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ void BinarySection::emitAsData(MCStreamer &Streamer,
112112
RI = ROE;
113113

114114
// Skip undefined symbols.
115-
auto HasUndefSym = [this](const auto &Relocation) {
116-
return BC.UndefinedSymbols.count(Relocation.Symbol);
115+
auto HasUndefSym = [](const auto &Relocation) {
116+
return Relocation.Symbol && Relocation.Symbol->isTemporary() &&
117+
Relocation.Symbol->isUndefined() &&
118+
!Relocation.Symbol->isRegistered();
117119
};
118120

119121
if (std::any_of(ROI, ROE, HasUndefSym))

0 commit comments

Comments
 (0)