Fix kfunc/extern codegen so sched_ext_simple compiles#21
Conversation
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
Signed-off-by: Cong Wang <cwang@multikernel.io>
263a6fc to
271a8bb
Compare
|
Remaining blockers for on my environment (Linux 7.0.0-15-generic), 1. Blocking: Redundant 2. Blocking: API Deprecation ( |
Summary
sched_ext_simple.ks(and other examples usingexternkfunc declarations) compiled in KernelScript but produced eBPF C that failed to build. This branch fixes the three distinct problems found along the way.1. Lower kfunc declarations into the IR
externkfunc declarations were registered in the type checker and symbol table but never lowered into the IR, so the eBPF C backend never emittedextern ... __ksym;declarations for them — generated.ebpf.ccalled kfuncs likescx_bpf_dsq_insertwith no declaration in scope.Both kernel-provided
externkfuncs and locally-defined@kfuncprototypes are now represented as a newIRDeclKfuncDeclsource declaration, emitted in source order from the IR. This replaces the~kfunc_declarations/~extern_declarationsside-channel arguments that previously smuggled AST fragments past the IR into the backend.2. Skip
__ksymexterns for standard BPF helpersKernelScript uses
externfor both kfuncs and BPF helpers, and shipped examples (extern_kfunc_demo.ks,include_demo.ks) declare helpers likebpf_ktime_get_nswith it. Emittingextern ... __ksym;for those clashed with libbpf'sbpf_helpers.h, which already declares every helper.A new
Bpf_helpersmodule enumerates the standard helpers (mirroring libbpf'sbpf_helper_defs.h); the backend skips the__ksymdeclaration for anyexternnaming one. Real kfuncs are unaffected.3. Compile eBPF objects with
-fno-builtinstruct_ops method names come from the kernel struct, so a
sched_ext_opsscheduler must define anexitmethod. eBPF objects never link libc, but clang still recognisesexitas a compiler builtin (void(int) noreturn) regardless of-target bpf— it compiled the fall-through body away to a zero-size section, and libbpf then rejected the object.-fno-builtinis added to the generated Makefile'sBPF_CFLAGS. eBPF C relies only on__builtin_*intrinsics (KernelScript emits__builtin_memcpy, never barememcpy; struct-copy lowering uses thellvm.memcpyintrinsic) — none of which-fno-builtinaffects.Testing
sched_ext_simplenow builds fully end-to-end (.ebpf.o, skeleton, userspace binary).-fno-builtin.🤖 Generated with Claude Code