forked from OSchip/llvm-project
[BOLT] Support -hot-text in lite mode
Summary: Update special symbol references in functions that are not emitted. (cherry picked from FBD22120995)
This commit is contained in:
parent
e7c3464226
commit
db4642d0a6
|
@ -40,6 +40,8 @@ namespace opts {
|
|||
extern cl::OptionCategory BoltCategory;
|
||||
|
||||
extern cl::opt<bool> AggregateOnly;
|
||||
extern cl::opt<bool> HotText;
|
||||
extern cl::opt<bool> HotData;
|
||||
extern cl::opt<bool> StrictMode;
|
||||
extern cl::opt<bool> UseOldText;
|
||||
extern cl::opt<unsigned> Verbosity;
|
||||
|
@ -279,6 +281,21 @@ BinaryContext::createBinaryContext(ObjectFile *File,
|
|||
return BC;
|
||||
}
|
||||
|
||||
bool BinaryContext::forceSymbolRelocations(StringRef SymbolName) const {
|
||||
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;
|
||||
}
|
||||
|
||||
std::unique_ptr<MCObjectWriter>
|
||||
BinaryContext::createObjectWriter(raw_pwrite_stream &OS) {
|
||||
return MAB->createObjectWriter(OS);
|
||||
|
|
|
@ -231,6 +231,10 @@ public:
|
|||
HasSymbolsWithFileName = true;
|
||||
}
|
||||
|
||||
/// Return true if relocations against symbol with a given name
|
||||
/// must be created.
|
||||
bool forceSymbolRelocations(StringRef SymbolName) const;
|
||||
|
||||
uint64_t getNumUnusedProfiledObjects() const {
|
||||
return NumUnusedProfiledObjects;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ extern cl::opt<JumpTableSupportLevel> JumpTables;
|
|||
extern cl::opt<bool> PreserveBlocksAlignment;
|
||||
extern cl::opt<bool> PrintCacheMetrics;
|
||||
extern cl::opt<bool> UpdateDebugSections;
|
||||
extern cl::opt<bool> UpdateEnd;
|
||||
extern cl::opt<unsigned> Verbosity;
|
||||
|
||||
cl::opt<bool>
|
||||
|
@ -205,10 +204,7 @@ void BinaryEmitter::emitAll(StringRef OrgSecPrefix) {
|
|||
|
||||
emitDataSections(OrgSecPrefix);
|
||||
|
||||
// Update _end if needed.
|
||||
if (opts::UpdateEnd) {
|
||||
Streamer.EmitLabel(BC.Ctx->getOrCreateSymbol("_end"));
|
||||
}
|
||||
Streamer.EmitLabel(BC.Ctx->getOrCreateSymbol("_end"));
|
||||
}
|
||||
|
||||
void BinaryEmitter::emitFunctions() {
|
||||
|
|
|
@ -1439,6 +1439,12 @@ bool BinaryFunction::scanExternalRefs() {
|
|||
|
||||
// Return true if we can ignore reference to the symbol.
|
||||
auto ignoreReference = [&](const MCSymbol *TargetSymbol) {
|
||||
if (!TargetSymbol)
|
||||
return true;
|
||||
|
||||
if (BC.forceSymbolRelocations(TargetSymbol->getName()))
|
||||
return false;
|
||||
|
||||
auto *TargetFunction = BC.getFunctionForSymbol(TargetSymbol);
|
||||
if (!TargetFunction)
|
||||
return true;
|
||||
|
|
|
@ -201,13 +201,6 @@ HotData("hot-data",
|
|||
cl::ZeroOrMore,
|
||||
cl::cat(BoltCategory));
|
||||
|
||||
cl::opt<bool>
|
||||
UpdateEnd("update-end",
|
||||
cl::desc("update the _end symbol to point to the end of all data sections"),
|
||||
cl::init(true),
|
||||
cl::ZeroOrMore,
|
||||
cl::cat(BoltCategory));
|
||||
|
||||
cl::opt<bool>
|
||||
KeepTmp("keep-tmp",
|
||||
cl::desc("preserve intermediate .o file"),
|
||||
|
@ -2013,20 +2006,7 @@ void RewriteInstance::readRelocations(const SectionRef &Section) {
|
|||
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);
|
||||
bool ForceRelocation = BC->forceSymbolRelocations(SymbolName);
|
||||
|
||||
if (BC->isAArch64() && RType == ELF::R_AARCH64_ADR_GOT_PAGE)
|
||||
ForceRelocation = true;
|
||||
|
@ -3907,7 +3887,6 @@ void RewriteInstance::updateELFSymbolTable(
|
|||
outs() << "BOLT-INFO: setting " << Name << " to 0x"
|
||||
<< Twine::utohexstr(NewSymbol.st_value) << '\n';
|
||||
++IsUpdated;
|
||||
return true;
|
||||
};
|
||||
|
||||
if (opts::HotText && (*SymbolName == "__hot_start" ||
|
||||
|
@ -3918,11 +3897,9 @@ void RewriteInstance::updateELFSymbolTable(
|
|||
*SymbolName == "__hot_data_end"))
|
||||
updateSymbolValue(*SymbolName, NumHotDataSymsUpdated);
|
||||
|
||||
if (opts::UpdateEnd && *SymbolName == "_end") {
|
||||
NewSymbol.st_value = getNewValueForSymbol(*SymbolName);
|
||||
NewSymbol.st_shndx = ELF::SHN_ABS;
|
||||
outs() << "BOLT-INFO: setting " << *SymbolName << " to 0x"
|
||||
<< Twine::utohexstr(NewSymbol.st_value) << '\n';
|
||||
if (*SymbolName == "_end") {
|
||||
unsigned Ignored;
|
||||
updateSymbolValue(*SymbolName, Ignored);
|
||||
}
|
||||
|
||||
if (PatchExisting) {
|
||||
|
|
Loading…
Reference in New Issue