[clang] [BPF] Support preserve_access_index attribute for enum (PR #232498)

via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 3 13:55:15 PST 2026


eddyz87 wrote:

> How is vmlinux.h going to use it?
> 
> With `apply_to = enum` the enumerators of every named enum in vmlinux.h stop being constants. `enum bpf_map_type` is one of them, and `CheckFieldDecl()` rejects the map definition:
> 
> ```
>   #define __uint(name, val) int (*name)[val]
> 
>   struct {
>           __uint(type, BPF_MAP_TYPE_HASH);
>   } m SEC(".maps");
> 
>   error: fields must have a constant size: 'variable length array in
>          structure' extension will never be supported
> ```
> 
> I don't know how to differentiate enums within vmlinux.h

Oops.
Options as I see them:
- Drop the error reporting (but it really is an error, sigh).
- Somehow mark uapi types, e.g. with `uapi` decl tag in pahole (e.g. based on origin file name), use that decl tag in bpftool to not wrap marked types with `preserve_access_index`. We wanted this for some time, I think. The downside is that one would need to upgrade pahole alongside clang, otherwise a combo of old pahole/vmlinux.h and new clang would break the compilation as Alexei points out.
- Andrii suggests allowing explicit casts, not reporting an error if `(u32)FOO` is used, however this still allows some misuse.

https://github.com/llvm/llvm-project/pull/232498


More information about the cfe-commits mailing list