kconfig: add kconfig-sym-check static checker
Hi,
Wasn't on the Cc list, hopefully I didn't mess up the headers. Just saw this on LWN:
[..]
Review
Quoted 4 lines
(quoted diff) +3
-0+ @echo ' kconfig-sym-check - Check for dangling Kconfig symbol references' +kconfig-sym-check: + $(Q)$(PERL) $(srctree)/scripts/kconfig/kconfig-sym-check.pl $(srctree) $(KCONFIG_SYM_CHECK_EXCLUDES)
I wonder if you have seen KCONFIG_WARN_UNKNOWN_SYMBOLS which seem to be addressing the same (or very similar) problem (unless I'm missing something).
Basically, what I have in my build script is
# perform kconfig symbol lookups: handles renamed, removed, etc. symbols export KCONFIG_WARN_UNKNOWN_SYMBOLS=1 # make kconfig symbol lookup warnings fatal export KCONFIG_WERROR=1
And then make fails whenever .config has something that is not supposed to be there anymore. E.g.
.config:1606:warning: unknown symbol: SENSORS_APDS990X .config:2498:warning: unknown symbol: APPLICOM make[3]: *** [scripts/kconfig/Makefile:85: syncconfig] Error 1 make[2]: *** [Makefile:760: syncconfig] Error 2
Quoted 22 lines · Sergey Senozhatsky
Hi,
Wasn't on the Cc list, hopefully I didn't mess up the headers. Just saw this on LWN:
[..]
Review
Quoted 4 lines
(quoted diff) +3
-0+ @echo ' kconfig-sym-check - Check for dangling Kconfig symbol references' +kconfig-sym-check: + $(Q)$(PERL) $(srctree)/scripts/kconfig/kconfig-sym-check.pl $(srctree) $(KCONFIG_SYM_CHECK_EXCLUDES)I wonder if you have seen
KCONFIG_WARN_UNKNOWN_SYMBOLSwhich seem to be addressing the same (or very similar) problem (unless I'm missing something).Basically, what I have in my build script is
# perform kconfig symbol lookups: handles renamed, removed, etc. symbols export KCONFIG_WARN_UNKNOWN_SYMBOLS=1 # make kconfig symbol lookup warnings fatal export KCONFIG_WERROR=1
Quoted 7 lines
And then make fails whenever .config has something that is not supposed to be there anymore. E.g.
.config:1606:warning: unknown symbol:
SENSORS_APDS990X.config:2498:warning: unknown symbol: APPLICOM make[3]: *** [scripts/kconfig/Makefile:85: syncconfig] Error 1 make[2]: *** [Makefile:760: syncconfig] Error 2
Thanks, Sergey. I wasn't aware of this. Is there a way to combine that with some "make all" type target in order to find all the dangling symbols that the static checker finds?
Thanks,
drew
Hi all:
Quoted 5 lines · Andrew Jones
Quoted 3 lines
I wonder if you have seen
KCONFIG_WARN_UNKNOWN_SYMBOLSwhich seem to be addressing the same (or very similar) problem (unless I'm missing something).Thanks, Sergey. I wasn't aware of this. Is there a way to combine that
The two tools do not do the same thing. One is a check on .config and the other is a check on the Kconfig spec.
Drew and Sergey, please try each other's checks.
- Julian Braha
Quoted 10 lines · Julian Braha
Quoted 5 lines · Andrew Jones
Quoted 3 lines
I wonder if you have seen
KCONFIG_WARN_UNKNOWN_SYMBOLSwhich seem to be addressing the same (or very similar) problem (unless I'm missing something).Thanks, Sergey. I wasn't aware of this. Is there a way to combine that
The two tools do not do the same thing. One is a check on .config and the other is a check on the
Kconfigspec.
...otherwise Sergey should never been able to cleanly build kernels for a long time, I suppose.
Quoted 1 line
Drew and Sergey, please try each other's checks.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 8 lines · Andrew Jones
Quoted 4 lines
.config:1606:warning: unknown symbol:
SENSORS_APDS990X.config:2498:warning: unknown symbol: APPLICOM make[3]: *** [scripts/kconfig/Makefile:85: syncconfig] Error 1 make[2]: *** [Makefile:760: syncconfig] Error 2Thanks, Sergey. I wasn't aware of this. Is there a way to combine that with some "make all" type target in order to find all the dangling symbols that the static checker finds?
That's how we wanted it to work. We've got beaten by symbols renames/removals in the past.
A demo:
- Add a dangling symbol
% echo "CONFIG_DISABLE_BUGS=y" >> .config
- Now run make (KCONFIG_WARN_UNKNOWN_SYMBOLS/KCONFIG_WERROR are env variables)
% KCONFIG_WARN_UNKNOWN_SYMBOLS=1 KCONFIG_WERROR=1 make oldconfig
.config:4693:warning: unknown symbol: DISABLE_BUGS make[2]: *** [scripts/kconfig/Makefile:85: oldconfig] Error 1 make[1]: *** [/media/dev/linux/Makefile:760: oldconfig] Error 2
make: *** [Makefile:248: __sub-make] Error 2
And make fails.
kconfig reads the symbols for (pretty much?) all the targets, it needs to make sure that nothing is missing (SAT), that there are no conflicts and so on. Detecting unrecognized .config symbols on the kconfig level is a low hanging fruit, in this regard.
Hi,
Quoted 8 lines · Julian Braha
Quoted 5 lines
Quoted 3 lines
I wonder if you have seen
KCONFIG_WARN_UNKNOWN_SYMBOLSwhich seem to be addressing the same (or very similar) problem (unless I'm missing something).Thanks, Sergey. I wasn't aware of this. Is there a way to combine that
The two tools do not do the same thing. One is a check on .config and the other is a check on the
Kconfigspec.
Ah, I see. I didn't check the code, obviously.
Quoted 12 lines · Sergey Senozhatsky
% echo "
CONFIG_DISABLE_BUGS=y" >> .config- Now run make (KCONFIG_WARN_UNKNOWN_SYMBOLS/KCONFIG_WERROR are env variables)
% KCONFIG_WARN_UNKNOWN_SYMBOLS=1 KCONFIG_WERROR=1 make oldconfig
.config:4693:warning: unknown symbol:
DISABLE_BUGSmake[2]: *** [scripts/kconfig/Makefile:85: oldconfig] Error 1 make[1]: *** [/media/dev/linux/Makefile:760: oldconfig] Error 2
make: *** [Makefile:248: __sub-make] Error 2
Quoted 6 lines
And make fails.
kconfig reads the symbols for (pretty much?) all the targets, it needs to make sure that nothing is missing (SAT), that there are no conflicts and so on. Detecting unrecognized .config symbols on the kconfig level is a low hanging fruit, in this regard.
OK, maybe they are not similar, as Julian pointed out. Makes we wonder is there any benefit in moving this functionality into kconfig (which is the tool that deals with Kconfig files).
Quoted 3 lines · Sergey Senozhatsky
OK, maybe they are not similar, as Julian pointed out. Makes we wonder is there any benefit in moving this functionality into kconfig (which is the tool that deals with
Kconfigfiles).
Agreed, it would be ideal if the check could be part of the kconfig interpeter.
However...
Linux does a funky thing with its architecture handling in kconfig:
it looks up the architecture from a makefile variable and uses that to resolve a kconfig file import in 'arch/Kconfig'.
This means e.g. when evaluating the kconfig on an x86 machine, all of the config options in the RISC-V kconfig are never reached, thus never parsed, and never added to the symbol table. As far as the interpeter is aware, any reference to, say, RISCV_SBI is a dead reference on x86.
Yet, options throughout the kernel can reference arch-specific options. Try searching in menuconfig for the RISCV-only option HVC_RISCV_SBI on x86, and you'll successfully find it, because it's defined in 'drivers/' (not downstream of arch/Kconfig). Then try searching for its dependency, RISCV_SBI. Apparently it doesn't exist? In my opinion, this should also be considered a bug in the frontend...
All this is to say, until architectures are restructured in kconfig, alarming on unknown options would output 99% noise.
- Julian Braha
Quoted 9 lines · Julian Braha
Quoted 3 lines · Sergey Senozhatsky
OK, maybe they are not similar, as Julian pointed out. Makes we wonder is there any benefit in moving this functionality into kconfig (which is the tool that deals with
Kconfigfiles).Agreed, it would be ideal if the check could be part of the kconfig interpeter.
However...
Right... There's always a "however" :)
Quoted 16 lines
Linux does a funky thing with its architecture handling in kconfig:
it looks up the architecture from a makefile variable and uses that to resolve a kconfig file import in 'arch/Kconfig'.This means e.g. when evaluating the kconfig on an x86 machine, all of the config options in the RISC-V kconfig are never reached, thus never parsed, and never added to the symbol table. As far as the interpeter is aware, any reference to, say,
RISCV_SBIis a dead reference on x86.Yet, options throughout the kernel can reference arch-specific options. Try searching in menuconfig for the RISCV-only option
HVC_RISCV_SBIon x86, and you'll successfully find it, because it's defined in 'drivers/' (not downstream ofarch/Kconfig). Then try searching for its dependency,RISCV_SBI. Apparently it doesn't exist? In my opinion, this should also be considered a bug in the frontend...
Quoted 2 lines
All this is to say, until architectures are restructured in kconfig, alarming on unknown options would output 99% noise.
Agreed, let's keep it simple. Thank you!