https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125991

--- Comment #6 from David Faust <dfaust at gcc dot gnu.org> ---
(In reply to Vineet Gupta from comment #2)
> (In reply to Drea Pinski from comment #1)
> 
> > There are interesting rules about where gnu attributes will apply to return
> > types vs the function decl vs the function type.
> 
> Ah interesting and those are documented ? In developer's guide section.

https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html

> 
> > So it night be clang not implementing those rules the same as gcc.
> > 
> > Note __attribute__ is a gnu extension first. Even though the attribute was
> > added for clang first.

Yes, the problem is that clang does not implement the __attribute__ syntax
rules the same as gcc. 

> 
> Understood. The practical issue / challenge here is clang took the lead and
> implemented some things which now stick in bpf world. Not suggesting we
> implement absurdities but lets get somewhere in the middle and at least do
> reasonable things.

For some background:

As far as I can tell (when I looked into this deeply while originally
implementing type_tag in GCC), the underlying issue is that things like __rcu,
__user etc. in the kernel were originally sparse [1] attributes, NOT compiler
attributes. Sparse had its own notion of how to associate them, and that was
fine because compilers like GCC would simply ignore unknown attributes.

See the #ifdef __SPARSE__ blocks in linux/include/linux/compiler_types.h and
note that 'noderef' and 'address_space' therein are the original sparse
attributes by those names [2].

At some point, people started adapting the existing sparse annotations into
compiler attributes in clang, and now they want to turn them into BTF tags.  I
think the adaption into clang is what spurred the difference in __attrbiute__
parsing in clang versus GCC.  This is afaict where the clang version of
address_space was introduced; copying the kernel sparse annotation.

The problem is that the sparse attribute parsing logic does not match the GNU
__attribute__ extension syntax, so we run into cases like this.
And then GCC is blamed for "incorrectly" associating the attributes when
specified with the GNU syntax, when the GNU attribute syntax is defined
by GCC...

[1] https://sparse.docs.kernel.org/en/latest/index.html
[2] https://sparse.docs.kernel.org/en/latest/annotations.html

Reply via email to