Skip to content

BPF_SNPRINTF: R3 does not point to a readonly map #722

Answered by lmb
huchen2021 asked this question in Q&A
Discussion options

You must be logged in to vote

From @dylandreimerink:

You are using a string literal directly in snprintf BPF_SNPRINTF(ip_str, sizeof(ip_str), "hello"). You must define it as a static const variable, which will cause the compiler to put it in the global data section(basically a read-only array map, hence the error).
The easiest way to fix it is to use the libbpf helper macros which do this for you so you can use the same syntax without thinking about it: https://github.com/libbpf/libbpf/blob/e5ff285a445af864af7f38e0b5c6904b099c9b7b/src/bpf_helpers.h#L231

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@orishuss
Comment options

Answer selected by lmb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #717 on June 24, 2022 15:10.