[llvm] Reland "[llvm-readobj] Dump callgraph section info for ELF" (PR #176260)

Prabhu Rajasekaran via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 28 13:54:41 PST 2026


================
@@ -5317,6 +5337,148 @@ template <class ELFT> void GNUELFDumper<ELFT>::printCGProfile() {
   OS << "GNUStyle::printCGProfile not implemented\n";
 }
 
+namespace callgraph {
+LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
+enum Flags : uint8_t {
+  None = 0,
+  IsIndirectTarget = 1u << 0,
+  HasDirectCallees = 1u << 1,
+  HasIndirectCallees = 1u << 2,
+  LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue*/ HasIndirectCallees)
+};
+} // namespace callgraph
+
+template <class ELFT>
+bool ELFDumper<ELFT>::processCallGraphSection(const Elf_Shdr *CGSection) {
+  ArrayRef<uint8_t> Contents =
+      unwrapOrError(FileName, Obj.getSectionContents(*CGSection));
+  DataExtractor Data(Contents, Obj.isLE(), ObjF.getBytesInAddress());
+  DataExtractor::Cursor C(0);
+  uint64_t UnknownCount = 0;
+  while (C && C.tell() < CGSection->sh_size) {
+    uint8_t FormatVersionNumber = Data.getU8(C);
+    assert(C && "always expect the one byte read to succeed when C.tell() < "
+                "CGSection->sh_size is true.");
+    if (!C)
+      consumeError(
+          C.takeError()); // To satisfy builds with assertion disabled mode
+    if (FormatVersionNumber != 0) {
+      reportWarning(createError("unknown format version value [" +
+                                std::to_string(FormatVersionNumber) +
+                                "] in SHT_LLVM_CALL_GRAPH type section"),
+                    FileName);
+      return false;
+    }
+
+    uint8_t FlagsVal = Data.getU8(C);
+    if (!C) {
+      reportWarning(
+          createError("failed while reading call graph info's Flags: " +
+                      toString(C.takeError())),
+          FileName);
+      return false;
+    }
+    callgraph::Flags CGFlags = static_cast<callgraph::Flags>(FlagsVal);
+    constexpr callgraph::Flags ValidFlags = callgraph::IsIndirectTarget |
+                                            callgraph::HasDirectCallees |
+                                            callgraph::HasIndirectCallees;
+    constexpr uint8_t ValidMask = static_cast<uint8_t>(ValidFlags);
+    if ((FlagsVal & ~ValidMask) != 0) {
+      reportWarning(createError("unsupported Flags value [" +
----------------
Prabhuk wrote:

https://github.com/llvm/llvm-project/blob/main/llvm/docs/CallGraphSection.md?plain=1#L12 - `Flags` matches the documentation.  

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


More information about the llvm-commits mailing list