AGENT SKILL

eBPF 程序构建验证

verify-bpf

为 ebpf-for-windows 项目构建并验证 eBPF 程序。当用户要求将 .c BPF 源码编译为 .o、使用 bpf2c 验证 .o ELF 文件或诊断验证失败时使用此技能。涵盖完整的 clang→bpf2c 流水线。

License 许可
MIT
最近更新
2026-11-14
Stars
★ 3.6k
Forks
311

01 前言 Front Matter

name
verify-bpf
description
Build and verify eBPF programs for the ebpf-for-windows project. Use this skill when asked to compile a .c BPF source to .o, verify a .o ELF file with bpf2c, or diagnose verification failures. Covers the full clang→bpf2c pipeline.

03 SKILL.md 正文

Build & Verify eBPF Programs (ebpf-for-windows)

Compile eBPF C source to ELF bytecode with clang, then verify (and optionally generate native code) with bpf2c. On verification failure, diagnose using the PREVAIL reference.

When to Use

  • User asks to compile/build a .c eBPF program to .o
  • User asks to verify a .o ELF file or check if it passes the verifier
  • User asks to debug or fix a verification failure from bpf2c output
  • User mentions bpf2c, clang+bpf, or PREVAIL verification in the ebpf-for-windows context

Prerequisites

  • clang.exe — find the first existing path (highest priority first): packages\llvm.tools\clang.exe, "$env:ProgramFiles\LLVM\bin\clang.exe", "$(& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath)\VC\Tools\Llvm\bin\clang.exe"
  • bpf2c.exe — if x64\Debug\bpf2c.exe is missing, build it: msbuild ebpf-for-windows.sln /m /p:Configuration=Debug /p:Platform=x64 /t:tools\bpf2c

Quick Reference

1. Compile: C → ELF (.o)

Run from the solution root directory (use the clang path found above):

# Standard sample programs
& '<clang-path>' -g -target bpf -O2 -Werror `
  -Iinclude -Iexternal\bpftool `
  -Itests\xdp -Itests\socket `
  -Itests\sample\ext\inc -Itests\include `
  -c <SOURCE>.c -o <OUTPUT>.o

For undocked programs (tests\sample\undocked\*.c), also add:

  • -Itests\sample
  • -Iundocked\tests\sample\ext\inc

2. Verify: ELF (.o) → native C (via bpf2c)

.\x64\Debug\bpf2c.exe --bpf <FILE>.o --sys <OUTPUT_DIR>\<name>_driver.c

Add --verbose to get detailed verifier output (pre/post invariants at each instruction) on failure.

bpf2c Options

Flag Purpose
--bpf <file> Input ELF file containing BPF bytecode
--sys <file> Generate Windows kernel driver C wrapper
--dll <file> Generate Windows DLL C wrapper
--raw <file> Generate C code without platform wrapper
--verbose Show detailed verifier failure info (invariants)
--type <str> Override eBPF program type string
--hash <alg> Algorithm used to hash ELF file

Workflow

Step 1: Identify the Source

Determine the .c source file and where the .o should go. Common patterns:

Source Location Include Flags
tests\sample\*.c -Iinclude -Iexternal\bpftool -Itests\xdp -Itests\socket -Itests\sample\ext\inc -Itests\include
tests\sample\undocked\*.c Same as above, plus -Itests\sample -Iundocked\tests\sample\ext\inc
User-provided file Start with the standard sample flags; add more -I paths as needed

Step 2: Compile with Clang

Run clang. If it fails, fix compiler errors in the C source (standard C/clang diagnostics).

Step 3: Verify with bpf2c

Run bpf2c with --sys (or --dll/--raw). Two outcomes:

  • Success → bpf2c generates the output C file. Verification passed.
  • Failure → bpf2c prints verifier errors. Proceed to diagnosis.

Step 4: Diagnose Failures

On verification failure:

  1. Re-run with --verbose if not already used, to get full invariant output.
  2. Read external/ebpf-verifier/docs/llm-context.md — the authoritative PREVAIL diagnostic reference.
  3. Follow the diagnosis protocol in that document (identify error → check pre-invariant → trace root cause → recommend fix).

Example: Full Pipeline

# Compile (undocked program — needs full include paths)
& '<clang-path>' -g -target bpf -O2 -Werror `
  -Iinclude -Iexternal\bpftool `
  -Itests\xdp -Itests\socket -Itests\sample\ext\inc -Itests\include `
  -Itests\sample -Iundocked\tests\sample\ext\inc `
  -c tests\sample\undocked\perf_event_burst.c `
  -o x64\Debug\perf_event_burst.o

# Verify + generate driver
.\x64\Debug\bpf2c.exe --bpf x64\Debug\perf_event_burst.o `
  --sys .\x64\Debug\perf_event_burst_km\perf_event_burst_driver.c

# If verification fails, re-run with --verbose for diagnosis
.\x64\Debug\bpf2c.exe --bpf x64\Debug\perf_event_burst.o `
  --sys .\x64\Debug\perf_event_burst_km\perf_event_burst_driver.c `
  --verbose

04 同仓库更多 Skills

microsoft
microsoft/ebpf-for-windows

PREVAIL 验证失败诊断

verify-prevail

诊断 PREVAIL 验证器报告的 eBPF 程序验证失败。此技能适用于在独立 PREVAIL 仓库(external/ebpf-verifier)中验证的 Linux 兼容 eBPF 程序。对于使用 Windows 特定功能的程序(bpf2c 流水线、Windows helpers、ebpf-for-windows 头文件),请改用 'verify-bpf' 技能。

软件开发工程师调试与故障排查
★ 3.6k
microsoft
microsoft/ebpf-for-windows

PR 分诊报告生成

pr-triage-report

为 microsoft/ebpf-for-windows 中开放的、非草稿状态的拉取请求(PR)生成 Markdown 分诊报告,包括 CI 状态、新鲜度、签署认可(sign-offs)以及下一负责人路由。

软件开发工程师代码仓库协作管理
★ 3.6k
microsoft
microsoft/ebpf-for-windows

崩溃转储文件调试分析

debug-crash-dump

使用 CDB/WinDbg 下载并分析 CI 失败产生的故障转储文件(crash dump)。当用户要求调试崩溃、分析转储文件、配置 WinDbg/CDB、调查故障注入失败或启动 mcp-windbg 时使用此技能。

软件开发工程师调试与故障排查
★ 3.6k
microsoft
microsoft/ebpf-for-windows

PREVAIL 验证器构建测试

build-prevail

独立构建并测试 PREVAIL 验证器(external/ebpf-verifier)。当需要构建、测试或迭代 PREVAIL 验证器,运行 YAML 验证测试,或使用该验证器的 cmake 构建系统时使用此技能。

软件开发工程师开发环境与工具链管理
★ 3.6k
microsoft
microsoft/ebpf-for-windows

eBPF for Windows 项目构建

build-ebpf

构建 eBPF for Windows 仓库——整个解决方案或特定组件。当需要构建、编译、重新构建、还原或清理项目及其任何组件(驱动、库、工具、测试等)时使用此技能。

软件开发工程师开发环境与工具链管理
★ 3.6k
microsoft
microsoft/ebpf-for-windows

ebPF C++ 分支变更对抗审查

adversarial-branch-review

对 ebpf-for-windows 中活动分支与基线分支之间的 C/C++ 变更执行深度对抗性审查,产出详细的审查报告和逐条修复清单。

软件开发工程师代码仓库协作管理
★ 3.6k