[PATCH] D107031: [llvm-objdump][CallGraphInfo] Get .callgraph section

Necip Fazil Yildiran via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 28 21:51:27 PDT 2021


necipfazil created this revision.
Herald added subscribers: rupprecht, emaste.
Herald added a reviewer: jhenderson.
Herald added a reviewer: MaskRay.
necipfazil requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Get the .callgraph section. Warn if there is no .callgraph section in the
binary.

Upcoming patches will parse and print information from this section.

Patch 4/6: Extract call graph information from binary

Original RFC: https://lists.llvm.org/pipermail/llvm-dev/2021-June/151044.html
Updated RFC: https://lists.llvm.org/pipermail/llvm-dev/2021-July/151739.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107031

Files:
  llvm/test/tools/llvm-objdump/ELF/call-graph-info-warn-no-callgraph-section.test
  llvm/tools/llvm-objdump/llvm-objdump.cpp


Index: llvm/tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -2103,6 +2103,24 @@
   // Get function info through disassembly.
   disassembleObject(Obj, /*InlineRelocs=*/false);
 
+  // Get the .callgraph section.
+  StringRef CallGraphSectionName(".callgraph");
+  Optional<object::SectionRef> CallGraphSection;
+  for (auto Sec : ToolSectionFilter(*Obj)) {
+    StringRef Name;
+    if (Expected<StringRef> NameOrErr = Sec.getName())
+      Name = *NameOrErr;
+    else
+      consumeError(NameOrErr.takeError());
+
+    if (Name == CallGraphSectionName) {
+      CallGraphSection = Sec;
+      break;
+    }
+  }
+  if (!CallGraphSection)
+    reportWarning("there is no .callgraph section", Obj->getFileName());
+
   // Print function entry to indirect call site addresses mapping from disasm.
   outs() << "\n\nINDIRECT CALL SITES (CALLER_ADDR [CALL_SITE_ADDR,])";
   for (const auto &El : FuncInfo) {
Index: llvm/test/tools/llvm-objdump/ELF/call-graph-info-warn-no-callgraph-section.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objdump/ELF/call-graph-info-warn-no-callgraph-section.test
@@ -0,0 +1,15 @@
+## Tests that --call-graph-info warns if there is no .callgraph section.
+
+# RUN: llvm-mc %s -filetype=obj -triple=x86_64-pc-linux -o %t
+# RUN: llvm-objdump --call-graph-info %t 2>&1 | FileCheck %s -DFILE=%t
+
+# CHECK: [[FILE]]: file format elf64-x86-64
+# CHECK-NEXT: llvm-objdump: warning: '[[FILE]]': there is no .callgraph section
+# CHECK-NOT: INDIRECT TARGET TYPES (TYPEID [FUNC_ADDR,])
+# CHECK-NOT: INDIRECT CALL TYPES (TYPEID [CALL_SITE_ADDR,])
+
+.text
+.globl _Z3foov
+.type _Z3foov, at function
+_Z3foov:
+ callq _Z3foov at PLT


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107031.362628.patch
Type: text/x-patch
Size: 1862 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210729/77821c21/attachment.bin>


More information about the llvm-commits mailing list