[llvm] [docs][llvm-readobj] Document the --call-graph-info output format (PR #227386)
Prabhu Rajasekaran via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 29 09:59:00 PDT 2026
https://github.com/Prabhuk created https://github.com/llvm/llvm-project/pull/227386
Describe the fields llvm-readobj prints for each call graph record, for
both executables and relocatable object files, with an example of each.
The relocatable object file format is added in #213156.
>From 41e1048c7ed01fd61af07cfcff6298831b2d685f Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Tue, 29 Sep 2026 09:56:06 -0700
Subject: [PATCH] [docs][llvm-readobj] Document the --call-graph-info output
format
Describe the fields llvm-readobj prints for each call graph record, for
both executables and relocatable object files, with an example of each.
The relocatable object file format is added in #213156.
---
llvm/docs/CallGraphSection.md | 102 ++++++++++++++++++++++++++++++++++
1 file changed, 102 insertions(+)
diff --git a/llvm/docs/CallGraphSection.md b/llvm/docs/CallGraphSection.md
index 84d606162718be..2bfa50dc39c3a2 100644
--- a/llvm/docs/CallGraphSection.md
+++ b/llvm/docs/CallGraphSection.md
@@ -16,3 +16,105 @@ Each record in the `.llvm.callgraph` section has the following binary layout:
| Direct Callees Array | `uintptr_t[]` | Variable | An array of unique direct callee entry point addresses. This field is only present if there is at least one direct callee. |
| Number of Unique Indirect Target Type IDs| `ULEB128` | Variable | The number of unique indirect call target type IDs. This field is only present if there is at least one indirect target type ID. |
| Indirect Target Type IDs Array | `uint64_t[]` | Variable | An array of unique indirect call target type IDs. This field is only present if there is at least one indirect target type ID. |
+
+## Dumping with llvm-readobj
+
+`llvm-readobj --call-graph-info` prints the records of every `SHT_LLVM_CALL_GRAPH` section in a file. With `--elf-output-style=JSON`, the output is a `CallGraph` array that holds one `Function` object per record. The default `LLVM` output style prints the same fields, with addresses and type IDs in hexadecimal.
+
+In executables and shared objects, functions are identified by their addresses. In relocatable object files the address fields are not final, so each function is identified by the relocation that applies to its address field instead.
+
+### Function Object
+
+| Field | Type | Description |
+| -------------------------- | ---------------- | ----------- |
+| `Names` | array of strings | The names of the function symbols at `Address`. Omitted if there are none. Executables and shared objects only. |
+| `Address` | integer | The function entry address. On ARM, the Thumb bit is cleared. Executables and shared objects only. |
+| `Reloc` | object | The relocation that applies to the function entry PC field. See below. Relocatable object files only. |
+| `Offset` | integer | The offset of the function entry PC field within the section. Printed instead of `Reloc` when the relocation cannot be determined. Relocatable object files only. |
+| `Version` | integer | The format version. |
+| `IsIndirectTarget` | boolean | Whether the function is a potential indirect call target. |
+| `TypeID` | integer | The function type ID. |
+| `NumDirectCallees` | integer | The number of entries in `DirectCallees`. |
+| `DirectCallees` | array of objects | One object per direct callee, identified the same way as the function: by `Names` and `Address`, or by `Reloc` or `Offset`. In executables and shared objects, each callee address is listed once. |
+| `NumIndirectTargetTypeIDs` | integer | The number of entries in `IndirectTypeIDs`. |
+| `IndirectTypeIDs` | array of integers | The indirect call target type IDs. |
+
+### Reloc Object
+
+| Field | Type | Description |
+| ------------- | ------- | ----------- |
+| `SymbolIndex` | integer | The symbol table index of the relocation's symbol, or 0 if it has none. |
+| `SymbolName` | string | The name that the symbol's `st_name` refers to, demangled if `--demangle` is given. Omitted if the symbol has no name, such as an `STT_SECTION` symbol. |
+| `Addend` | integer | The relocation addend. For relocations without an explicit addend, such as `SHT_REL` relocations, this is the value stored in the field. Omitted if zero. |
+
+### Examples
+
+A function in a shared object that calls `foo` and `bar`:
+
+```json
+"CallGraph": [
+ {
+ "Function": {
+ "Names": [
+ "main"
+ ],
+ "Address": 6080,
+ "Version": 0,
+ "IsIndirectTarget": false,
+ "TypeID": 0,
+ "NumDirectCallees": 2,
+ "DirectCallees": [
+ {
+ "Names": [
+ "foo"
+ ],
+ "Address": 6032
+ },
+ {
+ "Names": [
+ "bar"
+ ],
+ "Address": 6048
+ }
+ ],
+ "NumIndirectTargetTypeIDs": 0,
+ "IndirectTypeIDs": []
+ }
+ }
+]
+```
+
+A function in a relocatable object file that calls two local functions. The callees are referenced through the section symbol, so they have no `SymbolName`, and the addends give their offsets within the section:
+
+```json
+"CallGraph": [
+ {
+ "Function": {
+ "Reloc": {
+ "SymbolIndex": 3,
+ "SymbolName": "caller"
+ },
+ "Version": 0,
+ "IsIndirectTarget": true,
+ "TypeID": 9080559750644022485,
+ "NumDirectCallees": 2,
+ "DirectCallees": [
+ {
+ "Reloc": {
+ "SymbolIndex": 1,
+ "Addend": 16
+ }
+ },
+ {
+ "Reloc": {
+ "SymbolIndex": 1,
+ "Addend": 24
+ }
+ }
+ ],
+ "NumIndirectTargetTypeIDs": 0,
+ "IndirectTypeIDs": []
+ }
+ }
+]
+```
More information about the llvm-commits
mailing list