Re: [RFC bpf-next 08/12] kbuild: Script to infer header guard values for uapi headers

[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 script infers header guard defines in headers from
> include/uapi/**/*.h . E.g. header guard for the
> `include/uapi/linux/tcp.h` is `_UAPI_LINUX_TCP_H`:
>
>     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 */
>
> The output of the script could be used as an input to pahole's
> `--header_guards_db` parameter. This information is necessary to
> repeat the same header guards in the `vmlinux.h` generated from BTF.
>
> It is not possible to infer the guard names from header file names
> alone, the file content has to be analyzed. The following heuristic is
> used to infer guard for a specific file:
> - All pairs `#ifndef <candidate>` / `#define <candidate>` are collected;
> - If a unique candidate matching regex `${headername}.*_H(EADER)?` it
>   is selected;
> - If a unique candidate matching regex `_H(EADER)?_` it is selected;
> - If a unique candidate matching regex `_H(EADER)?$` it is selected;
>
> There is also a small list of headers that can't be caught by the
> rules above, 15 in total. These headers and corresponding guard values
> are listed in the `%OVERRIDES` hash table.
>

Instead of expecting naming pattern, why can't we just expect

/* some comments here */

#ifndef XXX
#define XXX
....
#endif

and extract XXX from such a pattern?

The harder part is skipping comments (but awk might help do this
easier), or we can just ignore all the lines before the first #ifndef.

WDYT?

> Signed-off-by: Eduard Zingerman <eddyz87@xxxxxxxxx>
> ---
>  scripts/infer_header_guards.pl | 191 +++++++++++++++++++++++++++++++++
>  1 file changed, 191 insertions(+)
>  create mode 100755 scripts/infer_header_guards.pl
>

[...]



[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