Skip to content

How do I rewrite global variables before loading a BPF object? #795

Answered by ti-mo
Ephemeraler asked this question in Q&A
Discussion options

You must be logged in to vote

@Ephemeraler ebpf-go implements this using CollectionSpec.RewriteConstants().

Given the following global variable in C:

volatile const uint32_t arg;

The following Go code takes care of rewriting that constant to hold the value 1 at runtime:

err := spec.RewriteConstants(map[string]interface{}{
	"arg":  uint32(1),
})

Replies: 1 comment 19 replies

Comment options

You must be logged in to vote
19 replies
@ti-mo
Comment options

@g0dA
Comment options

@thediveo
Comment options

@g0dA
Comment options

@thediveo
Comment options

Answer selected by ti-mo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants