Skip to content

Commit ca7dc27

Browse files
anakryikoAlexei Starovoitov
authored and
Alexei Starovoitov
committed
bpftool: Add header guards to generated vmlinux.h
Add canonical #ifndef/#define/#endif guard for generated vmlinux.h header with __VMLINUX_H__ symbol. __VMLINUX_H__ is also going to play double role of identifying whether vmlinux.h is being used, versus, say, BCC or non-CO-RE libbpf modes with dependency on kernel headers. This will make it possible to write helper macro/functions, agnostic to exact BPF program set up. Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 1507091 commit ca7dc27

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tools/bpf/bpftool/btf.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ static int dump_btf_c(const struct btf *btf,
389389
if (IS_ERR(d))
390390
return PTR_ERR(d);
391391

392+
printf("#ifndef __VMLINUX_H__\n");
393+
printf("#define __VMLINUX_H__\n");
394+
printf("\n");
392395
printf("#ifndef BPF_NO_PRESERVE_ACCESS_INDEX\n");
393396
printf("#pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)\n");
394397
printf("#endif\n\n");
@@ -412,6 +415,8 @@ static int dump_btf_c(const struct btf *btf,
412415
printf("#ifndef BPF_NO_PRESERVE_ACCESS_INDEX\n");
413416
printf("#pragma clang attribute pop\n");
414417
printf("#endif\n");
418+
printf("\n");
419+
printf("#endif /* __VMLINUX_H__ */\n");
415420

416421
done:
417422
btf_dump__free(d);

0 commit comments

Comments
 (0)