Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

samples/bpf: Change _kern suffix to .bpf with syscall tracing program

Currently old compile rule (CLANG-bpf) doesn't contains VMLINUX_H define
flag which is essential for the bpf program that includes "vmlinux.h".
Also old compile rule doesn't directly specify the compile target as bpf,
instead it uses bunch of extra options with clang followed by long chain
of commands. (e.g. clang | opt | llvm-dis | llc)

In Makefile, there is already new compile rule which is more simple and
neat. And it also has -D__VMLINUX_H__ option. By just changing the _kern
suffix to .bpf will inherit the benefit of the new CLANG-BPF compile
target.

Also, this commit adds dummy gnu/stub.h to the samples/bpf directory.
As commit 1c2dd16add7e ("selftests/bpf: get rid of -D__x86_64__") noted,
compiling with 'clang -target bpf' will raise an error with stubs.h
unless workaround (-D__x86_64) is used. This commit solves this problem
by adding dummy stub.h to make /usr/include/features.h to follow the
expected path as the same way selftests/bpf dealt with.

Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20221224071527.2292-4-danieltimlee@gmail.com

authored by

Daniel T. Lee and committed by
Andrii Nakryiko
d4fffba4 8a4dd0bc

+11 -10
+5 -5
samples/bpf/Makefile
··· 125 125 always-y += sockex2_kern.o 126 126 always-y += sockex3_kern.o 127 127 always-y += tracex1_kern.o 128 - always-y += tracex2_kern.o 128 + always-y += tracex2.bpf.o 129 129 always-y += tracex3_kern.o 130 130 always-y += tracex4_kern.o 131 131 always-y += tracex5_kern.o 132 132 always-y += tracex6_kern.o 133 133 always-y += tracex7_kern.o 134 134 always-y += sock_flags_kern.o 135 - always-y += test_probe_write_user_kern.o 136 - always-y += trace_output_kern.o 135 + always-y += test_probe_write_user.bpf.o 136 + always-y += trace_output.bpf.o 137 137 always-y += tcbpf1_kern.o 138 138 always-y += tc_l2_redirect_kern.o 139 139 always-y += lathist_kern.o 140 140 always-y += offwaketime_kern.o 141 141 always-y += spintest_kern.o 142 - always-y += map_perf_test_kern.o 142 + always-y += map_perf_test.bpf.o 143 143 always-y += test_overhead_tp_kern.o 144 144 always-y += test_overhead_raw_tp_kern.o 145 145 always-y += test_overhead_kprobe_kern.o ··· 147 147 always-y += test_cgrp2_tc_kern.o 148 148 always-y += xdp1_kern.o 149 149 always-y += xdp2_kern.o 150 - always-y += test_current_task_under_cgroup_kern.o 150 + always-y += test_current_task_under_cgroup.bpf.o 151 151 always-y += trace_event_kern.o 152 152 always-y += sampleip_kern.o 153 153 always-y += lwt_len_hist_kern.o
+1
samples/bpf/gnu/stubs.h
··· 1 + /* dummy .h to trick /usr/include/features.h to work with 'clang -target bpf' */
samples/bpf/map_perf_test_kern.c samples/bpf/map_perf_test.bpf.c
+1 -1
samples/bpf/map_perf_test_user.c
··· 443 443 if (argc > 4) 444 444 max_cnt = atoi(argv[4]); 445 445 446 - snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); 446 + snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]); 447 447 obj = bpf_object__open_file(filename, NULL); 448 448 if (libbpf_get_error(obj)) { 449 449 fprintf(stderr, "ERROR: opening BPF object file failed\n");
samples/bpf/test_current_task_under_cgroup_kern.c samples/bpf/test_current_task_under_cgroup.bpf.c
+1 -1
samples/bpf/test_current_task_under_cgroup_user.c
··· 21 21 char filename[256]; 22 22 int map_fd[2]; 23 23 24 - snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); 24 + snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]); 25 25 obj = bpf_object__open_file(filename, NULL); 26 26 if (libbpf_get_error(obj)) { 27 27 fprintf(stderr, "ERROR: opening BPF object file failed\n");
samples/bpf/test_probe_write_user_kern.c samples/bpf/test_probe_write_user.bpf.c
+1 -1
samples/bpf/test_probe_write_user_user.c
··· 24 24 mapped_addr_in = (struct sockaddr_in *)&mapped_addr; 25 25 tmp_addr_in = (struct sockaddr_in *)&tmp_addr; 26 26 27 - snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); 27 + snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]); 28 28 obj = bpf_object__open_file(filename, NULL); 29 29 if (libbpf_get_error(obj)) { 30 30 fprintf(stderr, "ERROR: opening BPF object file failed\n");
samples/bpf/trace_output_kern.c samples/bpf/trace_output.bpf.c
+1 -1
samples/bpf/trace_output_user.c
··· 51 51 char filename[256]; 52 52 FILE *f; 53 53 54 - snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); 54 + snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]); 55 55 obj = bpf_object__open_file(filename, NULL); 56 56 if (libbpf_get_error(obj)) { 57 57 fprintf(stderr, "ERROR: opening BPF object file failed\n");
samples/bpf/tracex2_kern.c samples/bpf/tracex2.bpf.c
+1 -1
samples/bpf/tracex2_user.c
··· 123 123 int i, j = 0; 124 124 FILE *f; 125 125 126 - snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); 126 + snprintf(filename, sizeof(filename), "%s.bpf.o", argv[0]); 127 127 obj = bpf_object__open_file(filename, NULL); 128 128 if (libbpf_get_error(obj)) { 129 129 fprintf(stderr, "ERROR: opening BPF object file failed\n");