forked from OSchip/llvm-project
[BOLT][NFC] Minor code refactoring
(cherry picked from FBD8882632)
This commit is contained in:
parent
49920a8fad
commit
771d976543
|
@ -644,7 +644,7 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation,
|
||||||
void BinaryFunction::printRelocations(raw_ostream &OS,
|
void BinaryFunction::printRelocations(raw_ostream &OS,
|
||||||
uint64_t Offset,
|
uint64_t Offset,
|
||||||
uint64_t Size) const {
|
uint64_t Size) const {
|
||||||
const char* Sep = " # Relocs: ";
|
const char *Sep = " # Relocs: ";
|
||||||
|
|
||||||
auto RI = Relocations.lower_bound(Offset);
|
auto RI = Relocations.lower_bound(Offset);
|
||||||
while (RI != Relocations.end() && RI->first < Offset + Size) {
|
while (RI != Relocations.end() && RI->first < Offset + Size) {
|
||||||
|
|
|
@ -325,7 +325,7 @@ void ValidateInternalCalls::runOnFunctions(
|
||||||
// case, we mark this function as non-simple and stop processing it.
|
// case, we mark this function as non-simple and stop processing it.
|
||||||
std::set<BinaryFunction *> Invalid;
|
std::set<BinaryFunction *> Invalid;
|
||||||
for (auto *Function : NeedsValidation) {
|
for (auto *Function : NeedsValidation) {
|
||||||
DEBUG(dbgs() << "Validating " << Function << "\n");
|
DEBUG(dbgs() << "Validating " << *Function << "\n");
|
||||||
if (!analyzeFunction(*Function)) {
|
if (!analyzeFunction(*Function)) {
|
||||||
Invalid.insert(Function);
|
Invalid.insert(Function);
|
||||||
}
|
}
|
||||||
|
@ -336,7 +336,7 @@ void ValidateInternalCalls::runOnFunctions(
|
||||||
errs() << "BOLT-ERROR: Unsupported internal calls detected in the "
|
errs() << "BOLT-ERROR: Unsupported internal calls detected in the "
|
||||||
"following functions:\n";
|
"following functions:\n";
|
||||||
for (auto *Function : Invalid) {
|
for (auto *Function : Invalid) {
|
||||||
errs() << " " << Function << "\n";
|
errs() << " " << *Function << "\n";
|
||||||
}
|
}
|
||||||
errs() << "BOLT-ERROR: Unable to proceed in relocation mode\n";
|
errs() << "BOLT-ERROR: Unable to proceed in relocation mode\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
|
@ -2030,8 +2030,7 @@ void RewriteInstance::readRelocations(const SectionRef &Section) {
|
||||||
auto Section = BC->getSectionForAddress(SymbolAddress);
|
auto Section = BC->getSectionForAddress(SymbolAddress);
|
||||||
dbgs() << "Relocation: offset = 0x"
|
dbgs() << "Relocation: offset = 0x"
|
||||||
<< Twine::utohexstr(Rel.getOffset())
|
<< Twine::utohexstr(Rel.getOffset())
|
||||||
<< "; type = " << Rel.getType()
|
<< "; type = " << TypeName
|
||||||
<< "; type name = " << TypeName
|
|
||||||
<< "; value = 0x" << Twine::utohexstr(ExtractedValue)
|
<< "; value = 0x" << Twine::utohexstr(ExtractedValue)
|
||||||
<< "; symbol = " << SymbolName
|
<< "; symbol = " << SymbolName
|
||||||
<< " (" << (Section ? Section->getName() : "") << ")"
|
<< " (" << (Section ? Section->getName() : "") << ")"
|
||||||
|
@ -2071,13 +2070,6 @@ void RewriteInstance::readRelocations(const SectionRef &Section) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto Address = SymbolAddress + Addend;
|
const auto Address = SymbolAddress + Addend;
|
||||||
const bool ForceRelocation =
|
|
||||||
(opts::HotText && (SymbolName == "__hot_start" ||
|
|
||||||
SymbolName == "__hot_end")) ||
|
|
||||||
(opts::HotData && (SymbolName == "__hot_data_start" ||
|
|
||||||
SymbolName == "__hot_data_end")) ||
|
|
||||||
SymbolName == "_end" ||
|
|
||||||
Rel.getType() == ELF::R_AARCH64_ADR_GOT_PAGE;
|
|
||||||
|
|
||||||
DEBUG(
|
DEBUG(
|
||||||
dbgs() << "BOLT-DEBUG: ";
|
dbgs() << "BOLT-DEBUG: ";
|
||||||
|
@ -2116,6 +2108,24 @@ void RewriteInstance::readRelocations(const SectionRef &Section) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto ForceRelocation = [&](StringRef SymbolName) {
|
||||||
|
if (opts::HotText && (SymbolName == "__hot_start" ||
|
||||||
|
SymbolName == "__hot_end"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (opts::HotData && (SymbolName == "__hot_data_start" ||
|
||||||
|
SymbolName == "__hot_data_end"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (SymbolName == "_end")
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}(SymbolName);
|
||||||
|
|
||||||
|
if (BC->isAArch64() && Rel.getType() == ELF::R_AARCH64_ADR_GOT_PAGE)
|
||||||
|
ForceRelocation = true;
|
||||||
|
|
||||||
// TODO: RefSection should be the same as **Rel.getSymbol().getSection()
|
// TODO: RefSection should be the same as **Rel.getSymbol().getSection()
|
||||||
auto RefSection = BC->getSectionForAddress(SymbolAddress);
|
auto RefSection = BC->getSectionForAddress(SymbolAddress);
|
||||||
if (!RefSection && !ForceRelocation) {
|
if (!RefSection && !ForceRelocation) {
|
||||||
|
@ -2163,9 +2173,8 @@ void RewriteInstance::readRelocations(const SectionRef &Section) {
|
||||||
ReferencedSymbol = BC->registerNameAtAddress(Name, 0, 0, 0);
|
ReferencedSymbol = BC->registerNameAtAddress(Name, 0, 0, 0);
|
||||||
SymbolAddress = 0;
|
SymbolAddress = 0;
|
||||||
Addend = Address;
|
Addend = Address;
|
||||||
DEBUG(dbgs() << "BOLT-DEBUG: creating relocations for huge pages against"
|
DEBUG(dbgs() << "BOLT-DEBUG: forcing relocation against symbol "
|
||||||
" symbol " << SymbolName << " with addend " << Addend
|
<< SymbolName << " with addend " << Addend << '\n');
|
||||||
<< '\n');
|
|
||||||
} else if (ReferencedBF) {
|
} else if (ReferencedBF) {
|
||||||
ReferencedSymbol = ReferencedBF->getSymbol();
|
ReferencedSymbol = ReferencedBF->getSymbol();
|
||||||
|
|
||||||
|
@ -2357,10 +2366,15 @@ void RewriteInstance::readRelocations(const SectionRef &Section) {
|
||||||
NumDataRelocations < opts::MaxDataRelocations);
|
NumDataRelocations < opts::MaxDataRelocations);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (IsFromCode && IsAArch64)
|
||||||
|
ForceRelocation = true;
|
||||||
|
|
||||||
|
if (refersToReorderedSection(RefSection) ||
|
||||||
|
(opts::ForceToDataRelocations && checkMaxDataRelocations()))
|
||||||
|
ForceRelocation = true;
|
||||||
|
|
||||||
if (IsFromCode) {
|
if (IsFromCode) {
|
||||||
if (ReferencedBF || ForceRelocation || IsAArch64 ||
|
if (ReferencedBF || ForceRelocation) {
|
||||||
refersToReorderedSection(RefSection) ||
|
|
||||||
(opts::ForceToDataRelocations && checkMaxDataRelocations())) {
|
|
||||||
ContainingBF->addRelocation(Rel.getOffset(),
|
ContainingBF->addRelocation(Rel.getOffset(),
|
||||||
ReferencedSymbol,
|
ReferencedSymbol,
|
||||||
Rel.getType(),
|
Rel.getType(),
|
||||||
|
@ -2370,11 +2384,7 @@ void RewriteInstance::readRelocations(const SectionRef &Section) {
|
||||||
DEBUG(dbgs() << "BOLT-DEBUG: ignoring relocation from code to data "
|
DEBUG(dbgs() << "BOLT-DEBUG: ignoring relocation from code to data "
|
||||||
<< ReferencedSymbol->getName() << "\n");
|
<< ReferencedSymbol->getName() << "\n");
|
||||||
}
|
}
|
||||||
} else if (IsToCode) {
|
} else if (IsToCode || ForceRelocation) {
|
||||||
BC->addRelocation(Rel.getOffset(), ReferencedSymbol, Rel.getType(),
|
|
||||||
Addend);
|
|
||||||
} else if (refersToReorderedSection(RefSection) ||
|
|
||||||
(opts::ForceToDataRelocations && checkMaxDataRelocations())) {
|
|
||||||
BC->addRelocation(Rel.getOffset(),
|
BC->addRelocation(Rel.getOffset(),
|
||||||
ReferencedSymbol,
|
ReferencedSymbol,
|
||||||
Rel.getType(),
|
Rel.getType(),
|
||||||
|
|
Loading…
Reference in New Issue