kfl / ebpf-tools

Experiments with eBPF bytecode
MIT License
8 stars 4 forks source link

export to ELF64 #4

Open madsobitsoe opened 2 years ago

madsobitsoe commented 2 years ago

Implement exporting an assembled eBPF bytecode program to an ELF object, similar to e.g. clang -target bpf someProgram -o someProgram.o.

This would allow us to use tools like bpftool to load programs as well as dump both their xlated and JIT'ed versions. It might be useful for asserting correctness in ebpf-tools, as well as making it easier to use ebpf-tools with projects like the PREVAIL-verifier and uBPF. (Although uBPF accepts non-ELF raw bytecode).

I am unsure of the extent of this proposal, but I am quite certain it amounts to more than "wrap the bytecode in a header".

kfl commented 2 years ago

The problem that that there are several "standards" for how to put the bytecode in ELF, different loaders have different standards last I checked.

kfl commented 2 years ago

A first step towards this might be to extend the AST and assembler syntax to support named sections.

To generate the ELF object files, the melf package might be used. I think it is the most complete package for working with ELF files, and the only one that allows writing ELF files.