History

Merge tag 'kbuild-v6.9' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild

Pull Kbuild updates from Masahiro Yamada: - Generate a list of built DTB files (arch/*/boot/dts/dtbs-list) - Use more threads when building Debian packages in parallel - Fix warnings shown during the RPM kernel package uninstallation - Change OBJECT_FILES_NON_STANDARD_*.o etc. to take a relative path to Makefile - Support GCC's -fmin-function-alignment flag - Fix a null pointer dereference bug in modpost - Add the DTB support to the RPM package - Various fixes and cleanups in Kconfig * tag 'kbuild-v6.9' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (67 commits) kconfig: tests: test dependency after shuffling choices kconfig: tests: add a test for randconfig with dependent choices kconfig: tests: support KCONFIG_SEED for the randconfig runner kbuild: rpm-pkg: add dtb files in kernel rpm kconfig: remove unneeded menu_is_visible() call in conf_write_defconfig() kconfig: check prompt for choice while parsing kconfig: lxdialog: remove unused dialog colors kconfig: lxdialog: fix button color for blackbg theme modpost: fix null pointer dereference kbuild: remove GCC's default -Wpacked-bitfield-compat flag kbuild: unexport abs_srctree and abs_objtree kbuild: Move -Wenum-{compare-conditional,enum-conversion} into W=1 kconfig: remove named choice support kconfig: use linked list in get_symbol_str() to iterate over menus kconfig: link menus to a symbol kbuild: fix inconsistent indentation in top Makefile kbuild: Use -fmin-function-alignment when available alpha: merge two entries for CONFIG_ALPHA_GAMMA alpha: merge two entries for CONFIG_ALPHA_EV4 kbuild: change DTC_FLAGS_<basetarget>.o to take the path relative to $(obj) ...

Linus Torvalds committed 2 years ago

Commit 1d35aae2 parents 88d92fb f2fd2aa69 files · +1133 −792Browse files

Showing the changes to scripts (45 of 69 files). Show all

Unified · Split

45 files
  1. scripts/Kbuild.include +0 −6
  2. scripts/Makefile.build +13 −9
  3. scripts/Makefile.dtbinst +18 −14
  4. scripts/Makefile.extrawarn +2 −1
  5. scripts/Makefile.lib +16 −10
  6. scripts/Makefile.package +1 −1
  7. scripts/kconfig/array_size.h +11 −0
  8. scripts/kconfig/conf.c +6 −6
  9. scripts/kconfig/confdata.c +18 −78
  10. scripts/kconfig/expr.h +11 −18
  11. scripts/kconfig/hashtable.h +48 −0
  12. scripts/kconfig/internal.h +12 −0
  13. scripts/kconfig/lexer.l +61 −69
  14. scripts/kconfig/list.h +189 −65
  15. scripts/kconfig/list_types.h +17 −0
  16. scripts/kconfig/lkc.h +3 −3
  17. scripts/kconfig/lkc_proto.h +0 −15
  18. scripts/kconfig/lxdialog/checklist.c +2 −3
  19. scripts/kconfig/lxdialog/dialog.h +0 −4
  20. scripts/kconfig/lxdialog/util.c +1 −19
  21. scripts/kconfig/mconf.c +1 −0
  22. scripts/kconfig/menu.c +20 −28
  23. scripts/kconfig/nconf.c +1 −0
  24. scripts/kconfig/parser.y +76 −49
  25. scripts/kconfig/preprocess.c +13 −10
  26. scripts/kconfig/preprocess.h +19 −0
  27. scripts/kconfig/qconf.cc +1 −1
  28. scripts/kconfig/symbol.c +22 −27
  29. scripts/kconfig/tests/choice_randomize/Kconfig +22 −0
  30. scripts/kconfig/tests/choice_randomize/__init__.py +34 −0
  31. scripts/kconfig/tests/choice_randomize/expected_config0 +6 −0
  32. scripts/kconfig/tests/choice_randomize/expected_config1 +8 −0
  33. scripts/kconfig/tests/choice_randomize/expected_config2 +8 −0
  34. scripts/kconfig/tests/choice_randomize2/Kconfig +32 −0
  35. scripts/kconfig/tests/choice_randomize2/__init__.py +18 −0
  36. scripts/kconfig/tests/choice_randomize2/expected_config0 +8 −0
  37. scripts/kconfig/tests/choice_randomize2/expected_config1 +7 −0
  38. scripts/kconfig/tests/choice_randomize2/expected_config2 +6 −0
  39. scripts/kconfig/tests/conftest.py +10 −6
  40. scripts/kconfig/tests/err_recursive_dep/expected_stderr +11 −11
  41. scripts/kconfig/util.c +36 −11
  42. scripts/mod/modpost.c +3 −1
  43. scripts/package/builddeb +12 −38
  44. scripts/package/debian/rules +54 −9
  45. scripts/package/kernel.spec +37 −11
scripts/Kbuild.include+0−6
@@ -113,12 +113,6 @@ endef · 112 unmodified lines
113113 # $(Q)$(MAKE) $(build)=dir
114114 build := -f $(srctree)/scripts/Makefile.build obj
115115
116−###
117−# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj=
118−# Usage:
119−# $(Q)$(MAKE) $(dtbinst)=dir
120−dtbinst := -f $(srctree)/scripts/Makefile.dtbinst obj
121−
122116 ###
123117 # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=
124118 # Usage:
scripts/Makefile.build+13−9
@@ -71,6 +71,7 @@ endif · 70 unmodified lines
7171 # subdir-builtin and subdir-modorder may contain duplications. Use $(sort ...)
7272 subdir-builtin := $(sort $(filter %/built-in.a, $(real-obj-y)))
7373 subdir-modorder := $(sort $(filter %/modules.order, $(obj-m)))
74+subdir-dtbslist := $(sort $(filter %/dtbs-list, $(dtb-y)))
7475
7576 targets-for-builtin := $(extra-y)
7677
@@ -213,7 +214,7 @@ endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT · 136 unmodified lines
213214 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
214215 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
215216
216−is-standard-object = $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
217+is-standard-object = $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(target-stem).o)$(OBJECT_FILES_NON_STANDARD)n),y)
217218
218219 $(obj)/%.o: objtool-enabled = $(if $(is-standard-object),$(if $(delay-objtool),$(is-single-obj-m),y))
219220
@@ -388,6 +389,7 @@ $(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler · 168 unmodified lines
388389 # To build objects in subdirs, we need to descend into the directories
389390 $(subdir-builtin): $(obj)/%/built-in.a: $(obj)/% ;
390391 $(subdir-modorder): $(obj)/%/modules.order: $(obj)/% ;
392+$(subdir-dtbslist): $(obj)/%/dtbs-list: $(obj)/% ;
391393
392394 #
393395 # 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 · 10 unmodified lines
404406 $(call if_changed,ar_builtin)
405407
406408 #
407−# Rule to create modules.order file
409+# Rule to create modules.order and dtbs-list
408410 #
409−# Create commands to either record .ko file or cat modules.order from
410−# a subdirectory
411−# Add $(obj-m) as the prerequisite to avoid updating the timestamp of
412−# modules.order unless contained modules are updated.
411+# This is a list of build artifacts (module or dtb) from the current Makefile
412+# and its sub-directories. The timestamp should be updated when any of the
413+# member files.
413414
414−cmd_modules_order = { $(foreach m, $(real-prereqs), \
415− $(if $(filter %/modules.order, $m), cat $m, echo $m);) :; } \
415+cmd_gen_order = { $(foreach m, $(real-prereqs), \
416+ $(if $(filter %/$(notdir $@), $m), cat $m, echo $m);) :; } \
416417 > $@
417418
418419 $(obj)/modules.order: $(obj-m) FORCE
419− $(call if_changed,modules_order)
420+ $(call if_changed,gen_order)
421+
422+$(obj)/dtbs-list: $(dtb-y) FORCE
423+ $(call if_changed,gen_order)
420424
421425 #
422426 # Rule to compile a set of .o files into one .a file (with symbol table)
scripts/Makefile.dtbinst+18−14
@@ -8,32 +8,36 @@ · 7 unmodified lines
88 # $INSTALL_PATH/dtbs/$KERNELRELEASE
99 # ==========================================================================
1010
11−src := $(obj)
12−
1311 PHONY := __dtbs_install
1412 __dtbs_install:
1513
1614 include include/config/auto.conf
1715 include $(srctree)/scripts/Kbuild.include
18−include $(kbuild-file)
19−
20−dtbs := $(addprefix $(dst)/, $(dtb-y) $(if $(CONFIG_OF_ALL_DTBS),$(dtb-)))
21−subdirs := $(addprefix $(obj)/, $(subdir-y) $(subdir-m))
2216
23−__dtbs_install: $(dtbs) $(subdirs)
24− @:
17+dst := $(INSTALL_DTBS_PATH)
2518
2619 quiet_cmd_dtb_install = INSTALL $@
2720 cmd_dtb_install = install -D $< $@
2821
29−$(dst)/%.dtb: $(obj)/%.dtb
22+$(dst)/%: $(obj)/%
3023 $(call cmd,dtb_install)
3124
32−$(dst)/%.dtbo: $(obj)/%.dtbo
33− $(call cmd,dtb_install)
25+dtbs := $(patsubst $(obj)/%,%,$(call read-file, $(obj)/dtbs-list))
26+
27+ifdef CONFIG_ARCH_WANT_FLAT_DTB_INSTALL
3428
35−PHONY += $(subdirs)
36−$(subdirs):
37− $(Q)$(MAKE) $(dtbinst)=$@ dst=$(if $(CONFIG_ARCH_WANT_FLAT_DTB_INSTALL),$(dst),$(patsubst $(obj)/%,$(dst)/%,$@))
29+define gen_install_rules
30+$(dst)/%: $(obj)/$(1)%
31+ $$(call cmd,dtb_install)
32+endef
33+
34+$(foreach d, $(sort $(dir $(dtbs))), $(eval $(call gen_install_rules,$(d))))
35+
36+dtbs := $(notdir $(dtbs))
37+
38+endif # CONFIG_ARCH_WANT_FLAT_DTB_INSTALL
39+
40+__dtbs_install: $(addprefix $(dst)/, $(dtbs))
41+ @:
3842
3943 .PHONY: $(PHONY)
scripts/Makefile.extrawarn+2−1
@@ -132,6 +132,8 @@ KBUILD_CFLAGS += $(call cc-disable-warning, pointer-to-enum-cast) · 131 unmodified lines
132132 KBUILD_CFLAGS += -Wno-tautological-constant-out-of-range-compare
133133 KBUILD_CFLAGS += $(call cc-disable-warning, unaligned-access)
134134 KBUILD_CFLAGS += $(call cc-disable-warning, cast-function-type-strict)
135+KBUILD_CFLAGS += -Wno-enum-compare-conditional
136+KBUILD_CFLAGS += -Wno-enum-enum-conversion
135137 endif
136138
137139 endif
@@ -185,7 +187,6 @@ KBUILD_CFLAGS += -Wpointer-arith · 47 unmodified lines
185187 KBUILD_CFLAGS += -Wredundant-decls
186188 KBUILD_CFLAGS += -Wsign-compare
187189 KBUILD_CFLAGS += -Wswitch-default
188−KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat)
189190
190191 KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3
191192
scripts/Makefile.lib+16−10
@@ -45,6 +45,11 @@ else · 44 unmodified lines
4545 obj-y := $(filter-out %/, $(obj-y))
4646 endif
4747
48+ifdef need-dtbslist
49+dtb-y += $(addsuffix /dtbs-list, $(subdir-ym))
50+always-y += dtbs-list
51+endif
52+
4853 # Expand $(foo-objs) $(foo-y) etc. by replacing their individuals
4954 suffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s))))
5055 # List composite targets that are constructed by combining other targets
@@ -99,6 +104,7 @@ lib-y := $(addprefix $(obj)/,$(lib-y)) · 48 unmodified lines
99104 real-obj-y := $(addprefix $(obj)/,$(real-obj-y))
100105 real-obj-m := $(addprefix $(obj)/,$(real-obj-m))
101106 multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m))
107+dtb-y := $(addprefix $(obj)/, $(dtb-y))
102108 multi-dtb-y := $(addprefix $(obj)/, $(multi-dtb-y))
103109 real-dtb-y := $(addprefix $(obj)/, $(real-dtb-y))
104110 subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
@@ -148,7 +154,7 @@ _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds) · 43 unmodified lines
148154 #
149155 ifeq ($(CONFIG_GCOV_KERNEL),y)
150156 _c_flags += $(if $(patsubst n%,, \
151− $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \
157+ $(GCOV_PROFILE_$(target-stem).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \
152158 $(CFLAGS_GCOV))
153159 endif
154160
@@ -159,32 +165,32 @@ endif · 4 unmodified lines
159165 ifeq ($(CONFIG_KASAN),y)
160166 ifneq ($(CONFIG_KASAN_HW_TAGS),y)
161167 _c_flags += $(if $(patsubst n%,, \
162− $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
168+ $(KASAN_SANITIZE_$(target-stem).o)$(KASAN_SANITIZE)y), \
163169 $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
164170 endif
165171 endif
166172
167173 ifeq ($(CONFIG_KMSAN),y)
168174 _c_flags += $(if $(patsubst n%,, \
169− $(KMSAN_SANITIZE_$(basetarget).o)$(KMSAN_SANITIZE)y), \
175+ $(KMSAN_SANITIZE_$(target-stem).o)$(KMSAN_SANITIZE)y), \
170176 $(CFLAGS_KMSAN))
171177 _c_flags += $(if $(patsubst n%,, \
172− $(KMSAN_ENABLE_CHECKS_$(basetarget).o)$(KMSAN_ENABLE_CHECKS)y), \
178+ $(KMSAN_ENABLE_CHECKS_$(target-stem).o)$(KMSAN_ENABLE_CHECKS)y), \
173179 , -mllvm -msan-disable-checks=1)
174180 endif
175181
176182 ifeq ($(CONFIG_UBSAN),y)
177183 _c_flags += $(if $(patsubst n%,, \
178− $(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)y), \
184+ $(UBSAN_SANITIZE_$(target-stem).o)$(UBSAN_SANITIZE)y), \
179185 $(CFLAGS_UBSAN))
180186 _c_flags += $(if $(patsubst n%,, \
181− $(UBSAN_SIGNED_WRAP_$(basetarget).o)$(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SIGNED_WRAP)$(UBSAN_SANITIZE)y), \
187+ $(UBSAN_SIGNED_WRAP_$(target-stem).o)$(UBSAN_SANITIZE_$(target-stem).o)$(UBSAN_SIGNED_WRAP)$(UBSAN_SANITIZE)y), \
182188 $(CFLAGS_UBSAN_SIGNED_WRAP))
183189 endif
184190
185191 ifeq ($(CONFIG_KCOV),y)
186192 _c_flags += $(if $(patsubst n%,, \
187− $(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
193+ $(KCOV_INSTRUMENT_$(target-stem).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
188194 $(CFLAGS_KCOV))
189195 endif
190196
@@ -194,12 +200,12 @@ endif · 3 unmodified lines
194200 #
195201 ifeq ($(CONFIG_KCSAN),y)
196202 _c_flags += $(if $(patsubst n%,, \
197− $(KCSAN_SANITIZE_$(basetarget).o)$(KCSAN_SANITIZE)y), \
203+ $(KCSAN_SANITIZE_$(target-stem).o)$(KCSAN_SANITIZE)y), \
198204 $(CFLAGS_KCSAN))
199205 # Some uninstrumented files provide implied barriers required to avoid false
200206 # positives: set KCSAN_INSTRUMENT_BARRIERS for barrier instrumentation only.
201207 _c_flags += $(if $(patsubst n%,, \
202− $(KCSAN_INSTRUMENT_BARRIERS_$(basetarget).o)$(KCSAN_INSTRUMENT_BARRIERS)n), \
208+ $(KCSAN_INSTRUMENT_BARRIERS_$(target-stem).o)$(KCSAN_INSTRUMENT_BARRIERS)n), \
203209 -D__KCSAN_INSTRUMENT_BARRIERS__)
204210 endif
205211
@@ -364,7 +370,7 @@ DTC_FLAGS += -Wnode_name_chars_strict \ · 158 unmodified lines
364370 -Wunique_unit_address
365371 endif
366372
367−DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
373+DTC_FLAGS += $(DTC_FLAGS_$(target-stem))
368374
369375 # Set -@ if the target is a base DTB that overlay is applied onto
370376 DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@)
scripts/Makefile.package+1−1
@@ -135,7 +135,7 @@ snap-pkg: · 134 unmodified lines
135135 mkdir $(objtree)/snap
136136 $(MAKE) clean
137137 sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \
138− s@SRCTREE@$(abs_srctree)@" \
138+ s@SRCTREE@$(realpath $(srctree))@" \
139139 $(srctree)/scripts/package/snapcraft.template > \
140140 $(objtree)/snap/snapcraft.yaml
141141 cd $(objtree)/snap && \
scripts/kconfig/array_size.h+11−0
@@ -0,0 +1,11 @@
1+/* SPDX-License-Identifier: GPL-2.0 */
2+#ifndef ARRAY_SIZE_H
3+#define ARRAY_SIZE_H
4+
5+/**
6+ * ARRAY_SIZE - get the number of elements in array @arr
7+ * @arr: array to be sized
8+ */
9+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
10+
11+#endif /* ARRAY_SIZE_H */
scripts/kconfig/conf.c+6−6
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414 #include <sys/time.h>
1515 #include <errno.h>
1616
17+#include "internal.h"
1718 #include "lkc.h"
1819
1920 static void conf(struct menu *menu);
@@ -171,7 +172,7 @@ enum conf_def_mode { · 151 unmodified lines
171172 static bool conf_set_all_new_symbols(enum conf_def_mode mode)
172173 {
173174 struct symbol *sym, *csym;
174− int i, cnt;
175+ int cnt;
175176 /*
176177 * can't go as the default in switch-case below, otherwise gcc whines
177178 * about -Wmaybe-uninitialized
@@ -226,7 +227,7 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode) · 48 unmodified lines
226227 }
227228 }
228229
229− for_all_symbols(i, sym) {
230+ for_all_symbols(sym) {
230231 if (sym_has_value(sym) || sym->flags & SYMBOL_VALID)
231232 continue;
232233 switch (sym_get_type(sym)) {
@@ -278,14 +279,14 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode) · 45 unmodified lines
278279 * and the rest to no.
279280 */
280281 if (mode != def_random) {
281− for_all_symbols(i, csym) {
282+ for_all_symbols(csym) {
282283 if ((sym_is_choice(csym) && !sym_has_value(csym)) ||
283284 sym_is_choice_value(csym))
284285 csym->flags |= SYMBOL_NEED_SET_CHOICE_VALUES;
285286 }
286287 }
287288
288− for_all_symbols(i, csym) {
289+ for_all_symbols(csym) {
289290 if (sym_has_value(csym) || !sym_is_choice(csym))
290291 continue;
291292
@@ -304,9 +305,8 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode) · 12 unmodified lines
304305 static void conf_rewrite_tristates(tristate old_val, tristate new_val)
305306 {
306307 struct symbol *sym;
307− int i;
308308
309− for_all_symbols(i, sym) {
309+ for_all_symbols(sym) {
310310 if (sym_get_type(sym) == S_TRISTATE &&
311311 sym->def[S_DEF_USER].tri == old_val)
312312 sym->def[S_DEF_USER].tri = new_val;
scripts/kconfig/confdata.c+18−78
@@ -18,8 +18,11 @@ · 17 unmodified lines
1818 #include <time.h>
1919 #include <unistd.h>
2020
21+#include "internal.h"
2122 #include "lkc.h"
2223
24+struct gstr autoconf_cmd;
25+
2326 /* return true if 'path' exists, false otherwise */
2427 static bool is_present(const char *path)
2528 {
@@ -293,63 +296,12 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p) · 267 unmodified lines
293296 return 0;
294297 }
295298
296−#define LINE_GROWTH 16
297−static int add_byte(int c, char **lineptr, size_t slen, size_t *n)
298−{
299− size_t new_size = slen + 1;
300−
301− if (new_size > *n) {
302− new_size += LINE_GROWTH - 1;
303− new_size *= 2;
304− *lineptr = xrealloc(*lineptr, new_size);
305− *n = new_size;
306− }
307−
308− (*lineptr)[slen] = c;
309−
310− return 0;
311−}
312−
313−static ssize_t compat_getline(char **lineptr, size_t *n, FILE *stream)
314−{
315− char *line = *lineptr;
316− size_t slen = 0;
317−
318− for (;;) {
319− int c = getc(stream);
320−
321− switch (c) {
322− case '\n':
323− if (add_byte(c, &line, slen, n) < 0)
324− goto e_out;
325− slen++;
326− /* fall through */
327− case EOF:
328− if (add_byte('\0', &line, slen, n) < 0)
329− goto e_out;
330− *lineptr = line;
331− if (slen == 0)
332− return -1;
333− return slen;
334− default:
335− if (add_byte(c, &line, slen, n) < 0)
336− goto e_out;
337− slen++;
338− }
339− }
340−
341−e_out:
342− line[slen-1] = '\0';
343− *lineptr = line;
344− return -1;
345−}
346−
347299 /* like getline(), but the newline character is stripped away */
348300 static ssize_t getline_stripped(char **lineptr, size_t *n, FILE *stream)
349301 {
350302 ssize_t len;
351303
352− len = compat_getline(lineptr, n, stream);
304+ len = getline(lineptr, n, stream);
353305
354306 if (len > 0 && (*lineptr)[len - 1] == '\n') {
355307 len--;
@@ -371,7 +323,7 @@ int conf_read_simple(const char *name, int def) · 15 unmodified lines
371323 size_t line_asize = 0;
372324 char *p, *val;
373325 struct symbol *sym;
374− int i, def_flags;
326+ int def_flags;
375327 const char *warn_unknown, *sym_name;
376328
377329 warn_unknown = getenv("KCONFIG_WARN_UNKNOWN_SYMBOLS");
@@ -429,7 +381,7 @@ load: · 51 unmodified lines
429381 conf_warnings = 0;
430382
431383 def_flags = SYMBOL_DEF << def;
432− for_all_symbols(i, sym) {
384+ for_all_symbols(sym) {
433385 sym->flags |= SYMBOL_CHANGED;
434386 sym->flags &= ~(def_flags|SYMBOL_VALID);
435387 if (sym_is_choice(sym))
@@ -538,7 +490,6 @@ int conf_read(const char *name) · 102 unmodified lines
538490 {
539491 struct symbol *sym;
540492 int conf_unsaved = 0;
541− int i;
542493
543494 conf_set_changed(false);
544495
@@ -549,7 +500,7 @@ int conf_read(const char *name) · 4 unmodified lines
549500
550501 sym_calc_value(modules_sym);
551502
552− for_all_symbols(i, sym) {
503+ for_all_symbols(sym) {
553504 sym_calc_value(sym);
554505 if (sym_is_choice(sym) || (sym->flags & SYMBOL_NO_WRITE))
555506 continue;
@@ -573,7 +524,7 @@ int conf_read(const char *name) · 17 unmodified lines
573524 /* maybe print value in verbose mode... */
574525 }
575526
576− for_all_symbols(i, sym) {
527+ for_all_symbols(sym) {
577528 if (sym_has_value(sym) && !sym_is_choice_value(sym)) {
578529 /* Reset values of generates values, so they'll appear
579530 * as new, if they should become visible, but that
@@ -848,10 +799,7 @@ int conf_write_defconfig(const char *filename) · 268 unmodified lines
848799 while (menu != NULL)
849800 {
850801 sym = menu->sym;
851− if (sym == NULL) {
852− if (!menu_is_visible(menu))
853− goto next_menu;
854− } else if (!sym_is_choice(sym)) {
802+ if (sym && !sym_is_choice(sym)) {
855803 sym_calc_value(sym);
856804 if (!(sym->flags & SYMBOL_WRITE))
857805 goto next_menu;
@@ -911,7 +859,6 @@ int conf_write(const char *name) · 53 unmodified lines
911859 const char *str;
912860 char tmpname[PATH_MAX + 1], oldname[PATH_MAX + 1];
913861 char *env;
914− int i;
915862 bool need_newline = false;
916863
917864 if (!name)
@@ -995,7 +942,7 @@ end_check: · 77 unmodified lines
995942 }
996943 fclose(out);
997944
998− for_all_symbols(i, sym)
945+ for_all_symbols(sym)
999946 sym->flags &= ~SYMBOL_WRITTEN;
1000947
1001948 if (*tmpname) {
@@ -1023,7 +970,6 @@ end_check: · 21 unmodified lines
1023970 static int conf_write_autoconf_cmd(const char *autoconf_name)
1024971 {
1025972 char name[PATH_MAX], tmp[PATH_MAX];
1026− struct file *file;
1027973 FILE *out;
1028974 int ret;
1029975
@@ -1044,15 +990,9 @@ static int conf_write_autoconf_cmd(const char *autoconf_name) · 14 unmodified lines
1044990 return -1;
1045991 }
1046992
1047− fprintf(out, "deps_config := \\\n");
1048− for (file = file_list; file; file = file->next)
1049− fprintf(out, "\t%s \\\n", file->name);
1050−
1051− fprintf(out, "\n%s: $(deps_config)\n\n", autoconf_name);
993+ fprintf(out, "autoconfig := %s\n", autoconf_name);
1052994
1053− env_write_dep(out, autoconf_name);
1054−
1055− fprintf(out, "\n$(deps_config): ;\n");
995+ fputs(str_get(&autoconf_cmd), out);
1056996
1057997 fflush(out);
1058998 ret = ferror(out); /* error check for all fprintf() calls */
@@ -1072,7 +1012,7 @@ static int conf_touch_deps(void) · 13 unmodified lines
10721012 {
10731013 const char *name, *tmp;
10741014 struct symbol *sym;
1075− int res, i;
1015+ int res;
10761016
10771017 name = conf_get_autoconfig_name();
10781018 tmp = strrchr(name, '/');
@@ -1086,7 +1026,7 @@ static int conf_touch_deps(void) · 7 unmodified lines
10861026 conf_read_simple(name, S_DEF_AUTO);
10871027 sym_calc_value(modules_sym);
10881028
1089− for_all_symbols(i, sym) {
1029+ for_all_symbols(sym) {
10901030 sym_calc_value(sym);
10911031 if ((sym->flags & SYMBOL_NO_WRITE) || !sym->name)
10921032 continue;
@@ -1152,7 +1092,7 @@ static int __conf_write_autoconf(const char *filename, · 59 unmodified lines
11521092 char tmp[PATH_MAX];
11531093 FILE *file;
11541094 struct symbol *sym;
1155− int ret, i;
1095+ int ret;
11561096
11571097 if (make_parent_dir(filename))
11581098 return -1;
@@ -1169,7 +1109,7 @@ static int __conf_write_autoconf(const char *filename, · 10 unmodified lines
11691109
11701110 conf_write_heading(file, comment_style);
11711111
1172− for_all_symbols(i, sym)
1112+ for_all_symbols(sym)
11731113 if ((sym->flags & SYMBOL_WRITE) && sym->name)
11741114 print_symbol(file, sym);
11751115
@@ -1192,7 +1132,7 @@ int conf_write_autoconf(int overwrite) · 16 unmodified lines
11921132 {
11931133 struct symbol *sym;
11941134 const char *autoconf_name = conf_get_autoconfig_name();
1195− int ret, i;
1135+ int ret;
11961136
11971137 if (!overwrite && is_present(autoconf_name))
11981138 return 0;
@@ -1204,7 +1144,7 @@ int conf_write_autoconf(int overwrite) · 5 unmodified lines
12041144 if (conf_touch_deps())
12051145 return 1;
12061146
1207− for_all_symbols(i, sym)
1147+ for_all_symbols(sym)
12081148 sym_calc_value(sym);
12091149
12101150 ret = __conf_write_autoconf(conf_get_autoheader_name(),
scripts/kconfig/expr.h+11−18
@@ -12,17 +12,12 @@ extern "C" { · 11 unmodified lines
1212
1313 #include <assert.h>
1414 #include <stdio.h>
15−#include "list.h"
15+#include "list_types.h"
1616 #ifndef __cplusplus
1717 #include <stdbool.h>
1818 #endif
1919
20−struct file {
21− struct file *next;
22− struct file *parent;
23− const char *name;
24− int lineno;
25−};
20+#include "list_types.h"
2621
2722 typedef enum tristate {
2823 no, mod, yes
@@ -81,8 +76,8 @@ enum { · 52 unmodified lines
8176 * SYMBOL_CHOICE bit set in 'flags'.
8277 */
8378 struct symbol {
84− /* The next symbol in the same bucket in the symbol hash table */
85− struct symbol *next;
79+ /* link node for the hash table */
80+ struct hlist_node node;
8681
8782 /* The name of the symbol, e.g. "FOO" for 'config FOO' */
8883 char *name;
@@ -113,6 +108,9 @@ struct symbol { · 24 unmodified lines
113108 */
114109 tristate visible;
115110
111+ /* config entries associated with this symbol */
112+ struct list_head menus;
113+
116114 /* SYMBOL_* flags */
117115 int flags;
118116
@@ -131,8 +129,6 @@ struct symbol { · 12 unmodified lines
131129 struct expr_value implied;
132130 };
133131
134−#define for_all_symbols(i, sym) for (i = 0; i < SYMBOL_HASHSIZE; i++) for (sym = symbol_hash[i]; sym; sym = sym->next)
135−
136132 #define SYMBOL_CONST 0x0001 /* symbol is const */
137133 #define SYMBOL_CHECK 0x0008 /* used during dependency checking */
138134 #define SYMBOL_CHOICE 0x0010 /* start of a choice block (null name) */
@@ -157,7 +153,6 @@ struct symbol { · 18 unmodified lines
157153 #define SYMBOL_NEED_SET_CHOICE_VALUES 0x100000
158154
159155 #define SYMBOL_MAXLENGTH 256
160−#define SYMBOL_HASHSIZE 9973
161156
162157 /* A property represent the config options that can be associated
163158 * with a config "symbol".
@@ -195,7 +190,7 @@ struct property { · 31 unmodified lines
195190 struct menu *menu; /* the menu the property are associated with
196191 * valid for: P_SELECT, P_RANGE, P_CHOICE,
197192 * P_PROMPT, P_DEFAULT, P_MENU, P_COMMENT */
198− struct file *file; /* what file was this property defined */
193+ const char *filename; /* what file was this property defined */
199194 int lineno; /* what lineno was this property defined */
200195 };
201196
@@ -230,6 +225,8 @@ struct menu { · 28 unmodified lines
230225 */
231226 struct symbol *sym;
232227
228+ struct list_head link; /* link to symbol::menus */
229+
233230 /*
234231 * The prompt associated with the node. This holds the prompt for a
235232 * symbol as well as the text for a menu or comment, along with the
@@ -256,7 +253,7 @@ struct menu { · 20 unmodified lines
256253 char *help;
257254
258255 /* The location where the menu node appears in the Kconfig files */
259− struct file *file;
256+ const char *filename;
260257 int lineno;
261258
262259 /* For use by front ends that need to store auxiliary data */
@@ -277,10 +274,6 @@ struct jump_key { · 14 unmodified lines
277274 struct menu *target;
278275 };
279276
280−extern struct file *file_list;
281−extern struct file *current_file;
282−struct file *lookup_file(const char *name);
283−
284277 extern struct symbol symbol_yes, symbol_no, symbol_mod;
285278 extern struct symbol *modules_sym;
286279 extern int cdebug;
scripts/kconfig/hashtable.h+48−0
@@ -0,0 +1,48 @@
1+/* SPDX-License-Identifier: GPL-2.0-only */
2+#ifndef HASHTABLE_H
3+#define HASHTABLE_H
4+
5+#include "array_size.h"
6+#include "list.h"
7+
8+#define HASH_SIZE(name) (ARRAY_SIZE(name))
9+
10+#define HASHTABLE_DECLARE(name, size) struct hlist_head name[size]
11+
12+#define HASHTABLE_DEFINE(name, size) \
13+ HASHTABLE_DECLARE(name, size) = \
14+ { [0 ... ((size) - 1)] = HLIST_HEAD_INIT }
15+
16+#define hash_head(table, key) (&(table)[(key) % HASH_SIZE(table)])
17+
18+/**
19+ * hash_add - add an object to a hashtable
20+ * @table: hashtable to add to
21+ * @node: the &struct hlist_node of the object to be added
22+ * @key: the key of the object to be added
23+ */
24+#define hash_add(table, node, key) \
25+ hlist_add_head(node, hash_head(table, key))
26+
27+/**
28+ * hash_for_each - iterate over a hashtable
29+ * @table: hashtable to iterate
30+ * @obj: the type * to use as a loop cursor for each entry
31+ * @member: the name of the hlist_node within the struct
32+ */
33+#define hash_for_each(table, obj, member) \
34+ for (int _bkt = 0; _bkt < HASH_SIZE(table); _bkt++) \
35+ hlist_for_each_entry(obj, &table[_bkt], member)
36+
37+/**
38+ * hash_for_each_possible - iterate over all possible objects hashing to the
39+ * same bucket
40+ * @table: hashtable to iterate
41+ * @obj: the type * to use as a loop cursor for each entry
42+ * @member: the name of the hlist_node within the struct
43+ * @key: the key of the objects to iterate over
44+ */
45+#define hash_for_each_possible(table, obj, member, key) \
46+ hlist_for_each_entry(obj, hash_head(table, key), member)
47+
48+#endif /* HASHTABLE_H */
scripts/kconfig/internal.h+12−0
@@ -2,8 +2,20 @@ · 1 unmodified line
22 #ifndef INTERNAL_H
33 #define INTERNAL_H
44
5+#include "hashtable.h"
6+
7+#define SYMBOL_HASHSIZE (1U << 14)
8+
9+extern HASHTABLE_DECLARE(sym_hashtable, SYMBOL_HASHSIZE);
10+
11+#define for_all_symbols(sym) \
12+ hash_for_each(sym_hashtable, sym, node)
13+
514 struct menu;
615
716 extern struct menu *current_menu, *current_entry;
817
18+extern const char *cur_filename;
19+extern int cur_lineno;
20+
921 #endif /* INTERNAL_H */
scripts/kconfig/lexer.l+61−69
@@ -14,16 +14,22 @@ · 13 unmodified lines
1414 #include <string.h>
1515
1616 #include "lkc.h"
17+#include "preprocess.h"
18+
1719 #include "parser.tab.h"
1820
1921 #define YY_DECL static int yylex1(void)
2022
2123 #define START_STRSIZE 16
2224
23−static struct {
24− struct file *file;
25− int lineno;
26−} current_pos;
25+/* The Kconfig file currently being parsed. */
26+const char *cur_filename;
27+
28+/*
29+ * The line number of the current statement. This does not match yylineno.
30+ * yylineno is used by the lexer, while cur_lineno is used by the parser.
31+ */
32+int cur_lineno;
2733
2834 static int prev_prev_token = T_EOL;
2935 static int prev_token = T_EOL;
@@ -33,6 +39,9 @@ static int text_size, text_asize; · 3 unmodified lines
3339 struct buffer {
3440 struct buffer *parent;
3541 YY_BUFFER_STATE state;
42+ int yylineno;
43+ const char *filename;
44+ int source_lineno;
3645 };
3746
3847 static struct buffer *current_buf;
@@ -77,7 +86,7 @@ static void warn_ignored_character(char chr) · 38 unmodified lines
7786 {
7887 fprintf(stderr,
7988 "%s:%d:warning: ignoring unsupported character '%c'\n",
80− current_file->name, yylineno, chr);
89+ cur_filename, yylineno, chr);
8190 }
8291 %}
8392
@@ -180,7 +189,7 @@ n [A-Za-z0-9_-] · 96 unmodified lines
180189 \n {
181190 fprintf(stderr,
182191 "%s:%d:warning: multi-line strings not supported\n",
183− zconf_curname(), zconf_lineno());
192+ cur_filename, cur_lineno);
184193 unput('\n');
185194 BEGIN(INITIAL);
186195 yylval.string = text;
@@ -246,9 +255,9 @@ n [A-Za-z0-9_-] · 59 unmodified lines
246255
247256 if (prev_token != T_EOL && prev_token != T_HELPTEXT)
248257 fprintf(stderr, "%s:%d:warning: no new line at end of file\n",
249− current_file->name, yylineno);
258+ cur_filename, yylineno);
250259
251− if (current_file) {
260+ if (current_buf) {
252261 zconf_endfile();
253262 return T_EOL;
254263 }
@@ -267,19 +276,17 @@ repeat: · 12 unmodified lines
267276 token = yylex1();
268277
269278 if (prev_token == T_EOL || prev_token == T_HELPTEXT) {
270− if (token == T_EOL) {
279+ if (token == T_EOL)
271280 /* Do not pass unneeded T_EOL to the parser. */
272281 goto repeat;
273− } else {
282+ else
274283 /*
275− * For the parser, update file/lineno at the first token
284+ * For the parser, update lineno at the first token
276285 * of each statement. Generally, \n is a statement
277286 * terminator in Kconfig, but it is not always true
278287 * because \n could be escaped by a backslash.
279288 */
280− current_pos.file = current_file;
281− current_pos.lineno = yylineno;
282− }
289+ cur_lineno = yylineno;
283290 }
284291
285292 if (prev_prev_token == T_EOL && prev_token == T_WORD &&
@@ -302,8 +309,11 @@ static char *expand_token(const char *in, size_t n) · 16 unmodified lines
302309 new_string();
303310 append_string(in, n);
304311
305− /* get the whole line because we do not know the end of token. */
306− while ((c = input()) != EOF) {
312+ /*
313+ * get the whole line because we do not know the end of token.
314+ * input() returns 0 (not EOF!) when it reachs the end of file.
315+ */
316+ while ((c = input()) != 0) {
307317 if (c == '\n') {
308318 unput(c);
309319 break;
@@ -391,78 +401,60 @@ void zconf_initscan(const char *name) · 81 unmodified lines
391401 exit(1);
392402 }
393403
394− current_buf = xmalloc(sizeof(*current_buf));
395− memset(current_buf, 0, sizeof(*current_buf));
396−
397− current_file = file_lookup(name);
404+ cur_filename = file_lookup(name);
398405 yylineno = 1;
399406 }
400407
401408 void zconf_nextfile(const char *name)
402409 {
403− struct file *iter;
404− struct file *file = file_lookup(name);
405410 struct buffer *buf = xmalloc(sizeof(*buf));
406− memset(buf, 0, sizeof(*buf));
411+ bool recur_include = false;
407412
408− current_buf->state = YY_CURRENT_BUFFER;
409− yyin = zconf_fopen(file->name);
413+ buf->state = YY_CURRENT_BUFFER;
414+ buf->yylineno = yylineno;
415+ buf->filename = cur_filename;
416+ buf->source_lineno = cur_lineno;
417+ buf->parent = current_buf;
418+ current_buf = buf;
419+ yyin = zconf_fopen(name);
410420 if (!yyin) {
411421 fprintf(stderr, "%s:%d: can't open file \"%s\"\n",
412− zconf_curname(), zconf_lineno(), file->name);
422+ cur_filename, cur_lineno, name);
413423 exit(1);
414424 }
415425 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
416− buf->parent = current_buf;
417− current_buf = buf;
418426
419− current_file->lineno = yylineno;
420− file->parent = current_file;
421−
422− for (iter = current_file; iter; iter = iter->parent) {
423− if (!strcmp(iter->name, file->name)) {
424− fprintf(stderr,
425− "Recursive inclusion detected.\n"
426− "Inclusion path:\n"
427− " current file : %s\n", file->name);
428− iter = file;
429− do {
430− iter = iter->parent;
431− fprintf(stderr, " included from: %s:%d\n",
432− iter->name, iter->lineno - 1);
433− } while (strcmp(iter->name, file->name));
434− exit(1);
435− }
427+ for (buf = current_buf; buf; buf = buf->parent) {
428+ if (!strcmp(buf->filename, name))
429+ recur_include = true;
436430 }
437431
438− yylineno = 1;
439− current_file = file;
440−}
441−
442−static void zconf_endfile(void)
443−{
444− struct buffer *parent;
445−
446− current_file = current_file->parent;
447− if (current_file)
448− yylineno = current_file->lineno;
432+ if (recur_include) {
433+ fprintf(stderr,
434+ "Recursive inclusion detected.\n"
435+ "Inclusion path:\n"
436+ " current file : %s\n", name);
449437
450− parent = current_buf->parent;
451− if (parent) {
452− fclose(yyin);
453− yy_delete_buffer(YY_CURRENT_BUFFER);
454− yy_switch_to_buffer(parent->state);
438+ for (buf = current_buf; buf; buf = buf->parent)
439+ fprintf(stderr, " included from: %s:%d\n",
440+ buf->filename, buf->source_lineno);
441+ exit(1);
455442 }
456− free(current_buf);
457− current_buf = parent;
458−}
459443
460−int zconf_lineno(void)
461−{
462− return current_pos.lineno;
444+ yylineno = 1;
445+ cur_filename = file_lookup(name);
463446 }
464447
465−const char *zconf_curname(void)
448+static void zconf_endfile(void)
466449 {
467− return current_pos.file ? current_pos.file->name : "<none>";
450+ struct buffer *tmp;
451+
452+ fclose(yyin);
453+ yy_delete_buffer(YY_CURRENT_BUFFER);
454+ yy_switch_to_buffer(current_buf->state);
455+ yylineno = current_buf->yylineno;
456+ cur_filename = current_buf->filename;
457+ tmp = current_buf;
458+ current_buf = current_buf->parent;
459+ free(tmp);
468460 }
scripts/kconfig/list.h+189−65
@@ -2,29 +2,39 @@ · 1 unmodified line
22 #ifndef LIST_H
33 #define LIST_H
44
5−/*
6− * Copied from include/linux/...
7− */
5+#include <stddef.h>
86
9−#undef offsetof
10−#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
7+#include "list_types.h"
8+
9+/* Are two types/vars the same type (ignoring qualifiers)? */
10+#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
1111
1212 /**
1313 * container_of - cast a member of a structure out to the containing structure
14− * @ptr: the pointer to the member.
15− * @type: the type of the container struct this is embedded in.
16− * @member: the name of the member within the struct.
14+ * @ptr: the pointer to the member.
15+ * @type: the type of the container struct this is embedded in.
16+ * @member: the name of the member within the struct.
1717 *
1818 */
19−#define container_of(ptr, type, member) ({ \
20− const typeof( ((type *)0)->member ) *__mptr = (ptr); \
21− (type *)( (char *)__mptr - offsetof(type,member) );})
22−
19+#define container_of(ptr, type, member) ({ \
20+ void *__mptr = (void *)(ptr); \
21+ _Static_assert(__same_type(*(ptr), ((type *)0)->member) || \
22+ __same_type(*(ptr), void), \
23+ "pointer type mismatch in container_of()"); \
24+ ((type *)(__mptr - offsetof(type, member))); })
2325
24−struct list_head {
25− struct list_head *next, *prev;
26−};
26+#define LIST_POISON1 ((void *) 0x100)
27+#define LIST_POISON2 ((void *) 0x122)
2728
29+/*
30+ * Circular doubly linked list implementation.
31+ *
32+ * Some of the internal functions ("__xxx") are useful when
33+ * manipulating whole lists rather than single entries, as
34+ * sometimes we already know the next/prev entries and we can
35+ * generate better code by using them directly rather than
36+ * using the generic single-entry routines.
37+ */
2838
2939 #define LIST_HEAD_INIT(name) { &(name), &(name) }
3040
@@ -32,45 +42,16 @@ struct list_head { · 1 unmodified line
3242 struct list_head name = LIST_HEAD_INIT(name)
3343
3444 /**
35− * list_entry - get the struct for this entry
36− * @ptr: the &struct list_head pointer.
37− * @type: the type of the struct this is embedded in.
38− * @member: the name of the list_head within the struct.
39− */
40−#define list_entry(ptr, type, member) \
41− container_of(ptr, type, member)
42−
43−/**
44− * list_for_each_entry - iterate over list of given type
45− * @pos: the type * to use as a loop cursor.
46− * @head: the head for your list.
47− * @member: the name of the list_head within the struct.
48− */
49−#define list_for_each_entry(pos, head, member) \
50− for (pos = list_entry((head)->next, typeof(*pos), member); \
51− &pos->member != (head); \
52− pos = list_entry(pos->member.next, typeof(*pos), member))
53−
54−/**
55− * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
56− * @pos: the type * to use as a loop cursor.
57− * @n: another type * to use as temporary storage
58− * @head: the head for your list.
59− * @member: the name of the list_head within the struct.
60− */
61−#define list_for_each_entry_safe(pos, n, head, member) \
62− for (pos = list_entry((head)->next, typeof(*pos), member), \
63− n = list_entry(pos->member.next, typeof(*pos), member); \
64− &pos->member != (head); \
65− pos = n, n = list_entry(n->member.next, typeof(*n), member))
66−
67−/**
68− * list_empty - tests whether a list is empty
69− * @head: the list to test.
45+ * INIT_LIST_HEAD - Initialize a list_head structure
46+ * @list: list_head structure to be initialized.
47+ *
48+ * Initializes the list_head to point to itself. If it is a list header,
49+ * the result is an empty list.
7050 */
71−static inline int list_empty(const struct list_head *head)
51+static inline void INIT_LIST_HEAD(struct list_head *list)
7252 {
73− return head->next == head;
53+ list->next = list;
54+ list->prev = list;
7455 }
7556
7657 /*
@@ -79,14 +60,27 @@ static inline int list_empty(const struct list_head *head) · 2 unmodified lines
7960 * This is only for internal list manipulation where we know
8061 * the prev/next entries already!
8162 */
82−static inline void __list_add(struct list_head *_new,
63+static inline void __list_add(struct list_head *new,
8364 struct list_head *prev,
8465 struct list_head *next)
8566 {
86− next->prev = _new;
87− _new->next = next;
88− _new->prev = prev;
89− prev->next = _new;
67+ next->prev = new;
68+ new->next = next;
69+ new->prev = prev;
70+ prev->next = new;
71+}
72+
73+/**
74+ * list_add - add a new entry
75+ * @new: new entry to be added
76+ * @head: list head to add it after
77+ *
78+ * Insert a new entry after the specified head.
79+ * This is good for implementing stacks.
80+ */
81+static inline void list_add(struct list_head *new, struct list_head *head)
82+{
83+ __list_add(new, head, head->next);
9084 }
9185
9286 /**
@@ -97,9 +91,9 @@ static inline void __list_add(struct list_head *_new, · 4 unmodified lines
9791 * Insert a new entry before the specified head.
9892 * This is useful for implementing queues.
9993 */
100−static inline void list_add_tail(struct list_head *_new, struct list_head *head)
94+static inline void list_add_tail(struct list_head *new, struct list_head *head)
10195 {
102− __list_add(_new, head->prev, head);
96+ __list_add(new, head->prev, head);
10397 }
10498
10599 /*
@@ -115,8 +109,11 @@ static inline void __list_del(struct list_head *prev, struct list_head *next) · 9 unmodified lines
115109 prev->next = next;
116110 }
117111
118−#define LIST_POISON1 ((void *) 0x00100100)
119−#define LIST_POISON2 ((void *) 0x00200200)
112+static inline void __list_del_entry(struct list_head *entry)
113+{
114+ __list_del(entry->prev, entry->next);
115+}
116+
120117 /**
121118 * list_del - deletes entry from list.
122119 * @entry: the element to delete from the list.
@@ -125,8 +122,135 @@ static inline void __list_del(struct list_head *prev, struct list_head *next) · 2 unmodified lines
125122 */
126123 static inline void list_del(struct list_head *entry)
127124 {
128− __list_del(entry->prev, entry->next);
129− entry->next = (struct list_head*)LIST_POISON1;
130− entry->prev = (struct list_head*)LIST_POISON2;
125+ __list_del_entry(entry);
126+ entry->next = LIST_POISON1;
127+ entry->prev = LIST_POISON2;
128+}
129+
130+/**
131+ * list_is_head - tests whether @list is the list @head
132+ * @list: the entry to test
133+ * @head: the head of the list
134+ */
135+static inline int list_is_head(const struct list_head *list, const struct list_head *head)
136+{
137+ return list == head;
138+}
139+
140+/**
141+ * list_empty - tests whether a list is empty
142+ * @head: the list to test.
143+ */
144+static inline int list_empty(const struct list_head *head)
145+{
146+ return head->next == head;
147+}
148+
149+/**
150+ * list_entry - get the struct for this entry
151+ * @ptr: the &struct list_head pointer.
152+ * @type: the type of the struct this is embedded in.
153+ * @member: the name of the list_head within the struct.
154+ */
155+#define list_entry(ptr, type, member) \
156+ container_of(ptr, type, member)
157+
158+/**
159+ * list_first_entry - get the first element from a list
160+ * @ptr: the list head to take the element from.
161+ * @type: the type of the struct this is embedded in.
162+ * @member: the name of the list_head within the struct.
163+ *
164+ * Note, that list is expected to be not empty.
165+ */
166+#define list_first_entry(ptr, type, member) \
167+ list_entry((ptr)->next, type, member)
168+
169+/**
170+ * list_next_entry - get the next element in list
171+ * @pos: the type * to cursor
172+ * @member: the name of the list_head within the struct.
173+ */
174+#define list_next_entry(pos, member) \
175+ list_entry((pos)->member.next, typeof(*(pos)), member)
176+
177+/**
178+ * list_entry_is_head - test if the entry points to the head of the list
179+ * @pos: the type * to cursor
180+ * @head: the head for your list.
181+ * @member: the name of the list_head within the struct.
182+ */
183+#define list_entry_is_head(pos, head, member) \
184+ (&pos->member == (head))
185+
186+/**
187+ * list_for_each_entry - iterate over list of given type
188+ * @pos: the type * to use as a loop cursor.
189+ * @head: the head for your list.
190+ * @member: the name of the list_head within the struct.
191+ */
192+#define list_for_each_entry(pos, head, member) \
193+ for (pos = list_first_entry(head, typeof(*pos), member); \
194+ !list_entry_is_head(pos, head, member); \
195+ pos = list_next_entry(pos, member))
196+
197+/**
198+ * list_for_each_entry_safe - iterate over list of given type. Safe against removal of list entry
199+ * @pos: the type * to use as a loop cursor.
200+ * @n: another type * to use as temporary storage
201+ * @head: the head for your list.
202+ * @member: the name of the list_head within the struct.
203+ */
204+#define list_for_each_entry_safe(pos, n, head, member) \
205+ for (pos = list_first_entry(head, typeof(*pos), member), \
206+ n = list_next_entry(pos, member); \
207+ !list_entry_is_head(pos, head, member); \
208+ pos = n, n = list_next_entry(n, member))
209+
210+/*
211+ * Double linked lists with a single pointer list head.
212+ * Mostly useful for hash tables where the two pointer list head is
213+ * too wasteful.
214+ * You lose the ability to access the tail in O(1).
215+ */
216+
217+#define HLIST_HEAD_INIT { .first = NULL }
218+
219+/**
220+ * hlist_add_head - add a new entry at the beginning of the hlist
221+ * @n: new entry to be added
222+ * @h: hlist head to add it after
223+ *
224+ * Insert a new entry after the specified head.
225+ * This is good for implementing stacks.
226+ */
227+static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
228+{
229+ struct hlist_node *first = h->first;
230+
231+ n->next = first;
232+ if (first)
233+ first->pprev = &n->next;
234+ h->first = n;
235+ n->pprev = &h->first;
131236 }
132−#endif
237+
238+#define hlist_entry(ptr, type, member) container_of(ptr, type, member)
239+
240+#define hlist_entry_safe(ptr, type, member) \
241+ ({ typeof(ptr) ____ptr = (ptr); \
242+ ____ptr ? hlist_entry(____ptr, type, member) : NULL; \
243+ })
244+
245+/**
246+ * hlist_for_each_entry - iterate over list of given type
247+ * @pos: the type * to use as a loop cursor.
248+ * @head: the head for your list.
249+ * @member: the name of the hlist_node within the struct.
250+ */
251+#define hlist_for_each_entry(pos, head, member) \
252+ for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
253+ pos; \
254+ pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
255+
256+#endif /* LIST_H */
scripts/kconfig/list_types.h+17−0
@@ -0,0 +1,17 @@
1+/* SPDX-License-Identifier: GPL-2.0 */
2+#ifndef LIST_TYPES_H
3+#define LIST_TYPES_H
4+
5+struct list_head {
6+ struct list_head *next, *prev;
7+};
8+
9+struct hlist_head {
10+ struct hlist_node *first;
11+};
12+
13+struct hlist_node {
14+ struct hlist_node *next, **pprev;
15+};
16+
17+#endif /* LIST_TYPES_H */
scripts/kconfig/lkc.h+3−3
@@ -36,10 +36,9 @@ void zconf_starthelp(void); · 35 unmodified lines
3636 FILE *zconf_fopen(const char *name);
3737 void zconf_initscan(const char *name);
3838 void zconf_nextfile(const char *name);
39−int zconf_lineno(void);
40−const char *zconf_curname(void);
4139
4240 /* confdata.c */
41+extern struct gstr autoconf_cmd;
4342 const char *conf_get_configname(void);
4443 void set_all_choice_values(struct symbol *csym);
4544
@@ -53,7 +52,8 @@ static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out) · 7 unmodified lines
5352 }
5453
5554 /* util.c */
56−struct file *file_lookup(const char *name);
55+unsigned int strhash(const char *s);
56+const char *file_lookup(const char *name);
5757 void *xmalloc(size_t size);
5858 void *xcalloc(size_t nmemb, size_t size);
5959 void *xrealloc(void *p, size_t size);
scripts/kconfig/lkc_proto.h+0−15
@@ -18,8 +18,6 @@ void conf_set_message_callback(void (*fn)(const char *s)); · 17 unmodified lines
1818 bool conf_errors(void);
1919
2020 /* symbol.c */
21−extern struct symbol * symbol_hash[SYMBOL_HASHSIZE];
22−
2321 struct symbol * sym_lookup(const char *name, int flags);
2422 struct symbol * sym_find(const char *name);
2523 void print_symbol_for_listconfig(struct symbol *sym);
@@ -40,19 +38,6 @@ const char * sym_get_string_value(struct symbol *sym); · 14 unmodified lines
4038
4139 const char * prop_get_type_name(enum prop_type type);
4240
43−/* preprocess.c */
44−enum variable_flavor {
45− VAR_SIMPLE,
46− VAR_RECURSIVE,
47− VAR_APPEND,
48−};
49−void env_write_dep(FILE *f, const char *auto_conf_name);
50−void variable_add(const char *name, const char *value,
51− enum variable_flavor flavor);
52−void variable_all_del(void);
53−char *expand_dollar(const char **str);
54−char *expand_one_token(const char **str);
55−
5641 /* expr.c */
5742 void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken);
5843
scripts/kconfig/lxdialog/checklist.c+2−3
@@ -188,9 +188,8 @@ do_resize: · 187 unmodified lines
188188
189189 print_buttons(dialog, height, width, 0);
190190
191− wnoutrefresh(dialog);
192− wnoutrefresh(list);
193− doupdate();
191+ wmove(list, choice, check_x + 1);
192+ wrefresh(list);
194193
195194 while (key != KEY_ESC) {
196195 key = wgetch(dialog);
scripts/kconfig/lxdialog/dialog.h+0−4
@@ -91,10 +91,6 @@ struct dialog_info { · 90 unmodified lines
9191 struct dialog_color button_label_active;
9292 struct dialog_color button_label_inactive;
9393 struct dialog_color inputbox;
94− struct dialog_color inputbox_border;
95− struct dialog_color searchbox;
96− struct dialog_color searchbox_title;
97− struct dialog_color searchbox_border;
9894 struct dialog_color position_indicator;
9995 struct dialog_color menubox;
10096 struct dialog_color menubox_border;
scripts/kconfig/lxdialog/util.c+1−19
@@ -29,10 +29,6 @@ static void set_mono_theme(void) · 28 unmodified lines
2929 dlg.button_label_active.atr = A_REVERSE;
3030 dlg.button_label_inactive.atr = A_NORMAL;
3131 dlg.inputbox.atr = A_NORMAL;
32− dlg.inputbox_border.atr = A_NORMAL;
33− dlg.searchbox.atr = A_NORMAL;
34− dlg.searchbox_title.atr = A_BOLD;
35− dlg.searchbox_border.atr = A_NORMAL;
3632 dlg.position_indicator.atr = A_BOLD;
3733 dlg.menubox.atr = A_NORMAL;
3834 dlg.menubox_border.atr = A_NORMAL;
@@ -69,10 +65,6 @@ static void set_classic_theme(void) · 30 unmodified lines
6965 DLG_COLOR(button_label_active, COLOR_YELLOW, COLOR_BLUE, true);
7066 DLG_COLOR(button_label_inactive, COLOR_BLACK, COLOR_WHITE, true);
7167 DLG_COLOR(inputbox, COLOR_BLACK, COLOR_WHITE, false);
72− DLG_COLOR(inputbox_border, COLOR_BLACK, COLOR_WHITE, false);
73− DLG_COLOR(searchbox, COLOR_BLACK, COLOR_WHITE, false);
74− DLG_COLOR(searchbox_title, COLOR_YELLOW, COLOR_WHITE, true);
75− DLG_COLOR(searchbox_border, COLOR_WHITE, COLOR_WHITE, true);
7668 DLG_COLOR(position_indicator, COLOR_YELLOW, COLOR_WHITE, true);
7769 DLG_COLOR(menubox, COLOR_BLACK, COLOR_WHITE, false);
7870 DLG_COLOR(menubox_border, COLOR_WHITE, COLOR_WHITE, true);
@@ -101,14 +93,9 @@ static void set_blackbg_theme(void) · 22 unmodified lines
10193 DLG_COLOR(button_key_active, COLOR_YELLOW, COLOR_RED, true);
10294 DLG_COLOR(button_key_inactive, COLOR_RED, COLOR_BLACK, false);
10395 DLG_COLOR(button_label_active, COLOR_WHITE, COLOR_RED, false);
104− DLG_COLOR(button_label_inactive, COLOR_BLACK, COLOR_BLACK, true);
96+ DLG_COLOR(button_label_inactive, COLOR_WHITE, COLOR_BLACK, false);
10597
10698 DLG_COLOR(inputbox, COLOR_YELLOW, COLOR_BLACK, false);
107− DLG_COLOR(inputbox_border, COLOR_YELLOW, COLOR_BLACK, false);
108−
109− DLG_COLOR(searchbox, COLOR_YELLOW, COLOR_BLACK, false);
110− DLG_COLOR(searchbox_title, COLOR_YELLOW, COLOR_BLACK, true);
111− DLG_COLOR(searchbox_border, COLOR_BLACK, COLOR_BLACK, true);
11299
113100 DLG_COLOR(position_indicator, COLOR_RED, COLOR_BLACK, false);
114101
@@ -136,7 +123,6 @@ static void set_bluetitle_theme(void) · 21 unmodified lines
136123 DLG_COLOR(title, COLOR_BLUE, COLOR_WHITE, true);
137124 DLG_COLOR(button_key_active, COLOR_YELLOW, COLOR_BLUE, true);
138125 DLG_COLOR(button_label_active, COLOR_WHITE, COLOR_BLUE, true);
139− DLG_COLOR(searchbox_title, COLOR_BLUE, COLOR_WHITE, true);
140126 DLG_COLOR(position_indicator, COLOR_BLUE, COLOR_WHITE, true);
141127 DLG_COLOR(tag, COLOR_BLUE, COLOR_WHITE, true);
142128 DLG_COLOR(tag_key, COLOR_BLUE, COLOR_WHITE, true);
@@ -189,10 +175,6 @@ static void init_dialog_colors(void) · 46 unmodified lines
189175 init_one_color(&dlg.button_label_active);
190176 init_one_color(&dlg.button_label_inactive);
191177 init_one_color(&dlg.inputbox);
192− init_one_color(&dlg.inputbox_border);
193− init_one_color(&dlg.searchbox);
194− init_one_color(&dlg.searchbox_title);
195− init_one_color(&dlg.searchbox_border);
196178 init_one_color(&dlg.position_indicator);
197179 init_one_color(&dlg.menubox);
198180 init_one_color(&dlg.menubox_border);
scripts/kconfig/mconf.c+1−0
@@ -19,6 +19,7 @@ · 18 unmodified lines
1919 #include <signal.h>
2020 #include <unistd.h>
2121
22+#include "list.h"
2223 #include "lkc.h"
2324 #include "lxdialog/dialog.h"
2425 #include "mnconf-common.h"
scripts/kconfig/menu.c+20−28
@@ -10,20 +10,18 @@ · 9 unmodified lines
1010
1111 #include "lkc.h"
1212 #include "internal.h"
13+#include "list.h"
1314
1415 static const char nohelp_text[] = "There is no help available for this option.";
1516
1617 struct menu rootmenu;
1718 static struct menu **last_entry_ptr;
1819
19−struct file *file_list;
20−struct file *current_file;
21−
2220 void menu_warn(struct menu *menu, const char *fmt, ...)
2321 {
2422 va_list ap;
2523 va_start(ap, fmt);
26− fprintf(stderr, "%s:%d:warning: ", menu->file->name, menu->lineno);
24+ fprintf(stderr, "%s:%d:warning: ", menu->filename, menu->lineno);
2725 vfprintf(stderr, fmt, ap);
2826 fprintf(stderr, "\n");
2927 va_end(ap);
@@ -33,7 +31,7 @@ static void prop_warn(struct property *prop, const char *fmt, ...) · 3 unmodified lines
3331 {
3432 va_list ap;
3533 va_start(ap, fmt);
36− fprintf(stderr, "%s:%d:warning: ", prop->file->name, prop->lineno);
34+ fprintf(stderr, "%s:%d:warning: ", prop->filename, prop->lineno);
3735 vfprintf(stderr, fmt, ap);
3836 fprintf(stderr, "\n");
3937 va_end(ap);
@@ -53,14 +51,16 @@ void menu_add_entry(struct symbol *sym) · 13 unmodified lines
5351 memset(menu, 0, sizeof(*menu));
5452 menu->sym = sym;
5553 menu->parent = current_menu;
56− menu->file = current_file;
57− menu->lineno = zconf_lineno();
54+ menu->filename = cur_filename;
55+ menu->lineno = cur_lineno;
5856
5957 *last_entry_ptr = menu;
6058 last_entry_ptr = &menu->next;
6159 current_entry = menu;
62− if (sym)
60+ if (sym) {
6361 menu_add_symbol(P_SYMBOL, sym, NULL);
62+ list_add_tail(&menu->link, &sym->menus);
63+ }
6464 }
6565
6666 struct menu *menu_add_menu(void)
@@ -134,8 +134,8 @@ static struct property *menu_add_prop(enum prop_type type, struct expr *expr, · 67 unmodified lines
134134 prop = xmalloc(sizeof(*prop));
135135 memset(prop, 0, sizeof(*prop));
136136 prop->type = type;
137− prop->file = current_file;
138− prop->lineno = zconf_lineno();
137+ prop->filename = cur_filename;
138+ prop->lineno = cur_lineno;
139139 prop->menu = current_entry;
140140 prop->expr = expr;
141141 prop->visible.expr = dep;
@@ -307,12 +307,6 @@ void menu_finalize(struct menu *parent) · 165 unmodified lines
307307 }
308308 }
309309 }
310− /* set the type of the remaining choice values */
311− for (menu = parent->list; menu; menu = menu->next) {
312− current_entry = menu;
313− if (menu->sym && menu->sym->type == S_UNKNOWN)
314− menu_set_type(sym->type);
315− }
316310
317311 /*
318312 * Use the choice itself as the parent dependency of
@@ -567,9 +561,6 @@ void menu_finalize(struct menu *parent) · 248 unmodified lines
567561 if (sym->type == S_UNKNOWN)
568562 menu_warn(parent, "config symbol defined without type");
569563
570− if (sym_is_choice(sym) && !parent->prompt)
571− menu_warn(parent, "choice must have a prompt");
572−
573564 /* Check properties connected to this symbol */
574565 sym_check_prop(sym);
575566 sym->flags |= SYMBOL_WARNED;
@@ -676,7 +667,7 @@ struct menu *menu_get_parent_menu(struct menu *menu) · 100 unmodified lines
676667 static void get_def_str(struct gstr *r, struct menu *menu)
677668 {
678669 str_printf(r, "Defined at %s:%d\n",
679− menu->file->name, menu->lineno);
670+ menu->filename, menu->lineno);
680671 }
681672
682673 static void get_dep_str(struct gstr *r, struct expr *expr, const char *prefix)
@@ -777,6 +768,7 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym, · 94 unmodified lines
777768 struct list_head *head)
778769 {
779770 struct property *prop;
771+ struct menu *menu;
780772
781773 if (sym && sym->name) {
782774 str_printf(r, "Symbol: %s [=%s]\n", sym->name,
@@ -793,17 +785,17 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym, · 10 unmodified lines
793785 }
794786
795787 /* Print the definitions with prompts before the ones without */
796− for_all_properties(sym, prop, P_SYMBOL) {
797− if (prop->menu->prompt) {
798− get_def_str(r, prop->menu);
799− get_prompt_str(r, prop->menu->prompt, head);
788+ list_for_each_entry(menu, &sym->menus, link) {
789+ if (menu->prompt) {
790+ get_def_str(r, menu);
791+ get_prompt_str(r, menu->prompt, head);
800792 }
801793 }
802794
803− for_all_properties(sym, prop, P_SYMBOL) {
804− if (!prop->menu->prompt) {
805− get_def_str(r, prop->menu);
806− get_dep_str(r, prop->menu->dep, " Depends on: ");
795+ list_for_each_entry(menu, &sym->menus, link) {
796+ if (!menu->prompt) {
797+ get_def_str(r, menu);
798+ get_dep_str(r, menu->dep, " Depends on: ");
807799 }
808800 }
809801
scripts/kconfig/nconf.c+1−0
@@ -11,6 +11,7 @@ · 10 unmodified lines
1111 #include <strings.h>
1212 #include <stdlib.h>
1313
14+#include "list.h"
1415 #include "lkc.h"
1516 #include "mnconf-common.h"
1617 #include "nconf.h"
scripts/kconfig/parser.y+76−49
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313
1414 #include "lkc.h"
1515 #include "internal.h"
16+#include "preprocess.h"
1617
1718 #define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
1819
@@ -27,8 +28,6 @@ static void zconf_error(const char *err, ...); · 8 unmodified lines
2728 static bool zconf_endtoken(const char *tokenname,
2829 const char *expected_tokenname);
2930
30−struct symbol *symbol_hash[SYMBOL_HASHSIZE];
31−
3231 struct menu *current_menu, *current_entry;
3332
3433 %}
@@ -95,12 +94,12 @@ struct menu *current_menu, *current_entry; · 60 unmodified lines
9594 %type <expr> if_expr
9695 %type <string> end
9796 %type <menu> if_entry menu_entry choice_entry
98−%type <string> word_opt assign_val
97+%type <string> assign_val
9998 %type <flavor> assign_op
10099
101100 %destructor {
102101 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
103− $$->file->name, $$->lineno);
102+ $$->filename, $$->lineno);
104103 if (current_menu == $$)
105104 menu_end_menu();
106105 } if_entry menu_entry choice_entry
@@ -143,19 +142,19 @@ config_entry_start: T_CONFIG nonconst_symbol T_EOL · 36 unmodified lines
143142 {
144143 $2->flags |= SYMBOL_OPTIONAL;
145144 menu_add_entry($2);
146− printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2->name);
145+ printd(DEBUG_PARSE, "%s:%d:config %s\n", cur_filename, cur_lineno, $2->name);
147146 };
148147
149148 config_stmt: config_entry_start config_option_list
150149 {
151− printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
150+ printd(DEBUG_PARSE, "%s:%d:endconfig\n", cur_filename, cur_lineno);
152151 };
153152
154153 menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL
155154 {
156155 $2->flags |= SYMBOL_OPTIONAL;
157156 menu_add_entry($2);
158− printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2->name);
157+ printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", cur_filename, cur_lineno, $2->name);
159158 };
160159
161160 menuconfig_stmt: menuconfig_entry_start config_option_list
@@ -164,7 +163,7 @@ menuconfig_stmt: menuconfig_entry_start config_option_list · 2 unmodified lines
164163 current_entry->prompt->type = P_MENU;
165164 else
166165 zconfprint("warning: menuconfig statement without prompt");
167− printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
166+ printd(DEBUG_PARSE, "%s:%d:endconfig\n", cur_filename, cur_lineno);
168167 };
169168
170169 config_option_list:
@@ -177,15 +176,13 @@ config_option_list: · 6 unmodified lines
177176 config_option: type prompt_stmt_opt T_EOL
178177 {
179178 menu_set_type($1);
180− printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
181− zconf_curname(), zconf_lineno(),
182− $1);
179+ printd(DEBUG_PARSE, "%s:%d:type(%u)\n", cur_filename, cur_lineno, $1);
183180 };
184181
185182 config_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL
186183 {
187184 menu_add_prompt(P_PROMPT, $2, $3);
188− printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
185+ printd(DEBUG_PARSE, "%s:%d:prompt\n", cur_filename, cur_lineno);
189186 };
190187
191188 config_option: default expr if_expr T_EOL
@@ -193,27 +190,26 @@ config_option: default expr if_expr T_EOL · 1 unmodified line
193190 menu_add_expr(P_DEFAULT, $2, $3);
194191 if ($1 != S_UNKNOWN)
195192 menu_set_type($1);
196− printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
197− zconf_curname(), zconf_lineno(),
193+ printd(DEBUG_PARSE, "%s:%d:default(%u)\n", cur_filename, cur_lineno,
198194 $1);
199195 };
200196
201197 config_option: T_SELECT nonconst_symbol if_expr T_EOL
202198 {
203199 menu_add_symbol(P_SELECT, $2, $3);
204− printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
200+ printd(DEBUG_PARSE, "%s:%d:select\n", cur_filename, cur_lineno);
205201 };
206202
207203 config_option: T_IMPLY nonconst_symbol if_expr T_EOL
208204 {
209205 menu_add_symbol(P_IMPLY, $2, $3);
210− printd(DEBUG_PARSE, "%s:%d:imply\n", zconf_curname(), zconf_lineno());
206+ printd(DEBUG_PARSE, "%s:%d:imply\n", cur_filename, cur_lineno);
211207 };
212208
213209 config_option: T_RANGE symbol symbol if_expr T_EOL
214210 {
215211 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
216− printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
212+ printd(DEBUG_PARSE, "%s:%d:range\n", cur_filename, cur_lineno);
217213 };
218214
219215 config_option: T_MODULES T_EOL
@@ -226,18 +222,23 @@ config_option: T_MODULES T_EOL · 6 unmodified lines
226222
227223 /* choice entry */
228224
229−choice: T_CHOICE word_opt T_EOL
225+choice: T_CHOICE T_EOL
230226 {
231− struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE);
227+ struct symbol *sym = sym_lookup(NULL, SYMBOL_CHOICE);
232228 sym->flags |= SYMBOL_NO_WRITE;
233229 menu_add_entry(sym);
234230 menu_add_expr(P_CHOICE, NULL, NULL);
235− free($2);
236− printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
231+ printd(DEBUG_PARSE, "%s:%d:choice\n", cur_filename, cur_lineno);
237232 };
238233
239234 choice_entry: choice choice_option_list
240235 {
236+ if (!current_entry->prompt) {
237+ fprintf(stderr, "%s:%d: error: choice must have a prompt\n",
238+ current_entry->filename, current_entry->lineno);
239+ yynerrs++;
240+ }
241+
241242 $$ = menu_add_menu();
242243 };
243244
@@ -245,7 +246,7 @@ choice_end: end · 1 unmodified line
245246 {
246247 if (zconf_endtoken($1, "choice")) {
247248 menu_end_menu();
248− printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
249+ printd(DEBUG_PARSE, "%s:%d:endchoice\n", cur_filename, cur_lineno);
249250 }
250251 };
251252
@@ -262,27 +263,25 @@ choice_option_list: · 10 unmodified lines
262263 choice_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL
263264 {
264265 menu_add_prompt(P_PROMPT, $2, $3);
265− printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
266+ printd(DEBUG_PARSE, "%s:%d:prompt\n", cur_filename, cur_lineno);
266267 };
267268
268269 choice_option: logic_type prompt_stmt_opt T_EOL
269270 {
270271 menu_set_type($1);
271− printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
272− zconf_curname(), zconf_lineno(), $1);
272+ printd(DEBUG_PARSE, "%s:%d:type(%u)\n", cur_filename, cur_lineno, $1);
273273 };
274274
275275 choice_option: T_OPTIONAL T_EOL
276276 {
277277 current_entry->sym->flags |= SYMBOL_OPTIONAL;
278− printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
278+ printd(DEBUG_PARSE, "%s:%d:optional\n", cur_filename, cur_lineno);
279279 };
280280
281281 choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL
282282 {
283283 menu_add_symbol(P_DEFAULT, $2, $3);
284− printd(DEBUG_PARSE, "%s:%d:default\n",
285− zconf_curname(), zconf_lineno());
284+ printd(DEBUG_PARSE, "%s:%d:default\n", cur_filename, cur_lineno);
286285 };
287286
288287 type:
@@ -304,7 +303,7 @@ default: · 15 unmodified lines
304303
305304 if_entry: T_IF expr T_EOL
306305 {
307− printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
306+ printd(DEBUG_PARSE, "%s:%d:if\n", cur_filename, cur_lineno);
308307 menu_add_entry(NULL);
309308 menu_add_dep($2);
310309 $$ = menu_add_menu();
@@ -314,7 +313,7 @@ if_end: end · 3 unmodified lines
314313 {
315314 if (zconf_endtoken($1, "if")) {
316315 menu_end_menu();
317− printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
316+ printd(DEBUG_PARSE, "%s:%d:endif\n", cur_filename, cur_lineno);
318317 }
319318 };
320319
@@ -330,7 +329,7 @@ menu: T_MENU T_WORD_QUOTE T_EOL · 9 unmodified lines
330329 {
331330 menu_add_entry(NULL);
332331 menu_add_prompt(P_MENU, $2, NULL);
333− printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
332+ printd(DEBUG_PARSE, "%s:%d:menu\n", cur_filename, cur_lineno);
334333 };
335334
336335 menu_entry: menu menu_option_list
@@ -342,7 +341,7 @@ menu_end: end · 5 unmodified lines
342341 {
343342 if (zconf_endtoken($1, "menu")) {
344343 menu_end_menu();
345− printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
344+ printd(DEBUG_PARSE, "%s:%d:endmenu\n", cur_filename, cur_lineno);
346345 }
347346 };
348347
@@ -357,7 +356,7 @@ menu_option_list: · 8 unmodified lines
357356
358357 source_stmt: T_SOURCE T_WORD_QUOTE T_EOL
359358 {
360− printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
359+ printd(DEBUG_PARSE, "%s:%d:source %s\n", cur_filename, cur_lineno, $2);
361360 zconf_nextfile($2);
362361 free($2);
363362 };
@@ -368,7 +367,7 @@ comment: T_COMMENT T_WORD_QUOTE T_EOL · 4 unmodified lines
368367 {
369368 menu_add_entry(NULL);
370369 menu_add_prompt(P_COMMENT, $2, NULL);
371− printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
370+ printd(DEBUG_PARSE, "%s:%d:comment\n", cur_filename, cur_lineno);
372371 };
373372
374373 comment_stmt: comment comment_option_list
@@ -383,7 +382,7 @@ comment_option_list: · 8 unmodified lines
383382
384383 help_start: T_HELP T_EOL
385384 {
386− printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
385+ printd(DEBUG_PARSE, "%s:%d:help\n", cur_filename, cur_lineno);
387386 zconf_starthelp();
388387 };
389388
@@ -408,7 +407,7 @@ help: help_start T_HELPTEXT · 18 unmodified lines
408407 depends: T_DEPENDS T_ON expr T_EOL
409408 {
410409 menu_add_dep($3);
411− printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
410+ printd(DEBUG_PARSE, "%s:%d:depends on\n", cur_filename, cur_lineno);
412411 };
413412
414413 /* visibility option */
@@ -455,9 +454,6 @@ symbol: nonconst_symbol · 40 unmodified lines
455454 | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
456455 ;
457456
458−word_opt: /* empty */ { $$ = NULL; }
459− | T_WORD
460−
461457 /* assignment statement */
462458
463459 assignment_stmt: T_WORD assign_op assign_val T_EOL { variable_add($1, $3, $2); free($1); free($3); }
@@ -477,8 +473,11 @@ assign_val: · 13 unmodified lines
477473
478474 void conf_parse(const char *name)
479475 {
480− struct symbol *sym;
481− int i;
476+ struct menu *menu;
477+
478+ autoconf_cmd = str_new();
479+
480+ str_printf(&autoconf_cmd, "\ndeps_config := \\\n");
482481
483482 zconf_initscan(name);
484483
@@ -488,13 +487,28 @@ void conf_parse(const char *name) · 3 unmodified lines
488487 yydebug = 1;
489488 yyparse();
490489
490+ /*
491+ * FIXME:
492+ * cur_filename and cur_lineno are used even after yyparse();
493+ * menu_finalize() calls menu_add_symbol(). This should be fixed.
494+ */
495+ cur_filename = "<none>";
496+ cur_lineno = 0;
497+
498+ str_printf(&autoconf_cmd,
499+ "\n"
500+ "$(autoconfig): $(deps_config)\n"
501+ "$(deps_config): ;\n");
502+
503+ env_write_dep(&autoconf_cmd);
504+
491505 /* Variables are expanded in the parse phase. We can free them here. */
492506 variable_all_del();
493507
494508 if (yynerrs)
495509 exit(1);
496510 if (!modules_sym)
497− modules_sym = sym_find( "n" );
511+ modules_sym = &symbol_no;
498512
499513 if (!menu_has_prompt(&rootmenu)) {
500514 current_entry = &rootmenu;
@@ -502,10 +516,23 @@ void conf_parse(const char *name) · 1 unmodified line
502516 }
503517
504518 menu_finalize(&rootmenu);
505− for_all_symbols(i, sym) {
506− if (sym_check_deps(sym))
519+
520+ menu = &rootmenu;
521+ while (menu) {
522+ if (menu->sym && sym_check_deps(menu->sym))
507523 yynerrs++;
524+
525+ if (menu->list) {
526+ menu = menu->list;
527+ continue;
528+ }
529+
530+ while (!menu->next && menu->parent)
531+ menu = menu->parent;
532+
533+ menu = menu->next;
508534 }
535+
509536 if (yynerrs)
510537 exit(1);
511538 conf_set_changed(true);
@@ -520,11 +547,11 @@ static bool zconf_endtoken(const char *tokenname, · 8 unmodified lines
520547 yynerrs++;
521548 return false;
522549 }
523− if (current_menu->file != current_file) {
550+ if (strcmp(current_menu->filename, cur_filename)) {
524551 zconf_error("'%s' in different file than '%s'",
525552 tokenname, expected_tokenname);
526553 fprintf(stderr, "%s:%d: location of the '%s'\n",
527− current_menu->file->name, current_menu->lineno,
554+ current_menu->filename, current_menu->lineno,
528555 expected_tokenname);
529556 yynerrs++;
530557 return false;
@@ -536,7 +563,7 @@ static void zconfprint(const char *err, ...) · 5 unmodified lines
536563 {
537564 va_list ap;
538565
539− fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
566+ fprintf(stderr, "%s:%d: ", cur_filename, cur_lineno);
540567 va_start(ap, err);
541568 vfprintf(stderr, err, ap);
542569 va_end(ap);
@@ -548,7 +575,7 @@ static void zconf_error(const char *err, ...) · 5 unmodified lines
548575 va_list ap;
549576
550577 yynerrs++;
551− fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
578+ fprintf(stderr, "%s:%d: ", cur_filename, cur_lineno);
552579 va_start(ap, err);
553580 vfprintf(stderr, err, ap);
554581 va_end(ap);
@@ -557,7 +584,7 @@ static void zconf_error(const char *err, ...) · 2 unmodified lines
557584
558585 static void yyerror(const char *err)
559586 {
560− fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
587+ fprintf(stderr, "%s:%d: %s\n", cur_filename, cur_lineno, err);
561588 }
562589
563590 static void print_quoted_string(FILE *out, const char *str)
scripts/kconfig/preprocess.c+13−10
@@ -9,10 +9,11 @@ · 8 unmodified lines
99 #include <stdlib.h>
1010 #include <string.h>
1111
12+#include "array_size.h"
13+#include "internal.h"
1214 #include "list.h"
1315 #include "lkc.h"
14−
15−#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
16+#include "preprocess.h"
1617
1718 static char *expand_string_with_args(const char *in, int argc, char *argv[]);
1819 static char *expand_string(const char *in);
@@ -21,7 +22,7 @@ static void __attribute__((noreturn)) pperror(const char *format, ...) · 2 unmodified lines
2122 {
2223 va_list ap;
2324
24− fprintf(stderr, "%s:%d: ", current_file->name, yylineno);
25+ fprintf(stderr, "%s:%d: ", cur_filename, yylineno);
2526 va_start(ap, format);
2627 vfprintf(stderr, format, ap);
2728 va_end(ap);
@@ -87,14 +88,17 @@ static char *env_expand(const char *name) · 59 unmodified lines
8788 return xstrdup(value);
8889 }
8990
90−void env_write_dep(FILE *f, const char *autoconfig_name)
91+void env_write_dep(struct gstr *s)
9192 {
9293 struct env *e, *tmp;
9394
9495 list_for_each_entry_safe(e, tmp, &env_list, node) {
95− fprintf(f, "ifneq \"$(%s)\" \"%s\"\n", e->name, e->value);
96− fprintf(f, "%s: FORCE\n", autoconfig_name);
97− fprintf(f, "endif\n");
96+ str_printf(s,
97+ "\n"
98+ "ifneq \"$(%s)\" \"%s\"\n"
99+ "$(autoconfig): FORCE\n"
100+ "endif\n",
101+ e->name, e->value);
98102 env_del(e);
99103 }
100104 }
@@ -119,7 +123,7 @@ static char *do_error_if(int argc, char *argv[]) · 18 unmodified lines
119123
120124 static char *do_filename(int argc, char *argv[])
121125 {
122− return xstrdup(current_file->name);
126+ return xstrdup(cur_filename);
123127 }
124128
125129 static char *do_info(int argc, char *argv[])
@@ -181,8 +185,7 @@ static char *do_shell(int argc, char *argv[]) · 55 unmodified lines
181185 static char *do_warning_if(int argc, char *argv[])
182186 {
183187 if (!strcmp(argv[0], "y"))
184− fprintf(stderr, "%s:%d: %s\n",
185− current_file->name, yylineno, argv[1]);
188+ fprintf(stderr, "%s:%d: %s\n", cur_filename, yylineno, argv[1]);
186189
187190 return xstrdup("");
188191 }
scripts/kconfig/preprocess.h+19−0
@@ -0,0 +1,19 @@
1+/* SPDX-License-Identifier: GPL-2.0-only */
2+#ifndef PREPROCESS_H
3+#define PREPROCESS_H
4+
5+enum variable_flavor {
6+ VAR_SIMPLE,
7+ VAR_RECURSIVE,
8+ VAR_APPEND,
9+};
10+
11+struct gstr;
12+void env_write_dep(struct gstr *gs);
13+void variable_add(const char *name, const char *value,
14+ enum variable_flavor flavor);
15+void variable_all_del(void);
16+char *expand_dollar(const char **str);
17+char *expand_one_token(const char **str);
18+
19+#endif /* PREPROCESS_H */
scripts/kconfig/qconf.cc+1−1
@@ -1058,7 +1058,7 @@ void ConfigInfoView::menuInfo(void) · 1057 unmodified lines
10581058 stream << "<br><br>";
10591059 }
10601060
1061− stream << "defined at " << _menu->file->name << ":"
1061+ stream << "defined at " << _menu->filename << ":"
10621062 << _menu->lineno << "<br><br>";
10631063 }
10641064 }
scripts/kconfig/symbol.c+22−27
@@ -9,23 +9,27 @@ · 8 unmodified lines
99 #include <string.h>
1010 #include <regex.h>
1111
12+#include "internal.h"
1213 #include "lkc.h"
1314
1415 struct symbol symbol_yes = {
1516 .name = "y",
1617 .curr = { "y", yes },
18+ .menus = LIST_HEAD_INIT(symbol_yes.menus),
1719 .flags = SYMBOL_CONST|SYMBOL_VALID,
1820 };
1921
2022 struct symbol symbol_mod = {
2123 .name = "m",
2224 .curr = { "m", mod },
25+ .menus = LIST_HEAD_INIT(symbol_mod.menus),
2326 .flags = SYMBOL_CONST|SYMBOL_VALID,
2427 };
2528
2629 struct symbol symbol_no = {
2730 .name = "n",
2831 .curr = { "n", no },
32+ .menus = LIST_HEAD_INIT(symbol_no.menus),
2933 .flags = SYMBOL_CONST|SYMBOL_VALID,
3034 };
3135
@@ -160,9 +164,8 @@ static void sym_set_changed(struct symbol *sym) · 128 unmodified lines
160164 static void sym_set_all_changed(void)
161165 {
162166 struct symbol *sym;
163− int i;
164167
165− for_all_symbols(i, sym)
168+ for_all_symbols(sym)
166169 sym_set_changed(sym);
167170 }
168171
@@ -475,9 +478,8 @@ void sym_calc_value(struct symbol *sym) · 306 unmodified lines
475478 void sym_clear_all_valid(void)
476479 {
477480 struct symbol *sym;
478− int i;
479481
480− for_all_symbols(i, sym)
482+ for_all_symbols(sym)
481483 sym->flags &= ~SYMBOL_VALID;
482484 conf_set_changed(true);
483485 sym_calc_value(modules_sym);
@@ -803,14 +805,7 @@ bool sym_is_changeable(struct symbol *sym) · 319 unmodified lines
803805 return sym->visible > sym->rev_dep.tri;
804806 }
805807
806−static unsigned strhash(const char *s)
807−{
808− /* fnv32 hash */
809− unsigned hash = 2166136261U;
810− for (; *s; s++)
811− hash = (hash ^ *s) * 0x01000193;
812− return hash;
813−}
808+HASHTABLE_DEFINE(sym_hashtable, SYMBOL_HASHSIZE);
814809
815810 struct symbol *sym_lookup(const char *name, int flags)
816811 {
@@ -826,9 +821,9 @@ struct symbol *sym_lookup(const char *name, int flags) · 9 unmodified lines
826821 case 'n': return &symbol_no;
827822 }
828823 }
829− hash = strhash(name) % SYMBOL_HASHSIZE;
824+ hash = strhash(name);
830825
831− for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) {
826+ hash_for_each_possible(sym_hashtable, symbol, node, hash) {
832827 if (symbol->name &&
833828 !strcmp(symbol->name, name) &&
834829 (flags ? symbol->flags & flags
@@ -846,9 +841,9 @@ struct symbol *sym_lookup(const char *name, int flags) · 11 unmodified lines
846841 symbol->name = new_name;
847842 symbol->type = S_UNKNOWN;
848843 symbol->flags = flags;
844+ INIT_LIST_HEAD(&symbol->menus);
849845
850− symbol->next = symbol_hash[hash];
851− symbol_hash[hash] = symbol;
846+ hash_add(sym_hashtable, &symbol->node, hash);
852847
853848 return symbol;
854849 }
@@ -868,9 +863,9 @@ struct symbol *sym_find(const char *name) · 13 unmodified lines
868863 case 'n': return &symbol_no;
869864 }
870865 }
871− hash = strhash(name) % SYMBOL_HASHSIZE;
866+ hash = strhash(name);
872867
873− for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) {
868+ hash_for_each_possible(sym_hashtable, symbol, node, hash) {
874869 if (symbol->name &&
875870 !strcmp(symbol->name, name) &&
876871 !(symbol->flags & SYMBOL_CONST))
@@ -930,7 +925,7 @@ struct symbol **sym_re_search(const char *pattern) · 53 unmodified lines
930925 if (regcomp(&re, pattern, REG_EXTENDED|REG_ICASE))
931926 return NULL;
932927
933− for_all_symbols(i, sym) {
928+ for_all_symbols(sym) {
934929 if (sym->flags & SYMBOL_CONST || !sym->name)
935930 continue;
936931 if (regexec(&re, sym->name, 1, match, 0))
@@ -1041,42 +1036,42 @@ static void sym_check_print_recursive(struct symbol *last_sym) · 104 unmodified lines
10411036 }
10421037 if (stack->sym == last_sym)
10431038 fprintf(stderr, "%s:%d:error: recursive dependency detected!\n",
1044− prop->file->name, prop->lineno);
1039+ prop->filename, prop->lineno);
10451040
10461041 if (sym_is_choice(sym)) {
10471042 fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n",
1048− menu->file->name, menu->lineno,
1043+ menu->filename, menu->lineno,
10491044 sym->name ? sym->name : "<choice>",
10501045 next_sym->name ? next_sym->name : "<choice>");
10511046 } else if (sym_is_choice_value(sym)) {
10521047 fprintf(stderr, "%s:%d:\tsymbol %s is part of choice %s\n",
1053− menu->file->name, menu->lineno,
1048+ menu->filename, menu->lineno,
10541049 sym->name ? sym->name : "<choice>",
10551050 next_sym->name ? next_sym->name : "<choice>");
10561051 } else if (stack->expr == &sym->dir_dep.expr) {
10571052 fprintf(stderr, "%s:%d:\tsymbol %s depends on %s\n",
1058− prop->file->name, prop->lineno,
1053+ prop->filename, prop->lineno,
10591054 sym->name ? sym->name : "<choice>",
10601055 next_sym->name ? next_sym->name : "<choice>");
10611056 } else if (stack->expr == &sym->rev_dep.expr) {
10621057 fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n",
1063− prop->file->name, prop->lineno,
1058+ prop->filename, prop->lineno,
10641059 sym->name ? sym->name : "<choice>",
10651060 next_sym->name ? next_sym->name : "<choice>");
10661061 } else if (stack->expr == &sym->implied.expr) {
10671062 fprintf(stderr, "%s:%d:\tsymbol %s is implied by %s\n",
1068− prop->file->name, prop->lineno,
1063+ prop->filename, prop->lineno,
10691064 sym->name ? sym->name : "<choice>",
10701065 next_sym->name ? next_sym->name : "<choice>");
10711066 } else if (stack->expr) {
10721067 fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n",
1073− prop->file->name, prop->lineno,
1068+ prop->filename, prop->lineno,
10741069 sym->name ? sym->name : "<choice>",
10751070 prop_get_type_name(prop->type),
10761071 next_sym->name ? next_sym->name : "<choice>");
10771072 } else {
10781073 fprintf(stderr, "%s:%d:\tsymbol %s %s is visible depending on %s\n",
1079− prop->file->name, prop->lineno,
1074+ prop->filename, prop->lineno,
10801075 sym->name ? sym->name : "<choice>",
10811076 prop_get_type_name(prop->type),
10821077 next_sym->name ? next_sym->name : "<choice>");
scripts/kconfig/tests/choice_randomize/Kconfig+22−0
@@ -0,0 +1,22 @@
1+choice
2+ prompt "choose A or B"
3+
4+config A
5+ bool "A"
6+
7+config B
8+ bool "B"
9+
10+endchoice
11+
12+choice
13+ prompt "choose X or Y"
14+ depends on B
15+
16+config X
17+ bool "X"
18+
19+config Y
20+ bool "Y"
21+
22+endchoice
scripts/kconfig/tests/choice_randomize/__init__.py+34−0
@@ -0,0 +1,34 @@
1+# SPDX-License-Identifier: GPL-2.0-only
2+"""
3+Randomize all dependent choices
4+
5+This is a somewhat tricky case for randconfig; the visibility of one choice is
6+determined by a member of another choice. Randconfig should be able to generate
7+all possible patterns.
8+"""
9+
10+
11+def test(conf):
12+
13+ expected0 = False
14+ expected1 = False
15+ expected2 = False
16+
17+ for i in range(100):
18+ assert conf.randconfig(seed=i) == 0
19+
20+ if conf.config_matches('expected_config0'):
21+ expected0 = True
22+ elif conf.config_matches('expected_config1'):
23+ expected1 = True
24+ elif conf.config_matches('expected_config2'):
25+ expected2 = True
26+ else:
27+ assert False
28+
29+ if expected0 and expected1 and expected2:
30+ break
31+
32+ assert expected0
33+ assert expected1
34+ assert expected2
scripts/kconfig/tests/choice_randomize/expected_config0+6−0
@@ -0,0 +1,6 @@
1+#
2+# Automatically generated file; DO NOT EDIT.
3+# Main menu
4+#
5+CONFIG_A=y
6+# CONFIG_B is not set
scripts/kconfig/tests/choice_randomize/expected_config1+8−0
@@ -0,0 +1,8 @@
1+#
2+# Automatically generated file; DO NOT EDIT.
3+# Main menu
4+#
5+# CONFIG_A is not set
6+CONFIG_B=y
7+CONFIG_X=y
8+# CONFIG_Y is not set
scripts/kconfig/tests/choice_randomize/expected_config2+8−0
@@ -0,0 +1,8 @@
1+#
2+# Automatically generated file; DO NOT EDIT.
3+# Main menu
4+#
5+# CONFIG_A is not set
6+CONFIG_B=y
7+# CONFIG_X is not set
8+CONFIG_Y=y
scripts/kconfig/tests/choice_randomize2/Kconfig+32−0
@@ -0,0 +1,32 @@
1+choice
2+ prompt "This is always invisible"
3+ depends on n
4+
5+config DUMMY
6+ bool "DUMMY"
7+
8+endchoice
9+
10+choice
11+ prompt "Choose A or B"
12+
13+config A
14+ bool "A"
15+
16+config B
17+ bool "B"
18+
19+endchoice
20+
21+config FOO
22+ bool "FOO"
23+ depends on A
24+
25+choice
26+ prompt "Choose X"
27+ depends on FOO
28+
29+config X
30+ bool "X"
31+
32+endchoice
scripts/kconfig/tests/choice_randomize2/__init__.py+18−0
@@ -0,0 +1,18 @@
1+# SPDX-License-Identifier: GPL-2.0-only
2+"""
3+Randomize choices with correct dependencies
4+
5+When shuffling a choice may potentially disrupt certain dependencies, symbol
6+values must be recalculated.
7+
8+Related Linux commits:
9+ - c8fb7d7e48d11520ad24808cfce7afb7b9c9f798
10+"""
11+
12+
13+def test(conf):
14+ for i in range(20):
15+ assert conf.randconfig(seed=i) == 0
16+ assert (conf.config_matches('expected_config0') or
17+ conf.config_matches('expected_config1') or
18+ conf.config_matches('expected_config2'))
scripts/kconfig/tests/choice_randomize2/expected_config0+8−0
@@ -0,0 +1,8 @@
1+#
2+# Automatically generated file; DO NOT EDIT.
3+# Main menu
4+#
5+CONFIG_A=y
6+# CONFIG_B is not set
7+CONFIG_FOO=y
8+CONFIG_X=y
scripts/kconfig/tests/choice_randomize2/expected_config1+7−0
@@ -0,0 +1,7 @@
1+#
2+# Automatically generated file; DO NOT EDIT.
3+# Main menu
4+#
5+CONFIG_A=y
6+# CONFIG_B is not set
7+# CONFIG_FOO is not set
scripts/kconfig/tests/choice_randomize2/expected_config2+6−0
@@ -0,0 +1,6 @@
1+#
2+# Automatically generated file; DO NOT EDIT.
3+# Main menu
4+#
5+# CONFIG_A is not set
6+CONFIG_B=y
scripts/kconfig/tests/conftest.py+10−6
@@ -154,12 +154,10 @@ class Conf: · 153 unmodified lines
154154 defconfig_path = os.path.join(self._test_dir, defconfig)
155155 return self._run_conf('--defconfig={}'.format(defconfig_path))
156156
157− def _allconfig(self, mode, all_config):
157+ def _allconfig(self, mode, all_config, extra_env={}):
158158 if all_config:
159159 all_config_path = os.path.join(self._test_dir, all_config)
160− extra_env = {'KCONFIG_ALLCONFIG': all_config_path}
161− else:
162− extra_env = {}
160+ extra_env['KCONFIG_ALLCONFIG'] = all_config_path
163161
164162 return self._run_conf('--{}config'.format(mode), extra_env=extra_env)
165163
@@ -195,13 +193,19 @@ class Conf: · 29 unmodified lines
195193 """
196194 return self._allconfig('alldef', all_config)
197195
198− def randconfig(self, all_config=None):
196+ def randconfig(self, all_config=None, seed=None):
199197 """Run randconfig.
200198
201199 all_config: fragment config file for KCONFIG_ALLCONFIG (optional)
200+ seed: the seed for randconfig (optional)
202201 returncode: exit status of the Kconfig executable
203202 """
204− return self._allconfig('rand', all_config)
203+ if seed is not None:
204+ extra_env = {'KCONFIG_SEED': hex(seed)}
205+ else:
206+ extra_env = {}
207+
208+ return self._allconfig('rand', all_config, extra_env=extra_env)
205209
206210 def savedefconfig(self, dot_config):
207211 """Run savedefconfig.
scripts/kconfig/tests/err_recursive_dep/expected_stderr+11−11
@@ -1,10 +1,10 @@
1−Kconfig:11:error: recursive dependency detected!
2−Kconfig:11: symbol B is selected by B
1+Kconfig:5:error: recursive dependency detected!
2+Kconfig:5: symbol A depends on A
33 For a resolution refer to Documentation/kbuild/kconfig-language.rst
44 subsection "Kconfig recursive dependency limitations"
55
6−Kconfig:5:error: recursive dependency detected!
7−Kconfig:5: symbol A depends on A
6+Kconfig:11:error: recursive dependency detected!
7+Kconfig:11: symbol B is selected by B
88 For a resolution refer to Documentation/kbuild/kconfig-language.rst
99 subsection "Kconfig recursive dependency limitations"
1010
@@ -14,9 +14,9 @@ Kconfig:21: symbol C2 depends on C1 · 3 unmodified lines
1414 For a resolution refer to Documentation/kbuild/kconfig-language.rst
1515 subsection "Kconfig recursive dependency limitations"
1616
17−Kconfig:32:error: recursive dependency detected!
18−Kconfig:32: symbol D2 is selected by D1
17+Kconfig:27:error: recursive dependency detected!
1918 Kconfig:27: symbol D1 depends on D2
19+Kconfig:32: symbol D2 is selected by D1
2020 For a resolution refer to Documentation/kbuild/kconfig-language.rst
2121 subsection "Kconfig recursive dependency limitations"
2222
@@ -26,13 +26,13 @@ Kconfig:42: symbol E2 is implied by E1 · 3 unmodified lines
2626 For a resolution refer to Documentation/kbuild/kconfig-language.rst
2727 subsection "Kconfig recursive dependency limitations"
2828
29−Kconfig:60:error: recursive dependency detected!
30−Kconfig:60: symbol G depends on G
29+Kconfig:49:error: recursive dependency detected!
30+Kconfig:49: symbol F1 default value contains F2
31+Kconfig:51: symbol F2 depends on F1
3132 For a resolution refer to Documentation/kbuild/kconfig-language.rst
3233 subsection "Kconfig recursive dependency limitations"
3334
34−Kconfig:51:error: recursive dependency detected!
35−Kconfig:51: symbol F2 depends on F1
36−Kconfig:49: symbol F1 default value contains F2
35+Kconfig:60:error: recursive dependency detected!
36+Kconfig:60: symbol G depends on G
3737 For a resolution refer to Documentation/kbuild/kconfig-language.rst
3838 subsection "Kconfig recursive dependency limitations"
scripts/kconfig/util.c+36−11
@@ -7,25 +7,50 @@ · 6 unmodified lines
77 #include <stdarg.h>
88 #include <stdlib.h>
99 #include <string.h>
10+
11+#include "hashtable.h"
1012 #include "lkc.h"
1113
14+unsigned int strhash(const char *s)
15+{
16+ /* fnv32 hash */
17+ unsigned int hash = 2166136261U;
18+
19+ for (; *s; s++)
20+ hash = (hash ^ *s) * 0x01000193;
21+ return hash;
22+}
23+
24+/* hash table of all parsed Kconfig files */
25+static HASHTABLE_DEFINE(file_hashtable, 1U << 11);
26+
27+struct file {
28+ struct hlist_node node;
29+ char name[];
30+};
31+
1232 /* file already present in list? If not add it */
13−struct file *file_lookup(const char *name)
33+const char *file_lookup(const char *name)
1434 {
1535 struct file *file;
36+ size_t len;
37+ int hash = strhash(name);
1638
17− for (file = file_list; file; file = file->next) {
18− if (!strcmp(name, file->name)) {
19− return file;
20− }
21− }
39+ hash_for_each_possible(file_hashtable, file, node, hash)
40+ if (!strcmp(name, file->name))
41+ return file->name;
2242
23− file = xmalloc(sizeof(*file));
43+ len = strlen(name);
44+ file = xmalloc(sizeof(*file) + len + 1);
2445 memset(file, 0, sizeof(*file));
25− file->name = xstrdup(name);
26− file->next = file_list;
27− file_list = file;
28− return file;
46+ memcpy(file->name, name, len);
47+ file->name[len] = '\0';
48+
49+ hash_add(file_hashtable, &file->node, hash);
50+
51+ str_printf(&autoconf_cmd, "\t%s \\\n", name);
52+
53+ return file->name;
2954 }
3055
3156 /* Allocate initial growable string */
scripts/mod/modpost.c+3−1
@@ -1050,7 +1050,9 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf, · 1049 unmodified lines
10501050 sec_mismatch_count++;
10511051
10521052 warn("%s: section mismatch in reference: %s+0x%x (section: %s) -> %s (section: %s)\n",
1053− modname, fromsym, (unsigned int)(faddr - from->st_value), fromsec, tosym, tosec);
1053+ modname, fromsym,
1054+ (unsigned int)(faddr - (from ? from->st_value : 0)),
1055+ fromsec, tosym, tosec);
10541056
10551057 if (mismatch->mismatch == EXTABLE_TO_NON_TEXT) {
10561058 if (match(tosec, mismatch->bad_tosec))
scripts/package/builddeb+12−38
@@ -24,24 +24,10 @@ if_enabled_echo() { · 23 unmodified lines
2424 fi
2525 }
2626
27−create_package() {
28− export DH_OPTIONS="-p${1}"
29−
30− dh_installdocs
31− dh_installchangelogs
32− dh_compress
33− dh_fixperms
34− dh_gencontrol
35− dh_md5sums
36− dh_builddeb -- ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS}
37−}
38−
3927 install_linux_image () {
4028 pname=$1
4129 pdir=debian/$1
4230
43− rm -rf ${pdir}
44−
4531 # Only some architectures with OF support have this target
4632 if is_enabled CONFIG_OF_EARLY_FLATTREE && [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then
4733 ${MAKE} -f ${srctree}/Makefile INSTALL_DTBS_PATH="${pdir}/usr/lib/linux-image-${KERNELRELEASE}" dtbs_install
@@ -109,8 +95,6 @@ install_linux_image () { · 61 unmodified lines
10995 install_linux_image_dbg () {
11096 pdir=debian/$1
11197
112− rm -rf ${pdir}
113−
11498 # Parse modules.order directly because 'make modules_install' may sign,
11599 # compress modules, and then run unneeded depmod.
116100 while read -r mod; do
@@ -140,8 +124,6 @@ install_kernel_headers () { · 23 unmodified lines
140124 pdir=debian/$1
141125 version=${1#linux-headers-}
142126
143− rm -rf $pdir
144−
145127 "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}"
146128
147129 mkdir -p $pdir/lib/modules/$version/
@@ -151,8 +133,6 @@ install_kernel_headers () { · 3 unmodified lines
151133 install_libc_headers () {
152134 pdir=debian/$1
153135
154− rm -rf $pdir
155−
156136 $MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH=$pdir/usr
157137
158138 # move asm headers to /usr/include/<libc-machine>/asm to match the structure
@@ -161,21 +141,15 @@ install_libc_headers () { · 2 unmodified lines
161141 mv "$pdir/usr/include/asm" "$pdir/usr/include/${DEB_HOST_MULTIARCH}"
162142 }
163143
164−rm -f debian/files
165−
166−packages_enabled=$(dh_listpackages)
167−
168−for package in ${packages_enabled}
169−do
170− case ${package} in
171− *-dbg)
172− install_linux_image_dbg "${package}";;
173− linux-image-*|user-mode-linux-*)
174− install_linux_image "${package}";;
175− linux-libc-dev)
176− install_libc_headers "${package}";;
177− linux-headers-*)
178− install_kernel_headers "${package}";;
179− esac
180− create_package "${package}"
181−done
144+package=$1
145+
146+case "${package}" in
147+*-dbg)
148+ install_linux_image_dbg "${package}";;
149+linux-image-*|user-mode-linux-*)
150+ install_linux_image "${package}";;
151+linux-libc-dev)
152+ install_libc_headers "${package}";;
153+linux-headers-*)
154+ install_kernel_headers "${package}";;
155+esac
scripts/package/debian/rules+54−9
@@ -11,28 +11,73 @@ ifneq (,$(filter-out parallel=1,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))) · 10 unmodified lines
1111 MAKEFLAGS += -j$(NUMJOBS)
1212 endif
1313
14+# When KBUILD_VERBOSE is undefined (presumably you are directly working with
15+# the debianized tree), show verbose logs unless DEB_BUILD_OPTION=terse is set.
16+ifeq ($(origin KBUILD_VERBOSE),undefined)
17+ ifeq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
18+ export KBUILD_VERBOSE := 1
19+ else
20+ Q := @
21+ endif
22+endif
23+
1424 revision = $(lastword $(subst -, ,$(shell dpkg-parsechangelog -S Version)))
1525 CROSS_COMPILE ?= $(filter-out $(DEB_BUILD_GNU_TYPE)-, $(DEB_HOST_GNU_TYPE)-)
1626 make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) KBUILD_BUILD_VERSION=$(revision) $(addprefix CROSS_COMPILE=,$(CROSS_COMPILE))
1727
28+binary-targets := $(addprefix binary-, image image-dbg headers libc-dev)
29+
30+all-packages = $(shell dh_listpackages)
31+image-package = $(filter linux-image-% user-%, $(filter-out %-dbg, $(all-packages)))
32+image-dbg-package = $(filter %-dbg, $(all-packages))
33+libc-dev-package = $(filter linux-libc-dev, $(all-packages))
34+headers-package = $(filter linux-headers-%, $(all-packages))
35+
36+mk-files = $(patsubst binary-%,debian/%.files,$1)
37+package = $($(@:binary-%=%-package))
38+
39+# DH_OPTION is an environment variable common for all debhelper commands.
40+# We could 'export' it, but here it is passed from the command line to clarify
41+# which package is being processed in the build log.
42+DH_OPTIONS = -p$(package)
43+
44+define binary
45+ $(Q)dh_testdir $(DH_OPTIONS)
46+ $(Q)dh_testroot $(DH_OPTIONS)
47+ $(Q)dh_prep $(DH_OPTIONS)
48+ $(Q)+$(MAKE) $(make-opts) run-command KBUILD_RUN_COMMAND='+$$(srctree)/scripts/package/builddeb $(package)'
49+ $(Q)dh_installdocs $(DH_OPTIONS)
50+ $(Q)dh_installchangelogs $(DH_OPTIONS)
51+ $(Q)dh_compress $(DH_OPTIONS)
52+ $(Q)dh_fixperms $(DH_OPTIONS)
53+ $(Q)dh_gencontrol $(DH_OPTIONS) -- -f$(call mk-files,$@)
54+ $(Q)dh_md5sums $(DH_OPTIONS)
55+ $(Q)dh_builddeb $(DH_OPTIONS) -- $(addprefix -Z,$(KDEB_COMPRESS))
56+endef
57+
58+.PHONY: $(binary-targets)
59+$(binary-targets): build-arch
60+ $(Q)truncate -s0 $(call mk-files,$@)
61+ $(if $(package),$(binary))
62+
1863 .PHONY: binary binary-indep binary-arch
1964 binary: binary-arch binary-indep
2065 binary-indep: build-indep
21−binary-arch: build-arch
22− $(MAKE) $(make-opts) \
23− run-command KBUILD_RUN_COMMAND='+$$(srctree)/scripts/package/builddeb'
66+binary-arch: $(binary-targets)
67+ $(Q)cat $(call mk-files,$^) > debian/files
2468
2569 .PHONY: build build-indep build-arch
2670 build: build-arch build-indep
2771 build-indep:
2872 build-arch:
29− $(MAKE) $(make-opts) olddefconfig
30− $(MAKE) $(make-opts) $(if $(filter um,$(ARCH)),,headers) all
73+ $(Q)$(MAKE) $(make-opts) olddefconfig
74+ $(Q)$(MAKE) $(make-opts) $(if $(filter um,$(ARCH)),,headers) all
3175
3276 .PHONY: clean
3377 clean:
34− rm -rf debian/files debian/linux-* debian/deb-env.vars*
35− $(MAKE) ARCH=$(ARCH) clean
78+ $(Q)dh_clean
79+ $(Q)rm -rf debian/deb-env.vars* debian/*.files
80+ $(Q)$(MAKE) ARCH=$(ARCH) clean
3681
3782 # If DEB_HOST_ARCH is empty, it is likely that debian/rules was executed
3883 # directly. Run 'dpkg-architecture --print-set --print-format=make' to
@@ -41,6 +86,6 @@ ifndef DEB_HOST_ARCH · 2 unmodified lines
4186 include debian/deb-env.vars
4287
4388 debian/deb-env.vars:
44− dpkg-architecture -a$$(cat debian/arch) --print-set --print-format=make > $@.tmp
45− mv $@.tmp $@
89+ $(Q)dpkg-architecture -a$$(cat debian/arch) --print-set --print-format=make > $@.tmp
90+ $(Q)mv $@.tmp $@
4691 endif
scripts/package/kernel.spec+37−11
@@ -61,11 +61,37 @@ cp $(%{make} %{makeflags} -s image_name) %{buildroot}/lib/modules/%{KERNELRELEAS · 60 unmodified lines
6161 %{make} %{makeflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install
6262 cp System.map %{buildroot}/lib/modules/%{KERNELRELEASE}
6363 cp .config %{buildroot}/lib/modules/%{KERNELRELEASE}/config
64+if %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='test -d ${srctree}/arch/${SRCARCH}/boot/dts' 2>/dev/null; then
65+ %{make} %{makeflags} INSTALL_DTBS_PATH=%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb dtbs_install
66+fi
6467 ln -fns /usr/src/kernels/%{KERNELRELEASE} %{buildroot}/lib/modules/%{KERNELRELEASE}/build
6568 %if %{with_devel}
6669 %{make} %{makeflags} run-command KBUILD_RUN_COMMAND='${srctree}/scripts/package/install-extmod-build %{buildroot}/usr/src/kernels/%{KERNELRELEASE}'
6770 %endif
6871
72+{
73+ for x in System.map config kernel modules.builtin \
74+ modules.builtin.modinfo modules.order vmlinuz; do
75+ echo "/lib/modules/%{KERNELRELEASE}/${x}"
76+ done
77+
78+ for x in alias alias.bin builtin.alias.bin builtin.bin dep dep.bin \
79+ devname softdep symbols symbols.bin; do
80+ echo "%ghost /lib/modules/%{KERNELRELEASE}/modules.${x}"
81+ done
82+
83+ for x in System.map config vmlinuz; do
84+ echo "%ghost /boot/${x}-%{KERNELRELEASE}"
85+ done
86+
87+ if [ -d "%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb" ];then
88+ echo "/lib/modules/%{KERNELRELEASE}/dtb"
89+ find "%{buildroot}/lib/modules/%{KERNELRELEASE}/dtb" -printf "%%%ghost /boot/dtb-%{KERNELRELEASE}/%%P\n"
90+ fi
91+
92+ echo "%exclude /lib/modules/%{KERNELRELEASE}/build"
93+} > %{buildroot}/kernel.list
94+
6995 %clean
7096 rm -rf %{buildroot}
7197
@@ -78,23 +104,23 @@ for file in vmlinuz System.map config; do · 6 unmodified lines
78104 cp "/lib/modules/%{KERNELRELEASE}/${file}" "/boot/${file}-%{KERNELRELEASE}"
79105 fi
80106 done
107+if [ -d "/lib/modules/%{KERNELRELEASE}/dtb" ] && \
108+ ! diff -rq "/lib/modules/%{KERNELRELEASE}/dtb" "/boot/dtb-%{KERNELRELEASE}" >/dev/null 2>&1; then
109+ rm -rf "/boot/dtb-%{KERNELRELEASE}"
110+ cp -r "/lib/modules/%{KERNELRELEASE}/dtb" "/boot/dtb-%{KERNELRELEASE}"
111+fi
112+if [ ! -e "/lib/modules/%{KERNELRELEASE}/modules.dep" ]; then
113+ /usr/sbin/depmod %{KERNELRELEASE}
114+fi
81115
82116 %preun
83−if [ -x /sbin/new-kernel-pkg ]; then
84−new-kernel-pkg --remove %{KERNELRELEASE} --rminitrd --initrdfile=/boot/initramfs-%{KERNELRELEASE}.img
85−elif [ -x /usr/bin/kernel-install ]; then
117+if [ -x /usr/bin/kernel-install ]; then
86118 kernel-install remove %{KERNELRELEASE}
87119 fi
88120
89−%postun
90−if [ -x /sbin/update-bootloader ]; then
91−/sbin/update-bootloader --remove %{KERNELRELEASE}
92−fi
93−
94−%files
121+%files -f %{buildroot}/kernel.list
95122 %defattr (-, root, root)
96−/lib/modules/%{KERNELRELEASE}
97−%exclude /lib/modules/%{KERNELRELEASE}/build
123+%exclude /kernel.list
98124
99125 %files headers
100126 %defattr (-, root, root)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t