[clang] [BPF] Support preserve_access_index attribute for enum (PR #232498)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 11 13:58:50 PST 2026
YJNSystems wrote:
> unfortunately quick fix doesn't work here, we'll have to do it right from the get go
Fair enough.
> > I think we really just have to differentiate clearly if the kernel has the authority over an enum, or if we want a "local copy" of it that is not relocated. I think forcing a BPF programmer to guess where "N" is 4 and where it is relocated to 8 is undesirable. An enumerator should always mean the same thing, independent of what kind of context/expression it is used in.
>
> I'm not sure I follow about kernel authority and/or local copy? kernel does have authority on a definition of enum, and those UAPI enums are never changing only by convention... sorry, just not following what the implication one way or another would be...
I just mean that either all uses of an enum should be relocated (the kernel has the authority over their values at load) or none (equivalent to the enum not refering to the kernel-internal one at all, like a local copy at the time of compilation).
My only complaint about the current state is really just that inconsistent middle grounds are possible. If at compilation some kernel header defines N as 4 but the kernel that loads the BPF program changes it to 8, I would prefer if the BPF programmer didn't have to expect N to have two different values in their code. E.g., "switch (i) { case N: ... }" should be the same as "if (i==N) ...", instead of getting "switch (i) { case 4: ... }" and "if (i==8) ..." at runtime.
To what extend this is actually a problem with existing BPF programs, I don't know. I suspect you are far more knowledgeable in that regard.
https://github.com/llvm/llvm-project/pull/232498
More information about the cfe-commits
mailing list