mirror-linux/tools/perf/util/bpf_skel
Sam James 4fc844347e perf bpf: Use __builtin_preserve_field_info for GCC compatibility
When exploring building bpf_skel with GCC's BPF support, there was a
build failure because of bpf_core_field_exists vs the mem_hops bitfield:
```
 In file included from util/bpf_skel/sample_filter.bpf.c:6:
util/bpf_skel/sample_filter.bpf.c: In function 'perf_get_sample':
tools/perf/libbpf/include/bpf/bpf_core_read.h:169:42: error: cannot take address of bit-field 'mem_hops'
  169 | #define ___bpf_field_ref1(field)        (&(field))
      |                                          ^
tools/perf/libbpf/include/bpf/bpf_helpers.h:222:29: note: in expansion of macro '___bpf_field_ref1'
  222 | #define ___bpf_concat(a, b) a ## b
      |                             ^
tools/perf/libbpf/include/bpf/bpf_helpers.h:225:29: note: in expansion of macro '___bpf_concat'
  225 | #define ___bpf_apply(fn, n) ___bpf_concat(fn, n)
      |                             ^~~~~~~~~~~~~
tools/perf/libbpf/include/bpf/bpf_core_read.h:173:9: note: in expansion of macro '___bpf_apply'
  173 |         ___bpf_apply(___bpf_field_ref, ___bpf_narg(args))(args)
      |         ^~~~~~~~~~~~
tools/perf/libbpf/include/bpf/bpf_core_read.h:188:39: note: in expansion of macro '___bpf_field_ref'
  188 |         __builtin_preserve_field_info(___bpf_field_ref(field), BPF_FIELD_EXISTS)
      |                                       ^~~~~~~~~~~~~~~~
util/bpf_skel/sample_filter.bpf.c:167:29: note: in expansion of macro 'bpf_core_field_exists'
  167 |                         if (bpf_core_field_exists(data->mem_hops))
      |                             ^~~~~~~~~~~~~~~~~~~~~
cc1: error: argument is not a field access
```

___bpf_field_ref1 was adapted for GCC in 12bbcf8e84
but the trick added for compatibility in 3a8b8fc317
isn't compatible with that as an address is used as an argument.

Workaround this by calling __builtin_preserve_field_info directly as the
bpf_core_field_exists macro does, but without the ___bpf_field_ref use.

Co-developed-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
Signed-off-by: Sam James <sam@gentoo.org>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Tested-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://gcc.gnu.org/PR121420
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2025-10-02 14:57:07 -03:00
..
vmlinux perf lock contention: Symbolize zone->lock using BTF 2025-04-29 12:23:53 -03:00
.gitignore perf build: Add ability to build with a generated vmlinux.h 2023-06-23 21:35:45 -07:00
augmented_raw_syscalls.bpf.c perf trace: Split BPF skel code to util/bpf_trace_augment.c 2025-06-26 10:31:05 -07:00
bench_uprobe.bpf.c perf bench uprobe: Add uretprobe variant of uprobe benchmarks 2024-04-12 17:54:02 -03:00
bperf_cgroup.bpf.c perf stat: Constify control data for BPF 2024-09-03 11:43:16 -03:00
bperf_follower.bpf.c perf stat: Support inherit events during fork() for bperf 2024-11-01 23:31:08 -07:00
bperf_leader.bpf.c
bperf_u.h perf stat: Support inherit events during fork() for bperf 2024-11-01 23:31:08 -07:00
bpf_prog_profiler.bpf.c
func_latency.bpf.c perf ftrace latency: Add -e option to measure time between two events 2025-07-14 22:51:58 -07:00
kwork_top.bpf.c perf: Completely remove possibility to override MAX_NR_CPUS 2025-09-12 10:52:22 -03:00
kwork_trace.bpf.c perf kwork: Remove unreachable judgments 2025-03-18 16:55:30 -07:00
lock_contention.bpf.c perf lock contention: Add -J/--inject-delay option 2025-05-09 14:32:15 -03:00
lock_data.h perf lock contention: Symbolize zone->lock using BTF 2025-04-29 12:23:53 -03:00
off_cpu.bpf.c perf record --off-cpu: Add --off-cpu-thresh option 2025-05-05 21:51:54 -03:00
perf_version.h perf test: add test for BPF metadata collection 2025-06-20 14:55:24 -07:00
sample-filter.h perf bpf-filter: Support filtering on cgroups 2024-08-28 18:21:49 -03:00
sample_filter.bpf.c perf bpf: Use __builtin_preserve_field_info for GCC compatibility 2025-10-02 14:57:07 -03:00
syscall_summary.bpf.c perf trace: Support --summary-mode=cgroup 2025-05-13 18:20:46 -03:00
syscall_summary.h perf trace: Support --summary-mode=cgroup 2025-05-13 18:20:46 -03:00