Skip to content

Commit

Permalink
[BOLT] Don't allow non-symbol targets in ICP
Browse files Browse the repository at this point in the history
Summary:
ICP was letting through call targets that weren't symbols.  This diff
filters out the non-symbol targets before running ICP.

(cherry picked from FBD4735358)
  • Loading branch information
Bill Nell authored and maksfb committed Mar 18, 2017
1 parent e6f96de commit b1ef186
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions bolt/Passes/BinaryPasses.cpp
Expand Up @@ -1092,6 +1092,14 @@ std::vector<BranchInfo> IndirectCallPromotion::getCallTargets(
return A.Branches > B.Branches;
});

// Remove non-symbol targets
auto Last = std::remove_if(Targets.begin(),
Targets.end(),
[](const BranchInfo &BI) {
return !BI.To.IsSymbol;
});
Targets.erase(Last, Targets.end());

return Targets;
}

Expand All @@ -1104,20 +1112,15 @@ IndirectCallPromotion::findCallTargetSymbols(
std::vector<std::pair<MCSymbol *, uint64_t>> SymTargets;

for (size_t I = 0; I < N; ++I) {
MCSymbol* Symbol = nullptr;
uint64_t Addr = 0;
if (Targets[I].To.IsSymbol) {
auto itr = BC.GlobalSymbols.find(Targets[I].To.Name);
if (itr == BC.GlobalSymbols.end()) {
// punt if we can't find a symbol.
break;
}
Symbol = BC.getOrCreateGlobalSymbol(itr->second, "FUNCat");
assert(Symbol);
} else {
Addr = Targets[I].To.Offset;
assert(Targets[I].To.IsSymbol && "All ICP targets must be symbols.");
auto Itr = BC.GlobalSymbols.find(Targets[I].To.Name);
if (Itr == BC.GlobalSymbols.end()) {
// punt if we can't find a symbol.
break;
}
SymTargets.push_back(std::make_pair(Symbol, Addr));
MCSymbol* Symbol = BC.getOrCreateGlobalSymbol(Itr->second, "FUNCat");
assert(Symbol && "All ICP targets must be known symbols.");
SymTargets.push_back(std::make_pair(Symbol, 0));
}

return SymTargets;
Expand Down

0 comments on commit b1ef186

Please sign in to comment.