From 12e3342fc7b0ec7fcb03f41bb49a1a6e3dcc0663 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 7 Jan 2024 22:19:47 +0900 Subject: [PATCH 01/67] kconfig: remove unneeded buffer allocation in zconf_initscan() In Kconfig, there is a stack to save the lexer state for each inclusion level. Currently, it operates as an empty stack, with the 'current_buf' always pointing to an empty buffer. There is no need to preallocate the buffer. Change it to a full stack. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lexer.l | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index cc386e443683..d75423ec4eae 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -391,9 +391,6 @@ void zconf_initscan(const char *name) exit(1); } - current_buf = xmalloc(sizeof(*current_buf)); - memset(current_buf, 0, sizeof(*current_buf)); - current_file = file_lookup(name); yylineno = 1; } @@ -403,9 +400,10 @@ void zconf_nextfile(const char *name) struct file *iter; struct file *file = file_lookup(name); struct buffer *buf = xmalloc(sizeof(*buf)); - memset(buf, 0, sizeof(*buf)); - current_buf->state = YY_CURRENT_BUFFER; + buf->state = YY_CURRENT_BUFFER; + buf->parent = current_buf; + current_buf = buf; yyin = zconf_fopen(file->name); if (!yyin) { fprintf(stderr, "%s:%d: can't open file \"%s\"\n", @@ -413,8 +411,6 @@ void zconf_nextfile(const char *name) exit(1); } yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); - buf->parent = current_buf; - current_buf = buf; current_file->lineno = yylineno; file->parent = current_file; @@ -441,20 +437,21 @@ void zconf_nextfile(const char *name) static void zconf_endfile(void) { - struct buffer *parent; + struct buffer *tmp; current_file = current_file->parent; if (current_file) yylineno = current_file->lineno; - parent = current_buf->parent; - if (parent) { - fclose(yyin); - yy_delete_buffer(YY_CURRENT_BUFFER); - yy_switch_to_buffer(parent->state); - } - free(current_buf); - current_buf = parent; + if (!current_buf) + return; + + fclose(yyin); + yy_delete_buffer(YY_CURRENT_BUFFER); + yy_switch_to_buffer(current_buf->state); + tmp = current_buf; + current_buf = current_buf->parent; + free(tmp); } int zconf_lineno(void) From 93c432e8c974dfd609a9c7777f731073e4de0c8e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 7 Jan 2024 22:19:48 +0900 Subject: [PATCH 02/67] kconfig: fix line number in recursive inclusion detection The error message shows a wrong line number if the 'source' directive is wrapped to the following line. [Test Code] source \ "Kconfig" This results in the following error message: Recursive inclusion detected. Inclusion path: current file : Kconfig included from: Kconfig:2 The correct message should be as follows: Recursive inclusion detected. Inclusion path: current file : Kconfig included from: Kconfig:1 Signed-off-by: Masahiro Yamada --- scripts/kconfig/lexer.l | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index d75423ec4eae..f93b535a080c 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -33,6 +33,7 @@ static int text_size, text_asize; struct buffer { struct buffer *parent; YY_BUFFER_STATE state; + int yylineno; }; static struct buffer *current_buf; @@ -402,6 +403,7 @@ void zconf_nextfile(const char *name) struct buffer *buf = xmalloc(sizeof(*buf)); buf->state = YY_CURRENT_BUFFER; + buf->yylineno = yylineno; buf->parent = current_buf; current_buf = buf; yyin = zconf_fopen(file->name); @@ -412,7 +414,7 @@ void zconf_nextfile(const char *name) } yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); - current_file->lineno = yylineno; + current_file->lineno = zconf_lineno(); file->parent = current_file; for (iter = current_file; iter; iter = iter->parent) { @@ -425,7 +427,7 @@ void zconf_nextfile(const char *name) do { iter = iter->parent; fprintf(stderr, " included from: %s:%d\n", - iter->name, iter->lineno - 1); + iter->name, iter->lineno); } while (strcmp(iter->name, file->name)); exit(1); } @@ -440,8 +442,6 @@ static void zconf_endfile(void) struct buffer *tmp; current_file = current_file->parent; - if (current_file) - yylineno = current_file->lineno; if (!current_buf) return; @@ -449,6 +449,7 @@ static void zconf_endfile(void) fclose(yyin); yy_delete_buffer(YY_CURRENT_BUFFER); yy_switch_to_buffer(current_buf->state); + yylineno = current_buf->yylineno; tmp = current_buf; current_buf = current_buf->parent; free(tmp); From f6314b76d826e58ca394c944e22a39855a995096 Mon Sep 17 00:00:00 2001 From: Vegard Nossum Date: Fri, 12 Jan 2024 13:58:30 +0100 Subject: [PATCH 03/67] docs: kbuild/kconfig: reformat/cleanup This document was using headings in an odd way, causing the sidebar to be quite messy. I've adding new headings and turned some of the old headings into description lists. The indentation was a mix of spaces and tabs; I've turned them all into 4 spaces so it always reads correctly regardless of tab settings. Also use ``...`` instead of `...`; the difference is that `` is meant for "inline literals" (and renders in a monospace font) while ` is for "interpreted text" (and renders with italics). Also changed the title of the document to be more descriptive. Signed-off-by: Vegard Nossum Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor Signed-off-by: Masahiro Yamada --- Documentation/kbuild/kconfig.rst | 363 ++++++++++++++----------------- 1 file changed, 166 insertions(+), 197 deletions(-) diff --git a/Documentation/kbuild/kconfig.rst b/Documentation/kbuild/kconfig.rst index c946eb44bd13..fc4e845bc249 100644 --- a/Documentation/kbuild/kconfig.rst +++ b/Documentation/kbuild/kconfig.rst @@ -1,10 +1,10 @@ -=================== -Kconfig make config -=================== +================================= +Configuration targets and editors +================================= -This file contains some assistance for using `make *config`. +This file contains some assistance for using ``make *config``. -Use "make help" to list all of the possible configuration targets. +Use ``make help`` to list all of the possible configuration targets. The xconfig ('qconf'), menuconfig ('mconf'), and nconfig ('nconf') programs also have embedded help text. Be sure to check that for @@ -12,8 +12,9 @@ navigation, search, and other general help text. The gconfig ('gconf') program has limited help text. + General -------- +======= New kernel releases often introduce new config symbols. Often more important, new kernel releases may rename config symbols. When @@ -24,118 +25,102 @@ symbols have been introduced. To see a list of new config symbols, use:: - cp user/some/old.config .config - make listnewconfig + cp user/some/old.config .config + make listnewconfig and the config program will list any new symbols, one per line. Alternatively, you can use the brute force method:: - make oldconfig - scripts/diffconfig .config.old .config | less + make oldconfig + scripts/diffconfig .config.old .config | less ----------------------------------------------------------------------- -Environment variables for `*config` +Environment variables +===================== -KCONFIG_CONFIG --------------- -This environment variable can be used to specify a default kernel config -file name to override the default name of ".config". +Environment variables for ``*config``: -KCONFIG_DEFCONFIG_LIST ----------------------- +``KCONFIG_CONFIG`` + This environment variable can be used to specify a default kernel config + file name to override the default name of ".config". -This environment variable specifies a list of config files which can be used -as a base configuration in case the .config does not exist yet. Entries in -the list are separated with whitespaces to each other, and the first one -that exists is used. +``KCONFIG_DEFCONFIG_LIST`` + This environment variable specifies a list of config files which can be + used as a base configuration in case the .config does not exist yet. + Entries in the list are separated with whitespaces to each other, and + the first one that exists is used. -KCONFIG_OVERWRITECONFIG ------------------------ -If you set KCONFIG_OVERWRITECONFIG in the environment, Kconfig will not -break symlinks when .config is a symlink to somewhere else. +``KCONFIG_OVERWRITECONFIG`` + If you set KCONFIG_OVERWRITECONFIG in the environment, Kconfig will not + break symlinks when .config is a symlink to somewhere else. -KCONFIG_WARN_UNKNOWN_SYMBOLS ----------------------------- -This environment variable makes Kconfig warn about all unrecognized -symbols in the config input. +``KCONFIG_WARN_UNKNOWN_SYMBOLS`` + This environment variable makes Kconfig warn about all unrecognized + symbols in the config input. -KCONFIG_WERROR --------------- -If set, Kconfig treats warnings as errors. +``KCONFIG_WERROR`` + If set, Kconfig treats warnings as errors. -`CONFIG_` ---------- -If you set `CONFIG_` in the environment, Kconfig will prefix all symbols -with its value when saving the configuration, instead of using the default, -`CONFIG_`. +``CONFIG_`` + If you set ``CONFIG_`` in the environment, Kconfig will prefix all symbols + with its value when saving the configuration, instead of using the + default, ``CONFIG_``. ----------------------------------------------------------------------- +Environment variables for ``{allyes/allmod/allno/rand}config``: -Environment variables for '{allyes/allmod/allno/rand}config' +``KCONFIG_ALLCONFIG`` + The allyesconfig/allmodconfig/allnoconfig/randconfig variants can also + use the environment variable KCONFIG_ALLCONFIG as a flag or a filename + that contains config symbols that the user requires to be set to a + specific value. If KCONFIG_ALLCONFIG is used without a filename where + KCONFIG_ALLCONFIG == "" or KCONFIG_ALLCONFIG == "1", ``make *config`` + checks for a file named "all{yes/mod/no/def/random}.config" + (corresponding to the ``*config`` command that was used) for symbol values + that are to be forced. If this file is not found, it checks for a + file named "all.config" to contain forced values. -KCONFIG_ALLCONFIG ------------------ -(partially based on lkml email from/by Rob Landley, re: miniconfig) + This enables you to create "miniature" config (miniconfig) or custom + config files containing just the config symbols that you are interested + in. Then the kernel config system generates the full .config file, + including symbols of your miniconfig file. --------------------------------------------------- + This ``KCONFIG_ALLCONFIG`` file is a config file which contains + (usually a subset of all) preset config symbols. These variable + settings are still subject to normal dependency checks. -The allyesconfig/allmodconfig/allnoconfig/randconfig variants can also -use the environment variable KCONFIG_ALLCONFIG as a flag or a filename -that contains config symbols that the user requires to be set to a -specific value. If KCONFIG_ALLCONFIG is used without a filename where -KCONFIG_ALLCONFIG == "" or KCONFIG_ALLCONFIG == "1", `make *config` -checks for a file named "all{yes/mod/no/def/random}.config" -(corresponding to the `*config` command that was used) for symbol values -that are to be forced. If this file is not found, it checks for a -file named "all.config" to contain forced values. + Examples:: -This enables you to create "miniature" config (miniconfig) or custom -config files containing just the config symbols that you are interested -in. Then the kernel config system generates the full .config file, -including symbols of your miniconfig file. + KCONFIG_ALLCONFIG=custom-notebook.config make allnoconfig -This 'KCONFIG_ALLCONFIG' file is a config file which contains -(usually a subset of all) preset config symbols. These variable -settings are still subject to normal dependency checks. + or:: -Examples:: + KCONFIG_ALLCONFIG=mini.config make allnoconfig - KCONFIG_ALLCONFIG=custom-notebook.config make allnoconfig + or:: -or:: + make KCONFIG_ALLCONFIG=mini.config allnoconfig - KCONFIG_ALLCONFIG=mini.config make allnoconfig + These examples will disable most options (allnoconfig) but enable or + disable the options that are explicitly listed in the specified + mini-config files. -or:: +Environment variables for ``randconfig``: - make KCONFIG_ALLCONFIG=mini.config allnoconfig +``KCONFIG_SEED`` + You can set this to the integer value used to seed the RNG, if you want + to somehow debug the behaviour of the kconfig parser/frontends. + If not set, the current time will be used. -These examples will disable most options (allnoconfig) but enable or -disable the options that are explicitly listed in the specified -mini-config files. - ----------------------------------------------------------------------- - -Environment variables for 'randconfig' - -KCONFIG_SEED ------------- -You can set this to the integer value used to seed the RNG, if you want -to somehow debug the behaviour of the kconfig parser/frontends. -If not set, the current time will be used. - -KCONFIG_PROBABILITY -------------------- -This variable can be used to skew the probabilities. This variable can -be unset or empty, or set to three different formats: +``KCONFIG_PROBABILITY`` + This variable can be used to skew the probabilities. This variable can + be unset or empty, or set to three different formats: ======================= ================== ===================== - KCONFIG_PROBABILITY y:n split y:m:n split + KCONFIG_PROBABILITY y:n split y:m:n split ======================= ================== ===================== - unset or empty 50 : 50 33 : 33 : 34 - N N : 100-N N/2 : N/2 : 100-N + unset or empty 50 : 50 33 : 33 : 34 + N N : 100-N N/2 : N/2 : 100-N [1] N:M N+M : 100-(N+M) N : M : 100-(N+M) [2] N:M:L N : 100-N M : L : 100-(M+L) ======================= ================== ===================== @@ -149,112 +134,98 @@ that: Examples:: - KCONFIG_PROBABILITY=10 - 10% of booleans will be set to 'y', 90% to 'n' - 5% of tristates will be set to 'y', 5% to 'm', 90% to 'n' - KCONFIG_PROBABILITY=15:25 - 40% of booleans will be set to 'y', 60% to 'n' - 15% of tristates will be set to 'y', 25% to 'm', 60% to 'n' - KCONFIG_PROBABILITY=10:15:15 - 10% of booleans will be set to 'y', 90% to 'n' - 15% of tristates will be set to 'y', 15% to 'm', 70% to 'n' + KCONFIG_PROBABILITY=10 + 10% of booleans will be set to 'y', 90% to 'n' + 5% of tristates will be set to 'y', 5% to 'm', 90% to 'n' + KCONFIG_PROBABILITY=15:25 + 40% of booleans will be set to 'y', 60% to 'n' + 15% of tristates will be set to 'y', 25% to 'm', 60% to 'n' + KCONFIG_PROBABILITY=10:15:15 + 10% of booleans will be set to 'y', 90% to 'n' + 15% of tristates will be set to 'y', 15% to 'm', 70% to 'n' ----------------------------------------------------------------------- +Environment variables for ``syncconfig``: -Environment variables for 'syncconfig' +``KCONFIG_NOSILENTUPDATE`` + If this variable has a non-blank value, it prevents silent kernel + config updates (requires explicit updates). -KCONFIG_NOSILENTUPDATE ----------------------- -If this variable has a non-blank value, it prevents silent kernel -config updates (requires explicit updates). +``KCONFIG_AUTOCONFIG`` + This environment variable can be set to specify the path & name of the + "auto.conf" file. Its default value is "include/config/auto.conf". -KCONFIG_AUTOCONFIG ------------------- -This environment variable can be set to specify the path & name of the -"auto.conf" file. Its default value is "include/config/auto.conf". +``KCONFIG_AUTOHEADER`` + This environment variable can be set to specify the path & name of the + "autoconf.h" (header) file. + Its default value is "include/generated/autoconf.h". -KCONFIG_AUTOHEADER ------------------- -This environment variable can be set to specify the path & name of the -"autoconf.h" (header) file. -Its default value is "include/generated/autoconf.h". - - ----------------------------------------------------------------------- menuconfig ----------- - -SEARCHING for CONFIG symbols +========== Searching in menuconfig: - The Search function searches for kernel configuration symbol - names, so you have to know something close to what you are - looking for. + The Search function searches for kernel configuration symbol + names, so you have to know something close to what you are + looking for. - Example:: + Example:: - /hotplug - This lists all config symbols that contain "hotplug", - e.g., HOTPLUG_CPU, MEMORY_HOTPLUG. + /hotplug + This lists all config symbols that contain "hotplug", + e.g., HOTPLUG_CPU, MEMORY_HOTPLUG. - For search help, enter / followed by TAB-TAB (to highlight - ) and Enter. This will tell you that you can also use - regular expressions (regexes) in the search string, so if you - are not interested in MEMORY_HOTPLUG, you could try:: + For search help, enter / followed by TAB-TAB (to highlight + ) and Enter. This will tell you that you can also use + regular expressions (regexes) in the search string, so if you + are not interested in MEMORY_HOTPLUG, you could try:: - /^hotplug + /^hotplug - When searching, symbols are sorted thus: + When searching, symbols are sorted thus: - - first, exact matches, sorted alphabetically (an exact match - is when the search matches the complete symbol name); - - then, other matches, sorted alphabetically. + - first, exact matches, sorted alphabetically (an exact match + is when the search matches the complete symbol name); + - then, other matches, sorted alphabetically. - For example: ^ATH.K matches: + For example, ^ATH.K matches: - ATH5K ATH9K ATH5K_AHB ATH5K_DEBUG [...] ATH6KL ATH6KL_DEBUG - [...] ATH9K_AHB ATH9K_BTCOEX_SUPPORT ATH9K_COMMON [...] + ATH5K ATH9K ATH5K_AHB ATH5K_DEBUG [...] ATH6KL ATH6KL_DEBUG + [...] ATH9K_AHB ATH9K_BTCOEX_SUPPORT ATH9K_COMMON [...] - of which only ATH5K and ATH9K match exactly and so are sorted - first (and in alphabetical order), then come all other symbols, - sorted in alphabetical order. + of which only ATH5K and ATH9K match exactly and so are sorted + first (and in alphabetical order), then come all other symbols, + sorted in alphabetical order. - In this menu, pressing the key in the (#) prefix will jump - directly to that location. You will be returned to the current - search results after exiting this new menu. + In this menu, pressing the key in the (#) prefix will jump + directly to that location. You will be returned to the current + search results after exiting this new menu. ----------------------------------------------------------------------- +User interface options for 'menuconfig': -User interface options for 'menuconfig' +``MENUCONFIG_COLOR`` + It is possible to select different color themes using the variable + MENUCONFIG_COLOR. To select a theme use:: -MENUCONFIG_COLOR ----------------- -It is possible to select different color themes using the variable -MENUCONFIG_COLOR. To select a theme use:: + make MENUCONFIG_COLOR= menuconfig - make MENUCONFIG_COLOR= menuconfig + Available themes are:: -Available themes are:: + - mono => selects colors suitable for monochrome displays + - blackbg => selects a color scheme with black background + - classic => theme with blue background. The classic look + - bluetitle => a LCD friendly version of classic. (default) - - mono => selects colors suitable for monochrome displays - - blackbg => selects a color scheme with black background - - classic => theme with blue background. The classic look - - bluetitle => a LCD friendly version of classic. (default) +``MENUCONFIG_MODE`` + This mode shows all sub-menus in one large tree. -MENUCONFIG_MODE ---------------- -This mode shows all sub-menus in one large tree. + Example:: -Example:: + make MENUCONFIG_MODE=single_menu menuconfig - make MENUCONFIG_MODE=single_menu menuconfig - ----------------------------------------------------------------------- nconfig -------- +======= nconfig is an alternate text-based configurator. It lists function keys across the bottom of the terminal (window) that execute commands. @@ -266,61 +237,59 @@ Use F1 for Global help or F3 for the Short help menu. Searching in nconfig: - You can search either in the menu entry "prompt" strings - or in the configuration symbols. + You can search either in the menu entry "prompt" strings + or in the configuration symbols. - Use / to begin a search through the menu entries. This does - not support regular expressions. Use or for - Next hit and Previous hit, respectively. Use to - terminate the search mode. + Use / to begin a search through the menu entries. This does + not support regular expressions. Use or for + Next hit and Previous hit, respectively. Use to + terminate the search mode. - F8 (SymSearch) searches the configuration symbols for the - given string or regular expression (regex). + F8 (SymSearch) searches the configuration symbols for the + given string or regular expression (regex). - In the SymSearch, pressing the key in the (#) prefix will - jump directly to that location. You will be returned to the - current search results after exiting this new menu. + In the SymSearch, pressing the key in the (#) prefix will + jump directly to that location. You will be returned to the + current search results after exiting this new menu. -NCONFIG_MODE ------------- -This mode shows all sub-menus in one large tree. +Environment variables: -Example:: +``NCONFIG_MODE`` + This mode shows all sub-menus in one large tree. - make NCONFIG_MODE=single_menu nconfig + Example:: + + make NCONFIG_MODE=single_menu nconfig ----------------------------------------------------------------------- xconfig -------- +======= Searching in xconfig: - The Search function searches for kernel configuration symbol - names, so you have to know something close to what you are - looking for. + The Search function searches for kernel configuration symbol + names, so you have to know something close to what you are + looking for. - Example:: + Example:: - Ctrl-F hotplug + Ctrl-F hotplug - or:: + or:: - Menu: File, Search, hotplug + Menu: File, Search, hotplug - lists all config symbol entries that contain "hotplug" in - the symbol name. In this Search dialog, you may change the - config setting for any of the entries that are not grayed out. - You can also enter a different search string without having - to return to the main menu. + lists all config symbol entries that contain "hotplug" in + the symbol name. In this Search dialog, you may change the + config setting for any of the entries that are not grayed out. + You can also enter a different search string without having + to return to the main menu. ----------------------------------------------------------------------- - gconfig -------- +======= Searching in gconfig: - There is no search command in gconfig. However, gconfig does - have several different viewing choices, modes, and options. + There is no search command in gconfig. However, gconfig does + have several different viewing choices, modes, and options. From 24507871c3c6ae4f6b460b016da7ff434cd34149 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 9 Jan 2024 21:07:34 +0900 Subject: [PATCH 04/67] kbuild: create a list of all built DTB files It is useful to have a list of all *.dtb and *.dtbo files generated from the current build. With this commit, 'make dtbs' creates arch/*/boot/dts/dtbs-list, which lists the dtb(o) files created in the current build. It maintains the order of the dtb-y additions in Makefiles although the order is not important for DTBs. It is a (good) side effect through the reuse of the modules.order rule. Please note this list only includes the files directly added to dtb-y. For example, consider this case: foo-dtbs := foo_base.dtb foo_overlay.dtbo dtb-y := foo.dtb In this example, the list will include foo.dtb, but not foo_base.dtb or foo_overlay.dtbo. Signed-off-by: Masahiro Yamada --- .gitignore | 1 + Makefile | 4 ++-- scripts/Makefile.build | 20 ++++++++++++-------- scripts/Makefile.lib | 6 ++++++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 689a4fa3f547..c59dc60ba62e 100644 --- a/.gitignore +++ b/.gitignore @@ -52,6 +52,7 @@ *.xz *.zst Module.symvers +dtbs-list modules.order # diff --git a/Makefile b/Makefile index 41fa8a2565f5..f5755b81591b 100644 --- a/Makefile +++ b/Makefile @@ -1393,7 +1393,7 @@ ifneq ($(dtstree),) PHONY += dtbs dtbs_prepare dtbs_install dtbs_check dtbs: dtbs_prepare - $(Q)$(MAKE) $(build)=$(dtstree) + $(Q)$(MAKE) $(build)=$(dtstree) need-dtbslist=1 # include/config/kernel.release is actually needed when installing DTBs because # INSTALL_DTBS_PATH contains $(KERNELRELEASE). However, we do not want to make @@ -1932,7 +1932,7 @@ clean: $(clean-dirs) -o -name '*.ko.*' \ -o -name '*.dtb' -o -name '*.dtbo' \ -o -name '*.dtb.S' -o -name '*.dtbo.S' \ - -o -name '*.dt.yaml' \ + -o -name '*.dt.yaml' -o -name 'dtbs-list' \ -o -name '*.dwo' -o -name '*.lst' \ -o -name '*.su' -o -name '*.mod' \ -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ diff --git a/scripts/Makefile.build b/scripts/Makefile.build index dae447a1ad30..4971f54c855e 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -71,6 +71,7 @@ endif # subdir-builtin and subdir-modorder may contain duplications. Use $(sort ...) subdir-builtin := $(sort $(filter %/built-in.a, $(real-obj-y))) subdir-modorder := $(sort $(filter %/modules.order, $(obj-m))) +subdir-dtbslist := $(sort $(filter %/dtbs-list, $(dtb-y))) targets-for-builtin := $(extra-y) @@ -388,6 +389,7 @@ $(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler # To build objects in subdirs, we need to descend into the directories $(subdir-builtin): $(obj)/%/built-in.a: $(obj)/% ; $(subdir-modorder): $(obj)/%/modules.order: $(obj)/% ; +$(subdir-dtbslist): $(obj)/%/dtbs-list: $(obj)/% ; # # Rule to compile a set of .o files into one .a file (without symbol table) @@ -404,19 +406,21 @@ $(obj)/built-in.a: $(real-obj-y) FORCE $(call if_changed,ar_builtin) # -# Rule to create modules.order file +# Rule to create modules.order and dtbs-list # -# Create commands to either record .ko file or cat modules.order from -# a subdirectory -# Add $(obj-m) as the prerequisite to avoid updating the timestamp of -# modules.order unless contained modules are updated. +# This is a list of build artifacts (module or dtb) from the current Makefile +# and its sub-directories. The timestamp should be updated when any of the +# member files. -cmd_modules_order = { $(foreach m, $(real-prereqs), \ - $(if $(filter %/modules.order, $m), cat $m, echo $m);) :; } \ +cmd_gen_order = { $(foreach m, $(real-prereqs), \ + $(if $(filter %/$(notdir $@), $m), cat $m, echo $m);) :; } \ > $@ $(obj)/modules.order: $(obj-m) FORCE - $(call if_changed,modules_order) + $(call if_changed,gen_order) + +$(obj)/dtbs-list: $(dtb-y) FORCE + $(call if_changed,gen_order) # # Rule to compile a set of .o files into one .a file (with symbol table) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index cd5b181060f1..b35d39022a30 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -45,6 +45,11 @@ else obj-y := $(filter-out %/, $(obj-y)) endif +ifdef need-dtbslist +dtb-y += $(addsuffix /dtbs-list, $(subdir-ym)) +always-y += dtbs-list +endif + # Expand $(foo-objs) $(foo-y) etc. by replacing their individuals suffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s)))) # List composite targets that are constructed by combining other targets @@ -99,6 +104,7 @@ lib-y := $(addprefix $(obj)/,$(lib-y)) real-obj-y := $(addprefix $(obj)/,$(real-obj-y)) real-obj-m := $(addprefix $(obj)/,$(real-obj-m)) multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m)) +dtb-y := $(addprefix $(obj)/, $(dtb-y)) multi-dtb-y := $(addprefix $(obj)/, $(multi-dtb-y)) real-dtb-y := $(addprefix $(obj)/, $(real-dtb-y)) subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) From 8f66864cee447835889ec0d91d52ff39bf2deabc Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 9 Jan 2024 21:07:35 +0900 Subject: [PATCH 05/67] kbuild: simplify dtbs_install by reading the list of compiled DTBs Retrieve the list of *.dtb(o) files from arch/*/boot/dts/dtbs-list instead of traversing the directory tree again. Please note that 'make dtbs_install' installs *.dtb(o) files directly added to dtb-y because scripts/Makefile.dtbinst installs $(dtb-y) without expanding the -dtbs suffix. This commit preserves this behavior. Signed-off-by: Masahiro Yamada --- Makefile | 2 +- scripts/Kbuild.include | 6 ------ scripts/Makefile.dtbinst | 32 ++++++++++++++++++-------------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index f5755b81591b..bc54a6cc8dc5 100644 --- a/Makefile +++ b/Makefile @@ -1411,7 +1411,7 @@ endif dtbs_check: dtbs dtbs_install: - $(Q)$(MAKE) $(dtbinst)=$(dtstree) dst=$(INSTALL_DTBS_PATH) + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.dtbinst obj=$(dtstree) ifdef CONFIG_OF_EARLY_FLATTREE all: dtbs diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 7778cc97a4e0..2f331879816b 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -113,12 +113,6 @@ endef # $(Q)$(MAKE) $(build)=dir build := -f $(srctree)/scripts/Makefile.build obj -### -# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj= -# Usage: -# $(Q)$(MAKE) $(dtbinst)=dir -dtbinst := -f $(srctree)/scripts/Makefile.dtbinst obj - ### # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj= # Usage: diff --git a/scripts/Makefile.dtbinst b/scripts/Makefile.dtbinst index 4405d5b67578..67956f6496a5 100644 --- a/scripts/Makefile.dtbinst +++ b/scripts/Makefile.dtbinst @@ -8,32 +8,36 @@ # $INSTALL_PATH/dtbs/$KERNELRELEASE # ========================================================================== -src := $(obj) - PHONY := __dtbs_install __dtbs_install: include include/config/auto.conf include $(srctree)/scripts/Kbuild.include -include $(kbuild-file) -dtbs := $(addprefix $(dst)/, $(dtb-y) $(if $(CONFIG_OF_ALL_DTBS),$(dtb-))) -subdirs := $(addprefix $(obj)/, $(subdir-y) $(subdir-m)) - -__dtbs_install: $(dtbs) $(subdirs) - @: +dst := $(INSTALL_DTBS_PATH) quiet_cmd_dtb_install = INSTALL $@ cmd_dtb_install = install -D $< $@ -$(dst)/%.dtb: $(obj)/%.dtb +$(dst)/%: $(obj)/% $(call cmd,dtb_install) -$(dst)/%.dtbo: $(obj)/%.dtbo - $(call cmd,dtb_install) +dtbs := $(patsubst $(obj)/%,%,$(call read-file, $(obj)/dtbs-list)) -PHONY += $(subdirs) -$(subdirs): - $(Q)$(MAKE) $(dtbinst)=$@ dst=$(if $(CONFIG_ARCH_WANT_FLAT_DTB_INSTALL),$(dst),$(patsubst $(obj)/%,$(dst)/%,$@)) +ifdef CONFIG_ARCH_WANT_FLAT_DTB_INSTALL + +define gen_install_rules +$(dst)/%: $(obj)/$(1)% + $$(call cmd,dtb_install) +endef + +$(foreach d, $(sort $(dir $(dtbs))), $(eval $(call gen_install_rules,$(d)))) + +dtbs := $(notdir $(dtbs)) + +endif # CONFIG_ARCH_WANT_FLAT_DTB_INSTALL + +__dtbs_install: $(addprefix $(dst)/, $(dtbs)) + @: .PHONY: $(PHONY) From cc3df32c9f3a99f715c551f76b040fcf2e5050a5 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 13 Jan 2024 19:43:36 +0900 Subject: [PATCH 06/67] kbuild: deb-pkg: show verbose log for direct package builds When the Debian package build is initiated by Kbuild ('make deb-pkg' or 'make bindeb-pkg'), the log messages are displayed in the short form, which is the Kbuild default. Otherwise, let's show verbose messages (unless the 'terse' tag is set in DEB_BUILD_OPTION), as suggested by Debian Policy: "The package build should be as verbose as reasonably possible, except where the terse tag is included in DEB_BUILD_OPTIONS." [1] This is what the Debian kernel also does. [2] [1]: https://www.debian.org/doc/debian-policy/ch-source.html#main-building-script-debian-rules [2]: https://salsa.debian.org/kernel-team/linux/-/blob/debian/6.7-1_exp1/debian/rules.real#L36 Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/package/debian/rules | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules index 098307780062..697fbfa7595f 100755 --- a/scripts/package/debian/rules +++ b/scripts/package/debian/rules @@ -11,6 +11,14 @@ ifneq (,$(filter-out parallel=1,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))) MAKEFLAGS += -j$(NUMJOBS) endif +# When KBUILD_VERBOSE is undefined (presumably you are directly working with +# the debianized tree), show verbose logs unless DEB_BUILD_OPTION=terse is set. +ifeq ($(origin KBUILD_VERBOSE),undefined) + ifeq (,$(filter terse,$(DEB_BUILD_OPTIONS))) + export KBUILD_VERBOSE := 1 + endif +endif + revision = $(lastword $(subst -, ,$(shell dpkg-parsechangelog -S Version))) CROSS_COMPILE ?= $(filter-out $(DEB_BUILD_GNU_TYPE)-, $(DEB_HOST_GNU_TYPE)-) make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) KBUILD_BUILD_VERSION=$(revision) $(addprefix CROSS_COMPILE=,$(CROSS_COMPILE)) From caf400c8b68af29568e39ef99b12d25966c3e76b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 13 Jan 2024 19:43:37 +0900 Subject: [PATCH 07/67] kbuild: deb-pkg: make debian/rules quiet for 'make deb-pkg' Add $(Q) to the commands in debian/rules to make them quiet when the package built is initiated by 'make deb-pkg' or when the 'terse' tag is set to DEB_BUILD_OPTIONS. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/package/debian/rules | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules index 697fbfa7595f..a183e95886e6 100755 --- a/scripts/package/debian/rules +++ b/scripts/package/debian/rules @@ -16,6 +16,8 @@ endif ifeq ($(origin KBUILD_VERBOSE),undefined) ifeq (,$(filter terse,$(DEB_BUILD_OPTIONS))) export KBUILD_VERBOSE := 1 + else + Q := @ endif endif @@ -27,20 +29,20 @@ make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) KBUILD_BUILD_VERSION=$(r binary: binary-arch binary-indep binary-indep: build-indep binary-arch: build-arch - $(MAKE) $(make-opts) \ + $(Q)$(MAKE) $(make-opts) \ run-command KBUILD_RUN_COMMAND='+$$(srctree)/scripts/package/builddeb' .PHONY: build build-indep build-arch build: build-arch build-indep build-indep: build-arch: - $(MAKE) $(make-opts) olddefconfig - $(MAKE) $(make-opts) $(if $(filter um,$(ARCH)),,headers) all + $(Q)$(MAKE) $(make-opts) olddefconfig + $(Q)$(MAKE) $(make-opts) $(if $(filter um,$(ARCH)),,headers) all .PHONY: clean clean: - rm -rf debian/files debian/linux-* debian/deb-env.vars* - $(MAKE) ARCH=$(ARCH) clean + $(Q)rm -rf debian/files debian/linux-* debian/deb-env.vars* + $(Q)$(MAKE) ARCH=$(ARCH) clean # If DEB_HOST_ARCH is empty, it is likely that debian/rules was executed # directly. Run 'dpkg-architecture --print-set --print-format=make' to @@ -49,6 +51,6 @@ ifndef DEB_HOST_ARCH include debian/deb-env.vars debian/deb-env.vars: - dpkg-architecture -a$$(cat debian/arch) --print-set --print-format=make > $@.tmp - mv $@.tmp $@ + $(Q)dpkg-architecture -a$$(cat debian/arch) --print-set --print-format=make > $@.tmp + $(Q)mv $@.tmp $@ endif From 1d7bae8f8c85ddf153f302cd8d2f33d34762b0fd Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 13 Jan 2024 19:43:38 +0900 Subject: [PATCH 08/67] kbuild: deb-pkg: build binary-arch in parallel 'make deb-pkg' builds build-arch in parallel, but binary-arch serially. Given that all binary packages are independent of one another, they can be built in parallel. I am uncertain whether debian/files is robust against a race condition. Just in case, make dh_gencontrol (dpkg-gencontrol) output to separate debian/*.files, which are then concatenated into debian/files. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/package/builddeb | 40 ++++++++++-------------------------- scripts/package/debian/rules | 39 +++++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/scripts/package/builddeb b/scripts/package/builddeb index bf96a3c24608..d31b16afe0db 100755 --- a/scripts/package/builddeb +++ b/scripts/package/builddeb @@ -24,18 +24,6 @@ if_enabled_echo() { fi } -create_package() { - export DH_OPTIONS="-p${1}" - - dh_installdocs - dh_installchangelogs - dh_compress - dh_fixperms - dh_gencontrol - dh_md5sums - dh_builddeb -- ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} -} - install_linux_image () { pname=$1 pdir=debian/$1 @@ -161,21 +149,15 @@ install_libc_headers () { mv "$pdir/usr/include/asm" "$pdir/usr/include/${DEB_HOST_MULTIARCH}" } -rm -f debian/files +package=$1 -packages_enabled=$(dh_listpackages) - -for package in ${packages_enabled} -do - case ${package} in - *-dbg) - install_linux_image_dbg "${package}";; - linux-image-*|user-mode-linux-*) - install_linux_image "${package}";; - linux-libc-dev) - install_libc_headers "${package}";; - linux-headers-*) - install_kernel_headers "${package}";; - esac - create_package "${package}" -done +case "${package}" in +*-dbg) + install_linux_image_dbg "${package}";; +linux-image-*|user-mode-linux-*) + install_linux_image "${package}";; +linux-libc-dev) + install_libc_headers "${package}";; +linux-headers-*) + install_kernel_headers "${package}";; +esac diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules index a183e95886e6..57f1cf7c6b32 100755 --- a/scripts/package/debian/rules +++ b/scripts/package/debian/rules @@ -25,12 +25,43 @@ revision = $(lastword $(subst -, ,$(shell dpkg-parsechangelog -S Version))) CROSS_COMPILE ?= $(filter-out $(DEB_BUILD_GNU_TYPE)-, $(DEB_HOST_GNU_TYPE)-) make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) KBUILD_BUILD_VERSION=$(revision) $(addprefix CROSS_COMPILE=,$(CROSS_COMPILE)) +binary-targets := $(addprefix binary-, image image-dbg headers libc-dev) + +all-packages = $(shell dh_listpackages) +image-package = $(filter linux-image-% user-%, $(filter-out %-dbg, $(all-packages))) +image-dbg-package = $(filter %-dbg, $(all-packages)) +libc-dev-package = $(filter linux-libc-dev, $(all-packages)) +headers-package = $(filter linux-headers-%, $(all-packages)) + +mk-files = $(patsubst binary-%,debian/%.files,$1) +package = $($(@:binary-%=%-package)) + +# DH_OPTION is an environment variable common for all debhelper commands. +# We could 'export' it, but here it is passed from the command line to clarify +# which package is being processed in the build log. +DH_OPTIONS = -p$(package) + +define binary + $(Q)+$(MAKE) $(make-opts) run-command KBUILD_RUN_COMMAND='+$$(srctree)/scripts/package/builddeb $(package)' + $(Q)dh_installdocs $(DH_OPTIONS) + $(Q)dh_installchangelogs $(DH_OPTIONS) + $(Q)dh_compress $(DH_OPTIONS) + $(Q)dh_fixperms $(DH_OPTIONS) + $(Q)dh_gencontrol $(DH_OPTIONS) -- -f$(call mk-files,$@) + $(Q)dh_md5sums $(DH_OPTIONS) + $(Q)dh_builddeb $(DH_OPTIONS) -- $(addprefix -Z,$(KDEB_COMPRESS)) +endef + +.PHONY: $(binary-targets) +$(binary-targets): build-arch + $(Q)truncate -s0 $(call mk-files,$@) + $(if $(package),$(binary)) + .PHONY: binary binary-indep binary-arch binary: binary-arch binary-indep binary-indep: build-indep -binary-arch: build-arch - $(Q)$(MAKE) $(make-opts) \ - run-command KBUILD_RUN_COMMAND='+$$(srctree)/scripts/package/builddeb' +binary-arch: $(binary-targets) + $(Q)cat $(call mk-files,$^) > debian/files .PHONY: build build-indep build-arch build: build-arch build-indep @@ -41,7 +72,7 @@ build-arch: .PHONY: clean clean: - $(Q)rm -rf debian/files debian/linux-* debian/deb-env.vars* + $(Q)rm -rf debian/files debian/linux-* debian/deb-env.vars* debian/*.files $(Q)$(MAKE) ARCH=$(ARCH) clean # If DEB_HOST_ARCH is empty, it is likely that debian/rules was executed From f96beb84eff698aefde7cea2bbf1de4f688c4750 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 13 Jan 2024 19:43:39 +0900 Subject: [PATCH 09/67] kbuild: deb-pkg: call more misc debhelper commands Use dh_prep instead of removing old build directories manually. Use dh_clean instead of removing build directories and debian/files manually. Call dh_testdir and dh_testroot for preliminary checks. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/package/builddeb | 8 -------- scripts/package/debian/rules | 6 +++++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/scripts/package/builddeb b/scripts/package/builddeb index d31b16afe0db..e797ad360f7a 100755 --- a/scripts/package/builddeb +++ b/scripts/package/builddeb @@ -28,8 +28,6 @@ install_linux_image () { pname=$1 pdir=debian/$1 - rm -rf ${pdir} - # Only some architectures with OF support have this target if is_enabled CONFIG_OF_EARLY_FLATTREE && [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then ${MAKE} -f ${srctree}/Makefile INSTALL_DTBS_PATH="${pdir}/usr/lib/linux-image-${KERNELRELEASE}" dtbs_install @@ -97,8 +95,6 @@ install_linux_image () { install_linux_image_dbg () { pdir=debian/$1 - rm -rf ${pdir} - # Parse modules.order directly because 'make modules_install' may sign, # compress modules, and then run unneeded depmod. while read -r mod; do @@ -128,8 +124,6 @@ install_kernel_headers () { pdir=debian/$1 version=${1#linux-headers-} - rm -rf $pdir - "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}" mkdir -p $pdir/lib/modules/$version/ @@ -139,8 +133,6 @@ install_kernel_headers () { install_libc_headers () { pdir=debian/$1 - rm -rf $pdir - $MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH=$pdir/usr # move asm headers to /usr/include//asm to match the structure diff --git a/scripts/package/debian/rules b/scripts/package/debian/rules index 57f1cf7c6b32..ca07243bd5cd 100755 --- a/scripts/package/debian/rules +++ b/scripts/package/debian/rules @@ -42,6 +42,9 @@ package = $($(@:binary-%=%-package)) DH_OPTIONS = -p$(package) define binary + $(Q)dh_testdir $(DH_OPTIONS) + $(Q)dh_testroot $(DH_OPTIONS) + $(Q)dh_prep $(DH_OPTIONS) $(Q)+$(MAKE) $(make-opts) run-command KBUILD_RUN_COMMAND='+$$(srctree)/scripts/package/builddeb $(package)' $(Q)dh_installdocs $(DH_OPTIONS) $(Q)dh_installchangelogs $(DH_OPTIONS) @@ -72,7 +75,8 @@ build-arch: .PHONY: clean clean: - $(Q)rm -rf debian/files debian/linux-* debian/deb-env.vars* debian/*.files + $(Q)dh_clean + $(Q)rm -rf debian/deb-env.vars* debian/*.files $(Q)$(MAKE) ARCH=$(ARCH) clean # If DEB_HOST_ARCH is empty, it is likely that debian/rules was executed From 615b3a3d2d41bf897168210a092811872561259f Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 2 Feb 2024 22:35:17 +0900 Subject: [PATCH 10/67] kbuild: rpm-pkg: do not include depmod-generated files Installing the kernel package is fine, but when uninstalling it, the following warnings are shown: warning: file modules.symbols.bin: remove failed: No such file or directory warning: file modules.symbols: remove failed: No such file or directory warning: file modules.softdep: remove failed: No such file or directory warning: file modules.devname: remove failed: No such file or directory warning: file modules.dep.bin: remove failed: No such file or directory warning: file modules.dep: remove failed: No such file or directory warning: file modules.builtin.bin: remove failed: No such file or directory warning: file modules.builtin.alias.bin: remove failed: No such file or directory warning: file modules.alias.bin: remove failed: No such file or directory warning: file modules.alias: remove failed: No such file or directory The %preun scriptlet runs 'kernel-install remove', which in turn invokes /usr/lib/kernel/install.d/50-depmod.install to remove those files before the actual package removal. RPM-based distributions do not ship files generated by depmod. Mark them as %ghost in order to exclude them from the package, but still claim the ownership on them. Signed-off-by: Masahiro Yamada Tested-by: Nathan Chancellor --- scripts/package/kernel.spec | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec index f58726671fb3..aaedb6d1b26f 100644 --- a/scripts/package/kernel.spec +++ b/scripts/package/kernel.spec @@ -66,6 +66,20 @@ ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEA %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}' %endif +{ + for x in System.map config kernel modules.builtin \ + modules.builtin.modinfo modules.order vmlinuz; do + echo "/lib/modules/%{KERNELRELEASE}/${x}" + done + + for x in alias alias.bin builtin.alias.bin builtin.bin dep dep.bin \ + devname softdep symbols symbols.bin; do + echo "%ghost /lib/modules/%{KERNELRELEASE}/modules.${x}" + done + + echo "%exclude /lib/modules/%{KERNELRELEASE}/build" +} > %{buildroot}/kernel.list + %clean rm -rf %{buildroot} @@ -78,6 +92,9 @@ for file in vmlinuz System.map config; do cp "/lib/modules/%{KERNELRELEASE}/${file}" "/boot/${file}-%{KERNELRELEASE}" fi done +if [ ! -e "/lib/modules/%{KERNELRELEASE}/modules.dep" ]; then + /usr/sbin/depmod %{KERNELRELEASE} +fi %preun if [ -x /sbin/new-kernel-pkg ]; then @@ -91,10 +108,9 @@ if [ -x /sbin/update-bootloader ]; then /sbin/update-bootloader --remove %{KERNELRELEASE} fi -%files +%files -f %{buildroot}/kernel.list %defattr (-, root, root) -/lib/modules/%{KERNELRELEASE} -%exclude /lib/modules/%{KERNELRELEASE}/build +%exclude /kernel.list %files headers %defattr (-, root, root) From bca17edb24cb0e9ebc9269a77fc0a15f4b526f65 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 2 Feb 2024 22:35:18 +0900 Subject: [PATCH 11/67] kbuild: rpm-pkg: mark installed files in /boot as %ghost Mark the files installed to /boot as %ghost to make sure they will be removed when the package is uninstalled. Signed-off-by: Masahiro Yamada Tested-by: Nathan Chancellor --- scripts/package/kernel.spec | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec index aaedb6d1b26f..ecedcfc11e73 100644 --- a/scripts/package/kernel.spec +++ b/scripts/package/kernel.spec @@ -77,6 +77,10 @@ ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEA echo "%ghost /lib/modules/%{KERNELRELEASE}/modules.${x}" done + for x in System.map config vmlinuz; do + echo "%ghost /boot/${x}-%{KERNELRELEASE}" + done + echo "%exclude /lib/modules/%{KERNELRELEASE}/build" } > %{buildroot}/kernel.list From 435e86998edf2a2308e7917c6368427f89664c61 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 2 Feb 2024 22:35:19 +0900 Subject: [PATCH 12/67] Revert "kbuild/mkspec: support 'update-bootloader'-based systems" This reverts commit 27c3bffd230abd0a598586aed0fe0ba7b61e0e2e. If this is still needed, we can bring it back. However, I'd like to understand why 'update-bootloader --remove' is needed for uninstallation, while 'update-bootloader --add' was not called during the installation. Signed-off-by: Masahiro Yamada --- scripts/package/kernel.spec | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec index ecedcfc11e73..c1b745967f64 100644 --- a/scripts/package/kernel.spec +++ b/scripts/package/kernel.spec @@ -107,11 +107,6 @@ elif [ -x /usr/bin/kernel-install ]; then kernel-install remove %{KERNELRELEASE} fi -%postun -if [ -x /sbin/update-bootloader ]; then -/sbin/update-bootloader --remove %{KERNELRELEASE} -fi - %files -f %{buildroot}/kernel.list %defattr (-, root, root) %exclude /kernel.list From fee9b6d14acde447805d14c0a0a926ced18aa8fa Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 2 Feb 2024 22:35:20 +0900 Subject: [PATCH 13/67] Revert "kbuild/mkspec: clean boot loader configuration on rpm removal" This reverts commit 6ef41e22a320d95a246d45b673aa7247cc1bbf7b. If this is still needed, we can bring it back. However, I'd like to understand why 'new-kernel-pkg --remove' is needed for uninstallation, while 'new-kernel-pkg --install' was not called during the installation. Signed-off-by: Masahiro Yamada --- scripts/package/kernel.spec | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec index c1b745967f64..c256b73cca3e 100644 --- a/scripts/package/kernel.spec +++ b/scripts/package/kernel.spec @@ -101,9 +101,7 @@ if [ ! -e "/lib/modules/%{KERNELRELEASE}/modules.dep" ]; then fi %preun -if [ -x /sbin/new-kernel-pkg ]; then -new-kernel-pkg --remove %{KERNELRELEASE} --rminitrd --initrdfile=/boot/initramfs-%{KERNELRELEASE}.img -elif [ -x /usr/bin/kernel-install ]; then +if [ -x /usr/bin/kernel-install ]; then kernel-install remove %{KERNELRELEASE} fi From af8bbce92044dc58e4cc039ab94ee5d470a621f5 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:57:59 +0900 Subject: [PATCH 14/67] kconfig: fix infinite loop when expanding a macro at the end of file A macro placed at the end of a file with no newline causes an infinite loop. [Test Kconfig] $(info,hello) \ No newline at end of file I realized that flex-provided input() returns 0 instead of EOF when it reaches the end of a file. Fixes: 104daea149c4 ("kconfig: reference environment variables directly and remove 'option env='") Signed-off-by: Masahiro Yamada --- scripts/kconfig/lexer.l | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index f93b535a080c..5f1bc3320307 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -303,8 +303,11 @@ static char *expand_token(const char *in, size_t n) new_string(); append_string(in, n); - /* get the whole line because we do not know the end of token. */ - while ((c = input()) != EOF) { + /* + * get the whole line because we do not know the end of token. + * input() returns 0 (not EOF!) when it reachs the end of file. + */ + while ((c = input()) != 0) { if (c == '\n') { unput(c); break; From 313c6cd3c2d538073b71f15a46c2cbcde5712f46 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:00 +0900 Subject: [PATCH 15/67] kconfig: fix off-by-one in zconf_error() yyerror() reports the line number of the next line. This +1 adjustment was introduced more than 20 years ago [1]. At that time, the line number was decremented then incremented back and forth. The line number management was refactored in a more maintainable way. Such compensation is no longer needed. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=d4f8a4530eb07a1385fd17b0e62a7dce97486f49 Signed-off-by: Masahiro Yamada --- scripts/kconfig/parser.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index 2af7ce4e1531..5ab2e3f7ca33 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -557,7 +557,7 @@ static void zconf_error(const char *err, ...) static void yyerror(const char *err) { - fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err); + fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno(), err); } static void print_quoted_string(FILE *out, const char *str) From 17787468d4e73dc478738a4e6d2809d907c50c25 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:01 +0900 Subject: [PATCH 16/67] kconfig: remove orphan lookup_file() declaration There is no definition, no caller for lookup_file(). Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.h | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 4a9a23b1b7e1..e0d866569155 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -279,7 +279,6 @@ struct jump_key { extern struct file *file_list; extern struct file *current_file; -struct file *lookup_file(const char *name); extern struct symbol symbol_yes, symbol_no, symbol_mod; extern struct symbol *modules_sym; From aa8427fb130f323e5e27dfe25dee9b514462dde7 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:02 +0900 Subject: [PATCH 17/67] kconfig: remove compat_getline() Commit 1a7a8c6fd8ca ("kconfig: allow long lines in config file") added a self-implemented getline() for better portability. However, getline() is standardized [1] and already used in other programs such as scripts/kallsyms.c. Use getline() provided by libc. [1]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getdelim.html Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 53 +------------------------------------- 1 file changed, 1 insertion(+), 52 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index f53dcdd44597..7f0aa39b68c1 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -293,63 +293,12 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p) return 0; } -#define LINE_GROWTH 16 -static int add_byte(int c, char **lineptr, size_t slen, size_t *n) -{ - size_t new_size = slen + 1; - - if (new_size > *n) { - new_size += LINE_GROWTH - 1; - new_size *= 2; - *lineptr = xrealloc(*lineptr, new_size); - *n = new_size; - } - - (*lineptr)[slen] = c; - - return 0; -} - -static ssize_t compat_getline(char **lineptr, size_t *n, FILE *stream) -{ - char *line = *lineptr; - size_t slen = 0; - - for (;;) { - int c = getc(stream); - - switch (c) { - case '\n': - if (add_byte(c, &line, slen, n) < 0) - goto e_out; - slen++; - /* fall through */ - case EOF: - if (add_byte('\0', &line, slen, n) < 0) - goto e_out; - *lineptr = line; - if (slen == 0) - return -1; - return slen; - default: - if (add_byte(c, &line, slen, n) < 0) - goto e_out; - slen++; - } - } - -e_out: - line[slen-1] = '\0'; - *lineptr = line; - return -1; -} - /* like getline(), but the newline character is stripped away */ static ssize_t getline_stripped(char **lineptr, size_t *n, FILE *stream) { ssize_t len; - len = compat_getline(lineptr, n, stream); + len = getline(lineptr, n, stream); if (len > 0 && (*lineptr)[len - 1] == '\n') { len--; From 73a6afc5a541f74ca84c72aad017866dfcf43680 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:03 +0900 Subject: [PATCH 18/67] kconfig: remove unneeded sym_find() call in conf_parse() sym_find("n") is equivalent to &symbol_no. Signed-off-by: Masahiro Yamada --- scripts/kconfig/parser.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index 5ab2e3f7ca33..625224973c51 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -494,7 +494,7 @@ void conf_parse(const char *name) if (yynerrs) exit(1); if (!modules_sym) - modules_sym = sym_find( "n" ); + modules_sym = &symbol_no; if (!menu_has_prompt(&rootmenu)) { current_entry = &rootmenu; From 526396b723a38dbeed35cb9e80814084b9f56329 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:04 +0900 Subject: [PATCH 19/67] kconfig: write Kconfig files to autoconf.cmd in order Currently, include/config/autoconf.cmd saves included Kconfig files in reverse order. While this is not a big deal, it is inconsistent with other *.cmd files generated by fixdep. Output the included Kconfig files in the included order. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 7 +++---- scripts/kconfig/lkc.h | 1 + scripts/kconfig/parser.y | 4 ++++ scripts/kconfig/util.c | 3 +++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 7f0aa39b68c1..f6a96fdddb7e 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -20,6 +20,8 @@ #include "lkc.h" +struct gstr autoconf_cmd; + /* return true if 'path' exists, false otherwise */ static bool is_present(const char *path) { @@ -972,7 +974,6 @@ end_check: static int conf_write_autoconf_cmd(const char *autoconf_name) { char name[PATH_MAX], tmp[PATH_MAX]; - struct file *file; FILE *out; int ret; @@ -993,9 +994,7 @@ static int conf_write_autoconf_cmd(const char *autoconf_name) return -1; } - fprintf(out, "deps_config := \\\n"); - for (file = file_list; file; file = file->next) - fprintf(out, "\t%s \\\n", file->name); + fputs(str_get(&autoconf_cmd), out); fprintf(out, "\n%s: $(deps_config)\n\n", autoconf_name); diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 5cdc8f5e6446..8616ad83be6d 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -40,6 +40,7 @@ int zconf_lineno(void); const char *zconf_curname(void); /* confdata.c */ +extern struct gstr autoconf_cmd; const char *conf_get_configname(void); void set_all_choice_values(struct symbol *csym); diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index 625224973c51..611038c502fc 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -480,6 +480,10 @@ void conf_parse(const char *name) struct symbol *sym; int i; + autoconf_cmd = str_new(); + + str_printf(&autoconf_cmd, "deps_config := \\\n"); + zconf_initscan(name); _menu_init(); diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 92e5b2b9761d..958543bb0a37 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -25,6 +25,9 @@ struct file *file_lookup(const char *name) file->name = xstrdup(name); file->next = file_list; file_list = file; + + str_printf(&autoconf_cmd, "\t%s \\\n", name); + return file; } From 56e634b06fd554b819ac9c45fc77a41500861ced Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:05 +0900 Subject: [PATCH 20/67] kconfig: call env_write_dep() right after yyparse() This allows preprocess.c to free up all of its resources when the parse stage is finished. It also ensures conf_write_autoconf_cmd() produces consistent results even if called multiple times for any reason. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 8 ++------ scripts/kconfig/lkc_proto.h | 2 +- scripts/kconfig/parser.y | 9 ++++++++- scripts/kconfig/preprocess.c | 11 +++++++---- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index f6a96fdddb7e..dafc572e7b7e 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -994,14 +994,10 @@ static int conf_write_autoconf_cmd(const char *autoconf_name) return -1; } + fprintf(out, "autoconfig := %s\n", autoconf_name); + fputs(str_get(&autoconf_cmd), out); - fprintf(out, "\n%s: $(deps_config)\n\n", autoconf_name); - - env_write_dep(out, autoconf_name); - - fprintf(out, "\n$(deps_config): ;\n"); - fflush(out); ret = ferror(out); /* error check for all fprintf() calls */ fclose(out); diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index a4ae5e9eadad..85491d74a094 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -46,7 +46,7 @@ enum variable_flavor { VAR_RECURSIVE, VAR_APPEND, }; -void env_write_dep(FILE *f, const char *auto_conf_name); +void env_write_dep(struct gstr *gs); void variable_add(const char *name, const char *value, enum variable_flavor flavor); void variable_all_del(void); diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index 611038c502fc..cfb82ba09037 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -482,7 +482,7 @@ void conf_parse(const char *name) autoconf_cmd = str_new(); - str_printf(&autoconf_cmd, "deps_config := \\\n"); + str_printf(&autoconf_cmd, "\ndeps_config := \\\n"); zconf_initscan(name); @@ -492,6 +492,13 @@ void conf_parse(const char *name) yydebug = 1; yyparse(); + str_printf(&autoconf_cmd, + "\n" + "$(autoconfig): $(deps_config)\n" + "$(deps_config): ;\n"); + + env_write_dep(&autoconf_cmd); + /* Variables are expanded in the parse phase. We can free them here. */ variable_all_del(); diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index d1f5bcff4b62..b9853d4a891c 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -87,14 +87,17 @@ static char *env_expand(const char *name) return xstrdup(value); } -void env_write_dep(FILE *f, const char *autoconfig_name) +void env_write_dep(struct gstr *s) { struct env *e, *tmp; list_for_each_entry_safe(e, tmp, &env_list, node) { - fprintf(f, "ifneq \"$(%s)\" \"%s\"\n", e->name, e->value); - fprintf(f, "%s: FORCE\n", autoconfig_name); - fprintf(f, "endif\n"); + str_printf(s, + "\n" + "ifneq \"$(%s)\" \"%s\"\n" + "$(autoconfig): FORCE\n" + "endif\n", + e->name, e->value); env_del(e); } } From d3d16228a520ce49884d3bb90b67c12726c63020 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:06 +0900 Subject: [PATCH 21/67] kconfig: split preprocessor prototypes into preprocess.h These are needed only for the parse stage. Move the prototypes into a separate header to make sure they are not used after that. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lexer.l | 2 ++ scripts/kconfig/lkc_proto.h | 13 ------------- scripts/kconfig/parser.y | 1 + scripts/kconfig/preprocess.c | 1 + scripts/kconfig/preprocess.h | 19 +++++++++++++++++++ 5 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 scripts/kconfig/preprocess.h diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index 5f1bc3320307..1bb372868ecf 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -14,6 +14,8 @@ #include #include "lkc.h" +#include "preprocess.h" + #include "parser.tab.h" #define YY_DECL static int yylex1(void) diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 85491d74a094..94299e42402f 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -40,19 +40,6 @@ const char * sym_get_string_value(struct symbol *sym); const char * prop_get_type_name(enum prop_type type); -/* preprocess.c */ -enum variable_flavor { - VAR_SIMPLE, - VAR_RECURSIVE, - VAR_APPEND, -}; -void env_write_dep(struct gstr *gs); -void variable_add(const char *name, const char *value, - enum variable_flavor flavor); -void variable_all_del(void); -char *expand_dollar(const char **str); -char *expand_one_token(const char **str); - /* expr.c */ void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken); diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index cfb82ba09037..ff68def09a2b 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -13,6 +13,7 @@ #include "lkc.h" #include "internal.h" +#include "preprocess.h" #define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt) diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index b9853d4a891c..12665b981c3e 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -11,6 +11,7 @@ #include "list.h" #include "lkc.h" +#include "preprocess.h" #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) diff --git a/scripts/kconfig/preprocess.h b/scripts/kconfig/preprocess.h new file mode 100644 index 000000000000..a7e4a550638c --- /dev/null +++ b/scripts/kconfig/preprocess.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef PREPROCESS_H +#define PREPROCESS_H + +enum variable_flavor { + VAR_SIMPLE, + VAR_RECURSIVE, + VAR_APPEND, +}; + +struct gstr; +void env_write_dep(struct gstr *gs); +void variable_add(const char *name, const char *value, + enum variable_flavor flavor); +void variable_all_del(void); +char *expand_dollar(const char **str); +char *expand_one_token(const char **str); + +#endif /* PREPROCESS_H */ From 52907c07c49b7b820924773d596c5eec5eaf7469 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:07 +0900 Subject: [PATCH 22/67] kconfig: replace current_pos with separate cur_{filename,lineno} Replace current_pos with separate variables representing the file name and the line number, respectively. No functional change is intended. By the way, you might wonder why the "" fallback exists in zconf_curname(). menu_add_symbol() saves the current file and the line number. It is intended to be called only during the yyparse() time. However, menu_finalize() calls it, where there is no file being parsed. This is a long-standing hack that should be fixed later. I left a FIXME comment. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lexer.l | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index 1bb372868ecf..540098435a3b 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -22,10 +22,14 @@ #define START_STRSIZE 16 -static struct { - struct file *file; - int lineno; -} current_pos; +/* The Kconfig file currently being parsed. */ +static const char *cur_filename; + +/* + * The line number of the current statement. This does not match yylineno. + * yylineno is used by the lexer, while cur_lineno is used by the parser. + */ +static int cur_lineno; static int prev_prev_token = T_EOL; static int prev_token = T_EOL; @@ -279,9 +283,14 @@ repeat: * of each statement. Generally, \n is a statement * terminator in Kconfig, but it is not always true * because \n could be escaped by a backslash. + * + * FIXME: + * cur_filename and cur_lineno are used even after + * yyparse(); menu_finalize() calls menu_add_symbol(). + * This should be fixed. */ - current_pos.file = current_file; - current_pos.lineno = yylineno; + cur_filename = current_file ? current_file->name : ""; + cur_lineno = yylineno; } } @@ -462,10 +471,10 @@ static void zconf_endfile(void) int zconf_lineno(void) { - return current_pos.lineno; + return cur_lineno; } const char *zconf_curname(void) { - return current_pos.file ? current_pos.file->name : ""; + return cur_filename; } From 1d7c4f10baacbc658918f7ddec31e1d1962df6fc Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:08 +0900 Subject: [PATCH 23/67] kconfig: remove zconf_curname() and zconf_lineno() Now zconf_curname() and zconf_lineno() are so simple that they just return cur_filename, cur_lineno, respectively. Remove these functions, and then use cur_filename and cur_lineno directly. Signed-off-by: Masahiro Yamada --- scripts/kconfig/internal.h | 3 ++ scripts/kconfig/lexer.l | 20 ++++--------- scripts/kconfig/lkc.h | 2 -- scripts/kconfig/menu.c | 4 +-- scripts/kconfig/parser.y | 59 +++++++++++++++++--------------------- 5 files changed, 37 insertions(+), 51 deletions(-) diff --git a/scripts/kconfig/internal.h b/scripts/kconfig/internal.h index 2f7298c21b64..788401cd5d6f 100644 --- a/scripts/kconfig/internal.h +++ b/scripts/kconfig/internal.h @@ -6,4 +6,7 @@ struct menu; extern struct menu *current_menu, *current_entry; +extern const char *cur_filename; +extern int cur_lineno; + #endif /* INTERNAL_H */ diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index 540098435a3b..3b3893f673dc 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -23,13 +23,13 @@ #define START_STRSIZE 16 /* The Kconfig file currently being parsed. */ -static const char *cur_filename; +const char *cur_filename; /* * The line number of the current statement. This does not match yylineno. * yylineno is used by the lexer, while cur_lineno is used by the parser. */ -static int cur_lineno; +int cur_lineno; static int prev_prev_token = T_EOL; static int prev_token = T_EOL; @@ -187,7 +187,7 @@ n [A-Za-z0-9_-] \n { fprintf(stderr, "%s:%d:warning: multi-line strings not supported\n", - zconf_curname(), zconf_lineno()); + cur_filename, cur_lineno); unput('\n'); BEGIN(INITIAL); yylval.string = text; @@ -423,12 +423,12 @@ void zconf_nextfile(const char *name) yyin = zconf_fopen(file->name); if (!yyin) { fprintf(stderr, "%s:%d: can't open file \"%s\"\n", - zconf_curname(), zconf_lineno(), file->name); + cur_filename, cur_lineno, file->name); exit(1); } yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); - current_file->lineno = zconf_lineno(); + current_file->lineno = cur_lineno; file->parent = current_file; for (iter = current_file; iter; iter = iter->parent) { @@ -468,13 +468,3 @@ static void zconf_endfile(void) current_buf = current_buf->parent; free(tmp); } - -int zconf_lineno(void) -{ - return cur_lineno; -} - -const char *zconf_curname(void) -{ - return cur_filename; -} diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 8616ad83be6d..d8249052f2e3 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -36,8 +36,6 @@ void zconf_starthelp(void); FILE *zconf_fopen(const char *name); void zconf_initscan(const char *name); void zconf_nextfile(const char *name); -int zconf_lineno(void); -const char *zconf_curname(void); /* confdata.c */ extern struct gstr autoconf_cmd; diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 2cce8b651f61..ddca95879631 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -54,7 +54,7 @@ void menu_add_entry(struct symbol *sym) menu->sym = sym; menu->parent = current_menu; menu->file = current_file; - menu->lineno = zconf_lineno(); + menu->lineno = cur_lineno; *last_entry_ptr = menu; last_entry_ptr = &menu->next; @@ -135,7 +135,7 @@ static struct property *menu_add_prop(enum prop_type type, struct expr *expr, memset(prop, 0, sizeof(*prop)); prop->type = type; prop->file = current_file; - prop->lineno = zconf_lineno(); + prop->lineno = cur_lineno; prop->menu = current_entry; prop->expr = expr; prop->visible.expr = dep; diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index ff68def09a2b..b9d7e26fc160 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -144,19 +144,19 @@ config_entry_start: T_CONFIG nonconst_symbol T_EOL { $2->flags |= SYMBOL_OPTIONAL; menu_add_entry($2); - printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2->name); + printd(DEBUG_PARSE, "%s:%d:config %s\n", cur_filename, cur_lineno, $2->name); }; config_stmt: config_entry_start config_option_list { - printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:endconfig\n", cur_filename, cur_lineno); }; menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL { $2->flags |= SYMBOL_OPTIONAL; menu_add_entry($2); - printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2->name); + printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", cur_filename, cur_lineno, $2->name); }; menuconfig_stmt: menuconfig_entry_start config_option_list @@ -165,7 +165,7 @@ menuconfig_stmt: menuconfig_entry_start config_option_list current_entry->prompt->type = P_MENU; else zconfprint("warning: menuconfig statement without prompt"); - printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:endconfig\n", cur_filename, cur_lineno); }; config_option_list: @@ -178,15 +178,13 @@ config_option_list: config_option: type prompt_stmt_opt T_EOL { menu_set_type($1); - printd(DEBUG_PARSE, "%s:%d:type(%u)\n", - zconf_curname(), zconf_lineno(), - $1); + printd(DEBUG_PARSE, "%s:%d:type(%u)\n", cur_filename, cur_lineno, $1); }; config_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL { menu_add_prompt(P_PROMPT, $2, $3); - printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:prompt\n", cur_filename, cur_lineno); }; config_option: default expr if_expr T_EOL @@ -194,27 +192,26 @@ config_option: default expr if_expr T_EOL menu_add_expr(P_DEFAULT, $2, $3); if ($1 != S_UNKNOWN) menu_set_type($1); - printd(DEBUG_PARSE, "%s:%d:default(%u)\n", - zconf_curname(), zconf_lineno(), + printd(DEBUG_PARSE, "%s:%d:default(%u)\n", cur_filename, cur_lineno, $1); }; config_option: T_SELECT nonconst_symbol if_expr T_EOL { menu_add_symbol(P_SELECT, $2, $3); - printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:select\n", cur_filename, cur_lineno); }; config_option: T_IMPLY nonconst_symbol if_expr T_EOL { menu_add_symbol(P_IMPLY, $2, $3); - printd(DEBUG_PARSE, "%s:%d:imply\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:imply\n", cur_filename, cur_lineno); }; config_option: T_RANGE symbol symbol if_expr T_EOL { menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4); - printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:range\n", cur_filename, cur_lineno); }; config_option: T_MODULES T_EOL @@ -234,7 +231,7 @@ choice: T_CHOICE word_opt T_EOL menu_add_entry(sym); menu_add_expr(P_CHOICE, NULL, NULL); free($2); - printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:choice\n", cur_filename, cur_lineno); }; choice_entry: choice choice_option_list @@ -246,7 +243,7 @@ choice_end: end { if (zconf_endtoken($1, "choice")) { menu_end_menu(); - printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:endchoice\n", cur_filename, cur_lineno); } }; @@ -263,27 +260,25 @@ choice_option_list: choice_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL { menu_add_prompt(P_PROMPT, $2, $3); - printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:prompt\n", cur_filename, cur_lineno); }; choice_option: logic_type prompt_stmt_opt T_EOL { menu_set_type($1); - printd(DEBUG_PARSE, "%s:%d:type(%u)\n", - zconf_curname(), zconf_lineno(), $1); + printd(DEBUG_PARSE, "%s:%d:type(%u)\n", cur_filename, cur_lineno, $1); }; choice_option: T_OPTIONAL T_EOL { current_entry->sym->flags |= SYMBOL_OPTIONAL; - printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:optional\n", cur_filename, cur_lineno); }; choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL { menu_add_symbol(P_DEFAULT, $2, $3); - printd(DEBUG_PARSE, "%s:%d:default\n", - zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:default\n", cur_filename, cur_lineno); }; type: @@ -305,7 +300,7 @@ default: if_entry: T_IF expr T_EOL { - printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:if\n", cur_filename, cur_lineno); menu_add_entry(NULL); menu_add_dep($2); $$ = menu_add_menu(); @@ -315,7 +310,7 @@ if_end: end { if (zconf_endtoken($1, "if")) { menu_end_menu(); - printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:endif\n", cur_filename, cur_lineno); } }; @@ -331,7 +326,7 @@ menu: T_MENU T_WORD_QUOTE T_EOL { menu_add_entry(NULL); menu_add_prompt(P_MENU, $2, NULL); - printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:menu\n", cur_filename, cur_lineno); }; menu_entry: menu menu_option_list @@ -343,7 +338,7 @@ menu_end: end { if (zconf_endtoken($1, "menu")) { menu_end_menu(); - printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:endmenu\n", cur_filename, cur_lineno); } }; @@ -358,7 +353,7 @@ menu_option_list: source_stmt: T_SOURCE T_WORD_QUOTE T_EOL { - printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2); + printd(DEBUG_PARSE, "%s:%d:source %s\n", cur_filename, cur_lineno, $2); zconf_nextfile($2); free($2); }; @@ -369,7 +364,7 @@ comment: T_COMMENT T_WORD_QUOTE T_EOL { menu_add_entry(NULL); menu_add_prompt(P_COMMENT, $2, NULL); - printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:comment\n", cur_filename, cur_lineno); }; comment_stmt: comment comment_option_list @@ -384,7 +379,7 @@ comment_option_list: help_start: T_HELP T_EOL { - printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:help\n", cur_filename, cur_lineno); zconf_starthelp(); }; @@ -409,7 +404,7 @@ help: help_start T_HELPTEXT depends: T_DEPENDS T_ON expr T_EOL { menu_add_dep($3); - printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:depends on\n", cur_filename, cur_lineno); }; /* visibility option */ @@ -548,7 +543,7 @@ static void zconfprint(const char *err, ...) { va_list ap; - fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno()); + fprintf(stderr, "%s:%d: ", cur_filename, cur_lineno); va_start(ap, err); vfprintf(stderr, err, ap); va_end(ap); @@ -560,7 +555,7 @@ static void zconf_error(const char *err, ...) va_list ap; yynerrs++; - fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno()); + fprintf(stderr, "%s:%d: ", cur_filename, cur_lineno); va_start(ap, err); vfprintf(stderr, err, ap); va_end(ap); @@ -569,7 +564,7 @@ static void zconf_error(const char *err, ...) static void yyerror(const char *err) { - fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno(), err); + fprintf(stderr, "%s:%d: %s\n", cur_filename, cur_lineno, err); } static void print_quoted_string(FILE *out, const char *str) From 40bab83a6595b3ab8afcfdb57903470f64fdbdb9 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:09 +0900 Subject: [PATCH 24/67] kconfig: associate struct menu with file name directly struct menu is linked to struct file for diagnostic purposes. It is always used to retrieve the file name through menu->file->name. Associate struct menu with the file name directly. Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.h | 2 +- scripts/kconfig/menu.c | 6 +++--- scripts/kconfig/parser.y | 6 +++--- scripts/kconfig/qconf.cc | 2 +- scripts/kconfig/symbol.c | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index e0d866569155..e8fc85d98cdd 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -256,7 +256,7 @@ struct menu { char *help; /* The location where the menu node appears in the Kconfig files */ - struct file *file; + const char *filename; int lineno; /* For use by front ends that need to store auxiliary data */ diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index ddca95879631..5ad4d2b9fb82 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -23,7 +23,7 @@ void menu_warn(struct menu *menu, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - fprintf(stderr, "%s:%d:warning: ", menu->file->name, menu->lineno); + fprintf(stderr, "%s:%d:warning: ", menu->filename, menu->lineno); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); va_end(ap); @@ -53,7 +53,7 @@ void menu_add_entry(struct symbol *sym) memset(menu, 0, sizeof(*menu)); menu->sym = sym; menu->parent = current_menu; - menu->file = current_file; + menu->filename = cur_filename; menu->lineno = cur_lineno; *last_entry_ptr = menu; @@ -676,7 +676,7 @@ struct menu *menu_get_parent_menu(struct menu *menu) static void get_def_str(struct gstr *r, struct menu *menu) { str_printf(r, "Defined at %s:%d\n", - menu->file->name, menu->lineno); + menu->filename, menu->lineno); } static void get_dep_str(struct gstr *r, struct expr *expr, const char *prefix) diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index b9d7e26fc160..d1d05c8cd89d 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -101,7 +101,7 @@ struct menu *current_menu, *current_entry; %destructor { fprintf(stderr, "%s:%d: missing end statement for this entry\n", - $$->file->name, $$->lineno); + $$->filename, $$->lineno); if (current_menu == $$) menu_end_menu(); } if_entry menu_entry choice_entry @@ -527,11 +527,11 @@ static bool zconf_endtoken(const char *tokenname, yynerrs++; return false; } - if (current_menu->file != current_file) { + if (strcmp(current_menu->filename, cur_filename)) { zconf_error("'%s' in different file than '%s'", tokenname, expected_tokenname); fprintf(stderr, "%s:%d: location of the '%s'\n", - current_menu->file->name, current_menu->lineno, + current_menu->filename, current_menu->lineno, expected_tokenname); yynerrs++; return false; diff --git a/scripts/kconfig/qconf.cc b/scripts/kconfig/qconf.cc index 620a3527c767..c6c42c0f4e5d 100644 --- a/scripts/kconfig/qconf.cc +++ b/scripts/kconfig/qconf.cc @@ -1058,7 +1058,7 @@ void ConfigInfoView::menuInfo(void) stream << "

"; } - stream << "defined at " << _menu->file->name << ":" + stream << "defined at " << _menu->filename << ":" << _menu->lineno << "

"; } } diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index e9e9fb8d8674..7647e3e87cd5 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -1045,12 +1045,12 @@ static void sym_check_print_recursive(struct symbol *last_sym) if (sym_is_choice(sym)) { fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n", - menu->file->name, menu->lineno, + menu->filename, menu->lineno, sym->name ? sym->name : "", next_sym->name ? next_sym->name : ""); } else if (sym_is_choice_value(sym)) { fprintf(stderr, "%s:%d:\tsymbol %s is part of choice %s\n", - menu->file->name, menu->lineno, + menu->filename, menu->lineno, sym->name ? sym->name : "", next_sym->name ? next_sym->name : ""); } else if (stack->expr == &sym->dir_dep.expr) { From 1a90b0cdc02a9efba97a2ea49e4b851958137053 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:10 +0900 Subject: [PATCH 25/67] kconfig: associate struct property with file name directly struct property is linked to struct file for diagnostic purposes. It is always used to retrieve the file name through prop->file->name. Associate struct property with the file name directly. Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.h | 2 +- scripts/kconfig/menu.c | 4 ++-- scripts/kconfig/symbol.c | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index e8fc85d98cdd..037db39c5bf0 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -195,7 +195,7 @@ struct property { struct menu *menu; /* the menu the property are associated with * valid for: P_SELECT, P_RANGE, P_CHOICE, * P_PROMPT, P_DEFAULT, P_MENU, P_COMMENT */ - struct file *file; /* what file was this property defined */ + const char *filename; /* what file was this property defined */ int lineno; /* what lineno was this property defined */ }; diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 5ad4d2b9fb82..0ded0b1830d0 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -33,7 +33,7 @@ static void prop_warn(struct property *prop, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - fprintf(stderr, "%s:%d:warning: ", prop->file->name, prop->lineno); + fprintf(stderr, "%s:%d:warning: ", prop->filename, prop->lineno); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); va_end(ap); @@ -134,7 +134,7 @@ static struct property *menu_add_prop(enum prop_type type, struct expr *expr, prop = xmalloc(sizeof(*prop)); memset(prop, 0, sizeof(*prop)); prop->type = type; - prop->file = current_file; + prop->filename = cur_filename; prop->lineno = cur_lineno; prop->menu = current_entry; prop->expr = expr; diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 7647e3e87cd5..dae630a74e50 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -1041,7 +1041,7 @@ static void sym_check_print_recursive(struct symbol *last_sym) } if (stack->sym == last_sym) fprintf(stderr, "%s:%d:error: recursive dependency detected!\n", - prop->file->name, prop->lineno); + prop->filename, prop->lineno); if (sym_is_choice(sym)) { fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n", @@ -1055,28 +1055,28 @@ static void sym_check_print_recursive(struct symbol *last_sym) next_sym->name ? next_sym->name : ""); } else if (stack->expr == &sym->dir_dep.expr) { fprintf(stderr, "%s:%d:\tsymbol %s depends on %s\n", - prop->file->name, prop->lineno, + prop->filename, prop->lineno, sym->name ? sym->name : "", next_sym->name ? next_sym->name : ""); } else if (stack->expr == &sym->rev_dep.expr) { fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n", - prop->file->name, prop->lineno, + prop->filename, prop->lineno, sym->name ? sym->name : "", next_sym->name ? next_sym->name : ""); } else if (stack->expr == &sym->implied.expr) { fprintf(stderr, "%s:%d:\tsymbol %s is implied by %s\n", - prop->file->name, prop->lineno, + prop->filename, prop->lineno, sym->name ? sym->name : "", next_sym->name ? next_sym->name : ""); } else if (stack->expr) { fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n", - prop->file->name, prop->lineno, + prop->filename, prop->lineno, sym->name ? sym->name : "", prop_get_type_name(prop->type), next_sym->name ? next_sym->name : ""); } else { fprintf(stderr, "%s:%d:\tsymbol %s %s is visible depending on %s\n", - prop->file->name, prop->lineno, + prop->filename, prop->lineno, sym->name ? sym->name : "", prop_get_type_name(prop->type), next_sym->name ? next_sym->name : ""); From fe273c6fc318da07bdbb42d26d8e6e150aa947af Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:11 +0900 Subject: [PATCH 26/67] kconfig: replace file->name with name in zconf_nextfile() The 'file->name' and 'name' are the same in this function. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lexer.l | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index 3b3893f673dc..35ad1b256470 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -420,10 +420,10 @@ void zconf_nextfile(const char *name) buf->yylineno = yylineno; buf->parent = current_buf; current_buf = buf; - yyin = zconf_fopen(file->name); + yyin = zconf_fopen(name); if (!yyin) { fprintf(stderr, "%s:%d: can't open file \"%s\"\n", - cur_filename, cur_lineno, file->name); + cur_filename, cur_lineno, name); exit(1); } yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); @@ -432,17 +432,17 @@ void zconf_nextfile(const char *name) file->parent = current_file; for (iter = current_file; iter; iter = iter->parent) { - if (!strcmp(iter->name, file->name)) { + if (!strcmp(iter->name, name)) { fprintf(stderr, "Recursive inclusion detected.\n" "Inclusion path:\n" - " current file : %s\n", file->name); + " current file : %s\n", name); iter = file; do { iter = iter->parent; fprintf(stderr, " included from: %s:%d\n", iter->name, iter->lineno); - } while (strcmp(iter->name, file->name)); + } while (strcmp(iter->name, name)); exit(1); } } From d3e4a68fe20f3c05de77f5e300e3d76a9f68d942 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:12 +0900 Subject: [PATCH 27/67] kconfig: do not delay the cur_filename update Currently, cur_filename is updated at the first token of each statement. However, this seems unnecessary based on my understanding; the parser can use the same variable as the lexer tracks. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lexer.l | 17 +++++++---------- scripts/kconfig/parser.y | 8 ++++++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index 35ad1b256470..28e279cd5a22 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -274,24 +274,17 @@ repeat: token = yylex1(); if (prev_token == T_EOL || prev_token == T_HELPTEXT) { - if (token == T_EOL) { + if (token == T_EOL) /* Do not pass unneeded T_EOL to the parser. */ goto repeat; - } else { + else /* - * For the parser, update file/lineno at the first token + * For the parser, update lineno at the first token * of each statement. Generally, \n is a statement * terminator in Kconfig, but it is not always true * because \n could be escaped by a backslash. - * - * FIXME: - * cur_filename and cur_lineno are used even after - * yyparse(); menu_finalize() calls menu_add_symbol(). - * This should be fixed. */ - cur_filename = current_file ? current_file->name : ""; cur_lineno = yylineno; - } } if (prev_prev_token == T_EOL && prev_token == T_WORD && @@ -407,6 +400,7 @@ void zconf_initscan(const char *name) } current_file = file_lookup(name); + cur_filename = current_file->name; yylineno = 1; } @@ -448,6 +442,7 @@ void zconf_nextfile(const char *name) } yylineno = 1; + cur_filename = file->name; current_file = file; } @@ -456,6 +451,8 @@ static void zconf_endfile(void) struct buffer *tmp; current_file = current_file->parent; + if (current_file) + cur_filename = current_file->name; if (!current_buf) return; diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index d1d05c8cd89d..e58c24d2e5ab 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -488,6 +488,14 @@ void conf_parse(const char *name) yydebug = 1; yyparse(); + /* + * FIXME: + * cur_filename and cur_lineno are used even after yyparse(); + * menu_finalize() calls menu_add_symbol(). This should be fixed. + */ + cur_filename = ""; + cur_lineno = 0; + str_printf(&autoconf_cmd, "\n" "$(autoconfig): $(deps_config)\n" From 4ff7ceae83bea6afcd0325b88e3f3d9f168cc432 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:13 +0900 Subject: [PATCH 28/67] kconfig: replace remaining current_file->name with cur_filename Replace the remaining current_file->name in the lexer context. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lexer.l | 4 ++-- scripts/kconfig/preprocess.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index 28e279cd5a22..db2397c4e343 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -84,7 +84,7 @@ static void warn_ignored_character(char chr) { fprintf(stderr, "%s:%d:warning: ignoring unsupported character '%c'\n", - current_file->name, yylineno, chr); + cur_filename, yylineno, chr); } %} @@ -253,7 +253,7 @@ n [A-Za-z0-9_-] if (prev_token != T_EOL && prev_token != T_HELPTEXT) fprintf(stderr, "%s:%d:warning: no new line at end of file\n", - current_file->name, yylineno); + cur_filename, yylineno); if (current_file) { zconf_endfile(); diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index 12665b981c3e..69b806a6d8b7 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -9,6 +9,7 @@ #include #include +#include "internal.h" #include "list.h" #include "lkc.h" #include "preprocess.h" @@ -22,7 +23,7 @@ static void __attribute__((noreturn)) pperror(const char *format, ...) { va_list ap; - fprintf(stderr, "%s:%d: ", current_file->name, yylineno); + fprintf(stderr, "%s:%d: ", cur_filename, yylineno); va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap); @@ -123,7 +124,7 @@ static char *do_error_if(int argc, char *argv[]) static char *do_filename(int argc, char *argv[]) { - return xstrdup(current_file->name); + return xstrdup(cur_filename); } static char *do_info(int argc, char *argv[]) @@ -185,8 +186,7 @@ static char *do_shell(int argc, char *argv[]) static char *do_warning_if(int argc, char *argv[]) { if (!strcmp(argv[0], "y")) - fprintf(stderr, "%s:%d: %s\n", - current_file->name, yylineno, argv[1]); + fprintf(stderr, "%s:%d: %s\n", cur_filename, yylineno, argv[1]); return xstrdup(""); } From 8facc5f31954d5fddc2759de474eb6fae1135ced Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:14 +0900 Subject: [PATCH 29/67] kconfig: move the file and lineno in struct file to struct buffer struct file has two link nodes, 'next' and 'parent'. The former is used to link files in the 'file_list' linked list, which manages the list of Kconfig files seen so far. The latter is used to link files in the 'current_file' linked list, which manages the inclusion ("source") tree. The latter should be tracked together with the lexer state. Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.h | 3 --- scripts/kconfig/lexer.l | 50 ++++++++++++++++++----------------------- scripts/kconfig/menu.c | 1 - 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 037db39c5bf0..85e0d1ab3c8a 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -19,9 +19,7 @@ extern "C" { struct file { struct file *next; - struct file *parent; const char *name; - int lineno; }; typedef enum tristate { @@ -278,7 +276,6 @@ struct jump_key { }; extern struct file *file_list; -extern struct file *current_file; extern struct symbol symbol_yes, symbol_no, symbol_mod; extern struct symbol *modules_sym; diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index db2397c4e343..71f651bb82ba 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -40,6 +40,8 @@ struct buffer { struct buffer *parent; YY_BUFFER_STATE state; int yylineno; + const char *filename; + int source_lineno; }; static struct buffer *current_buf; @@ -255,7 +257,7 @@ n [A-Za-z0-9_-] fprintf(stderr, "%s:%d:warning: no new line at end of file\n", cur_filename, yylineno); - if (current_file) { + if (current_buf) { zconf_endfile(); return T_EOL; } @@ -399,19 +401,20 @@ void zconf_initscan(const char *name) exit(1); } - current_file = file_lookup(name); - cur_filename = current_file->name; + cur_filename = file_lookup(name)->name; yylineno = 1; } void zconf_nextfile(const char *name) { - struct file *iter; struct file *file = file_lookup(name); struct buffer *buf = xmalloc(sizeof(*buf)); + bool recur_include = false; buf->state = YY_CURRENT_BUFFER; buf->yylineno = yylineno; + buf->filename = cur_filename; + buf->source_lineno = cur_lineno; buf->parent = current_buf; current_buf = buf; yyin = zconf_fopen(name); @@ -422,45 +425,36 @@ void zconf_nextfile(const char *name) } yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); - current_file->lineno = cur_lineno; - file->parent = current_file; + for (buf = current_buf; buf; buf = buf->parent) { + if (!strcmp(buf->filename, name)) + recur_include = true; + } - for (iter = current_file; iter; iter = iter->parent) { - if (!strcmp(iter->name, name)) { - fprintf(stderr, - "Recursive inclusion detected.\n" - "Inclusion path:\n" - " current file : %s\n", name); - iter = file; - do { - iter = iter->parent; - fprintf(stderr, " included from: %s:%d\n", - iter->name, iter->lineno); - } while (strcmp(iter->name, name)); - exit(1); - } + if (recur_include) { + fprintf(stderr, + "Recursive inclusion detected.\n" + "Inclusion path:\n" + " current file : %s\n", name); + + for (buf = current_buf; buf; buf = buf->parent) + fprintf(stderr, " included from: %s:%d\n", + buf->filename, buf->source_lineno); + exit(1); } yylineno = 1; cur_filename = file->name; - current_file = file; } static void zconf_endfile(void) { struct buffer *tmp; - current_file = current_file->parent; - if (current_file) - cur_filename = current_file->name; - - if (!current_buf) - return; - fclose(yyin); yy_delete_buffer(YY_CURRENT_BUFFER); yy_switch_to_buffer(current_buf->state); yylineno = current_buf->yylineno; + cur_filename = current_buf->filename; tmp = current_buf; current_buf = current_buf->parent; free(tmp); diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 0ded0b1830d0..b879576d1ab4 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -17,7 +17,6 @@ struct menu rootmenu; static struct menu **last_entry_ptr; struct file *file_list; -struct file *current_file; void menu_warn(struct menu *menu, const char *fmt, ...) { From 6676c5bc15e66268c9c9669d5852aa779689c74e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:15 +0900 Subject: [PATCH 30/67] kconfig: make file::name a flexible array member Call malloc() just once to allocate needed memory. Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.h | 2 +- scripts/kconfig/util.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 85e0d1ab3c8a..760b1e681b43 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -19,7 +19,7 @@ extern "C" { struct file { struct file *next; - const char *name; + char name[]; }; typedef enum tristate { diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 958543bb0a37..2636dccea0c9 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -13,6 +13,7 @@ struct file *file_lookup(const char *name) { struct file *file; + size_t len; for (file = file_list; file; file = file->next) { if (!strcmp(name, file->name)) { @@ -20,9 +21,11 @@ struct file *file_lookup(const char *name) } } - file = xmalloc(sizeof(*file)); + len = strlen(name); + file = xmalloc(sizeof(*file) + len + 1); memset(file, 0, sizeof(*file)); - file->name = xstrdup(name); + memcpy(file->name, name, len); + file->name[len] = '\0'; file->next = file_list; file_list = file; From 5b058034e3aa600802ab609e8264dc2ca1300ebe Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:16 +0900 Subject: [PATCH 31/67] kconfig: change file_lookup() to return the file name Currently, file_lookup() returns a pointer to (struct file), but the callers use only file->name. Make it return the ->name member directly. This adjustment encapsulates struct file and file_list as internal implementation. Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.h | 7 ------- scripts/kconfig/lexer.l | 5 ++--- scripts/kconfig/lkc.h | 2 +- scripts/kconfig/menu.c | 2 -- scripts/kconfig/util.c | 13 ++++++++++--- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 760b1e681b43..d667f9aa041e 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -17,11 +17,6 @@ extern "C" { #include #endif -struct file { - struct file *next; - char name[]; -}; - typedef enum tristate { no, mod, yes } tristate; @@ -275,8 +270,6 @@ struct jump_key { struct menu *target; }; -extern struct file *file_list; - extern struct symbol symbol_yes, symbol_no, symbol_mod; extern struct symbol *modules_sym; extern int cdebug; diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index 71f651bb82ba..89544c3a1a29 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -401,13 +401,12 @@ void zconf_initscan(const char *name) exit(1); } - cur_filename = file_lookup(name)->name; + cur_filename = file_lookup(name); yylineno = 1; } void zconf_nextfile(const char *name) { - struct file *file = file_lookup(name); struct buffer *buf = xmalloc(sizeof(*buf)); bool recur_include = false; @@ -443,7 +442,7 @@ void zconf_nextfile(const char *name) } yylineno = 1; - cur_filename = file->name; + cur_filename = file_lookup(name); } static void zconf_endfile(void) diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index d8249052f2e3..71afcbd56273 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -52,7 +52,7 @@ static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out) } /* util.c */ -struct file *file_lookup(const char *name); +const char *file_lookup(const char *name); void *xmalloc(size_t size); void *xcalloc(size_t nmemb, size_t size); void *xrealloc(void *p, size_t size); diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index b879576d1ab4..f701382f8a69 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -16,8 +16,6 @@ static const char nohelp_text[] = "There is no help available for this option."; struct menu rootmenu; static struct menu **last_entry_ptr; -struct file *file_list; - void menu_warn(struct menu *menu, const char *fmt, ...) { va_list ap; diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 2636dccea0c9..610d64c01479 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -9,15 +9,22 @@ #include #include "lkc.h" +struct file { + struct file *next; + char name[]; +}; + +static struct file *file_list; + /* file already present in list? If not add it */ -struct file *file_lookup(const char *name) +const char *file_lookup(const char *name) { struct file *file; size_t len; for (file = file_list; file; file = file->next) { if (!strcmp(name, file->name)) { - return file; + return file->name; } } @@ -31,7 +38,7 @@ struct file *file_lookup(const char *name) str_printf(&autoconf_cmd, "\t%s \\\n", name); - return file; + return file->name; } /* Allocate initial growable string */ From 4dae9cf5cbb863c7ca23899446885dbc457f81ae Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:17 +0900 Subject: [PATCH 32/67] kconfig: split list_head into a separate header The struct list_head is often embedded in other structures, while other code is used in C functions. By separating struct list_head into its own header, other headers are no longer required to include the entire list.h. This is similar to the kernel space, where struct list_head is defined in instead of . Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.h | 2 +- scripts/kconfig/list.h | 8 ++------ scripts/kconfig/list_types.h | 9 +++++++++ scripts/kconfig/mconf.c | 1 + scripts/kconfig/menu.c | 1 + scripts/kconfig/nconf.c | 1 + 6 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 scripts/kconfig/list_types.h diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index d667f9aa041e..dd3350aed302 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -12,7 +12,7 @@ extern "C" { #include #include -#include "list.h" +#include "list_types.h" #ifndef __cplusplus #include #endif diff --git a/scripts/kconfig/list.h b/scripts/kconfig/list.h index 45cb237ab7ef..babed0baf4ae 100644 --- a/scripts/kconfig/list.h +++ b/scripts/kconfig/list.h @@ -2,6 +2,8 @@ #ifndef LIST_H #define LIST_H +#include "list_types.h" + /* * Copied from include/linux/... */ @@ -20,12 +22,6 @@ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) - -struct list_head { - struct list_head *next, *prev; -}; - - #define LIST_HEAD_INIT(name) { &(name), &(name) } #define LIST_HEAD(name) \ diff --git a/scripts/kconfig/list_types.h b/scripts/kconfig/list_types.h new file mode 100644 index 000000000000..32899f424983 --- /dev/null +++ b/scripts/kconfig/list_types.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef LIST_TYPES_H +#define LIST_TYPES_H + +struct list_head { + struct list_head *next, *prev; +}; + +#endif /* LIST_TYPES_H */ diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c index 5df32148a869..f4bb391d50cf 100644 --- a/scripts/kconfig/mconf.c +++ b/scripts/kconfig/mconf.c @@ -19,6 +19,7 @@ #include #include +#include "list.h" #include "lkc.h" #include "lxdialog/dialog.h" #include "mnconf-common.h" diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index f701382f8a69..696803d944e0 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -10,6 +10,7 @@ #include "lkc.h" #include "internal.h" +#include "list.h" static const char nohelp_text[] = "There is no help available for this option."; diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c index 1148163cfa7e..9d22b0f3197b 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c @@ -11,6 +11,7 @@ #include #include +#include "list.h" #include "lkc.h" #include "mnconf-common.h" #include "nconf.h" From 55f649b73de1585de8608ad5afa764cd7646f9c2 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:18 +0900 Subject: [PATCH 33/67] kconfig: resync list.h Update the existing macros and inline functions based on include/linux/list.h. The variable name '_new' can be reverted to 'new' because this header is no longer included from the C++ file, scripts/kconfig/qconf.cc. Signed-off-by: Masahiro Yamada --- scripts/kconfig/list.h | 183 +++++++++++++++++++++++++++-------------- 1 file changed, 121 insertions(+), 62 deletions(-) diff --git a/scripts/kconfig/list.h b/scripts/kconfig/list.h index babed0baf4ae..2bce2b8f21d1 100644 --- a/scripts/kconfig/list.h +++ b/scripts/kconfig/list.h @@ -2,25 +2,39 @@ #ifndef LIST_H #define LIST_H +#include + #include "list_types.h" -/* - * Copied from include/linux/... - */ - -#undef offsetof -#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +/* Are two types/vars the same type (ignoring qualifiers)? */ +#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) /** * container_of - cast a member of a structure out to the containing structure - * @ptr: the pointer to the member. - * @type: the type of the container struct this is embedded in. - * @member: the name of the member within the struct. + * @ptr: the pointer to the member. + * @type: the type of the container struct this is embedded in. + * @member: the name of the member within the struct. * */ -#define container_of(ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) +#define container_of(ptr, type, member) ({ \ + void *__mptr = (void *)(ptr); \ + _Static_assert(__same_type(*(ptr), ((type *)0)->member) || \ + __same_type(*(ptr), void), \ + "pointer type mismatch in container_of()"); \ + ((type *)(__mptr - offsetof(type, member))); }) + +#define LIST_POISON1 ((void *) 0x100) +#define LIST_POISON2 ((void *) 0x122) + +/* + * Circular doubly linked list implementation. + * + * Some of the internal functions ("__xxx") are useful when + * manipulating whole lists rather than single entries, as + * sometimes we already know the next/prev entries and we can + * generate better code by using them directly rather than + * using the generic single-entry routines. + */ #define LIST_HEAD_INIT(name) { &(name), &(name) } @@ -28,45 +42,16 @@ struct list_head name = LIST_HEAD_INIT(name) /** - * list_entry - get the struct for this entry - * @ptr: the &struct list_head pointer. - * @type: the type of the struct this is embedded in. - * @member: the name of the list_head within the struct. + * INIT_LIST_HEAD - Initialize a list_head structure + * @list: list_head structure to be initialized. + * + * Initializes the list_head to point to itself. If it is a list header, + * the result is an empty list. */ -#define list_entry(ptr, type, member) \ - container_of(ptr, type, member) - -/** - * list_for_each_entry - iterate over list of given type - * @pos: the type * to use as a loop cursor. - * @head: the head for your list. - * @member: the name of the list_head within the struct. - */ -#define list_for_each_entry(pos, head, member) \ - for (pos = list_entry((head)->next, typeof(*pos), member); \ - &pos->member != (head); \ - pos = list_entry(pos->member.next, typeof(*pos), member)) - -/** - * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry - * @pos: the type * to use as a loop cursor. - * @n: another type * to use as temporary storage - * @head: the head for your list. - * @member: the name of the list_head within the struct. - */ -#define list_for_each_entry_safe(pos, n, head, member) \ - for (pos = list_entry((head)->next, typeof(*pos), member), \ - n = list_entry(pos->member.next, typeof(*pos), member); \ - &pos->member != (head); \ - pos = n, n = list_entry(n->member.next, typeof(*n), member)) - -/** - * list_empty - tests whether a list is empty - * @head: the list to test. - */ -static inline int list_empty(const struct list_head *head) +static inline void INIT_LIST_HEAD(struct list_head *list) { - return head->next == head; + list->next = list; + list->prev = list; } /* @@ -75,14 +60,14 @@ static inline int list_empty(const struct list_head *head) * This is only for internal list manipulation where we know * the prev/next entries already! */ -static inline void __list_add(struct list_head *_new, +static inline void __list_add(struct list_head *new, struct list_head *prev, struct list_head *next) { - next->prev = _new; - _new->next = next; - _new->prev = prev; - prev->next = _new; + next->prev = new; + new->next = next; + new->prev = prev; + prev->next = new; } /** @@ -93,9 +78,9 @@ static inline void __list_add(struct list_head *_new, * Insert a new entry before the specified head. * This is useful for implementing queues. */ -static inline void list_add_tail(struct list_head *_new, struct list_head *head) +static inline void list_add_tail(struct list_head *new, struct list_head *head) { - __list_add(_new, head->prev, head); + __list_add(new, head->prev, head); } /* @@ -111,8 +96,11 @@ static inline void __list_del(struct list_head *prev, struct list_head *next) prev->next = next; } -#define LIST_POISON1 ((void *) 0x00100100) -#define LIST_POISON2 ((void *) 0x00200200) +static inline void __list_del_entry(struct list_head *entry) +{ + __list_del(entry->prev, entry->next); +} + /** * list_del - deletes entry from list. * @entry: the element to delete from the list. @@ -121,8 +109,79 @@ static inline void __list_del(struct list_head *prev, struct list_head *next) */ static inline void list_del(struct list_head *entry) { - __list_del(entry->prev, entry->next); - entry->next = (struct list_head*)LIST_POISON1; - entry->prev = (struct list_head*)LIST_POISON2; + __list_del_entry(entry); + entry->next = LIST_POISON1; + entry->prev = LIST_POISON2; } -#endif + +/** + * list_empty - tests whether a list is empty + * @head: the list to test. + */ +static inline int list_empty(const struct list_head *head) +{ + return head->next == head; +} + +/** + * list_entry - get the struct for this entry + * @ptr: the &struct list_head pointer. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_head within the struct. + */ +#define list_entry(ptr, type, member) \ + container_of(ptr, type, member) + +/** + * list_first_entry - get the first element from a list + * @ptr: the list head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_head within the struct. + * + * Note, that list is expected to be not empty. + */ +#define list_first_entry(ptr, type, member) \ + list_entry((ptr)->next, type, member) + +/** + * list_next_entry - get the next element in list + * @pos: the type * to cursor + * @member: the name of the list_head within the struct. + */ +#define list_next_entry(pos, member) \ + list_entry((pos)->member.next, typeof(*(pos)), member) + +/** + * list_entry_is_head - test if the entry points to the head of the list + * @pos: the type * to cursor + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_entry_is_head(pos, head, member) \ + (&pos->member == (head)) + +/** + * list_for_each_entry - iterate over list of given type + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_for_each_entry(pos, head, member) \ + for (pos = list_first_entry(head, typeof(*pos), member); \ + !list_entry_is_head(pos, head, member); \ + pos = list_next_entry(pos, member)) + +/** + * list_for_each_entry_safe - iterate over list of given type. Safe against removal of list entry + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_for_each_entry_safe(pos, n, head, member) \ + for (pos = list_first_entry(head, typeof(*pos), member), \ + n = list_next_entry(pos, member); \ + !list_entry_is_head(pos, head, member); \ + pos = n, n = list_next_entry(n, member)) + +#endif /* LIST_H */ From 5e3cf304a0bdc7a3d7ba4805bb2bb05c5e6916ff Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:19 +0900 Subject: [PATCH 34/67] kconfig: import more list macros and inline functions Import more macros and inline functions from include/linux/list.h and include/linux/types.h. Signed-off-by: Masahiro Yamada --- scripts/kconfig/list.h | 69 ++++++++++++++++++++++++++++++++++++ scripts/kconfig/list_types.h | 8 +++++ 2 files changed, 77 insertions(+) diff --git a/scripts/kconfig/list.h b/scripts/kconfig/list.h index 2bce2b8f21d1..882859ddf9f4 100644 --- a/scripts/kconfig/list.h +++ b/scripts/kconfig/list.h @@ -70,6 +70,19 @@ static inline void __list_add(struct list_head *new, prev->next = new; } +/** + * list_add - add a new entry + * @new: new entry to be added + * @head: list head to add it after + * + * Insert a new entry after the specified head. + * This is good for implementing stacks. + */ +static inline void list_add(struct list_head *new, struct list_head *head) +{ + __list_add(new, head, head->next); +} + /** * list_add_tail - add a new entry * @new: new entry to be added @@ -114,6 +127,16 @@ static inline void list_del(struct list_head *entry) entry->prev = LIST_POISON2; } +/** + * list_is_head - tests whether @list is the list @head + * @list: the entry to test + * @head: the head of the list + */ +static inline int list_is_head(const struct list_head *list, const struct list_head *head) +{ + return list == head; +} + /** * list_empty - tests whether a list is empty * @head: the list to test. @@ -184,4 +207,50 @@ static inline int list_empty(const struct list_head *head) !list_entry_is_head(pos, head, member); \ pos = n, n = list_next_entry(n, member)) +/* + * Double linked lists with a single pointer list head. + * Mostly useful for hash tables where the two pointer list head is + * too wasteful. + * You lose the ability to access the tail in O(1). + */ + +#define HLIST_HEAD_INIT { .first = NULL } + +/** + * hlist_add_head - add a new entry at the beginning of the hlist + * @n: new entry to be added + * @h: hlist head to add it after + * + * Insert a new entry after the specified head. + * This is good for implementing stacks. + */ +static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) +{ + struct hlist_node *first = h->first; + + n->next = first; + if (first) + first->pprev = &n->next; + h->first = n; + n->pprev = &h->first; +} + +#define hlist_entry(ptr, type, member) container_of(ptr, type, member) + +#define hlist_entry_safe(ptr, type, member) \ + ({ typeof(ptr) ____ptr = (ptr); \ + ____ptr ? hlist_entry(____ptr, type, member) : NULL; \ + }) + +/** + * hlist_for_each_entry - iterate over list of given type + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry(pos, head, member) \ + for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\ + pos; \ + pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) + #endif /* LIST_H */ diff --git a/scripts/kconfig/list_types.h b/scripts/kconfig/list_types.h index 32899f424983..d935b7c5aa81 100644 --- a/scripts/kconfig/list_types.h +++ b/scripts/kconfig/list_types.h @@ -6,4 +6,12 @@ struct list_head { struct list_head *next, *prev; }; +struct hlist_head { + struct hlist_node *first; +}; + +struct hlist_node { + struct hlist_node *next, **pprev; +}; + #endif /* LIST_TYPES_H */ From 0a3128e75108cc23401aa5059b851ed047bfff0e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:20 +0900 Subject: [PATCH 35/67] kconfig: add macros useful for hashtable This is similar to include/linux/hashtable.h, but the implementation has been simplified. Signed-off-by: Masahiro Yamada --- scripts/kconfig/hashtable.h | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 scripts/kconfig/hashtable.h diff --git a/scripts/kconfig/hashtable.h b/scripts/kconfig/hashtable.h new file mode 100644 index 000000000000..a0a2c8f5f639 --- /dev/null +++ b/scripts/kconfig/hashtable.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef HASHTABLE_H +#define HASHTABLE_H + +#include "array_size.h" +#include "list.h" + +#define HASH_SIZE(name) (ARRAY_SIZE(name)) + +#define HASHTABLE_DECLARE(name, size) struct hlist_head name[size] + +#define HASHTABLE_DEFINE(name, size) \ + HASHTABLE_DECLARE(name, size) = \ + { [0 ... ((size) - 1)] = HLIST_HEAD_INIT } + +#define hash_head(table, key) (&(table)[(key) % HASH_SIZE(table)]) + +/** + * hash_add - add an object to a hashtable + * @table: hashtable to add to + * @node: the &struct hlist_node of the object to be added + * @key: the key of the object to be added + */ +#define hash_add(table, node, key) \ + hlist_add_head(node, hash_head(table, key)) + +/** + * hash_for_each - iterate over a hashtable + * @table: hashtable to iterate + * @obj: the type * to use as a loop cursor for each entry + * @member: the name of the hlist_node within the struct + */ +#define hash_for_each(table, obj, member) \ + for (int _bkt = 0; _bkt < HASH_SIZE(table); _bkt++) \ + hlist_for_each_entry(obj, &table[_bkt], member) + +/** + * hash_for_each_possible - iterate over all possible objects hashing to the + * same bucket + * @table: hashtable to iterate + * @obj: the type * to use as a loop cursor for each entry + * @member: the name of the hlist_node within the struct + * @key: the key of the objects to iterate over + */ +#define hash_for_each_possible(table, obj, member, key) \ + hlist_for_each_entry(obj, hash_head(table, key), member) + +#endif /* HASHTABLE_H */ From a6dac4002b88f0ad242ac20d9de86d11321ecf84 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:21 +0900 Subject: [PATCH 36/67] kconfig: move ARRAY_SIZE to a header To use ARRAY_SIZE from other files, move it to its own header, just like include/linux/array_size.h. Signed-off-by: Masahiro Yamada --- scripts/kconfig/array_size.h | 11 +++++++++++ scripts/kconfig/preprocess.c | 3 +-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 scripts/kconfig/array_size.h diff --git a/scripts/kconfig/array_size.h b/scripts/kconfig/array_size.h new file mode 100644 index 000000000000..26ba78d867d1 --- /dev/null +++ b/scripts/kconfig/array_size.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef ARRAY_SIZE_H +#define ARRAY_SIZE_H + +/** + * ARRAY_SIZE - get the number of elements in array @arr + * @arr: array to be sized + */ +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +#endif /* ARRAY_SIZE_H */ diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index 69b806a6d8b7..f0a4a218c4a5 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -9,13 +9,12 @@ #include #include +#include "array_size.h" #include "internal.h" #include "list.h" #include "lkc.h" #include "preprocess.h" -#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) - static char *expand_string_with_args(const char *in, int argc, char *argv[]); static char *expand_string(const char *in); From 7c4aa901bd9d7e95be95a5c888d026b3214bae05 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:22 +0900 Subject: [PATCH 37/67] kconfig: move strhash() to util.c as a global function Remove the 'static' qualifier from strhash() so that it can be accessed from other files. Move it to util.c, which is a more appropriate location. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lkc.h | 1 + scripts/kconfig/symbol.c | 9 --------- scripts/kconfig/util.c | 10 ++++++++++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 71afcbd56273..e69d7c59d930 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -52,6 +52,7 @@ static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out) } /* util.c */ +unsigned int strhash(const char *s); const char *file_lookup(const char *name); void *xmalloc(size_t size); void *xcalloc(size_t nmemb, size_t size); diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index dae630a74e50..3dbe3a19622b 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -803,15 +803,6 @@ bool sym_is_changeable(struct symbol *sym) return sym->visible > sym->rev_dep.tri; } -static unsigned strhash(const char *s) -{ - /* fnv32 hash */ - unsigned hash = 2166136261U; - for (; *s; s++) - hash = (hash ^ *s) * 0x01000193; - return hash; -} - struct symbol *sym_lookup(const char *name, int flags) { struct symbol *symbol; diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 610d64c01479..d6172f2f64c9 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -9,6 +9,16 @@ #include #include "lkc.h" +unsigned int strhash(const char *s) +{ + /* fnv32 hash */ + unsigned int hash = 2166136261U; + + for (; *s; s++) + hash = (hash ^ *s) * 0x01000193; + return hash; +} + struct file { struct file *next; char name[]; From 980c9e198f1c5563380bed2a2672e592edf9efaa Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:23 +0900 Subject: [PATCH 38/67] kconfig: convert linked list of files to hash table Currently, a linked list is used to keep track of all the Kconfig files that have ever been parsed. Every time the "source" statement is encountered, the linked list is traversed to check if the file has been opened before. This prevents the same file from being recorded in include/config/auto.conf.cmd again. Given 1500+ Kconfig files parsed, a hashtable is now a more optimal data structure. By the way, you may wonder why we check this in the first place. It matters only when the same file is included multiple times. In old days, such a use case was forbidden, but commit f094f8a1b273 ("kconfig: allow multiple inclusion of the same file") provided a bit more flexibility. Of course, it is almost hypothetical... Signed-off-by: Masahiro Yamada --- scripts/kconfig/util.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index d6172f2f64c9..439c131b424e 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -7,6 +7,8 @@ #include #include #include + +#include "hashtable.h" #include "lkc.h" unsigned int strhash(const char *s) @@ -19,32 +21,32 @@ unsigned int strhash(const char *s) return hash; } +/* hash table of all parsed Kconfig files */ +static HASHTABLE_DEFINE(file_hashtable, 1U << 11); + struct file { - struct file *next; + struct hlist_node node; char name[]; }; -static struct file *file_list; - /* file already present in list? If not add it */ const char *file_lookup(const char *name) { struct file *file; size_t len; + int hash = strhash(name); - for (file = file_list; file; file = file->next) { - if (!strcmp(name, file->name)) { + hash_for_each_possible(file_hashtable, file, node, hash) + if (!strcmp(name, file->name)) return file->name; - } - } len = strlen(name); file = xmalloc(sizeof(*file) + len + 1); memset(file, 0, sizeof(*file)); memcpy(file->name, name, len); file->name[len] = '\0'; - file->next = file_list; - file_list = file; + + hash_add(file_hashtable, &file->node, hash); str_printf(&autoconf_cmd, "\t%s \\\n", name); From 7d5f52a4334c5227408b14c2e76d8840aa26f132 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 3 Feb 2024 00:58:25 +0900 Subject: [PATCH 39/67] kconfig: do not imply the type of choice value Do not feed back the choice type to choice values. Each choice value should explicitly specify 'bool' or 'tristate', as all the Kconfig files already do. If the type were missing, "config symbol defined without type" would be shown. Signed-off-by: Masahiro Yamada --- scripts/kconfig/menu.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 696803d944e0..44465945d6b1 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -305,12 +305,6 @@ void menu_finalize(struct menu *parent) } } } - /* set the type of the remaining choice values */ - for (menu = parent->list; menu; menu = menu->next) { - current_entry = menu; - if (menu->sym && menu->sym->type == S_UNKNOWN) - menu_set_type(sym->type); - } /* * Use the choice itself as the parent dependency of From cc25cfc563adc48c84f1eec6432b369bcab73ca6 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 11 Feb 2024 21:41:04 +0900 Subject: [PATCH 40/67] kconfig: print recursive dependency errors in the parsed order for_all_symbols() iterates in the symbol hash table. The order of iteration depends on the hash table implementation. If you use it for printing errors, they are shown in random order. For example, the order of following test input and the corresponding error do not match: - scripts/kconfig/tests/err_recursive_dep/Kconfig - scripts/kconfig/tests/err_recursive_dep/expected_stderr Signed-off-by: Masahiro Yamada --- scripts/kconfig/parser.y | 20 ++++++++++++---- .../tests/err_recursive_dep/expected_stderr | 24 +++++++++---------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index e58c24d2e5ab..efd0e234e0d2 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -473,8 +473,7 @@ assign_val: void conf_parse(const char *name) { - struct symbol *sym; - int i; + struct menu *menu; autoconf_cmd = str_new(); @@ -517,10 +516,23 @@ void conf_parse(const char *name) } menu_finalize(&rootmenu); - for_all_symbols(i, sym) { - if (sym_check_deps(sym)) + + menu = &rootmenu; + while (menu) { + if (menu->sym && sym_check_deps(menu->sym)) yynerrs++; + + if (menu->list) { + menu = menu->list; + continue; + } + + while (!menu->next && menu->parent) + menu = menu->parent; + + menu = menu->next; } + if (yynerrs) exit(1); conf_set_changed(true); diff --git a/scripts/kconfig/tests/err_recursive_dep/expected_stderr b/scripts/kconfig/tests/err_recursive_dep/expected_stderr index c9f4abf9a791..05d4ced70320 100644 --- a/scripts/kconfig/tests/err_recursive_dep/expected_stderr +++ b/scripts/kconfig/tests/err_recursive_dep/expected_stderr @@ -1,10 +1,10 @@ -Kconfig:11:error: recursive dependency detected! -Kconfig:11: symbol B is selected by B +Kconfig:5:error: recursive dependency detected! +Kconfig:5: symbol A depends on A For a resolution refer to Documentation/kbuild/kconfig-language.rst subsection "Kconfig recursive dependency limitations" -Kconfig:5:error: recursive dependency detected! -Kconfig:5: symbol A depends on A +Kconfig:11:error: recursive dependency detected! +Kconfig:11: symbol B is selected by B For a resolution refer to Documentation/kbuild/kconfig-language.rst subsection "Kconfig recursive dependency limitations" @@ -14,9 +14,9 @@ Kconfig:21: symbol C2 depends on C1 For a resolution refer to Documentation/kbuild/kconfig-language.rst subsection "Kconfig recursive dependency limitations" -Kconfig:32:error: recursive dependency detected! -Kconfig:32: symbol D2 is selected by D1 +Kconfig:27:error: recursive dependency detected! Kconfig:27: symbol D1 depends on D2 +Kconfig:32: symbol D2 is selected by D1 For a resolution refer to Documentation/kbuild/kconfig-language.rst subsection "Kconfig recursive dependency limitations" @@ -26,13 +26,13 @@ Kconfig:42: symbol E2 is implied by E1 For a resolution refer to Documentation/kbuild/kconfig-language.rst subsection "Kconfig recursive dependency limitations" +Kconfig:49:error: recursive dependency detected! +Kconfig:49: symbol F1 default value contains F2 +Kconfig:51: symbol F2 depends on F1 +For a resolution refer to Documentation/kbuild/kconfig-language.rst +subsection "Kconfig recursive dependency limitations" + Kconfig:60:error: recursive dependency detected! Kconfig:60: symbol G depends on G For a resolution refer to Documentation/kbuild/kconfig-language.rst subsection "Kconfig recursive dependency limitations" - -Kconfig:51:error: recursive dependency detected! -Kconfig:51: symbol F2 depends on F1 -Kconfig:49: symbol F1 default value contains F2 -For a resolution refer to Documentation/kbuild/kconfig-language.rst -subsection "Kconfig recursive dependency limitations" From 91b69454f93d1c905f3a56bb39856db9a220c791 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 11 Feb 2024 21:41:05 +0900 Subject: [PATCH 41/67] kconfig: use generic macros to implement symbol hashtable Use helper macros in hashtable.h for generic hashtable implementation. We can git rid of the hash head index of for_all_symbols(). Signed-off-by: Masahiro Yamada --- scripts/kconfig/conf.c | 12 ++++++------ scripts/kconfig/confdata.c | 25 ++++++++++++------------- scripts/kconfig/expr.h | 9 ++++----- scripts/kconfig/internal.h | 9 +++++++++ scripts/kconfig/lkc_proto.h | 2 -- scripts/kconfig/parser.y | 2 -- scripts/kconfig/symbol.c | 22 +++++++++++----------- 7 files changed, 42 insertions(+), 39 deletions(-) diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 662a5e7c37c2..b5730061872b 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -14,6 +14,7 @@ #include #include +#include "internal.h" #include "lkc.h" static void conf(struct menu *menu); @@ -171,7 +172,7 @@ enum conf_def_mode { static bool conf_set_all_new_symbols(enum conf_def_mode mode) { struct symbol *sym, *csym; - int i, cnt; + int cnt; /* * can't go as the default in switch-case below, otherwise gcc whines * about -Wmaybe-uninitialized @@ -226,7 +227,7 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode) } } - for_all_symbols(i, sym) { + for_all_symbols(sym) { if (sym_has_value(sym) || sym->flags & SYMBOL_VALID) continue; switch (sym_get_type(sym)) { @@ -278,14 +279,14 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode) * and the rest to no. */ if (mode != def_random) { - for_all_symbols(i, csym) { + for_all_symbols(csym) { if ((sym_is_choice(csym) && !sym_has_value(csym)) || sym_is_choice_value(csym)) csym->flags |= SYMBOL_NEED_SET_CHOICE_VALUES; } } - for_all_symbols(i, csym) { + for_all_symbols(csym) { if (sym_has_value(csym) || !sym_is_choice(csym)) continue; @@ -304,9 +305,8 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode) static void conf_rewrite_tristates(tristate old_val, tristate new_val) { struct symbol *sym; - int i; - for_all_symbols(i, sym) { + for_all_symbols(sym) { if (sym_get_type(sym) == S_TRISTATE && sym->def[S_DEF_USER].tri == old_val) sym->def[S_DEF_USER].tri = new_val; diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index dafc572e7b7e..c5b6487d68ac 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -18,6 +18,7 @@ #include #include +#include "internal.h" #include "lkc.h" struct gstr autoconf_cmd; @@ -322,7 +323,7 @@ int conf_read_simple(const char *name, int def) size_t line_asize = 0; char *p, *val; struct symbol *sym; - int i, def_flags; + int def_flags; const char *warn_unknown, *sym_name; warn_unknown = getenv("KCONFIG_WARN_UNKNOWN_SYMBOLS"); @@ -380,7 +381,7 @@ load: conf_warnings = 0; def_flags = SYMBOL_DEF << def; - for_all_symbols(i, sym) { + for_all_symbols(sym) { sym->flags |= SYMBOL_CHANGED; sym->flags &= ~(def_flags|SYMBOL_VALID); if (sym_is_choice(sym)) @@ -489,7 +490,6 @@ int conf_read(const char *name) { struct symbol *sym; int conf_unsaved = 0; - int i; conf_set_changed(false); @@ -500,7 +500,7 @@ int conf_read(const char *name) sym_calc_value(modules_sym); - for_all_symbols(i, sym) { + for_all_symbols(sym) { sym_calc_value(sym); if (sym_is_choice(sym) || (sym->flags & SYMBOL_NO_WRITE)) continue; @@ -524,7 +524,7 @@ int conf_read(const char *name) /* maybe print value in verbose mode... */ } - for_all_symbols(i, sym) { + for_all_symbols(sym) { if (sym_has_value(sym) && !sym_is_choice_value(sym)) { /* Reset values of generates values, so they'll appear * as new, if they should become visible, but that @@ -862,7 +862,6 @@ int conf_write(const char *name) const char *str; char tmpname[PATH_MAX + 1], oldname[PATH_MAX + 1]; char *env; - int i; bool need_newline = false; if (!name) @@ -946,7 +945,7 @@ end_check: } fclose(out); - for_all_symbols(i, sym) + for_all_symbols(sym) sym->flags &= ~SYMBOL_WRITTEN; if (*tmpname) { @@ -1016,7 +1015,7 @@ static int conf_touch_deps(void) { const char *name, *tmp; struct symbol *sym; - int res, i; + int res; name = conf_get_autoconfig_name(); tmp = strrchr(name, '/'); @@ -1030,7 +1029,7 @@ static int conf_touch_deps(void) conf_read_simple(name, S_DEF_AUTO); sym_calc_value(modules_sym); - for_all_symbols(i, sym) { + for_all_symbols(sym) { sym_calc_value(sym); if ((sym->flags & SYMBOL_NO_WRITE) || !sym->name) continue; @@ -1096,7 +1095,7 @@ static int __conf_write_autoconf(const char *filename, char tmp[PATH_MAX]; FILE *file; struct symbol *sym; - int ret, i; + int ret; if (make_parent_dir(filename)) return -1; @@ -1113,7 +1112,7 @@ static int __conf_write_autoconf(const char *filename, conf_write_heading(file, comment_style); - for_all_symbols(i, sym) + for_all_symbols(sym) if ((sym->flags & SYMBOL_WRITE) && sym->name) print_symbol(file, sym); @@ -1136,7 +1135,7 @@ int conf_write_autoconf(int overwrite) { struct symbol *sym; const char *autoconf_name = conf_get_autoconfig_name(); - int ret, i; + int ret; if (!overwrite && is_present(autoconf_name)) return 0; @@ -1148,7 +1147,7 @@ int conf_write_autoconf(int overwrite) if (conf_touch_deps()) return 1; - for_all_symbols(i, sym) + for_all_symbols(sym) sym_calc_value(sym); ret = __conf_write_autoconf(conf_get_autoheader_name(), diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index dd3350aed302..3bc375f1a1cd 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -17,6 +17,8 @@ extern "C" { #include #endif +#include "list_types.h" + typedef enum tristate { no, mod, yes } tristate; @@ -74,8 +76,8 @@ enum { * SYMBOL_CHOICE bit set in 'flags'. */ struct symbol { - /* The next symbol in the same bucket in the symbol hash table */ - struct symbol *next; + /* link node for the hash table */ + struct hlist_node node; /* The name of the symbol, e.g. "FOO" for 'config FOO' */ char *name; @@ -124,8 +126,6 @@ struct symbol { struct expr_value implied; }; -#define for_all_symbols(i, sym) for (i = 0; i < SYMBOL_HASHSIZE; i++) for (sym = symbol_hash[i]; sym; sym = sym->next) - #define SYMBOL_CONST 0x0001 /* symbol is const */ #define SYMBOL_CHECK 0x0008 /* used during dependency checking */ #define SYMBOL_CHOICE 0x0010 /* start of a choice block (null name) */ @@ -150,7 +150,6 @@ struct symbol { #define SYMBOL_NEED_SET_CHOICE_VALUES 0x100000 #define SYMBOL_MAXLENGTH 256 -#define SYMBOL_HASHSIZE 9973 /* A property represent the config options that can be associated * with a config "symbol". diff --git a/scripts/kconfig/internal.h b/scripts/kconfig/internal.h index 788401cd5d6f..6c721c4cfd72 100644 --- a/scripts/kconfig/internal.h +++ b/scripts/kconfig/internal.h @@ -2,6 +2,15 @@ #ifndef INTERNAL_H #define INTERNAL_H +#include "hashtable.h" + +#define SYMBOL_HASHSIZE (1U << 14) + +extern HASHTABLE_DECLARE(sym_hashtable, SYMBOL_HASHSIZE); + +#define for_all_symbols(sym) \ + hash_for_each(sym_hashtable, sym, node) + struct menu; extern struct menu *current_menu, *current_entry; diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 94299e42402f..2807fa584c2b 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -18,8 +18,6 @@ void conf_set_message_callback(void (*fn)(const char *s)); bool conf_errors(void); /* symbol.c */ -extern struct symbol * symbol_hash[SYMBOL_HASHSIZE]; - struct symbol * sym_lookup(const char *name, int flags); struct symbol * sym_find(const char *name); void print_symbol_for_listconfig(struct symbol *sym); diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index efd0e234e0d2..b505e43e0d02 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -28,8 +28,6 @@ static void zconf_error(const char *err, ...); static bool zconf_endtoken(const char *tokenname, const char *expected_tokenname); -struct symbol *symbol_hash[SYMBOL_HASHSIZE]; - struct menu *current_menu, *current_entry; %} diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 3dbe3a19622b..dd5cf9727a9a 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -9,6 +9,7 @@ #include #include +#include "internal.h" #include "lkc.h" struct symbol symbol_yes = { @@ -160,9 +161,8 @@ static void sym_set_changed(struct symbol *sym) static void sym_set_all_changed(void) { struct symbol *sym; - int i; - for_all_symbols(i, sym) + for_all_symbols(sym) sym_set_changed(sym); } @@ -475,9 +475,8 @@ void sym_calc_value(struct symbol *sym) void sym_clear_all_valid(void) { struct symbol *sym; - int i; - for_all_symbols(i, sym) + for_all_symbols(sym) sym->flags &= ~SYMBOL_VALID; conf_set_changed(true); sym_calc_value(modules_sym); @@ -803,6 +802,8 @@ bool sym_is_changeable(struct symbol *sym) return sym->visible > sym->rev_dep.tri; } +HASHTABLE_DEFINE(sym_hashtable, SYMBOL_HASHSIZE); + struct symbol *sym_lookup(const char *name, int flags) { struct symbol *symbol; @@ -817,9 +818,9 @@ struct symbol *sym_lookup(const char *name, int flags) case 'n': return &symbol_no; } } - hash = strhash(name) % SYMBOL_HASHSIZE; + hash = strhash(name); - for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) { + hash_for_each_possible(sym_hashtable, symbol, node, hash) { if (symbol->name && !strcmp(symbol->name, name) && (flags ? symbol->flags & flags @@ -838,8 +839,7 @@ struct symbol *sym_lookup(const char *name, int flags) symbol->type = S_UNKNOWN; symbol->flags = flags; - symbol->next = symbol_hash[hash]; - symbol_hash[hash] = symbol; + hash_add(sym_hashtable, &symbol->node, hash); return symbol; } @@ -859,9 +859,9 @@ struct symbol *sym_find(const char *name) case 'n': return &symbol_no; } } - hash = strhash(name) % SYMBOL_HASHSIZE; + hash = strhash(name); - for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) { + hash_for_each_possible(sym_hashtable, symbol, node, hash) { if (symbol->name && !strcmp(symbol->name, name) && !(symbol->flags & SYMBOL_CONST)) @@ -921,7 +921,7 @@ struct symbol **sym_re_search(const char *pattern) if (regcomp(&re, pattern, REG_EXTENDED|REG_ICASE)) return NULL; - for_all_symbols(i, sym) { + for_all_symbols(sym) { if (sym->flags & SYMBOL_CONST || !sym->name) continue; if (regexec(&re, sym->name, 1, match, 0)) From cd14b01846612f3f3277e97bfbecba4c8cee5ce9 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 11 Feb 2024 21:48:08 +0900 Subject: [PATCH 42/67] treewide: replace or remove redundant def_bool in Kconfig files 'def_bool X' is a shorthand for 'bool' plus 'default X'. 'def_bool' is redundant where 'bool' is already present, so 'def_bool X' can be replaced with 'default X', or removed if X is 'n'. Signed-off-by: Masahiro Yamada --- arch/parisc/Kconfig | 4 ++-- arch/riscv/kernel/tests/Kconfig.debug | 2 +- arch/x86/kvm/Kconfig | 2 +- arch/x86/xen/Kconfig | 1 - drivers/acpi/Kconfig | 1 - drivers/iommu/intel/Kconfig | 2 +- drivers/md/Kconfig | 1 - init/Kconfig | 2 +- lib/Kconfig.debug | 2 +- mm/Kconfig | 7 +++---- net/dccp/ccids/Kconfig | 2 +- 11 files changed, 11 insertions(+), 15 deletions(-) diff --git a/arch/parisc/Kconfig b/arch/parisc/Kconfig index 5c845e8d59d9..03ce7e185935 100644 --- a/arch/parisc/Kconfig +++ b/arch/parisc/Kconfig @@ -237,9 +237,9 @@ config PARISC_HUGE_KERNEL def_bool y if !MODULES || UBSAN || FTRACE || COMPILE_TEST config MLONGCALLS - def_bool y if PARISC_HUGE_KERNEL bool "Enable the -mlong-calls compiler option for big kernels" if !PARISC_HUGE_KERNEL depends on PA8X00 + default PARISC_HUGE_KERNEL help If you configure the kernel to include many drivers built-in instead as modules, the kernel executable may become too big, so that the @@ -254,9 +254,9 @@ config MLONGCALLS Enabling this option will probably slow down your kernel. config 64BIT - def_bool y if "$(ARCH)" = "parisc64" bool "64-bit kernel" if "$(ARCH)" = "parisc" depends on PA8X00 + default "$(ARCH)" = "parisc64" help Enable this if you want to support 64bit kernel on PA-RISC platform. diff --git a/arch/riscv/kernel/tests/Kconfig.debug b/arch/riscv/kernel/tests/Kconfig.debug index 5dba64e8e977..78cea5d2c270 100644 --- a/arch/riscv/kernel/tests/Kconfig.debug +++ b/arch/riscv/kernel/tests/Kconfig.debug @@ -6,7 +6,7 @@ config AS_HAS_ULEB128 menuconfig RUNTIME_KERNEL_TESTING_MENU bool "arch/riscv/kernel runtime Testing" - def_bool y + default y help Enable riscv kernel runtime testing. diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig index 87e3da7b0439..d72be552c86d 100644 --- a/arch/x86/kvm/Kconfig +++ b/arch/x86/kvm/Kconfig @@ -119,8 +119,8 @@ config KVM_AMD will be called kvm-amd. config KVM_AMD_SEV - def_bool y bool "AMD Secure Encrypted Virtualization (SEV) support" + default y depends on KVM_AMD && X86_64 depends on CRYPTO_DEV_SP_PSP && !(KVM_AMD=y && CRYPTO_DEV_CCP_DD=m) help diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig index a65fc2ae15b4..77e788e928cd 100644 --- a/arch/x86/xen/Kconfig +++ b/arch/x86/xen/Kconfig @@ -81,7 +81,6 @@ config XEN_PVH bool "Xen PVH guest support" depends on XEN && XEN_PVHVM && ACPI select PVH - def_bool n help Support for running as a Xen PVH guest. diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 3c3f8037ebed..8ce591679d50 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -474,7 +474,6 @@ config ACPI_BGRT config ACPI_REDUCED_HARDWARE_ONLY bool "Hardware-reduced ACPI support only" if EXPERT - def_bool n help This config item changes the way the ACPI code is built. When this option is selected, the kernel will use a specialized version of diff --git a/drivers/iommu/intel/Kconfig b/drivers/iommu/intel/Kconfig index 012cd2541a68..95d9f4e1a176 100644 --- a/drivers/iommu/intel/Kconfig +++ b/drivers/iommu/intel/Kconfig @@ -97,8 +97,8 @@ config INTEL_IOMMU_SCALABLE_MODE_DEFAULT_ON the default value. config INTEL_IOMMU_PERF_EVENTS - def_bool y bool "Intel IOMMU performance events" + default y depends on INTEL_IOMMU && PERF_EVENTS help Selecting this option will enable the performance monitoring diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig index a743e2c572fc..0392154bbcab 100644 --- a/drivers/md/Kconfig +++ b/drivers/md/Kconfig @@ -519,7 +519,6 @@ config DM_VERITY If unsure, say N. config DM_VERITY_VERIFY_ROOTHASH_SIG - def_bool n bool "Verity data device root hash signature verification support" depends on DM_VERITY select SYSTEM_DATA_VERIFICATION diff --git a/init/Kconfig b/init/Kconfig index 8426d59cc634..a4b80754e580 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1504,7 +1504,7 @@ config MULTIUSER config SGETMASK_SYSCALL bool "sgetmask/ssetmask syscalls support" if EXPERT - def_bool PARISC || M68K || PPC || MIPS || X86 || SPARC || MICROBLAZE || SUPERH + default PARISC || M68K || PPC || MIPS || X86 || SPARC || MICROBLAZE || SUPERH help sys_sgetmask and sys_ssetmask are obsolete system calls no longer supported in libc but still enabled by default in some diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 975a07f9f1cc..e9b3b9543661 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2127,7 +2127,7 @@ config KCOV_IRQ_AREA_SIZE menuconfig RUNTIME_TESTING_MENU bool "Runtime Testing" - def_bool y + default y if RUNTIME_TESTING_MENU diff --git a/mm/Kconfig b/mm/Kconfig index ffc3a2ba3a8c..4914eb3216fc 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -599,7 +599,7 @@ config MEMORY_BALLOON # support for memory balloon compaction config BALLOON_COMPACTION bool "Allow for balloon memory compaction/migration" - def_bool y + default y depends on COMPACTION && MEMORY_BALLOON help Memory fragmentation introduced by ballooning might reduce @@ -614,7 +614,7 @@ config BALLOON_COMPACTION # support for memory compaction config COMPACTION bool "Allow for memory compaction" - def_bool y + default y select MIGRATION depends on MMU help @@ -637,7 +637,6 @@ config COMPACT_UNEVICTABLE_DEFAULT # support for free page reporting config PAGE_REPORTING bool "Free page reporting" - def_bool n help Free page reporting allows for the incremental acquisition of free pages from the buddy allocator for the purpose of reporting @@ -649,7 +648,7 @@ config PAGE_REPORTING # config MIGRATION bool "Page migration" - def_bool y + default y depends on (NUMA || ARCH_ENABLE_MEMORY_HOTREMOVE || COMPACTION || CMA) && MMU help Allows the migration of the physical location of pages of processes diff --git a/net/dccp/ccids/Kconfig b/net/dccp/ccids/Kconfig index a3eeb84d16f9..e3d388c33d25 100644 --- a/net/dccp/ccids/Kconfig +++ b/net/dccp/ccids/Kconfig @@ -13,7 +13,7 @@ config IP_DCCP_CCID2_DEBUG config IP_DCCP_CCID3 bool "CCID-3 (TCP-Friendly)" - def_bool y if (IP_DCCP = y || IP_DCCP = m) + default IP_DCCP = y || IP_DCCP = m help CCID-3 denotes TCP-Friendly Rate Control (TFRC), an equation-based rate-controlled congestion control mechanism. TFRC is designed to From 6b1c2a19cb30563c11c6d2dd0b6fc7af6a8e4455 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 15 Feb 2024 23:07:02 +0900 Subject: [PATCH 43/67] hexagon: select FRAME_POINTER instead of redefining it Because FRAME_POINTER is defined in lib/Kconfig.debug, the arch Kconfig should select it. Add 'select FRAME_POINTER' to HEXAGON. ARCH_WANT_FRAME_POINTERS must also be selected to avoid the unmet dependency warning. Signed-off-by: Masahiro Yamada Reviewed-by: Randy Dunlap Acked-by: Brian Cain --- arch/hexagon/Kconfig | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig index a880ee067d2e..e922026fef09 100644 --- a/arch/hexagon/Kconfig +++ b/arch/hexagon/Kconfig @@ -7,7 +7,9 @@ config HEXAGON select ARCH_32BIT_OFF_T select ARCH_HAS_SYNC_DMA_FOR_DEVICE select ARCH_NO_PREEMPT + select ARCH_WANT_FRAME_POINTERS select DMA_GLOBAL_POOL + select FRAME_POINTER # Other pending projects/to-do items. # select HAVE_REGS_AND_STACK_ACCESS_API # select HAVE_HW_BREAKPOINT if PERF_EVENTS @@ -43,9 +45,6 @@ config HEXAGON_PHYS_OFFSET help Platforms that don't load the kernel at zero set this. -config FRAME_POINTER - def_bool y - config LOCKDEP_SUPPORT def_bool y From ec923eaa1d3ff7a544eeb0fa282daeaeaa911cbf Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 15 Feb 2024 23:08:19 +0900 Subject: [PATCH 44/67] hexagon: select GENERIC_IRQ_PROBE instead of redefining it Select GENERIC_IRQ_PROBE, as the other architectures do. Signed-off-by: Masahiro Yamada Reviewed-by: Randy Dunlap Acked-by: Brian Cain --- arch/hexagon/Kconfig | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig index e922026fef09..89672ef0666f 100644 --- a/arch/hexagon/Kconfig +++ b/arch/hexagon/Kconfig @@ -21,6 +21,7 @@ config HEXAGON select HAVE_PERF_EVENTS # GENERIC_ALLOCATOR is used by dma_alloc_coherent() select GENERIC_ALLOCATOR + select GENERIC_IRQ_PROBE select GENERIC_IRQ_SHOW select HAVE_ARCH_KGDB select HAVE_ARCH_TRACEHOOK @@ -57,12 +58,6 @@ config MMU config GENERIC_CSUM def_bool y -# -# Use the generic interrupt handling code in kernel/irq/: -# -config GENERIC_IRQ_PROBE - def_bool y - config GENERIC_HWEIGHT def_bool y From d2d5cba5d92c4ed23caa86228a1bc31b07e90fe9 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 15 Feb 2024 23:15:01 +0900 Subject: [PATCH 45/67] kbuild: remove EXPERT and !COMPILE_TEST guarding from TRIM_UNUSED_KSYMS This reverts the following two commits: - a555bdd0c58c ("Kbuild: enable TRIM_UNUSED_KSYMS again, with some guarding") - 5cf0fd591f2e ("Kbuild: disable TRIM_UNUSED_KSYMS option") Commit 5e9e95cc9148 ("kbuild: implement CONFIG_TRIM_UNUSED_KSYMS without recursion") solved the build time issue. Signed-off-by: Masahiro Yamada --- kernel/module/Kconfig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/module/Kconfig b/kernel/module/Kconfig index 0ea1b2970a23..c3ced519e14b 100644 --- a/kernel/module/Kconfig +++ b/kernel/module/Kconfig @@ -362,8 +362,7 @@ config MODPROBE_PATH userspace can still load modules explicitly). config TRIM_UNUSED_KSYMS - bool "Trim unused exported kernel symbols" if EXPERT - depends on !COMPILE_TEST + bool "Trim unused exported kernel symbols" help The kernel and some modules make many symbols available for other modules to use via EXPORT_SYMBOL() and variants. Depending From ba3b759fb688c09cd9b09852d2728b012cf040ba Mon Sep 17 00:00:00 2001 From: Matthew Bystrin Date: Fri, 16 Feb 2024 17:10:14 +0300 Subject: [PATCH 46/67] kconfig: lxdialog: fix cursor render in checklist When a checklist is opened, the cursor is rendered in a wrong position (after the last list element on the screen). You can observe it by opening any checklist in menuconfig. Added wmove() to set the cursor in the proper position, just like in menubox.c. Removed wnoutrefresh(dialog) because dialog window has already been updated in print_buttons(). Replaced wnoutrefresh(list) and doupdate() calls with one wrefresh(list) call. Signed-off-by: Matthew Bystrin Signed-off-by: Masahiro Yamada --- scripts/kconfig/lxdialog/checklist.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c index fd161cfff121..31d0a89fbeb7 100644 --- a/scripts/kconfig/lxdialog/checklist.c +++ b/scripts/kconfig/lxdialog/checklist.c @@ -188,9 +188,8 @@ do_resize: print_buttons(dialog, height, width, 0); - wnoutrefresh(dialog); - wnoutrefresh(list); - doupdate(); + wmove(list, choice, check_x + 1); + wrefresh(list); while (key != KEY_ESC) { key = wgetch(dialog); From bf48d9b756b91e3c656511fa8b63eaba1f50dbd0 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 17 Feb 2024 14:55:03 +0900 Subject: [PATCH 47/67] kbuild: change tool coverage variables to take the path relative to $(obj) Commit 54b8ae66ae1a ("kbuild: change *FLAGS_.o to take the path relative to $(obj)") changed the syntax of per-file compiler flags. The situation is the same for the following variables: OBJECT_FILES_NON_STANDARD_.o GCOV_PROFILE_.o KASAN_SANITIZE_.o KMSAN_SANITIZE_.o KMSAN_ENABLE_CHECKS_.o UBSAN_SANITIZE_.o KCOV_INSTRUMENT_.o KCSAN_SANITIZE_.o KCSAN_INSTRUMENT_BARRIERS_.o The is the filename of the target with its directory and suffix stripped. This syntax comes into a trouble when two files with the same basename appear in one Makefile, for example: obj-y += dir1/foo.o obj-y += dir2/foo.o OBJECT_FILES_NON_STANDARD_foo.o := y OBJECT_FILES_NON_STANDARD_foo.o is applied to both dir1/foo.o and dir2/foo.o. This syntax is not flexbile enough to handle cases where one of them is a standard object, but the other is not. It is more sensible to use the relative path to the Makefile, like this: obj-y += dir1/foo.o OBJECT_FILES_NON_STANDARD_dir1/foo.o := y obj-y += dir2/foo.o OBJECT_FILES_NON_STANDARD_dir2/foo.o := y To maintain the current behavior, I made adjustments to the following two Makefiles: - arch/x86/entry/vdso/Makefile, which compiles vclock_gettime.o, vgetcpu.o, and their vdso32 variants. - arch/x86/kvm/Makefile, which compiles vmx/vmenter.o and svm/vmenter.o Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier Acked-by: Sean Christopherson --- arch/x86/entry/vdso/Makefile | 2 ++ arch/x86/kvm/Makefile | 3 ++- scripts/Makefile.build | 2 +- scripts/Makefile.lib | 16 ++++++++-------- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile index b1b8dd1608f7..fa0a27503606 100644 --- a/arch/x86/entry/vdso/Makefile +++ b/arch/x86/entry/vdso/Makefile @@ -9,7 +9,9 @@ include $(srctree)/lib/vdso/Makefile # Sanitizer runtimes are unavailable and cannot be linked here. KASAN_SANITIZE := n KMSAN_SANITIZE_vclock_gettime.o := n +KMSAN_SANITIZE_vdso32/vclock_gettime.o := n KMSAN_SANITIZE_vgetcpu.o := n +KMSAN_SANITIZE_vdso32/vgetcpu.o := n UBSAN_SANITIZE := n KCSAN_SANITIZE := n diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile index 475b5fa917a6..a88bb14266b6 100644 --- a/arch/x86/kvm/Makefile +++ b/arch/x86/kvm/Makefile @@ -4,7 +4,8 @@ ccflags-y += -I $(srctree)/arch/x86/kvm ccflags-$(CONFIG_KVM_WERROR) += -Werror ifeq ($(CONFIG_FRAME_POINTER),y) -OBJECT_FILES_NON_STANDARD_vmenter.o := y +OBJECT_FILES_NON_STANDARD_vmx/vmenter.o := y +OBJECT_FILES_NON_STANDARD_svm/vmenter.o := y endif include $(srctree)/virt/kvm/Makefile.kvm diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 4971f54c855e..256db2a0e984 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -214,7 +214,7 @@ endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file -is-standard-object = $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y) +is-standard-object = $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(target-stem).o)$(OBJECT_FILES_NON_STANDARD)n),y) $(obj)/%.o: objtool-enabled = $(if $(is-standard-object),$(if $(delay-objtool),$(is-single-obj-m),y)) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index b35d39022a30..328c0d77ed48 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -154,7 +154,7 @@ _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds) # ifeq ($(CONFIG_GCOV_KERNEL),y) _c_flags += $(if $(patsubst n%,, \ - $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \ + $(GCOV_PROFILE_$(target-stem).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \ $(CFLAGS_GCOV)) endif @@ -165,29 +165,29 @@ endif ifeq ($(CONFIG_KASAN),y) ifneq ($(CONFIG_KASAN_HW_TAGS),y) _c_flags += $(if $(patsubst n%,, \ - $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \ + $(KASAN_SANITIZE_$(target-stem).o)$(KASAN_SANITIZE)y), \ $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE)) endif endif ifeq ($(CONFIG_KMSAN),y) _c_flags += $(if $(patsubst n%,, \ - $(KMSAN_SANITIZE_$(basetarget).o)$(KMSAN_SANITIZE)y), \ + $(KMSAN_SANITIZE_$(target-stem).o)$(KMSAN_SANITIZE)y), \ $(CFLAGS_KMSAN)) _c_flags += $(if $(patsubst n%,, \ - $(KMSAN_ENABLE_CHECKS_$(basetarget).o)$(KMSAN_ENABLE_CHECKS)y), \ + $(KMSAN_ENABLE_CHECKS_$(target-stem).o)$(KMSAN_ENABLE_CHECKS)y), \ , -mllvm -msan-disable-checks=1) endif ifeq ($(CONFIG_UBSAN),y) _c_flags += $(if $(patsubst n%,, \ - $(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \ + $(UBSAN_SANITIZE_$(target-stem).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \ $(CFLAGS_UBSAN)) endif ifeq ($(CONFIG_KCOV),y) _c_flags += $(if $(patsubst n%,, \ - $(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \ + $(KCOV_INSTRUMENT_$(target-stem).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \ $(CFLAGS_KCOV)) endif @@ -197,12 +197,12 @@ endif # ifeq ($(CONFIG_KCSAN),y) _c_flags += $(if $(patsubst n%,, \ - $(KCSAN_SANITIZE_$(basetarget).o)$(KCSAN_SANITIZE)y), \ + $(KCSAN_SANITIZE_$(target-stem).o)$(KCSAN_SANITIZE)y), \ $(CFLAGS_KCSAN)) # Some uninstrumented files provide implied barriers required to avoid false # positives: set KCSAN_INSTRUMENT_BARRIERS for barrier instrumentation only. _c_flags += $(if $(patsubst n%,, \ - $(KCSAN_INSTRUMENT_BARRIERS_$(basetarget).o)$(KCSAN_INSTRUMENT_BARRIERS)n), \ + $(KCSAN_INSTRUMENT_BARRIERS_$(target-stem).o)$(KCSAN_INSTRUMENT_BARRIERS)n), \ -D__KCSAN_INSTRUMENT_BARRIERS__) endif From 223390b1c4d266c3b684b99d0a1980c49ebccf0d Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 17 Feb 2024 14:55:04 +0900 Subject: [PATCH 48/67] kbuild: change DTC_FLAGS_.o to take the path relative to $(obj) For the same rationale as commit 54b8ae66ae1a ("kbuild: change *FLAGS_.o to take the path relative to $(obj)"). Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/Makefile.lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 328c0d77ed48..56f7fe2b476d 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -368,7 +368,7 @@ DTC_FLAGS += -Wnode_name_chars_strict \ -Wunique_unit_address endif -DTC_FLAGS += $(DTC_FLAGS_$(basetarget)) +DTC_FLAGS += $(DTC_FLAGS_$(target-stem)) # Set -@ if the target is a base DTB that overlay is applied onto DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@) From 403198019890f2fdf8ad1cd2acb25a490e94da6b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 21 Feb 2024 23:01:44 +0900 Subject: [PATCH 49/67] alpha: merge two entries for CONFIG_ALPHA_EV4 There are two entries for CONFIG_ALPHA_EV4, on line 337 and line 368. Merge them together. Signed-off-by: Masahiro Yamada --- arch/alpha/Kconfig | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig index d6968d090d49..70e8343d00ba 100644 --- a/arch/alpha/Kconfig +++ b/arch/alpha/Kconfig @@ -338,6 +338,7 @@ config ALPHA_EV4 bool depends on ALPHA_JENSEN || (ALPHA_SABLE && !ALPHA_GAMMA) || ALPHA_LYNX || ALPHA_NORITAKE && !ALPHA_PRIMO || ALPHA_MIKASA && !ALPHA_PRIMO || ALPHA_CABRIOLET || ALPHA_AVANTI_CH || ALPHA_EB64P_CH || ALPHA_XL || ALPHA_NONAME || ALPHA_EB66 || ALPHA_EB66P || ALPHA_P2K default y if !ALPHA_LYNX + default y if !ALPHA_EV5 config ALPHA_LCA bool @@ -365,10 +366,6 @@ config ALPHA_EV5 bool "EV5 CPU(s) (model 5/xxx)?" if ALPHA_LYNX default y if ALPHA_RX164 || ALPHA_RAWHIDE || ALPHA_MIATA || ALPHA_LX164 || ALPHA_SX164 || ALPHA_RUFFIAN || ALPHA_SABLE && ALPHA_GAMMA || ALPHA_NORITAKE && ALPHA_PRIMO || ALPHA_MIKASA && ALPHA_PRIMO || ALPHA_PC164 || ALPHA_TAKARA || ALPHA_EB164 || ALPHA_ALCOR -config ALPHA_EV4 - bool - default y if ALPHA_LYNX && !ALPHA_EV5 - config ALPHA_CIA bool depends on ALPHA_MIATA || ALPHA_LX164 || ALPHA_SX164 || ALPHA_RUFFIAN || ALPHA_NORITAKE && ALPHA_PRIMO || ALPHA_MIKASA && ALPHA_PRIMO || ALPHA_PC164 || ALPHA_TAKARA || ALPHA_EB164 || ALPHA_ALCOR From c31f96a00f652a96a1a097b0c6a333509560900f Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 21 Feb 2024 23:01:45 +0900 Subject: [PATCH 50/67] alpha: merge two entries for CONFIG_ALPHA_GAMMA There are two entries for CONFIG_ALPHA_GAMMA, with the second one 7 lines below. Merge them together. Signed-off-by: Masahiro Yamada --- arch/alpha/Kconfig | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig index 70e8343d00ba..fe5ae3aea999 100644 --- a/arch/alpha/Kconfig +++ b/arch/alpha/Kconfig @@ -390,16 +390,12 @@ config ALPHA_PRIMO Say Y if you have an AS 1000 5/xxx or an AS 1000A 5/xxx. config ALPHA_GAMMA - bool "EV5 CPU(s) (model 5/xxx)?" - depends on ALPHA_SABLE + bool "EV5 CPU(s) (model 5/xxx)?" if ALPHA_SABLE + depends on ALPHA_SABLE || ALPHA_LYNX + default ALPHA_LYNX help Say Y if you have an AS 2000 5/xxx or an AS 2100 5/xxx. -config ALPHA_GAMMA - bool - depends on ALPHA_LYNX - default y - config ALPHA_T2 bool depends on ALPHA_SABLE || ALPHA_LYNX From 5270316c9fec8cc99aa0e0a258509c5c7f789d12 Mon Sep 17 00:00:00 2001 From: Petr Pavlu Date: Thu, 22 Feb 2024 14:35:00 +0100 Subject: [PATCH 51/67] kbuild: Use -fmin-function-alignment when available GCC recently added option -fmin-function-alignment, which should appear in GCC 14. Unlike -falign-functions, this option causes all functions to be aligned at the specified value, including the cold ones. In particular, when an arm64 kernel is built with DYNAMIC_FTRACE_WITH_CALL_OPS=y, the 8-byte function alignment is required for correct functionality. This was done by -falign-functions=8 and having workarounds in the kernel to force the compiler to follow this alignment. The new -fmin-function-alignment option directly guarantees it. Detect availability of -fmin-function-alignment and use it instead of -falign-functions when present. Introduce CC_HAS_SANE_FUNCTION_ALIGNMENT and enable __cold to work as expected when it is set. Signed-off-by: Petr Pavlu Reviewed-by: Nathan Chancellor Acked-by: Mark Rutland Signed-off-by: Masahiro Yamada --- Makefile | 7 +++++++ arch/Kconfig | 12 ++++++++++++ include/linux/compiler_types.h | 10 +++++----- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index bc54a6cc8dc5..d84c0fb215fd 100644 --- a/Makefile +++ b/Makefile @@ -974,8 +974,15 @@ export CC_FLAGS_CFI endif ifneq ($(CONFIG_FUNCTION_ALIGNMENT),0) +# Set the minimal function alignment. Use the newer GCC option +# -fmin-function-alignment if it is available, or fall back to -falign-funtions. +# See also CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT. +ifdef CONFIG_CC_HAS_MIN_FUNCTION_ALIGNMENT +KBUILD_CFLAGS += -fmin-function-alignment=$(CONFIG_FUNCTION_ALIGNMENT) +else KBUILD_CFLAGS += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT) endif +endif # arch Makefile may override CC so keep this after arch Makefile is included NOSTDINC_FLAGS += -nostdinc diff --git a/arch/Kconfig b/arch/Kconfig index a5af0edd3eb8..bd6c6335efac 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1507,4 +1507,16 @@ config FUNCTION_ALIGNMENT default 4 if FUNCTION_ALIGNMENT_4B default 0 +config CC_HAS_MIN_FUNCTION_ALIGNMENT + # Detect availability of the GCC option -fmin-function-alignment which + # guarantees minimal alignment for all functions, unlike + # -falign-functions which the compiler ignores for cold functions. + def_bool $(cc-option, -fmin-function-alignment=8) + +config CC_HAS_SANE_FUNCTION_ALIGNMENT + # Set if the guaranteed alignment with -fmin-function-alignment is + # available or extra care is required in the kernel. Clang provides + # strict alignment always, even with -falign-functions. + def_bool CC_HAS_MIN_FUNCTION_ALIGNMENT || CC_IS_CLANG + endmenu diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index 0caf354cb94b..fb8888678687 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -99,17 +99,17 @@ static inline void __chk_io_ptr(const volatile void __iomem *ptr) { } * gcc: https://gcc.gnu.org/onlinedocs/gcc/Label-Attributes.html#index-cold-label-attribute * * When -falign-functions=N is in use, we must avoid the cold attribute as - * contemporary versions of GCC drop the alignment for cold functions. Worse, - * GCC can implicitly mark callees of cold functions as cold themselves, so - * it's not sufficient to add __function_aligned here as that will not ensure - * that callees are correctly aligned. + * GCC drops the alignment for cold functions. Worse, GCC can implicitly mark + * callees of cold functions as cold themselves, so it's not sufficient to add + * __function_aligned here as that will not ensure that callees are correctly + * aligned. * * See: * * https://lore.kernel.org/lkml/Y77%2FqVgvaJidFpYt@FVFF77S0Q05N * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88345#c9 */ -#if !defined(CONFIG_CC_IS_GCC) || (CONFIG_FUNCTION_ALIGNMENT == 0) +#if defined(CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT) || (CONFIG_FUNCTION_ALIGNMENT == 0) #define __cold __attribute__((__cold__)) #else #define __cold From 50a339981780e233a5be88b9116a6dfd0e00231a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 1 Mar 2024 20:21:07 +0900 Subject: [PATCH 52/67] kbuild: fix inconsistent indentation in top Makefile Commit 3b9ab248bc45 ("kbuild: use 4-space indentation when followed by conditionals") introduced inconsistent indentation because it deliberately touched only the conditional directives to minimize the change set. This commit reformats some blocks in the top Makefile so they are consistently indented with 4 spaces. Signed-off-by: Masahiro Yamada Reviewed-by: Nathan Chancellor --- Makefile | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index d84c0fb215fd..859b0f52949e 100644 --- a/Makefile +++ b/Makefile @@ -295,51 +295,51 @@ single-build := ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),) ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),) - need-config := + need-config := endif endif ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),) ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),) - may-sync-config := + may-sync-config := endif endif need-compiler := $(may-sync-config) ifneq ($(KBUILD_EXTMOD),) - may-sync-config := + may-sync-config := endif ifeq ($(KBUILD_EXTMOD),) - ifneq ($(filter %config,$(MAKECMDGOALS)),) - config-build := 1 - ifneq ($(words $(MAKECMDGOALS)),1) - mixed-build := 1 - endif + ifneq ($(filter %config,$(MAKECMDGOALS)),) + config-build := 1 + ifneq ($(words $(MAKECMDGOALS)),1) + mixed-build := 1 endif + endif endif # We cannot build single targets and the others at the same time ifneq ($(filter $(single-targets), $(MAKECMDGOALS)),) - single-build := 1 + single-build := 1 ifneq ($(filter-out $(single-targets), $(MAKECMDGOALS)),) - mixed-build := 1 + mixed-build := 1 endif endif # For "make -j clean all", "make -j mrproper defconfig all", etc. ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),) - ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),) - mixed-build := 1 - endif + ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),) + mixed-build := 1 + endif endif # install and modules_install need also be processed one by one ifneq ($(filter install,$(MAKECMDGOALS)),) - ifneq ($(filter modules_install,$(MAKECMDGOALS)),) - mixed-build := 1 - endif + ifneq ($(filter modules_install,$(MAKECMDGOALS)),) + mixed-build := 1 + endif endif ifdef mixed-build From e0492219a6d752942b054cbfbbcbc1e8ab294d26 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 3 Mar 2024 13:00:33 +0900 Subject: [PATCH 53/67] kconfig: link menus to a symbol Currently, there is no direct link from (struct symbol) to (struct menu). It is still possible to access associated menus through the P_SYMBOL property, because property::menu is the relevant menu entry, but it results in complex code, as seen in get_symbol_str(). Use a linked list for simpler traversal of relevant menus. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/kconfig/expr.h | 5 +++++ scripts/kconfig/menu.c | 4 +++- scripts/kconfig/symbol.c | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 3bc375f1a1cd..0158f5eac454 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -108,6 +108,9 @@ struct symbol { */ tristate visible; + /* config entries associated with this symbol */ + struct list_head menus; + /* SYMBOL_* flags */ int flags; @@ -222,6 +225,8 @@ struct menu { */ struct symbol *sym; + struct list_head link; /* link to symbol::menus */ + /* * The prompt associated with the node. This holds the prompt for a * symbol as well as the text for a menu or comment, along with the diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 44465945d6b1..571394ed71e0 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -57,8 +57,10 @@ void menu_add_entry(struct symbol *sym) *last_entry_ptr = menu; last_entry_ptr = &menu->next; current_entry = menu; - if (sym) + if (sym) { menu_add_symbol(P_SYMBOL, sym, NULL); + list_add_tail(&menu->link, &sym->menus); + } } struct menu *menu_add_menu(void) diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index dd5cf9727a9a..81fe1884ef8a 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -15,18 +15,21 @@ struct symbol symbol_yes = { .name = "y", .curr = { "y", yes }, + .menus = LIST_HEAD_INIT(symbol_yes.menus), .flags = SYMBOL_CONST|SYMBOL_VALID, }; struct symbol symbol_mod = { .name = "m", .curr = { "m", mod }, + .menus = LIST_HEAD_INIT(symbol_mod.menus), .flags = SYMBOL_CONST|SYMBOL_VALID, }; struct symbol symbol_no = { .name = "n", .curr = { "n", no }, + .menus = LIST_HEAD_INIT(symbol_no.menus), .flags = SYMBOL_CONST|SYMBOL_VALID, }; @@ -838,6 +841,7 @@ struct symbol *sym_lookup(const char *name, int flags) symbol->name = new_name; symbol->type = S_UNKNOWN; symbol->flags = flags; + INIT_LIST_HEAD(&symbol->menus); hash_add(sym_hashtable, &symbol->node, hash); From bedf92362317adff1da6ac787b09626d30e60b00 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 3 Mar 2024 13:00:34 +0900 Subject: [PATCH 54/67] kconfig: use linked list in get_symbol_str() to iterate over menus Currently, get_symbol_str() uses a tricky approach to traverse the associated menus. With relevant menus now linked to the symbol using a linked list, use list_for_each_entry() for iterating on the menus. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- scripts/kconfig/menu.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 571394ed71e0..840ce642ec43 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -771,6 +771,7 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym, struct list_head *head) { struct property *prop; + struct menu *menu; if (sym && sym->name) { str_printf(r, "Symbol: %s [=%s]\n", sym->name, @@ -787,17 +788,17 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym, } /* Print the definitions with prompts before the ones without */ - for_all_properties(sym, prop, P_SYMBOL) { - if (prop->menu->prompt) { - get_def_str(r, prop->menu); - get_prompt_str(r, prop->menu->prompt, head); + list_for_each_entry(menu, &sym->menus, link) { + if (menu->prompt) { + get_def_str(r, menu); + get_prompt_str(r, menu->prompt, head); } } - for_all_properties(sym, prop, P_SYMBOL) { - if (!prop->menu->prompt) { - get_def_str(r, prop->menu); - get_dep_str(r, prop->menu->dep, " Depends on: "); + list_for_each_entry(menu, &sym->menus, link) { + if (!menu->prompt) { + get_def_str(r, menu); + get_dep_str(r, menu->dep, " Depends on: "); } } From c83f020973bc72d9eec65474d8c47495191aef20 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 3 Mar 2024 13:00:35 +0900 Subject: [PATCH 55/67] kconfig: remove named choice support Commit 5a1aa8a1aff6 ("kconfig: add named choice group") did not provide enough explanation regarding its benefits. A use case was found in another project [1] sometime later, this feature has never been used in the kernel. [1]: https://lore.kernel.org/all/201012150034.01356.yann.morin.1998@anciens.enib.fr/ Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Documentation/kbuild/kconfig-language.rst | 6 +----- scripts/kconfig/parser.y | 10 +++------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Documentation/kbuild/kconfig-language.rst b/Documentation/kbuild/kconfig-language.rst index 0135905c0aa3..79ac2e8184f6 100644 --- a/Documentation/kbuild/kconfig-language.rst +++ b/Documentation/kbuild/kconfig-language.rst @@ -393,7 +393,7 @@ of C0, which doesn't depend on M:: choices:: - "choice" [symbol] + "choice" "endchoice" @@ -412,10 +412,6 @@ the kernel, but all drivers can be compiled as modules. A choice accepts another option "optional", which allows to set the choice to 'n' and no entry needs to be selected. -If no [symbol] is associated with a choice, then you can not have multiple -definitions of that choice. If a [symbol] is associated to the choice, -then you may define the same choice (i.e. with the same entries) in another -place. comment:: diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index b505e43e0d02..22f616334585 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -94,7 +94,7 @@ struct menu *current_menu, *current_entry; %type if_expr %type end %type if_entry menu_entry choice_entry -%type word_opt assign_val +%type assign_val %type assign_op %destructor { @@ -222,13 +222,12 @@ config_option: T_MODULES T_EOL /* choice entry */ -choice: T_CHOICE word_opt T_EOL +choice: T_CHOICE T_EOL { - struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE); + struct symbol *sym = sym_lookup(NULL, SYMBOL_CHOICE); sym->flags |= SYMBOL_NO_WRITE; menu_add_entry(sym); menu_add_expr(P_CHOICE, NULL, NULL); - free($2); printd(DEBUG_PARSE, "%s:%d:choice\n", cur_filename, cur_lineno); }; @@ -449,9 +448,6 @@ symbol: nonconst_symbol | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); } ; -word_opt: /* empty */ { $$ = NULL; } - | T_WORD - /* assignment statement */ assignment_stmt: T_WORD assign_op assign_val T_EOL { variable_add($1, $3, $2); free($1); free($3); } From 75b5ab134bb5f657ef7979a59106dce0657e8d87 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Tue, 5 Mar 2024 15:12:47 -0700 Subject: [PATCH 56/67] kbuild: Move -Wenum-{compare-conditional,enum-conversion} into W=1 Clang enables -Wenum-enum-conversion and -Wenum-compare-conditional under -Wenum-conversion. A recent change in Clang strengthened these warnings and they appear frequently in common builds, primarily due to several instances in common headers but there are quite a few drivers that have individual instances as well. include/linux/vmstat.h:508:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion] 508 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS + | ~~~~~~~~~~~~~~~~~~~~~ ^ 509 | item]; | ~~~~ drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c:955:24: warning: conditional expression between different enumeration types ('enum iwl_mac_beacon_flags' and 'enum iwl_mac_beacon_flags_v1') [-Wenum-compare-conditional] 955 | flags |= is_new_rate ? IWL_MAC_BEACON_CCK | ^ ~~~~~~~~~~~~~~~~~~ 956 | : IWL_MAC_BEACON_CCK_V1; | ~~~~~~~~~~~~~~~~~~~~~ drivers/net/wireless/intel/iwlwifi/mvm/mac-ctxt.c:1120:21: warning: conditional expression between different enumeration types ('enum iwl_mac_beacon_flags' and 'enum iwl_mac_beacon_flags_v1') [-Wenum-compare-conditional] 1120 | 0) > 10 ? | ^ 1121 | IWL_MAC_BEACON_FILS : | ~~~~~~~~~~~~~~~~~~~ 1122 | IWL_MAC_BEACON_FILS_V1; | ~~~~~~~~~~~~~~~~~~~~~~ Doing arithmetic between or returning two different types of enums could be a bug, so each of the instance of the warning needs to be evaluated. Unfortunately, as mentioned above, there are many instances of this warning in many different configurations, which can break the build when CONFIG_WERROR is enabled. To avoid introducing new instances of the warnings while cleaning up the disruption for the majority of users, disable these warnings for the default build while leaving them on for W=1 builds. Cc: stable@vger.kernel.org Closes: https://github.com/ClangBuiltLinux/linux/issues/2002 Link: https://github.com/llvm/llvm-project/commit/8c2ae42b3e1c6aa7c18f873edcebff7c0b45a37e Acked-by: Yonghong Song Signed-off-by: Nathan Chancellor Acked-by: Arnd Bergmann Signed-off-by: Masahiro Yamada --- scripts/Makefile.extrawarn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn index a9e552a1e910..2f25a1de129d 100644 --- a/scripts/Makefile.extrawarn +++ b/scripts/Makefile.extrawarn @@ -132,6 +132,8 @@ KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast) KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare KBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access) KBUILD_CFLAGS += $(call cc-disable-warning, cast-function-type-strict) +KBUILD_CFLAGS += -Wno-enum-compare-conditional +KBUILD_CFLAGS += -Wno-enum-enum-conversion endif endif From e2bad142bb3de836c5fbb3dff704578f5a73d8e6 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 6 Mar 2024 19:42:22 +0900 Subject: [PATCH 57/67] kbuild: unexport abs_srctree and abs_objtree Commit 25b146c5b8ce ("kbuild: allow Kbuild to start from any directory") exported abs_srctree and abs_objtree to avoid recomputation after the sub-make. However, this approach turned out to be fragile. Commit 5fa94ceb793e ("kbuild: set correct abs_srctree and abs_objtree for package builds") moved them above "ifneq ($(sub_make_done),1)", eliminating the need for exporting them. These are only needed in the top Makefile. If an absolute path is required in sub-directories, you can use $(abspath ) or $(realpath ) as needed. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Makefile | 4 ++-- rust/Makefile | 4 ++-- scripts/Makefile.package | 2 +- tools/lib/bpf/Makefile | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 859b0f52949e..104e62560eed 100644 --- a/Makefile +++ b/Makefile @@ -39,8 +39,8 @@ __all: # prepare rule. this-makefile := $(lastword $(MAKEFILE_LIST)) -export abs_srctree := $(realpath $(dir $(this-makefile))) -export abs_objtree := $(CURDIR) +abs_srctree := $(realpath $(dir $(this-makefile))) +abs_objtree := $(CURDIR) ifneq ($(sub_make_done),1) diff --git a/rust/Makefile b/rust/Makefile index 9d2a16cc91cb..ae691b71d9fc 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -100,7 +100,7 @@ rustdoc: rustdoc-core rustdoc-macros rustdoc-compiler_builtins \ -e 's:rust-logo-[0-9a-f]+\.svg:logo.svg:g' \ -e 's:favicon-[0-9a-f]+\.svg:logo.svg:g' \ -e 's:::g' \ - -e 's:::g' + -e 's:::g' $(Q)for f in $(rustdoc_output)/static.files/rustdoc-*.css; do \ echo ".logo-container > img { object-fit: contain; }" >> $$f; done @@ -413,7 +413,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L rust-analyzer: $(Q)$(srctree)/scripts/generate_rust_analyzer.py \ --cfgs='core=$(core-cfgs)' --cfgs='alloc=$(alloc-cfgs)' \ - $(abs_srctree) $(abs_objtree) \ + $(realpath $(srctree)) $(realpath $(objtree)) \ $(RUST_LIB_SRC) $(KBUILD_EXTMOD) > \ $(if $(KBUILD_EXTMOD),$(extmod_prefix),$(objtree))/rust-project.json diff --git a/scripts/Makefile.package b/scripts/Makefile.package index a81dfb1f5181..38653f3e8108 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -135,7 +135,7 @@ snap-pkg: mkdir $(objtree)/snap $(MAKE) clean sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \ - s@SRCTREE@$(abs_srctree)@" \ + s@SRCTREE@$(realpath $(srctree))@" \ $(srctree)/scripts/package/snapcraft.template > \ $(objtree)/snap/snapcraft.yaml cd $(objtree)/snap && \ diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile index 4be7144e4803..2cf892774346 100644 --- a/tools/lib/bpf/Makefile +++ b/tools/lib/bpf/Makefile @@ -2,7 +2,7 @@ # Most of this file is copied from tools/lib/traceevent/Makefile RM ?= rm -srctree = $(abs_srctree) +srctree := $(realpath $(srctree)) VERSION_SCRIPT := libbpf.map LIBBPF_VERSION := $(shell \ From 44929bfaceaaa6a854ddc6df6de9433fab1eef92 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 6 Mar 2024 21:47:09 +0900 Subject: [PATCH 58/67] kbuild: remove GCC's default -Wpacked-bitfield-compat flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 4a5838ad9d2d ("kbuild: Add extra gcc checks") added the -Wpacked-bitfield-compat flag, but there is no need to add it explicitly. GCC manual says: "This warning is enabled by default. Use -Wno-packed-bitfield-compat to disable this warning." The test code in the manual: struct foo { char a:4; char b:8; } __attribute__ ((packed)); ... emits "note: offset of packed bit-field ‘b’ has changed in GCC 4.4" without W=3. Let's remove it, as it is a default with GCC. Clang does not support this flag, so its removal will not affect Clang builds. Signed-off-by: Masahiro Yamada Reviewed-by: Nathan Chancellor --- scripts/Makefile.extrawarn | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn index 2f25a1de129d..3ce5d503a6da 100644 --- a/scripts/Makefile.extrawarn +++ b/scripts/Makefile.extrawarn @@ -187,7 +187,6 @@ KBUILD_CFLAGS += -Wpointer-arith KBUILD_CFLAGS += -Wredundant-decls KBUILD_CFLAGS += -Wsign-compare KBUILD_CFLAGS += -Wswitch-default -KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat) KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3 From 23dfd914d2bfc4c9938b0084dffd7105de231d98 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 15 Feb 2024 15:13:21 +0100 Subject: [PATCH 59/67] modpost: fix null pointer dereference If the find_fromsym() call fails and returns NULL, the warn() call will dereference this NULL pointer and cause the program to crash. This happened when I tried to build with "test_user_copy" module. With this fix, it prints lots of warnings like this: WARNING: modpost: lib/test_user_copy: section mismatch in reference: (unknown)+0x4 (section: .text.fixup) -> (unknown) (section: .init.text) masahiroy@kernel.org: The issue is reproduced with ARCH=arm allnoconfig + CONFIG_MODULES=y + CONFIG_RUNTIME_TESTING_MENU=y + CONFIG_TEST_USER_COPY=m Signed-off-by: Max Kellermann Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 267b9a0a3abc..9106fe757946 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1050,7 +1050,9 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf, sec_mismatch_count++; warn("%s: section mismatch in reference: %s+0x%x (section: %s) -> %s (section: %s)\n", - modname, fromsym, (unsigned int)(faddr - from->st_value), fromsec, tosym, tosec); + modname, fromsym, + (unsigned int)(faddr - (from ? from->st_value : 0)), + fromsec, tosym, tosec); if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) { if (match(tosec, mismatch->bad_tosec)) From 137bb8b814be5d0056e8eaf593e71bf340cdc06f Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 10 Mar 2024 22:32:57 +0900 Subject: [PATCH 60/67] kconfig: lxdialog: fix button color for blackbg theme For MENUCONFIG_COLOR=blackbg, the text in inactive buttons is invisible because both the foreground and background are black. Change the foreground color to white and remove the highlighting. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lxdialog/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c index 3f78fb265136..d5315315b066 100644 --- a/scripts/kconfig/lxdialog/util.c +++ b/scripts/kconfig/lxdialog/util.c @@ -101,7 +101,7 @@ static void set_blackbg_theme(void) DLG_COLOR(button_key_active, COLOR_YELLOW, COLOR_RED, true); DLG_COLOR(button_key_inactive, COLOR_RED, COLOR_BLACK, false); DLG_COLOR(button_label_active, COLOR_WHITE, COLOR_RED, false); - DLG_COLOR(button_label_inactive, COLOR_BLACK, COLOR_BLACK, true); + DLG_COLOR(button_label_inactive, COLOR_WHITE, COLOR_BLACK, false); DLG_COLOR(inputbox, COLOR_YELLOW, COLOR_BLACK, false); DLG_COLOR(inputbox_border, COLOR_YELLOW, COLOR_BLACK, false); From c33a4315c4095be368fe127db3385b248d38df8f Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 10 Mar 2024 22:32:58 +0900 Subject: [PATCH 61/67] kconfig: lxdialog: remove unused dialog colors Remove inputbox_order, searchbox, searchbox_title, searchbox_border because they are initialized, but not used anywhere. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lxdialog/dialog.h | 4 ---- scripts/kconfig/lxdialog/util.c | 18 ------------------ 2 files changed, 22 deletions(-) diff --git a/scripts/kconfig/lxdialog/dialog.h b/scripts/kconfig/lxdialog/dialog.h index a501abf9fa31..2d15ba893fbf 100644 --- a/scripts/kconfig/lxdialog/dialog.h +++ b/scripts/kconfig/lxdialog/dialog.h @@ -91,10 +91,6 @@ struct dialog_info { struct dialog_color button_label_active; struct dialog_color button_label_inactive; struct dialog_color inputbox; - struct dialog_color inputbox_border; - struct dialog_color searchbox; - struct dialog_color searchbox_title; - struct dialog_color searchbox_border; struct dialog_color position_indicator; struct dialog_color menubox; struct dialog_color menubox_border; diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c index d5315315b066..3fb7508b68a2 100644 --- a/scripts/kconfig/lxdialog/util.c +++ b/scripts/kconfig/lxdialog/util.c @@ -29,10 +29,6 @@ static void set_mono_theme(void) dlg.button_label_active.atr = A_REVERSE; dlg.button_label_inactive.atr = A_NORMAL; dlg.inputbox.atr = A_NORMAL; - dlg.inputbox_border.atr = A_NORMAL; - dlg.searchbox.atr = A_NORMAL; - dlg.searchbox_title.atr = A_BOLD; - dlg.searchbox_border.atr = A_NORMAL; dlg.position_indicator.atr = A_BOLD; dlg.menubox.atr = A_NORMAL; dlg.menubox_border.atr = A_NORMAL; @@ -69,10 +65,6 @@ static void set_classic_theme(void) DLG_COLOR(button_label_active, COLOR_YELLOW, COLOR_BLUE, true); DLG_COLOR(button_label_inactive, COLOR_BLACK, COLOR_WHITE, true); DLG_COLOR(inputbox, COLOR_BLACK, COLOR_WHITE, false); - DLG_COLOR(inputbox_border, COLOR_BLACK, COLOR_WHITE, false); - DLG_COLOR(searchbox, COLOR_BLACK, COLOR_WHITE, false); - DLG_COLOR(searchbox_title, COLOR_YELLOW, COLOR_WHITE, true); - DLG_COLOR(searchbox_border, COLOR_WHITE, COLOR_WHITE, true); DLG_COLOR(position_indicator, COLOR_YELLOW, COLOR_WHITE, true); DLG_COLOR(menubox, COLOR_BLACK, COLOR_WHITE, false); DLG_COLOR(menubox_border, COLOR_WHITE, COLOR_WHITE, true); @@ -104,11 +96,6 @@ static void set_blackbg_theme(void) DLG_COLOR(button_label_inactive, COLOR_WHITE, COLOR_BLACK, false); DLG_COLOR(inputbox, COLOR_YELLOW, COLOR_BLACK, false); - DLG_COLOR(inputbox_border, COLOR_YELLOW, COLOR_BLACK, false); - - DLG_COLOR(searchbox, COLOR_YELLOW, COLOR_BLACK, false); - DLG_COLOR(searchbox_title, COLOR_YELLOW, COLOR_BLACK, true); - DLG_COLOR(searchbox_border, COLOR_BLACK, COLOR_BLACK, true); DLG_COLOR(position_indicator, COLOR_RED, COLOR_BLACK, false); @@ -136,7 +123,6 @@ static void set_bluetitle_theme(void) DLG_COLOR(title, COLOR_BLUE, COLOR_WHITE, true); DLG_COLOR(button_key_active, COLOR_YELLOW, COLOR_BLUE, true); DLG_COLOR(button_label_active, COLOR_WHITE, COLOR_BLUE, true); - DLG_COLOR(searchbox_title, COLOR_BLUE, COLOR_WHITE, true); DLG_COLOR(position_indicator, COLOR_BLUE, COLOR_WHITE, true); DLG_COLOR(tag, COLOR_BLUE, COLOR_WHITE, true); DLG_COLOR(tag_key, COLOR_BLUE, COLOR_WHITE, true); @@ -189,10 +175,6 @@ static void init_dialog_colors(void) init_one_color(&dlg.button_label_active); init_one_color(&dlg.button_label_inactive); init_one_color(&dlg.inputbox); - init_one_color(&dlg.inputbox_border); - init_one_color(&dlg.searchbox); - init_one_color(&dlg.searchbox_title); - init_one_color(&dlg.searchbox_border); init_one_color(&dlg.position_indicator); init_one_color(&dlg.menubox); init_one_color(&dlg.menubox_border); From 4957515b9c3aa3d32a1ee44ab77f0a44f29263dc Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 10 Mar 2024 22:45:15 +0900 Subject: [PATCH 62/67] kconfig: check prompt for choice while parsing This can be checked on-the-fly. Signed-off-by: Masahiro Yamada --- scripts/kconfig/menu.c | 3 --- scripts/kconfig/parser.y | 6 ++++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 840ce642ec43..8498481e6afe 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -561,9 +561,6 @@ void menu_finalize(struct menu *parent) if (sym->type == S_UNKNOWN) menu_warn(parent, "config symbol defined without type"); - if (sym_is_choice(sym) && !parent->prompt) - menu_warn(parent, "choice must have a prompt"); - /* Check properties connected to this symbol */ sym_check_prop(sym); sym->flags |= SYMBOL_WARNED; diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index 22f616334585..b45bfaf0a02b 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -233,6 +233,12 @@ choice: T_CHOICE T_EOL choice_entry: choice choice_option_list { + if (!current_entry->prompt) { + fprintf(stderr, "%s:%d: error: choice must have a prompt\n", + current_entry->filename, current_entry->lineno); + yynerrs++; + } + $$ = menu_add_menu(); }; From b27a91383abc4acca39f4402cdcc74ce4a476d8e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 10 Mar 2024 23:16:17 +0900 Subject: [PATCH 63/67] kconfig: remove unneeded menu_is_visible() call in conf_write_defconfig() When the condition 'sym == NULL' is met, the code will reach the 'next_menu' label regardless of the return value from menu_is_visible(). menu_is_visible() calculates some symbol values as a side-effect, for instance by calling expr_calc_value(menu->visibility), but all the symbol values will be calculated eventually. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index c5b6487d68ac..0e35c4819cf1 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -799,10 +799,7 @@ int conf_write_defconfig(const char *filename) while (menu != NULL) { sym = menu->sym; - if (sym == NULL) { - if (!menu_is_visible(menu)) - goto next_menu; - } else if (!sym_is_choice(sym)) { + if (sym && !sym_is_choice(sym)) { sym_calc_value(sym); if (!(sym->flags & SYMBOL_WRITE)) goto next_menu; From 097f1200bf7ea19fb39ccf538a07a153260a7763 Mon Sep 17 00:00:00 2001 From: Jose Ignacio Tornos Martinez Date: Mon, 11 Mar 2024 17:22:38 +0100 Subject: [PATCH 64/67] kbuild: rpm-pkg: add dtb files in kernel rpm Some architectures, like aarch64 ones, need a dtb file to configure the hardware. The default dtb file can be preloaded from u-boot, but the final and/or more complete dtb file needs to be able to be loaded later from rootfs. Add the possible dtb files to the kernel rpm and mimic Fedora shipping process, storing the dtb files in the module directory. These dtb files will be copied to /boot directory by the install scripts, but add fallback just in case, checking if the content in /boot directory is correct. Mark the files installed to /boot as %ghost to make sure they will be removed when the package is uninstalled. Tested with Fedora Rawhide (x86_64 and aarch64) with dnf and rpm tools. In addition, fallback was also tested after modifying the install scripts. Signed-off-by: Jose Ignacio Tornos Martinez Tested-by: Nathan Chancellor Signed-off-by: Masahiro Yamada --- scripts/package/kernel.spec | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/package/kernel.spec b/scripts/package/kernel.spec index c256b73cca3e..e095eb1e290e 100644 --- a/scripts/package/kernel.spec +++ b/scripts/package/kernel.spec @@ -61,6 +61,9 @@ cp $(%{make} %{makeflags} -s image_name) %{buildroot}/lib/modules/%{KERNELRELEAS %{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install cp System.map %{buildroot}/lib/modules/%{KERNELRELEASE} cp .config %{buildroot}/lib/modules/%{KERNELRELEASE}/config +if %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='test -d ${srctree}/arch/${SRCARCH}/boot/dts' 2>/dev/null; then + %{make} %{makeflags} INSTALL_DTBS_PATH=%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb dtbs_install +fi ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/build %if %{with_devel} %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}' @@ -81,6 +84,11 @@ ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEA echo "%ghost /boot/${x}-%{KERNELRELEASE}" done + if [ -d "%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb" ];then + echo "/lib/modules/%{KERNELRELEASE}/dtb" + find "%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb" -printf "%%%ghost /boot/dtb-%{KERNELRELEASE}/%%P\n" + fi + echo "%exclude /lib/modules/%{KERNELRELEASE}/build" } > %{buildroot}/kernel.list @@ -96,6 +104,11 @@ for file in vmlinuz System.map config; do cp "/lib/modules/%{KERNELRELEASE}/${file}" "/boot/${file}-%{KERNELRELEASE}" fi done +if [ -d "/lib/modules/%{KERNELRELEASE}/dtb" ] && \ + ! diff -rq "/lib/modules/%{KERNELRELEASE}/dtb" "/boot/dtb-%{KERNELRELEASE}" >/dev/null 2>&1; then + rm -rf "/boot/dtb-%{KERNELRELEASE}" + cp -r "/lib/modules/%{KERNELRELEASE}/dtb" "/boot/dtb-%{KERNELRELEASE}" +fi if [ ! -e "/lib/modules/%{KERNELRELEASE}/modules.dep" ]; then /usr/sbin/depmod %{KERNELRELEASE} fi From c9aa7d862144f7b5d74cf316fc1172629a3b438f Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 21 Mar 2024 01:52:09 +0900 Subject: [PATCH 65/67] kconfig: tests: support KCONFIG_SEED for the randconfig runner This will help get consistent results for randconfig tests. Signed-off-by: Masahiro Yamada --- scripts/kconfig/tests/conftest.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/kconfig/tests/conftest.py b/scripts/kconfig/tests/conftest.py index af8774a5697c..2a2a7e2da060 100644 --- a/scripts/kconfig/tests/conftest.py +++ b/scripts/kconfig/tests/conftest.py @@ -154,12 +154,10 @@ class Conf: defconfig_path = os.path.join(self._test_dir, defconfig) return self._run_conf('--defconfig={}'.format(defconfig_path)) - def _allconfig(self, mode, all_config): + def _allconfig(self, mode, all_config, extra_env={}): if all_config: all_config_path = os.path.join(self._test_dir, all_config) - extra_env = {'KCONFIG_ALLCONFIG': all_config_path} - else: - extra_env = {} + extra_env['KCONFIG_ALLCONFIG'] = all_config_path return self._run_conf('--{}config'.format(mode), extra_env=extra_env) @@ -195,13 +193,19 @@ class Conf: """ return self._allconfig('alldef', all_config) - def randconfig(self, all_config=None): + def randconfig(self, all_config=None, seed=None): """Run randconfig. all_config: fragment config file for KCONFIG_ALLCONFIG (optional) + seed: the seed for randconfig (optional) returncode: exit status of the Kconfig executable """ - return self._allconfig('rand', all_config) + if seed is not None: + extra_env = {'KCONFIG_SEED': hex(seed)} + else: + extra_env = {} + + return self._allconfig('rand', all_config, extra_env=extra_env) def savedefconfig(self, dot_config): """Run savedefconfig. From 47ad16894c4a25e6cb342666f0fa203701a88476 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 21 Mar 2024 01:52:10 +0900 Subject: [PATCH 66/67] kconfig: tests: add a test for randconfig with dependent choices Since commit 3b9a19e08960 ("kconfig: loop as long as we changed some symbols in randconfig"), conf_set_all_new_symbols() is repeated until there is no more choice left to be shuffled. The motivation was to shuffle a choice nested in another choice. Although commit 09d5873e4d1f ("kconfig: allow only 'config', 'comment', and 'if' inside 'choice'") disallowed the nested choice structure, we must still keep 3b9a19e08960 because there are still cases where conf_set_all_new_symbols() must iterate. scripts/kconfig/tests/choice_randomize/Kconfig is the test case. The second choice depends on 'B', which is the member of the first choice. With 3b9a19e08960 reverted, we would never get the pattern specified by scripts/kconfig/tests/choice_randomize/expected_config2. A real example can be found in lib/Kconfig.debug. Without 3b9a19e08960, the randconfig would not shuffle the "Compressed Debug information" choice, which depends on DEBUG_INFO, which is derived from another choice "Debug information". My goal is to refactor Kconfig so that randconfig will work more simply, without using the loop. For now, let's add a test case to ensure all dependent choices are shuffled, as it is a somewhat tricky case for the current Kconfig. Signed-off-by: Masahiro Yamada --- .../kconfig/tests/choice_randomize/Kconfig | 22 ++++++++++++ .../tests/choice_randomize/__init__.py | 34 +++++++++++++++++++ .../tests/choice_randomize/expected_config0 | 6 ++++ .../tests/choice_randomize/expected_config1 | 8 +++++ .../tests/choice_randomize/expected_config2 | 8 +++++ 5 files changed, 78 insertions(+) create mode 100644 scripts/kconfig/tests/choice_randomize/Kconfig create mode 100644 scripts/kconfig/tests/choice_randomize/__init__.py create mode 100644 scripts/kconfig/tests/choice_randomize/expected_config0 create mode 100644 scripts/kconfig/tests/choice_randomize/expected_config1 create mode 100644 scripts/kconfig/tests/choice_randomize/expected_config2 diff --git a/scripts/kconfig/tests/choice_randomize/Kconfig b/scripts/kconfig/tests/choice_randomize/Kconfig new file mode 100644 index 000000000000..93a1699ce3cb --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize/Kconfig @@ -0,0 +1,22 @@ +choice + prompt "choose A or B" + +config A + bool "A" + +config B + bool "B" + +endchoice + +choice + prompt "choose X or Y" + depends on B + +config X + bool "X" + +config Y + bool "Y" + +endchoice diff --git a/scripts/kconfig/tests/choice_randomize/__init__.py b/scripts/kconfig/tests/choice_randomize/__init__.py new file mode 100644 index 000000000000..d380045be79c --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize/__init__.py @@ -0,0 +1,34 @@ +# SPDX-License-Identifier: GPL-2.0-only +""" +Randomize all dependent choices + +This is a somewhat tricky case for randconfig; the visibility of one choice is +determined by a member of another choice. Randconfig should be able to generate +all possible patterns. +""" + + +def test(conf): + + expected0 = False + expected1 = False + expected2 = False + + for i in range(100): + assert conf.randconfig(seed=i) == 0 + + if conf.config_matches('expected_config0'): + expected0 = True + elif conf.config_matches('expected_config1'): + expected1 = True + elif conf.config_matches('expected_config2'): + expected2 = True + else: + assert False + + if expected0 and expected1 and expected2: + break + + assert expected0 + assert expected1 + assert expected2 diff --git a/scripts/kconfig/tests/choice_randomize/expected_config0 b/scripts/kconfig/tests/choice_randomize/expected_config0 new file mode 100644 index 000000000000..f69227323759 --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize/expected_config0 @@ -0,0 +1,6 @@ +# +# Automatically generated file; DO NOT EDIT. +# Main menu +# +CONFIG_A=y +# CONFIG_B is not set diff --git a/scripts/kconfig/tests/choice_randomize/expected_config1 b/scripts/kconfig/tests/choice_randomize/expected_config1 new file mode 100644 index 000000000000..bf83784c9b2a --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize/expected_config1 @@ -0,0 +1,8 @@ +# +# Automatically generated file; DO NOT EDIT. +# Main menu +# +# CONFIG_A is not set +CONFIG_B=y +CONFIG_X=y +# CONFIG_Y is not set diff --git a/scripts/kconfig/tests/choice_randomize/expected_config2 b/scripts/kconfig/tests/choice_randomize/expected_config2 new file mode 100644 index 000000000000..38f93a8f37bd --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize/expected_config2 @@ -0,0 +1,8 @@ +# +# Automatically generated file; DO NOT EDIT. +# Main menu +# +# CONFIG_A is not set +CONFIG_B=y +# CONFIG_X is not set +CONFIG_Y=y From f2fd2aad1908554fbc4ad6e8ef23bad3086bebd1 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 21 Mar 2024 01:52:11 +0900 Subject: [PATCH 67/67] kconfig: tests: test dependency after shuffling choices Commit c8fb7d7e48d1 ("kconfig: fix broken dependency in randconfig- generated .config") fixed the issue, but I did not add a test case. This commit adds a test case that emulates the reported situation. The test would fail without c8fb7d7e48d1. To handle the choice "choose X", FOO must be calculated beforehand. FOO depends on A, which is a member of another choice "choose A or B". Kconfig _temporarily_ assumes the value of A to proceed. The choice "choose A or B" will be shuffled later, but the result may or may not meet "FOO depends on A". Kconfig should invalidate the symbol values and recompute them. In the real example for ARCH=arm64, the choice "Instrumentation type" needs the value of CPU_BIG_ENDIAN. The choice "Endianness" will be shuffled later. Signed-off-by: Masahiro Yamada --- .../kconfig/tests/choice_randomize2/Kconfig | 32 +++++++++++++++++++ .../tests/choice_randomize2/__init__.py | 18 +++++++++++ .../tests/choice_randomize2/expected_config0 | 8 +++++ .../tests/choice_randomize2/expected_config1 | 7 ++++ .../tests/choice_randomize2/expected_config2 | 6 ++++ 5 files changed, 71 insertions(+) create mode 100644 scripts/kconfig/tests/choice_randomize2/Kconfig create mode 100644 scripts/kconfig/tests/choice_randomize2/__init__.py create mode 100644 scripts/kconfig/tests/choice_randomize2/expected_config0 create mode 100644 scripts/kconfig/tests/choice_randomize2/expected_config1 create mode 100644 scripts/kconfig/tests/choice_randomize2/expected_config2 diff --git a/scripts/kconfig/tests/choice_randomize2/Kconfig b/scripts/kconfig/tests/choice_randomize2/Kconfig new file mode 100644 index 000000000000..530cf2ef7f47 --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize2/Kconfig @@ -0,0 +1,32 @@ +choice + prompt "This is always invisible" + depends on n + +config DUMMY + bool "DUMMY" + +endchoice + +choice + prompt "Choose A or B" + +config A + bool "A" + +config B + bool "B" + +endchoice + +config FOO + bool "FOO" + depends on A + +choice + prompt "Choose X" + depends on FOO + +config X + bool "X" + +endchoice diff --git a/scripts/kconfig/tests/choice_randomize2/__init__.py b/scripts/kconfig/tests/choice_randomize2/__init__.py new file mode 100644 index 000000000000..2066757b80b9 --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize2/__init__.py @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0-only +""" +Randomize choices with correct dependencies + +When shuffling a choice may potentially disrupt certain dependencies, symbol +values must be recalculated. + +Related Linux commits: + - c8fb7d7e48d11520ad24808cfce7afb7b9c9f798 +""" + + +def test(conf): + for i in range(20): + assert conf.randconfig(seed=i) == 0 + assert (conf.config_matches('expected_config0') or + conf.config_matches('expected_config1') or + conf.config_matches('expected_config2')) diff --git a/scripts/kconfig/tests/choice_randomize2/expected_config0 b/scripts/kconfig/tests/choice_randomize2/expected_config0 new file mode 100644 index 000000000000..5c9e1c172c15 --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize2/expected_config0 @@ -0,0 +1,8 @@ +# +# Automatically generated file; DO NOT EDIT. +# Main menu +# +CONFIG_A=y +# CONFIG_B is not set +CONFIG_FOO=y +CONFIG_X=y diff --git a/scripts/kconfig/tests/choice_randomize2/expected_config1 b/scripts/kconfig/tests/choice_randomize2/expected_config1 new file mode 100644 index 000000000000..5b975d91bef1 --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize2/expected_config1 @@ -0,0 +1,7 @@ +# +# Automatically generated file; DO NOT EDIT. +# Main menu +# +CONFIG_A=y +# CONFIG_B is not set +# CONFIG_FOO is not set diff --git a/scripts/kconfig/tests/choice_randomize2/expected_config2 b/scripts/kconfig/tests/choice_randomize2/expected_config2 new file mode 100644 index 000000000000..5a5ebb90d1d7 --- /dev/null +++ b/scripts/kconfig/tests/choice_randomize2/expected_config2 @@ -0,0 +1,6 @@ +# +# Automatically generated file; DO NOT EDIT. +# Main menu +# +# CONFIG_A is not set +CONFIG_B=y