Skip to content

Add a generator of vmlinux.h for C++ - #7

Merged
maxskokov merged 2 commits into
mainfrom
vmlinux-gen
Oct 20, 2026
Merged

maxskokov merged 2 commits into
mainfrom
vmlinux-gen

Conversation

@maxskokov

Copy link
Copy Markdown
Member

bpftool's vmlinux.h has 100-160 C++ errors depending on the kernel. scripts/gen-vmlinux.py changes the names and types in BTF where C++ needs it and lets bpftool dump the result; scripts/check-vmlinux.sh checks in CI that C++ sees the same type layout as C. mk/cppbpf.mk builds the header as $(OUT)/include/vmlinux.h, and the tests and syscount use it instead of hand-written kernel types. Closes #2.

AIL:2

The vmlinux.h from bpftool has about 160 C++ errors: keywords as names,
typedef _Bool bool, tags that clash with typedefs, enum declarations
without a type, anonymous members of named struct types, and empty
structs, which have size 1 in C++ and shift the members after them.

scripts/gen-vmlinux.py changes the names and types in BTF where C++
needs it and lets bpftool dump the result, so the layout stays bpftool's.
Renamed types get a ___cpp suffix, which libbpf ignores in CO-RE.

scripts/check-vmlinux.sh compiles the header as C and C++ with static
asserts on the size and member offsets of each type from BTF, and checks
that C++ fails none that C passes. CI runs it on the runner's kernel.

Signed-off-by: Maxim Skokov <[email protected]>
mk/cppbpf.mk builds $(OUT)/include/vmlinux.h from VMLINUX_BTF, by
default the running kernel's; an empty VMLINUX_BTF builds without it.
The tests and syscount use it instead of hand-written kernel types, and
the basic test checks a CO-RE relocation against a renamed type, struct
class___cpp.

Signed-off-by: Maxim Skokov <[email protected]>
@maxskokov maxskokov added the ail:2 Human Created, Major AI Augmentation. Authored by Human with significant AI modification. label Oct 20, 2026
@maxskokov
maxskokov merged commit aae54a7 into main Oct 20, 2026
7 checks passed
@maxskokov
maxskokov deleted the vmlinux-gen branch October 20, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ail:2 Human Created, Major AI Augmentation. Authored by Human with significant AI modification.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vmlinux.h is not valid C++

1 participant