Skip to content

libbpf: Fix cast away const qualifiers in btf.h

Jiri Olsa bpf netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest7 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7libbpf: Use const cast for btf_int_* functionstools/lib/bpf/btf.h+3 -30 replies
2/7libbpf: Return const btf_array from btf_array inline functiontools/lib/bpf/btf.c tools/lib/bpf/btf.h+4 -40 replies
3/7libbpf: Return const btf_enum from btf_enum inline functiontools/lib/bpf/btf.c tools/lib/bpf/btf.h+3 -30 replies
4/7libbpf: Return const btf_member from btf_members inline functiontools/lib/bpf/btf.c tools/lib/bpf/btf.h tools/lib/bpf/libbpf.c+5 -50 replies
5/7libbpf: Return const btf_param from btf_params inline functiontools/lib/bpf/btf.c tools/lib/bpf/btf.h+5 -50 replies
6/7libbpf: Return const btf_var from btf_var inline functiontools/lib/bpf/btf.h+2 -20 replies
7/7libbpf: Return const struct btf_var_secinfo from btf_var_secinfos inline functiontools/lib/bpf/btf.c tools/lib/bpf/btf.h+5 -40 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h

hi,
when including btf.h in bpftrace, I'm getting -Wcast-qual warnings like:

bpf/btf.h: In function ‘btf_var_secinfo* btf_var_secinfos(const btf_type*)’:
bpf/btf.h:302:41: warning: cast from type ‘const btf_type*’ to type ‘btf_var_secinfo*’ casts away qualifiers [-Wcast-qual]

    302 |  return (struct btf_var_secinfo *)(t + 1);
        |                                         ^

I changed the btf.h header to comply with -Wcast-qual checks and used const cast away casting in libbpf objects, where it's all related to deduplication code, so I believe loosing const is fine there.

thanks,
jirka

---
Jiri Olsa (7):
libbpf: Use const cast for btf_int_* functions
libbpf: Return const btf_array from btf_array inline function
libbpf: Return const btf_enum from btf_enum inline function
libbpf: Return const btf_member from btf_members inline function
libbpf: Return const btf_param from btf_params inline function
libbpf: Return const btf_var from btf_var inline function
libbpf: Return const struct btf_var_secinfo from btf_var_secinfos inline function

 tools/lib/bpf/btf.c    | 21 +++++++++++----------
 tools/lib/bpf/btf.h    | 30 +++++++++++++++---------------
 tools/lib/bpf/libbpf.c |  2 +-
 3 files changed, 27 insertions(+), 26 deletions(-)