Title: Fix kfunc/extern codegen so sched_ext_simple compiles by congwang-mk · Pull Request #21 · multikernel/kernelscript · GitHub
Open Graph Title: Fix kfunc/extern codegen so sched_ext_simple compiles by congwang-mk · Pull Request #21 · multikernel/kernelscript
X Title: Fix kfunc/extern codegen so sched_ext_simple compiles by congwang-mk · Pull Request #21 · multikernel/kernelscript
Description: Summary sched_ext_simple.ks (and other examples using extern kfunc 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 extern kfunc declarations were registered in the type checker and symbol table but never lowered into the IR, so the eBPF C backend never emitted extern ... __ksym; declarations for them — generated .ebpf.c called kfuncs like scx_bpf_dsq_insert with no declaration in scope. Both kernel-provided extern kfuncs and locally-defined @kfunc prototypes are now represented as a new IRDeclKfuncDecl source declaration, emitted in source order from the IR. This replaces the ~kfunc_declarations / ~extern_declarations side-channel arguments that previously smuggled AST fragments past the IR into the backend. 2. Skip __ksym externs for standard BPF helpers KernelScript uses extern for both kfuncs and BPF helpers, and shipped examples (extern_kfunc_demo.ks, include_demo.ks) declare helpers like bpf_ktime_get_ns with it. Emitting extern ... __ksym; for those clashed with libbpf's bpf_helpers.h, which already declares every helper. A new Bpf_helpers module enumerates the standard helpers (mirroring libbpf's bpf_helper_defs.h); the backend skips the __ksym declaration for any extern naming one. Real kfuncs are unaffected. 3. Compile eBPF objects with -fno-builtin struct_ops method names come from the kernel struct, so a sched_ext_ops scheduler must define an exit method. eBPF objects never link libc, but clang still recognises exit as 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-builtin is added to the generated Makefile's BPF_CFLAGS. eBPF C relies only on __builtin_* intrinsics (KernelScript emits __builtin_memcpy, never bare memcpy; struct-copy lowering uses the llvm.memcpy intrinsic) — none of which -fno-builtin affects. Testing Full suite: 85 test suites pass, 0 failures. New tests cover extern-kfunc IR codegen, the BPF-helper skip, and verbatim emission of builtin-named struct_ops methods. sched_ext_simple now builds fully end-to-end (.ebpf.o, skeleton, userspace binary). Verified every example's eBPF object builds with -fno-builtin. 🤖 Generated with Claude Code
Open Graph Description: Summary sched_ext_simple.ks (and other examples using extern kfunc declarations) compiled in KernelScript but produced eBPF C that failed to build. This branch fixes the three distinct problems fou...
X Description: Summary sched_ext_simple.ks (and other examples using extern kfunc declarations) compiled in KernelScript but produced eBPF C that failed to build. This branch fixes the three distinct problems fou...
Opengraph URL: https://github.com/multikernel/kernelscript/pull/21
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:a3907f80-69e1-6d1c-1440-6020eb15dafc |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D058:36DFDE:936E62:D3E8A8:6A621556 |
| html-safe-nonce | 8c974d07f1477b818530054422ecdd300cfbe12c05dca220b61633ab4652dedc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMDU4OjM2REZERTo5MzZFNjI6RDNFOEE4OjZBNjIxNTU2IiwidmlzaXRvcl9pZCI6IjY2NzAxOTM1MzIyNzUzOTc5NzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ed45b7e31c65aa79f9e20cc17b7c39cde278fddcefccb1c0ce8bc0f0c58961cb |
| hovercard-subject-tag | pull_request:3685051289 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/multikernel/kernelscript/pull/21/files |
| twitter:image | https://avatars.githubusercontent.com/u/227915880?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/227915880?s=400&v=4 |
| og:image:alt | Summary sched_ext_simple.ks (and other examples using extern kfunc declarations) compiled in KernelScript but produced eBPF C that failed to build. This branch fixes the three distinct problems fou... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | ccf61cb7ab435725b916ed640f57c45b2c4721db9469bc32656080efc5214b3e |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/multikernel/kernelscript git https://github.com/multikernel/kernelscript.git |
| octolytics-dimension-user_id | 202362072 |
| octolytics-dimension-user_login | multikernel |
| octolytics-dimension-repository_id | 1019261571 |
| octolytics-dimension-repository_nwo | multikernel/kernelscript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1019261571 |
| octolytics-dimension-repository_network_root_nwo | multikernel/kernelscript |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | a7585b3d2ee639495a70ce464d0a18bad88ea12c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width