Re: [RFC PATCH tip 5/5] tracing filter examples in BPF
From: Alexei Starovoitov
Date: Tue Dec 03 2013 - 20:21:46 EST
On Tue, Dec 3, 2013 at 4:35 PM, Jonathan Corbet <corbet@xxxxxxx> wrote:
> On Mon, 2 Dec 2013 20:28:50 -0800
> Alexei Starovoitov <ast@xxxxxxxxxxxx> wrote:
>
>> GCC-BPF backend is available on github
>> (since gcc plugin infrastructure doesn't allow for out-of-tree backends)
>
> Do you have a pointer to where this backend can be found? I've
> done a bit of digging around but seem to be unable to find it…
here it is:
https://github.com/iovisor/bpf_gcc/commit/9e7223f8f09c822ecc6e18309e89a574a23dbf63
It's quite small comparing to normal backend:
config.me | 3 +
config.sub | 12 +-
gcc/common/config/bpf/bpf-common.c | 39 ++
gcc/config.gcc | 18 +
gcc/config/bpf/bpf-modes.def | 22 +
gcc/config/bpf/bpf-protos.h | 60 ++
gcc/config/bpf/bpf.c | 1063 ++++++++++++++++++++++++++++++++++++
gcc/config/bpf/bpf.h | 746 +++++++++++++++++++++++++
gcc/config/bpf/bpf.md | 895 ++++++++++++++++++++++++++++++
gcc/config/bpf/linux.h | 67 +++
10 files changed, 2922 insertions(+), 3 deletions(-)
Instruction emission is in bpf.md in functions like:
(define_insn "adddi3"
[(set (match_operand:DI 0 "int_reg_operand" "=r, r")
(plus:DI (match_operand:DI 1 "int_reg_operand" "0, 0")
(match_operand:DI 2 "int_reg_or_const_operand" "r, K")))]
""
"@
BPF_INSN_ALU(BPF_ADD, %0, %2), // %0 += %2
BPF_INSN_ALU_IMM(BPF_ADD, %0, %2), // %0 += %2"
[(set_attr "type" "arith,arith") ])
So it takes C and emits BPF_* macros from include/linux/bpf.h
tools/bpf/trace/ examples were generated by it.
Eventually it will be changed to emit binary hex directly, but macros
are much easier to understand for now.
Thanks
Alexei
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/