Page MenuHomeFreeBSD

LinuxKPI: add __counted_by() and __nonstring
ClosedPublic

Authored by bz on Apr 2 2024, 10:00 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, May 8, 4:24 AM
Unknown Object (File)
Thu, May 2, 8:10 PM
Unknown Object (File)
Thu, May 2, 4:30 AM
Unknown Object (File)
Sat, Apr 27, 2:16 AM
Unknown Object (File)
Fri, Apr 26, 4:38 AM
Unknown Object (File)
Tue, Apr 16, 3:06 AM
Unknown Object (File)
Mon, Apr 15, 8:04 PM
Unknown Object (File)
Mon, Apr 15, 7:55 AM
Subscribers

Details

Summary

Add checks for counted_by(_x) and nonstring as and depending
on compiler support enable the attribute/feature.

This is needed to make mtk76 and ath1xk drivers to compile.

Sposnored by: The FreeBSD Foundation
MFC after: 3 days

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bz requested review of this revision.Apr 2 2024, 10:00 AM

In general __has_attribute(foo) to check
I think this is fine to get the driver compiling but ought to have a TODO comment

This revision is now accepted and ready to land.Apr 2 2024, 12:12 PM

In general __has_attribute(foo) to check
I think this is fine to get the driver compiling but ought to have a TODO comment

And how to figure out the naming of "foo" in an implementation in these cases?

From a textcase in the LLVM review that introduced it (https://reviews.llvm.org/D148381):

#if !__has_attribute(counted_by)
#error "has attribute broken"
#endif

#ifdef COUNTED_BY
#define __counted_by(member)    __attribute__((__counted_by__(member)))
#else
#define __counted_by(member)
#endif

From a textcase in the LLVM review that introduced it (https://reviews.llvm.org/D148381):

#if !__has_attribute(counted_by)
#error "has attribute broken"
#endif

#ifdef COUNTED_BY
#define __counted_by(member)    __attribute__((__counted_by__(member)))
#else
#define __counted_by(member)
#endif

Hmm. Thanks! That review is a year old. I wonder if I had mis-spelled it.
Today when searching again https://clang.llvm.org/docs/AttributeReference.html#counted-by came up. That was kind-of what I was looking for. I'll update the review once I updated my base system after the latest clang import. 16.0.6 clearly didn't have it yet.

add logic for counted_by and also add __nonstring

This revision now requires review to proceed.Sun, Apr 14, 11:07 PM
bz retitled this revision from LinuxKPI: add __counted_by() to LinuxKPI: add __counted_by() and __nonstring.Sun, Apr 14, 11:08 PM
bz edited the summary of this revision. (Show Details)
bz removed a subscriber: dim.

@emaste it seems most attributes in cdef.h have the __x__ instea dof just x. This seems to work with gcc as well for as much as I could test. It seems up-to gcc14-devel non of our gccs recognizes the counter_by in either spelling.

Is this fine now?

emaste added a subscriber: dim.

LGTM, CC @dim in case he has any extra insight on the two forms.

This revision is now accepted and ready to land.Mon, Apr 15, 5:01 PM

LGTM. (The forms without underscores have a higher probability of clashing with user-defined macros, which is why the forms with underscores are normally preferred.)

This revision was automatically updated to reflect the committed changes.