[llvm] [llvm-readobj] Dump callgraph section info for ELF (PR #157499)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 19 02:27:34 PST 2025
================
@@ -8094,6 +8307,69 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printCGProfile() {
}
}
+template <class ELFT> void LLVMELFDumper<ELFT>::printCallGraphInfo() {
+ if (!this->processCallGraphSection() || this->FuncCGInfos.empty())
+ return;
+
+ std::vector<Relocation<ELFT>> Relocations;
+ const Elf_Shdr *RelocSymTab = nullptr;
+ this->getCallGraphRelocations(Relocations, RelocSymTab);
+
+ auto PrintFunc = [](uint64_t FuncEntryPC, ArrayRef<std::string> FuncNames,
+ ScopedPrinter &W) {
+ if (!FuncNames.empty())
+ W.printList("Names", FuncNames);
+ W.printHex("Address", FuncEntryPC);
+ };
+
+ auto PrintReloc = [&](uint64_t RelocOffset) {
+ auto Reloc = llvm::find_if(Relocations, [&](const Relocation<ELFT> &R) {
+ return R.Offset == RelocOffset;
+ });
+ if (Reloc == Relocations.end()) {
+ W.printHex("Offset", RelocOffset);
+ return;
+ }
+ Expected<RelSymbol<ELFT>> RelSymOrErr =
+ this->getRelocationTarget(*Reloc, RelocSymTab);
+ if (!RelSymOrErr) {
+ this->reportUniqueWarning(RelSymOrErr.takeError());
+ return;
+ }
+ if (!RelSymOrErr->Name.empty())
+ W.printString("Name", RelSymOrErr->Name);
+ };
+
+ auto PrintFunctionInfo = [&](uint64_t FuncEntryPC) {
+ if (this->Obj.getHeader().e_type != ELF::ET_REL) {
+ PrintFunc(FuncEntryPC, this->getFunctionNames(FuncEntryPC), W);
+ return;
+ }
+ PrintReloc(FuncEntryPC);
+ };
+
+ ListScope CGI(W, "CallGraph");
+ for (const auto &CGInfo : this->FuncCGInfos) {
+ DictScope D(W, "Function");
+ PrintFunctionInfo(CGInfo.FunctionAddress);
+ W.printNumber("Version", CGInfo.FormatVersionNumber);
+ W.printBoolean("IsIndirectTarget", CGInfo.IsIndirectTarget);
+ W.printHex("TypeId", CGInfo.FunctionTypeId);
+ W.printNumber("NumDirectCallees", CGInfo.DirectCallees.size());
+ {
+ ListScope DCs(W, "DirectCallees");
+ for (auto CalleePC : CGInfo.DirectCallees) {
+ DictScope D(W);
+ PrintFunctionInfo(CalleePC);
+ }
+ }
+ W.printNumber("NumIndirectTargetTypeIDs", CGInfo.IndirectTypeIDs.size());
+ auto IndirectTypeIdsList = SmallVector<uint64_t, 4>(
----------------
jh7370 wrote:
```suggestion
SmallVector<uint64_t, 4> IndirectTypeIdsList(
```
This is more standard syntax in LLVM, I feel?
https://github.com/llvm/llvm-project/pull/157499
More information about the llvm-commits
mailing list