[Bug target/121420] Failed to build BPF program accepted by Clang (error: cannot take address of bit-field 'mem_hops')

2025-08-05 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121420

--- Comment #8 from Andrew Pinski  ---
(In reply to Sam James from comment #7)
> ->
> https://lore.kernel.org/linux-perf-users/
> fea380fb0934d039d19821bba88130e632bbfe8d.1754438581.git@gentoo.org/T/#u
> 
> MOVED then?

Let's wait for the reply ...

[Bug target/121420] Failed to build BPF program accepted by Clang (error: cannot take address of bit-field 'mem_hops')

2025-08-05 Thread sjames at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121420

--- Comment #7 from Sam James  ---
->
https://lore.kernel.org/linux-perf-users/fea380fb0934d039d19821bba88130e632bbfe8d.1754438581.git@gentoo.org/T/#u

MOVED then?

[Bug target/121420] Failed to build BPF program accepted by Clang (error: cannot take address of bit-field 'mem_hops')

2025-08-05 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121420

--- Comment #6 from Andrew Pinski  ---
s/FIELD_EXISTENCE/BPF_FIELD_EXISTS/

But you get the idea.

[Bug target/121420] Failed to build BPF program accepted by Clang (error: cannot take address of bit-field 'mem_hops')

2025-08-05 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121420

--- Comment #5 from Andrew Pinski  ---
(In reply to Andrew Pinski from comment #4)
> I think this patch fixes the issue:

diff --git a/tools/perf/util/bpf_skel/sample_filter.bpf.c
b/tools/perf/util/bpf_skel/sample_filter.bpf.c
index b195e6efeb8b..83b5b13ebe1d 100644
--- a/tools/perf/util/bpf_skel/sample_filter.bpf.c
+++ b/tools/perf/util/bpf_skel/sample_filter.bpf.c
@@ -164,7 +164,7 @@ static inline __u64 perf_get_sample(struct
bpf_perf_event_data_kern *kctx,
if (entry->part == 8) {
union perf_mem_data_src___new *data = (void
*)&kctx->data->data_src;

-   if (bpf_core_field_exists(data->mem_hops))
+   if (__builtin_preserve_field_info(data->mem_hops,
FIELD_EXISTENCE))
return data->mem_hops;

return 0;

[Bug target/121420] Failed to build BPF program accepted by Clang (error: cannot take address of bit-field 'mem_hops')

2025-08-05 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121420

--- Comment #4 from Andrew Pinski  ---
I think this patch fixes the issue:
```
diff --git a/tools/perf/util/bpf_skel/sample_filter.bpf.c
b/tools/perf/util/bpf_skel/sample_filter.bpf.c
index b195e6efeb8b..f1ffef44f603 100644
--- a/tools/perf/util/bpf_skel/sample_filter.bpf.c
+++ b/tools/perf/util/bpf_skel/sample_filter.bpf.c
@@ -76,7 +76,7 @@ static inline __u64 perf_get_sample(struct
bpf_perf_event_data_kern *kctx,
 {
struct perf_sample_data___new *data = (void *)kctx->data;

-   if (!bpf_core_field_exists(data->sample_flags))
+   if (!__builtin_preserve_field_info(data->sample_flags,
FIELD_EXISTENCE))
return 0;

 #define BUILD_CHECK_SAMPLE(x) 
```

[Bug target/121420] Failed to build BPF program accepted by Clang (error: cannot take address of bit-field 'mem_hops')

2025-08-05 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121420

--- Comment #3 from Andrew Pinski  ---
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3a8b8fc3174891c4c12f5766d82184a82d4b2e3e
introduced the brokenness after the Cupertino Miranda's patch.

commit 3a8b8fc3174891c4c12f5766d82184a82d4b2e3e
Author: Ian Rogers 
Date:   Fri Apr 7 22:52:08 2023 -0700

perf bpf filter: Support pre-5.16 kernels where 'mem_hops' isn't in 'union
perf_mem_data_src'

The 'mem_hops' bits were added in 5.16 with no prior equivalent.

Signed-off-by: Ian Rogers 
Acked-by: Namhyung Kim 
Cc: Adrian Hunter 
Cc: Alexander Shishkin 
Cc: Ingo Molnar 
Cc: Jiri Olsa 
Cc: Mark Rutland 
Cc: Peter Zijlstra 
Cc: [email protected]
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo 

[Bug target/121420] Failed to build BPF program accepted by Clang (error: cannot take address of bit-field 'mem_hops')

2025-08-05 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121420

--- Comment #2 from Andrew Pinski  ---
This looks like it is doing the old way.

because GCC documentation says it should be just done as:
__builtin_preserve_field_info (arg->y, FIELD_BYTE_OFFSET);


https://gcc.gnu.org/onlinedocs/gcc/BPF-Built-in-Functions.html

[Bug target/121420] Failed to build BPF program accepted by Clang (error: cannot take address of bit-field 'mem_hops')

2025-08-05 Thread sjames at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121420

--- Comment #1 from Sam James  ---
The header does:

#ifdef __clang__
#define ___bpf_field_ref1(field)(field)
#define ___bpf_field_ref2(type, field)  (___bpf_typeof(type)->field)
#else
#define ___bpf_field_ref1(field)(&(field))
#define ___bpf_field_ref2(type, field)  (&(___bpf_typeof(type)->field))
#endif

which comes from
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=12bbcf8e840f40b82b02981e96e0a5fbb0703ea9