
Mapping the Linux kernel call graph - including indirect calls
- Markus Kreidl
- Linux kernel , Tooling
- November 18, 2026
Table of Contents
Who calls vfs_read(), and what does it call? For direct calls a grep or cscope gives a rough answer. But a large part of the kernel’s control flow goes through function pointers: file_operations, net_device_ops, work items, timers, tracepoints, LSM hooks. Text-based tools stop at file->f_op->read(...). Safety arguments, patch-impact analysis and CRA vulnerability assessments still need the full answer.
So I wrote kcg, a GCC plugin that records the call graph while the kernel is compiled, including the indirect calls.

How it works
Direct calls are easy: the plugin runs as a GIMPLE pass right after SSA construction and records every caller -> callee.
Indirect calls are resolved by type, an approach known from Multi-Layer Type Analysis (Lu & Hu, CCS 2019). For every call through a pointer, the plugin walks the SSA def chain backwards through copies, casts, PHI nodes and ?: until it finds where the pointer came from:
- loaded from a struct field:
file_operations.read - a global or static variable, or an array of them
- a parameter of the current function: a callback passed in
- the return value of another function
It then records the other side, i.e. which functions end up in such a slot. Sources are static initializers (including nested ones and compound literals), stores, WRITE_ONCE(), call arguments, return values, and slots passed by pointer. A merge step combines the facts of all translation units and computes the transitive closure. That way chains like INIT_WORK() -> work_struct.func -> worker->current_func resolve across files.
Some kernel idioms needed special handling:
void *slots (tracepoints, static calls) and unions are type-erased, so their targets are additionally filtered by the call signaturesymbol_get()/dvb_attach()look functions up by name, and the name is a string constant the plugin can read- an explicit
NULLis tracked, so optional hooks that are never set are reported as such
Results: Linux 6.12, x86_64 defconfig
| functions defined | 102,142 |
| direct call edges | 333,995 |
| indirect call sites | 11,804 |
| resolved by type | 10,365 |
no target in this build (not configured, #ifdef’d out, only NULL) | 1,343 |
| open (possible analysis gaps) | 96 |
| resolved, of the calls that can have a target | 99.1 % |
| targets per resolved call site | median 2, mean 4.4 |
Spot checks look right. vfs_read() reaches the 129 implementations of file_operations.read. __traceiter_sched_switch reaches exactly its 5 registered probes. process_one_work() reaches the 398 work functions of the build.
A second, late pass records what actually ends up in the binary. 70 % of the direct call edges are inlined away, mostly static inline helpers from headers. In 493 cases GCC itself turned an indirect call into the same direct call the plugin had resolved by type, which is an independent confirmation.
Every unresolved call gets a reason
Unresolved calls are as interesting as resolved ones. Most of them are not a weakness of the analysis: in the build that was analysed, these calls simply have no target. That is why they are reported as a separate class and not counted as failures. Every one of them is explained in a JSON file with the location, the reason and a readable message. To find out why a call has no target, the tool scans the source tree and the struct definitions and evaluates the .config:
- not built: the assigning driver is not built in this config. The Kconfig symbols are reported, e.g.
CONFIG_NET_SCH_DRR=n. - disabled: the assignment sits in
#ifdef/IS_ENABLED()branches that are off, or in dead code. - firmware: the pointer comes from the firmware (UEFI boot and runtime services).
- only NULL: the hook is only ever set to
NULLin this build.
For x86_64 defconfig, 1,343 of the calls without a type-resolved target fall into these classes. Only 96 stay open, mostly initializers generated by macros, and pointers loaded through a plain *pp. On a Raspberry Pi config, where most drivers are modules, building the modules as well (make all) matters a lot.
Looking at it
The output is a poster, an interactive WebGL viewer (search, callers and callees), and a 3D “space” view. In the 3D view, clicking a function lights up its call tree down to a chosen depth:

Try it yourself: pages.fynq.rocks/kcg-537ba1 has the 2D viewer, the 3D view, the poster and the unresolved-call report for each kernel configuration.
The whole pipeline runs in GitLab CI: build per kernel config (x86_64, arm64 cross), resolve, explain, render, publish to GitLab Pages.
What it is for
- Patch impact: which code paths can reach a changed function, including through function pointers.
- Safety and security arguments: freedom from interference, attack surface from a syscall or an ioctl, CRA vulnerability triage (“is the vulnerable function reachable in our configuration?”).
- Understanding a subsystem before you modify it.
If you work on kernel-based products and need this kind of analysis for your configuration, get in touch.