On Wed, Apr 02, 2025 at 09:16:47PM +0000, Qing Zhao wrote: > Hi, Bill, > > Thanks for the summary. > > I think that this is good. > > Two more questions: > > 1. Shall we keep the same name of the attribute counted_by for the 2nd new > syntax? > Or use a new name, such as, “counted_by_exp"?
FWIW, the Linux kernel will likely need to create its own macros for all of this stuff (just to do the compiler version testing), so there should be no problem with different names (or same names) in the compiler API. > I don’t have strong preference here. As mentioned by Jacub in a > previous email, these two syntaxes can be distinguished by the number > of arguments of the attribute. > > So for GCC, there should be no issue with either old name of a new name. > However, I am not sure about CLANG. (Considering the complication with > APPLE’s implementation) > > 2. The 2nd new syntax should resolve all the following new requests from > Linux Kernel: > 2.1 Refer to a field in the nested structure > 2.2 Refer to globals or locals > 2.3 Represent simple expression > 2.4 Forward referencing > > Except not very sure on 2.1: refer to a field in the nested structure > > struct Y { > int n; > int other; > } > > struct Z { > struct Y y; > int array[] __attribute__ ((counted_by(?y.n))); > }; > > in the above, what should be put instead of "?" to refer to the field "n" of > the field "y" of the current object of this struct Z? > > Based on my understanding, with the new syntax, > > struct Z { > struct Y y; > int array[] __attribute__ ((counted_by(struct Y y, y.n))); > }; > > i.e, the compiler will lookup “y” inside the current structure, then > resolving the member access operator “.” as an expression. > > Is this correct understanding? I had the same question, e.g. how is this supposed to be declared: struct Y { int n; int other; } struct Z { int *ints __attribute__ ((counted_by(y.n))); struct Y y; }; -- Kees Cook