Page MenuHomeFreeBSD

LinuxKPI: add __counted_by() and __nonstring
ClosedPublic

Authored by bz on Apr 2 2024, 10:00 AM.
Tags
None
Referenced Files
F103085246: D44587.diff
Wed, Nov 20, 6:23 PM
F103036882: D44587.diff
Wed, Nov 20, 2:59 AM
Unknown Object (File)
Tue, Nov 19, 5:08 PM
Unknown Object (File)
Sat, Nov 9, 2:32 AM
Unknown Object (File)
Wed, Nov 6, 8:34 PM
Unknown Object (File)
Tue, Nov 5, 8:02 PM
Unknown Object (File)
Wed, Oct 23, 11:00 PM
Unknown Object (File)
Oct 16 2024, 12:43 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 Passed
Unit
No Test Coverage
Build Status
Buildable 56865
Build 53753: arc lint + arc unit

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.Apr 14 2024, 11:07 PM
bz retitled this revision from LinuxKPI: add __counted_by() to LinuxKPI: add __counted_by() and __nonstring.Apr 14 2024, 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.Apr 15 2024, 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.