Metalanguage for the Linux UAPI

Linus Torvalds torvalds@linux-foundation.org
Thu May 15 22:06:40 GMT 2025


On Thu, 15 May 2025 at 14:42, H. Peter Anvin <hpa@zytor.com> wrote:
>
> Building it on top of sparse might still very well be The Right Thing.

You can look at the 'ctags.c' file in the sparse code, it basically
does a lot of this kind of thing: it parses the file, then walks
through all the symbols and #defines that it found.

It then obviously prints out filenames and line numbers rather than
converting the result into something else, so I'm not claiming it's
useful as-is, but from a "how to parse a file and walk the symbols it
declares" standpoint it does almost everything.

I just tested, and it looks like it hates the kernel headers because
it hasn't been updated to understand about the bitwise type and dies
with a

    builtin:0:0: error: unknown symbol __le16 namespace:0 type:13

but when I just made it not die it seems to actually do its thing, and
knows about how sparse considers preprocessor symbols to be symbols
just like C symbols are, just in a different namespace.

Obviously for things like ioctl numbers, you'd need to then make it
also actually *evaluate* the #define etc after you list them. You
could do that in sparse itself, or you could do it by just creating a
list of #define's from within sparse, and then have a separate pass
that evaluates their values. That 'ctags' thing doesn't do any of
that, of course.

              Linus


More information about the Libc-alpha mailing list