libbpf: Fix build warning on ref_ctr_off
PATCH 1/1 libbpf: Fix build warning on ref_ctr_off
Clang warns on 32-bit ARM on this comparision
libbpf.c:10497:18: error: result of comparison of constant 4294967296 with expression of type 'size_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]
if (ref_ctr_off >= (1ULL << PERF_UPROBE_REF_CTR_OFFSET_BITS))
~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Check for platform long int to be larger than 32-bits before enabling this check, it false on 32bit anyways.
--- tools/lib/bpf/libbpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +1 -1
@@ -9837,7 +9837,7 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,char errmsg[STRERR_BUFSIZE ];int type, pfd; -if (ref_ctr_off >= (1ULL <<PERF_UPROBE_REF_CTR_OFFSET_BITS )) +if (BITS_PER_LONG >32 && ref_ctr_off >= (1ULL <<PERF_UPROBE_REF_CTR_OFFSET_BITS ))return -EINVAL ;memset (&attr,0 , attr_sz);
Signature · 1 line
2.38.1
Quoted 30 lines · Khem Raj
Clang warns on 32-bit ARM on this comparision
libbpf.c:10497:18: error: result of comparison of constant 4294967296 with expression of type '
size_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]if (ref_ctr_off >= (1ULL << PERF_UPROBE_REF_CTR_OFFSET_BITS)) ~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Check for platform long int to be larger than 32-bits before enabling this check, it false on 32bit anyways.
Cc Alexei Starovoitov <[email protected]>Cc Daniel Borkmann <[email protected]>Cc Song Liu <[email protected]>Cc Yonghong Song <[email protected]>Cc Jiri Olsa <[email protected]>Cc Paul Walmsley <[email protected]>Cc Palmer Dabbelt <[email protected]>Cc Nathan Chancellor <[email protected]>Cc Nick Desaulniers <[email protected]>Signed-off-by Khem Raj <[email protected]>--- tools/lib/bpf/libbpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/lib/bpf/libbpf.c +0
-0
tools/lib/bpf/libbpf.c static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name, · line 9840
Quoted 5 lines
tools/lib/bpf/libbpf.c +1
-1@@ -9837,7 +9837,7 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,char errmsg[STRERR_BUFSIZE ];int type, pfd; -if (ref_ctr_off >= (1ULL <<PERF_UPROBE_REF_CTR_OFFSET_BITS )) +if (BITS_PER_LONG >32 && ref_ctr_off >= (1ULL <<PERF_UPROBE_REF_CTR_OFFSET_BITS ))
Where is BITS_PER_LONG defined? Is it a compiler-provided macro? A bit hesitant about taking dependency on such a macro. Also quick googling suggests user-space programs should use __BITS_PER_LONG?
Can you try if just casting ref_ctr_off to __u64 would make this warning go away?
Quoted 6 lines
tools/lib/bpf/libbpf.c +0
-1return -EINVAL ;memset (&attr,0 , attr_sz); --2.38.1
Quoted 35 lines · Andrii Nakryiko
Quoted 33 lines · Khem Raj
Clang warns on 32-bit ARM on this comparision
libbpf.c:10497:18: error: result of comparison of constant 4294967296 with expression of type '
size_t' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare]if (ref_ctr_off >= (1ULL << PERF_UPROBE_REF_CTR_OFFSET_BITS)) ~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Check for platform long int to be larger than 32-bits before enabling this check, it false on 32bit anyways.
Cc Alexei Starovoitov <[email protected]>Cc Daniel Borkmann <[email protected]>Cc Song Liu <[email protected]>Cc Yonghong Song <[email protected]>Cc Jiri Olsa <[email protected]>Cc Paul Walmsley <[email protected]>Cc Palmer Dabbelt <[email protected]>Cc Nathan Chancellor <[email protected]>Cc Nick Desaulniers <[email protected]>Signed-off-by Khem Raj <[email protected]>--- tools/lib/bpf/libbpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/lib/bpf/libbpf.c +0
-0@@ -9837,7 +9837,7 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,char errmsg[STRERR_BUFSIZE ];int type, pfd;
Quoted 6 lines
tools/lib/bpf/libbpf.c static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name, · line 9840
Quoted 2 lines
tools/lib/bpf/libbpf.c +1
-1-if (ref_ctr_off >= (1ULL <<PERF_UPROBE_REF_CTR_OFFSET_BITS )) +if (BITS_PER_LONG >32 && ref_ctr_off >= (1ULL <<PERF_UPROBE_REF_CTR_OFFSET_BITS ))Where is
BITS_PER_LONGdefined? Is it a compiler-provided macro? A bit hesitant about taking dependency on such a macro. Also quick googling suggests user-space programs should use__BITS_PER_LONG?
BITS_PER_LONG is in include/asm-generic/bitsperlong.h, I have sent v2 which implements your suggestion
Quoted 10 lines
Can you try if just casting
ref_ctr_offto__u64would make this warning go away?Quoted 6 lines
tools/lib/bpf/libbpf.c +0
-1return -EINVAL ;memset (&attr,0 , attr_sz); --2.38.1