I have written a BPF program that I can install using gobpf, i.e. using their bcc tooling. While this works alright from a main package, this breaks as soon as I move it into a package for importing it as a module.
To clarify: It works with all code in package main
, but as soon as I rename the package and move the main()
to cmd/command.go
it stops working with go run
complaining that it can't find an included lib (bcc/proto.h
). Incidentally, this is the same error as I always got when running gcc
on my .c
file without any indication I want to use BPF (the part that gobpf
did for me, until I moved its invocation to a module...).
I realize this is question very specific and sits in a weird place between Go, CGo, the way C and C++ handle includes, BPF, and bcc, but I am at a loss here.
You can check out my code here https://github.com/bwNetFlow/bpfdump if that helps. It needs bcc
installed in addition to go run
doing its thing. Basically:
HEAD
is the modularized version that does not work (go run cmd/dump.go
)HEAD~
is my initial experiment that does work (go run bpfdump.go
) (you'll get an permission error as user, which is fine as it has compiled anyways).
PS: I think it might have to do with this (rather creative?) construction of bcc/proto.h
: https://github.com/iovisor/bcc/blob/master/src/cc/exported_files.cc