Skip to content

Commit e12e388

Browse files
committed
[BOLT][runtime] Add start & fini symbols
Add absent start & fini symbols, currently setted by bolt for runtime libraries at DT_INIT and DT_FINI. The proper tests would be added by the llvm#67348 PR.
1 parent f99bd29 commit e12e388

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4568,15 +4568,12 @@ void RewriteInstance::updateELFSymbolTable(
45684568
}
45694569
}
45704570

4571-
assert((!NumHotTextSymsUpdated || NumHotTextSymsUpdated == 2) &&
4572-
"either none or both __hot_start/__hot_end symbols were expected");
4573-
assert((!NumHotDataSymsUpdated || NumHotDataSymsUpdated == 2) &&
4574-
"either none or both __hot_data_start/__hot_data_end symbols were "
4575-
"expected");
4571+
auto AddSymbol = [&](const StringRef &Name, uint64_t Address) {
4572+
if (!Address)
4573+
return;
45764574

4577-
auto addSymbol = [&](const std::string &Name) {
45784575
ELFSymTy Symbol;
4579-
Symbol.st_value = getNewValueForSymbol(Name);
4576+
Symbol.st_value = Address;
45804577
Symbol.st_shndx = ELF::SHN_ABS;
45814578
Symbol.st_name = AddToStrTab(Name);
45824579
Symbol.st_size = 0;
@@ -4589,14 +4586,30 @@ void RewriteInstance::updateELFSymbolTable(
45894586
Symbols.emplace_back(Symbol);
45904587
};
45914588

4589+
// Add runtime library start and fini address symbols
4590+
if (RuntimeLibrary *RtLibrary = BC->getRuntimeLibrary()) {
4591+
AddSymbol("__bolt_runtime_start", RtLibrary->getRuntimeStartAddress());
4592+
AddSymbol("__bolt_runtime_fini", RtLibrary->getRuntimeFiniAddress());
4593+
}
4594+
4595+
assert((!NumHotTextSymsUpdated || NumHotTextSymsUpdated == 2) &&
4596+
"either none or both __hot_start/__hot_end symbols were expected");
4597+
assert((!NumHotDataSymsUpdated || NumHotDataSymsUpdated == 2) &&
4598+
"either none or both __hot_data_start/__hot_data_end symbols were "
4599+
"expected");
4600+
4601+
auto AddEmittedSymbol = [&](const StringRef &Name) {
4602+
AddSymbol(Name, getNewValueForSymbol(Name));
4603+
};
4604+
45924605
if (opts::HotText && !NumHotTextSymsUpdated) {
4593-
addSymbol("__hot_start");
4594-
addSymbol("__hot_end");
4606+
AddEmittedSymbol("__hot_start");
4607+
AddEmittedSymbol("__hot_end");
45954608
}
45964609

45974610
if (opts::HotData && !NumHotDataSymsUpdated) {
4598-
addSymbol("__hot_data_start");
4599-
addSymbol("__hot_data_end");
4611+
AddEmittedSymbol("__hot_data_start");
4612+
AddEmittedSymbol("__hot_data_end");
46004613
}
46014614

46024615
// Put local symbols at the beginning.

0 commit comments

Comments
 (0)