Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error compiling go programme #400

Closed
sidahmedabdelillah opened this issue Jan 24, 2024 · 2 comments
Closed

Error compiling go programme #400

sidahmedabdelillah opened this issue Jan 24, 2024 · 2 comments

Comments

@sidahmedabdelillah
Copy link

Hello. I am working demonstration for ebpf.

This is the go programme

package main

import "C"

import (
	"fmt"
	"os"
	"unsafe"

	bpf "github.com/aquasecurity/libbpfgo"
)

type Target struct {
	Pid  uint32
	Comm [16]byte
	Path [256]byte
}

func main() {
	bpfModule, err := bpf.NewModuleFromFile("ebpf.o")
	if err != nil {
		panic(err)
	}
	defer bpfModule.Close()
	if err := bpfModule.BPFLoadObject(); err != nil {
		panic(err)
	}
	targetMap, err := bpfModule.GetMap("target")
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(-1)
	}

	// update the map

	key := uint32(0x1337)
	var val Target
	copy(val.Comm[:], "procname")
	copy(val.Path[:], "/home/azureuser/ebpf/secret")
	val.Pid = uint32(9999)
	keyUnsafe := unsafe.Pointer(&key)
	valueUnsafe := unsafe.Pointer(&val)
	targetMap.Update(keyUnsafe, valueUnsafe)
}

I compiled the bpf using this commande

clang -g -O2 -c -target bpf -o ebpf.o ebpf.c

and tried building the go using this
CC=gcc CGO_CFLAGS="-I /usr/include/bpf" CGO_LDFLAGS="/usr/lib64/libbpf.a" sudo go build -o libbpfgo-prog
I got the error
../../../go/pkg/mod/github.com/aquasecurity/libbpfgo@v0.6.0-libbpf-1.3/map-common.go:51:39: could not determine kind of name for C.BPF_MAP_TYPE_BLOOM_FILTER

@geyslan
Copy link
Member

geyslan commented Jan 25, 2024

CGO_CFLAGS="-I /usr/include/bpf"

It seems you're using the installed libbpf include and not the one provided by libbpfgo. I guess your system libbpf version hasn't support to BPF_MAP_TYPE_BLOOM_FILTER (introduced by libbpf/libbpf@168cf9b).

Take a look at libbpfgo selftest building process for more information:

CGO_CFLAGS_STATIC = "-I$(abspath $(OUTPUT)) -I$(abspath ../common)"
CGO_LDFLAGS_STATIC = "-lelf -lz $(LIBBPF_OBJ)"

@geyslan
Copy link
Member

geyslan commented Jan 31, 2024

Closing as it doesn't seem a problem. Please reopen it if relevant.

@geyslan geyslan closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants