Skip to content

Compile Once – Run Everywhere

Step 4 of 8Solution
BUILD
once in CI
PROD CLANG
zero
BINARY SIZE
~35 KiB ELF
RELOCATION
at load time
  • compile / emit relocs
  • BTF offset patch
  • load verified ELF
BTF, CO-RE & Toolchains, step 4 of 8

CO-RE (Compile Once – Run Everywhere) combines Clang, BTF, and libbpf. At build time, Clang records field access recipes (like sk_buff->len) inside the ELF’s .BTF.ext section.

When the tiny binary starts on a target host, libbpf reads /sys/kernel/btf/vmlinux, calculates each field’s true byte offset on that kernel, and rewrites the bytecode before calling bpf().

What changed

  • Clang on every server → single CI compile (~35 KiB .bpf.o)
  • Hardcoded offsets → .BTF.ext relocation records
  • Runtime guesswork → exact patch against host vmlinux BTF

Type to search…

↑↓ navigate↵ selectEsc close