Re: [RFC bpf-next 05/12] libbpf: Header guards for selected data structures in vmlinux.h

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Oct 25, 2022 at 3:28 PM Eduard Zingerman <eddyz87@xxxxxxxxx> wrote:
>
> The goal of the patch is to allow usage of header files from
> `include/uapi` alongside with `vmlinux.h`. E.g. as follows:
>
>   #include <uapi/linux/tcp.h>
>   #include "vmlinux.h"
>
> This goal is achieved by adding #ifndef / #endif guards in vmlinux.h
> around definitions that originate from the `include/uapi` headers. The
> guards emitted match the guards used in the original headers.
> E.g. as follows:
>
> include/uapi/linux/tcp.h:
>
>   #ifndef _UAPI_LINUX_TCP_H
>   #define _UAPI_LINUX_TCP_H
>   ...
>   union tcp_word_hdr {
>         struct tcphdr hdr;
>         __be32        words[5];
>   };
>   ...
>   #endif /* _UAPI_LINUX_TCP_H */
>
> vmlinux.h:
>
>   ...
>   #ifndef _UAPI_LINUX_TCP_H
>
>   union tcp_word_hdr {
>         struct tcphdr hdr;
>         __be32 words[5];
>   };
>
>   #endif /* _UAPI_LINUX_TCP_H */
>   ...
>
> The problem of identifying data structures from uapi and selecting
> proper guard names is delegated to pahole. When configured pahole
> generates fake `BTF_DECL_TAG` records with header guards information.
> The fake tag is distinguished from a real tag by a prefix
> "header_guard:" in its value. These tags could be present for unions,
> structures, enums and typedefs, e.g.:
>
> [24139] STRUCT 'tcphdr' size=20 vlen=17
>   ...
> [24296] DECL_TAG 'header_guard:_UAPI_LINUX_TCP_H' type_id=24139 ...
>
> This patch adds An option `emit_header_guards` to `struct btf_dump_opts`.
> When this option is present the function `btf_dump__dump_type` emits
> header guards for top-level declarations. The header guards are
> identified by inspecting fake `BTF_DECL_TAG` records described above.

This looks like a completely arbitrary convention that libbpf has no
business knowing or caring about. I think bpftool should be emitting
these guards when generating vmlinux.h. Let's solve this somehow
differently.

>
> Signed-off-by: Eduard Zingerman <eddyz87@xxxxxxxxx>
> ---
>  tools/lib/bpf/btf.h      |  7 +++-
>  tools/lib/bpf/btf_dump.c | 89 +++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 94 insertions(+), 2 deletions(-)
>

[...]



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux