[llvm] [llvm-readobj] Dump callgraph section info for ELF (PR #157499)

Paul Kirth via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 22 14:06:11 PDT 2025


================
@@ -8091,6 +8379,65 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printCGProfile() {
   }
 }
 
+template <class ELFT> void LLVMELFDumper<ELFT>::printCallGraphInfo() {
+  if (!this->processCallGraphSection())
+    return;
+  if (this->FuncCGInfos.size() == 0)
+    return;
+  using FunctionCallgraphInfo =
+      ::FunctionCallgraphInfoImpl<typename ELFT::uint>;
+
+  auto GetFunctionName = [&](typename ELFT::uint EntryPc) {
+    SmallVector<uint32_t> FuncSymIndexes =
+        this->getSymbolIndexesForFunctionAddress(EntryPc, std::nullopt);
+    if (FuncSymIndexes.empty())
+      return std::string("");
+
+    SmallVector<std::string> FuncSymNames;
+    for (uint32_t Index : FuncSymIndexes)
+      FuncSymNames.push_back(this->getStaticSymbolName(Index));
+    return join(FuncSymNames, ", ");
+  };
+
+  ListScope CGI(W, "callgraph_info");
+
+  for (const auto &El : this->FuncCGInfos) {
+    DictScope D(W, "Function");
+    typename ELFT::uint FuncEntryPc = El.first;
+    FunctionCallgraphInfo CGInfo = El.second;
+    std::string FuncSymName = GetFunctionName(FuncEntryPc);
+    if (!FuncSymName.empty())
+      W.printString("Name", FuncSymName);
+
+    W.printHex("Address", FuncEntryPc);
+    W.printNumber("Version", CGInfo.FormatVersionNumber);
+    W.printString("KindStr", GetFuntionKindString(CGInfo.Kind));
+    W.printNumber("Kind", (uint64_t)CGInfo.Kind);
+    if (CGInfo.Kind == FunctionKind::INDIRECT_TARGET_KNOWN_TID)
+      W.printHex("TypeId", CGInfo.FunctionTypeId);
+    W.printNumber("NumIndirectCallSites", CGInfo.IndirectCallsites.size());
+    if (CGInfo.IndirectCallsites.size() > 0) {
+      ListScope ICSs(W, "IndirectCallsites");
+      for (auto &[IndirCallSitePc, TypeId] : CGInfo.IndirectCallsites) {
+        DictScope ICS(W, "IndirectCallsite");
+        W.printHex("Address", IndirCallSitePc);
+        W.printHex("TypeId", TypeId);
+      }
+    }
+    W.printNumber("NumDirectCallSites", CGInfo.DirectCallees.size());
+    if (CGInfo.DirectCallees.size() > 0) {
----------------
ilovepi wrote:

These should always be printed, so a parser can always expect them to be there.

https://github.com/llvm/llvm-project/pull/157499


More information about the llvm-commits mailing list