Skip to content

Commit 2dd2909

Browse files
maksfbmemfrob
authored andcommitted
[BOLT] Change function order file format for linker script
Summary: Change output of "-generate-function-order=<file>" to match expected format used for a linker script: * Prefix function names with ".text". * Strip internal suffix from local function names. E.g. for function with names "foo/1" and "foo/foo.c/1" we will only output "foo". * Output (with indentation) duplicate names for folded functions. (cherry picked from FBD6071020)
1 parent e9935a9 commit 2dd2909

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

bolt/Passes/ReorderFunctions.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,20 @@ void ReorderFunctions::runOnFunctions(BinaryContext &BC,
444444
for (const auto *Func : SortedFunctions) {
445445
if (!Func->hasValidIndex())
446446
break;
447-
FuncsFile << Func->getSymbol()->getName().data() << "\n";
447+
if (Func->isPLTFunction())
448+
continue;
449+
const char *Indent = "";
450+
for (auto Name : Func->getNames()) {
451+
const auto SlashPos = Name.find('/');
452+
if (SlashPos != std::string::npos) {
453+
// Avoid duplicates for local functions.
454+
if (Name.find('/', SlashPos + 1) != std::string::npos)
455+
continue;
456+
Name = Name.substr(0, SlashPos);
457+
}
458+
FuncsFile << Indent << ".text." << Name << "\n";
459+
Indent = " ";
460+
}
448461
}
449462
FuncsFile.close();
450463

0 commit comments

Comments
 (0)