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

Prabhu Rajasekaran via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 22 15:46:34 PDT 2025


================
@@ -0,0 +1,765 @@
+## Tests how --call-graph-info prints the call graph information.
+# RUN: yaml2obj --docnum=1 %s -o %t
+# RUN: llvm-readelf --call-graph-info %t 2>&1 | FileCheck %s --match-full-lines -DFILE=%t
+# RUN: llvm-readelf --elf-output-style=LLVM --call-graph-info %t 2>&1 | FileCheck %s --match-full-lines --check-prefix=LLVM -DFILE=%t
+# RUN: llvm-readelf --elf-output-style=JSON --pretty-print --call-graph-info %t 2>&1 | FileCheck %s --match-full-lines --check-prefix=JSON -DFILE=%t
+
+# Yaml input is obtained by compiling the below source to object with:
+#   clang -fexperimental-call-graph-section test.c -o test.o
+# then to yaml with:
+#   obj2yaml test.o > test.yaml
+# Remove ProgramHeaders if obj2yaml fails.
+
+# The content of the .callgraph section is fixed with this yaml in raw format.
+
+# Source:
+#   void foo() {}
+#
+#   void bar() {}
+#
+#   int baz(char a) {
+#     return 0;
+#   }
+#
+#   int main() {
+#     // Indirect calls.
+#     void (*fp_foo)() = foo;
+#     fp_foo();
+#
+#     void (*fp_bar)() = bar;
+#     fp_bar();
+#
+#     char a;
+#     int (*fp_baz)(char) = baz;
+#     fp_baz(a);
+#
+#     // Direct calls.
+#     foo();
+#     bar();
+#     baz(a);
+#
+#     return 0;
+#   }
+
+# CHECK: Per-function call graph information:: 
+# CHECK-EMPTY: 
+# CHECK-NEXT: Function:: foo
+# CHECK-NEXT: Function PC:: 0x1790
+# CHECK-NEXT: FormatVersionNumber:: 0
+# CHECK-NEXT: Function Kind:: KNOWN_TID
+# CHECK-NEXT: Function Type ID:: 0x3ecbeef531f74424
+# CHECK-NEXT: Indirect callee count:: 0
+# CHECK-NEXT: Direct callee count:: 0
+# CHECK-EMPTY: 
+# CHECK-NEXT: Function:: bar
+# CHECK-NEXT: Function PC:: 0x17a0
+# CHECK-NEXT: FormatVersionNumber:: 0
+# CHECK-NEXT: Function Kind:: KNOWN_TID
+# CHECK-NEXT: Function Type ID:: 0x3ecbeef531f74424
+# CHECK-NEXT: Indirect callee count:: 0
+# CHECK-NEXT: Direct callee count:: 0
+# CHECK-EMPTY: 
+# CHECK-NEXT: Function:: baz
+# CHECK-NEXT: Function PC:: 0x17b0
+# CHECK-NEXT: FormatVersionNumber:: 0
+# CHECK-NEXT: Function Kind:: KNOWN_TID
+# CHECK-NEXT: Function Type ID:: 0x308e4b8159bc8654
+# CHECK-NEXT: Indirect callee count:: 0
+# CHECK-NEXT: Direct callee count:: 0
+# CHECK-EMPTY: 
+# CHECK-NEXT: Function:: main
+# CHECK-NEXT: Function PC:: 0x17c0
+# CHECK-NEXT: FormatVersionNumber:: 0
+# CHECK-NEXT: Function Kind:: KNOWN_TID
+# CHECK-NEXT: Function Type ID:: 0xfa6809609a76afca
+# CHECK-NEXT: Indirect callee count:: 3
+# CHECK-NEXT: {
+# CHECK-NEXT:   callsite: 0x17ef
+# CHECK-NEXT:   calleeTypeId: 0x3ecbeef531f74424
+# CHECK-NEXT:   callsite: 0x17df
+# CHECK-NEXT:   calleeTypeId: 0x3ecbeef531f74424
+# CHECK-NEXT:   callsite: 0x1804
+# CHECK-NEXT:   calleeTypeId: 0x308e4b8159bc8654
+# CHECK-NEXT: }
+# CHECK-NEXT: Direct callee count:: 3
+# CHECK-NEXT: {
+# CHECK-NEXT:   Callee:: foo
+# CHECK-NEXT:   CalleePC:: 0x1790
+# CHECK-NEXT:   Callee:: bar
+# CHECK-NEXT:   CalleePC:: 0x17a0
+# CHECK-NEXT:   Callee:: baz
+# CHECK-NEXT:   CalleePC:: 0x17b0
----------------
Prabhuk wrote:

Ack. One of the offline feedback I received is to turn GNU output into a tabular format to match existing readelf output style. I will work on that and update the patch.

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


More information about the llvm-commits mailing list