[BPF] Add exception handling support with .bpf_cleanup section (#192164) Add support for invoke/landingpad/resume instructions in the BPF backend so that Rust programs compiled with panic=unwind can run cleanup code (Drop implementations) when bpf_throw fires. Changes: 1. BPFISelLowering: Define exception pointer and selector registers (both R0) so SelectionDAG can lower landingpad instructions. 2. BPFAsmPrinter::emitFunctionBodyEnd: Emit a .bpf_cleanup section with a flat table of (begin, end, landing_pad) triples using R_BPF_64_NODYLD32 relocations. The .bpf_cleanup section layout (12 bytes per entry): u32 begin // start of the invoke region u32 end // end of the invoke region u32 landing_pad // address of the cleanup block The invoke region [begin, end) includes argument setup instructions before the call. The runtime checks begin <= PC < end to find the matching landing pad. Landing pad blocks survive optimization because invoke maintains CFG edges to them throughout codegen, same as every other backend. The standard .gcc_except_table and .eh_frame are also emitted by the existing DwarfCFIException handler; libbpf will ignore them. In runtime: - bpf_throw() is called (from panic handler) - Kernel walks the BPF call stack with arch_bpf_stack_walk() - For each frame, look up current PC in .bpf_cleanup table - If match found: redirect execution to the cleanup function . cleanup function runs Drop impls (bpf_free, rcu_read_unlock, etc.) . calls _Unwind_Resume() which is patched to just 'ret' by the verifier . bpf_throw() pops frame goes to next - If no match: go to next frame Signed-off-by: Alexei Starovoitov <ast@kernel.org> Co-authored-by: Alexei Starovoitov <ast@kernel.org>
Welcome to the LLVM project!
This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.
The LLVM project has multiple components. The core of the project is itself called “LLVM”. This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.
C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.
Other components include: the libc++ C++ standard library, the LLD linker, and more.
Consult the Getting Started with LLVM page for information on building and running LLVM.
For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.
Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.
The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.