forked from OSchip/llvm-project
[BOLT] Fix out-of-bounds entry points
Summary: Check that a symbol address is less than the next function address before considering it for a secondary entry. (cherry picked from FBD16056468)
This commit is contained in:
parent
e89ad0db4b
commit
078ece1691
|
@ -1685,6 +1685,9 @@ void RewriteInstance::adjustFunctionBoundaries() {
|
||||||
BFE = BC->getBinaryFunctions().end();
|
BFE = BC->getBinaryFunctions().end();
|
||||||
BFI != BFE; ++BFI) {
|
BFI != BFE; ++BFI) {
|
||||||
auto &Function = BFI->second;
|
auto &Function = BFI->second;
|
||||||
|
const BinaryFunction *NextFunction{nullptr};
|
||||||
|
if (std::next(BFI) != BFE)
|
||||||
|
NextFunction = &std::next(BFI)->second;
|
||||||
|
|
||||||
// Check if it's a fragment of a function.
|
// Check if it's a fragment of a function.
|
||||||
const auto *FragName = Function.hasNameRegex(".*\\.cold\\..*");
|
const auto *FragName = Function.hasNameRegex(".*\\.cold\\..*");
|
||||||
|
@ -1710,7 +1713,11 @@ void RewriteInstance::adjustFunctionBoundaries() {
|
||||||
auto NextSymRefI = FileSymRefs.upper_bound(Function.getAddress());
|
auto NextSymRefI = FileSymRefs.upper_bound(Function.getAddress());
|
||||||
while (NextSymRefI != FileSymRefs.end()) {
|
while (NextSymRefI != FileSymRefs.end()) {
|
||||||
auto &Symbol = NextSymRefI->second;
|
auto &Symbol = NextSymRefI->second;
|
||||||
auto SymbolSize = ELFSymbolRef(Symbol).getSize();
|
const auto SymbolAddress = NextSymRefI->first;
|
||||||
|
const auto SymbolSize = ELFSymbolRef(Symbol).getSize();
|
||||||
|
|
||||||
|
if (NextFunction && SymbolAddress >= NextFunction->getAddress())
|
||||||
|
break;
|
||||||
|
|
||||||
if (!Function.isSymbolValidInScope(Symbol, SymbolSize))
|
if (!Function.isSymbolValidInScope(Symbol, SymbolSize))
|
||||||
break;
|
break;
|
||||||
|
@ -1736,9 +1743,8 @@ void RewriteInstance::adjustFunctionBoundaries() {
|
||||||
NextObjectAddress = std::min(NextSymRefI->first, NextObjectAddress);
|
NextObjectAddress = std::min(NextSymRefI->first, NextObjectAddress);
|
||||||
}
|
}
|
||||||
// Or till the next function not marked by a symbol.
|
// Or till the next function not marked by a symbol.
|
||||||
if (std::next(BFI) != BFE) {
|
if (NextFunction) {
|
||||||
const auto &NextFunction = std::next(BFI)->second;
|
NextObjectAddress = std::min(NextFunction->getAddress(),
|
||||||
NextObjectAddress = std::min(NextFunction.getAddress(),
|
|
||||||
NextObjectAddress);
|
NextObjectAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue