Skip to content

Commit c6731d3

Browse files
authored
[BOLT][runtime] Add start & fini symbols (#68505)
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 #67348 PR.
1 parent 49cb159 commit c6731d3

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
@@ -4587,15 +4587,12 @@ void RewriteInstance::updateELFSymbolTable(
45874587
}
45884588
}
45894589

4590-
assert((!NumHotTextSymsUpdated || NumHotTextSymsUpdated == 2) &&
4591-
"either none or both __hot_start/__hot_end symbols were expected");
4592-
assert((!NumHotDataSymsUpdated || NumHotDataSymsUpdated == 2) &&
4593-
"either none or both __hot_data_start/__hot_data_end symbols were "
4594-
"expected");
4590+
auto AddSymbol = [&](const StringRef &Name, uint64_t Address) {
4591+
if (!Address)
4592+
return;
45954593

4596-
auto addSymbol = [&](const std::string &Name) {
45974594
ELFSymTy Symbol;
4598-
Symbol.st_value = getNewValueForSymbol(Name);
4595+
Symbol.st_value = Address;
45994596
Symbol.st_shndx = ELF::SHN_ABS;
46004597
Symbol.st_name = AddToStrTab(Name);
46014598
Symbol.st_size = 0;
@@ -4608,14 +4605,30 @@ void RewriteInstance::updateELFSymbolTable(
46084605
Symbols.emplace_back(Symbol);
46094606
};
46104607

4608+
// Add runtime library start and fini address symbols
4609+
if (RuntimeLibrary *RtLibrary = BC->getRuntimeLibrary()) {
4610+
AddSymbol("__bolt_runtime_start", RtLibrary->getRuntimeStartAddress());
4611+
AddSymbol("__bolt_runtime_fini", RtLibrary->getRuntimeFiniAddress());
4612+
}
4613+
4614+
assert((!NumHotTextSymsUpdated || NumHotTextSymsUpdated == 2) &&
4615+
"either none or both __hot_start/__hot_end symbols were expected");
4616+
assert((!NumHotDataSymsUpdated || NumHotDataSymsUpdated == 2) &&
4617+
"either none or both __hot_data_start/__hot_data_end symbols were "
4618+
"expected");
4619+
4620+
auto AddEmittedSymbol = [&](const StringRef &Name) {
4621+
AddSymbol(Name, getNewValueForSymbol(Name));
4622+
};
4623+
46114624
if (opts::HotText && !NumHotTextSymsUpdated) {
4612-
addSymbol("__hot_start");
4613-
addSymbol("__hot_end");
4625+
AddEmittedSymbol("__hot_start");
4626+
AddEmittedSymbol("__hot_end");
46144627
}
46154628

46164629
if (opts::HotData && !NumHotDataSymsUpdated) {
4617-
addSymbol("__hot_data_start");
4618-
addSymbol("__hot_data_end");
4630+
AddEmittedSymbol("__hot_data_start");
4631+
AddEmittedSymbol("__hot_data_end");
46194632
}
46204633

46214634
// Put local symbols at the beginning.

0 commit comments

Comments
 (0)