Re: [PATCH v4 02/35] compiler-context-analysis: Add infrastructure for Context Analysis with Clang
Linus Torvalds <[email protected]> Thu, 20 Nov 2025 10:14:34 -0800
| Newsgroups | org.kernel.vger.linux-sparse,dev.linux.lists.llvm,org.kernel.vger.linux-crypto,org.kernel.vger.linux-doc,org.kernel.vger.linux-kbuild,org.kernel.vger.linux-kernel,org.kernel.vger.linux-security-module,org.kernel.vger.linux-wireless,org.kernel.vger.rcu,org.kvack.linux-mm |
|---|---|
| Message-ID | <CAHk-=whyKteNtcLON-gScv6tu8ssvKWdNw-k371ufDrjOv374g@mail.gmail.com> |
On Thu, 20 Nov 2025 at 07:13, Marco Elver <[email protected]> wrote: > > --- a/include/linux/compiler-context-analysis.h > +++ b/include/linux/compiler-context-analysis.h > @@ -6,27 +6,465 @@ > #ifndef _LINUX_COMPILER_CONTEXT_ANALYSIS_H > #define _LINUX_COMPILER_CONTEXT_ANALYSIS_H > > +#if defined(WARN_CONTEXT_ANALYSIS) Note the 400+ added lines to this header... And then note how the header gets used: > +++ b/scripts/Makefile.context-analysis > @@ -0,0 +1,7 @@ > +# SPDX-License-Identifier: GPL-2.0 > + > +context-analysis-cflags := -DWARN_CONTEXT_ANALYSIS \ > + -fexperimental-late-parse-attributes -Wthread-safety \ > + -Wthread-safety-pointer -Wthread-safety-beta > + > +export CFLAGS_CONTEXT_ANALYSIS := $(context-analysis-cflags) Please let's *not* do it this way, where the header contents basically get enabled or not based on a compiler flag, but then everybody includes this 400+ line file whether they need it or not. Can we please just make the header file *itself* not have any conditionals, and what happens is that the header file is included (or not) using a pattern something like -include $(srctree)/include/linux/$(context-analysis-header) instead. IOW, we'd have three different header files entirely: the "no context analysis", the "sparse" and the "clang context analysis" header, and instead of having a "-DWARN_CONTEXT_ANALYSIS" define, we'd just include the appropriate header automatically. We already use that "-include" pattern for <linux/kconfig.h> and <linux/compiler-version.h>. It's probably what we should have done for <linux/compiler.h> and friends too. The reason I react to things like this is that I've actually seen just the parsing of header files being a surprisingly big cost in build times. People think that optimizations are expensive, and yes, some of them really are, but when a lot of the code we parse is never actually *used*, but just hangs out in header files that gets included by everybody, the parsing overhead tends to be noticeable. There's a reason why most C compilers end up integrating the C pre-processor: it avoids parsing and tokenizing things multiple times. The other reason is that I often use "git grep" for looking up definitions of things, and when there are multiple definitions of the same thing, I actually find it much more informative when they are in two different files than when I see two different definitions (or declarations) in the same file and then I have to go look at what the #ifdef condition is. In contrast, when it's something where there are per-architecture definitions, you *see* that, because the grep results come from different header files. I dunno. This is not a huge deal, but I do think that it would seem to be much simpler and more straightforward to treat this as a kind of "N different baseline header files" than as "include this one header file in everything, and then we'll have #ifdef's for the configuration". Particularly when that config is not even a global config, but a per-file one. Hmm? Maybe there's some reason why this suggestion is very inconvenient, but please at least consider it. Linus