From 8f0c32c788fffa8e88f995372415864039347c8a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 31 Aug 2021 16:39:52 +0900 Subject: kbuild: move objtool_args back to scripts/Makefile.build Commit b1a1a1a09b46 ("kbuild: lto: postpone objtool") moved objtool_args to Makefile.lib, so the arguments can be used in Makefile.modfinal as well as Makefile.build. With commit 850ded46c642 ("kbuild: Fix TRIM_UNUSED_KSYMS with LTO_CLANG"), module LTO linking came back to scripts/Makefile.build again. So, there is no more reason to keep objtool_args in a separate file. Get it back to the original place, close to the objtool command. Remove the stale comment too. Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook Acked-by: Josh Poimboeuf --- scripts/Makefile.build | 10 ++++++++++ scripts/Makefile.lib | 11 ----------- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 3efc984d4c69..17508c0e4358 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -224,6 +224,16 @@ cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)), endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT ifdef CONFIG_STACK_VALIDATION + +objtool_args = \ + $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \ + $(if $(part-of-module), --module) \ + $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ + $(if $(CONFIG_GCOV_KERNEL)$(CONFIG_LTO_CLANG), --no-unreachable)\ + $(if $(CONFIG_RETPOLINE), --retpoline) \ + $(if $(CONFIG_X86_SMAP), --uaccess) \ + $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) + ifndef CONFIG_LTO_CLANG __objtool_obj := $(objtree)/tools/objtool/objtool diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 54582673fc1a..0a8a4689c3eb 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -232,17 +232,6 @@ ifeq ($(CONFIG_LTO_CLANG),y) mod-prelink-ext := .lto endif -# Objtool arguments are also needed for modfinal with LTO, so we define -# then here to avoid duplication. -objtool_args = \ - $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \ - $(if $(part-of-module), --module) \ - $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ - $(if $(CONFIG_GCOV_KERNEL)$(CONFIG_LTO_CLANG), --no-unreachable)\ - $(if $(CONFIG_RETPOLINE), --retpoline) \ - $(if $(CONFIG_X86_SMAP), --uaccess) \ - $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) - # Useful for describing the dependency of composite objects # Usage: # $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add) -- cgit v1.2.3 From 5c4859e77aa11f9a8d9533962389893d199df70e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 31 Aug 2021 16:39:53 +0900 Subject: kbuild: rename __objtool_obj and reuse it for cmd_cc_lto_link_modules Rename __objtool_obj to objtool, and move it out of the 'ifndef CONFIG_LTO_CLANG' conditional, so it can be used for cmd_cc_lto_link_modules as well. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers Reviewed-by: Kees Cook Acked-by: Josh Poimboeuf --- scripts/Makefile.build | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 17508c0e4358..e78096cd396b 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -225,6 +225,8 @@ endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT ifdef CONFIG_STACK_VALIDATION +objtool := $(objtree)/tools/objtool/objtool + objtool_args = \ $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \ $(if $(part-of-module), --module) \ @@ -236,17 +238,15 @@ objtool_args = \ ifndef CONFIG_LTO_CLANG -__objtool_obj := $(objtree)/tools/objtool/objtool - # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file cmd_objtool = $(if $(patsubst y%,, \ $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \ - $(__objtool_obj) $(objtool_args) $@) + $(objtool) $(objtool_args) $@) objtool_obj = $(if $(patsubst y%,, \ $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \ - $(__objtool_obj)) + $(objtool)) endif # CONFIG_LTO_CLANG endif # CONFIG_STACK_VALIDATION @@ -300,8 +300,7 @@ cmd_cc_lto_link_modules = \ ifdef CONFIG_STACK_VALIDATION # objtool was skipped for LLVM bitcode, run it now that we have compiled # modules into native code -cmd_cc_lto_link_modules += ; \ - $(objtree)/tools/objtool/objtool $(objtool_args) --module $@ +cmd_cc_lto_link_modules += ; $(objtool) $(objtool_args) --module $@ endif $(obj)/%.lto.o: $(obj)/%.o FORCE -- cgit v1.2.3 From 92594d569b6d377168fa74c6bb27c5696af02a9d Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 31 Aug 2021 16:39:54 +0900 Subject: kbuild: store the objtool command in *.cmd files objtool_dep includes include/config/{ORC_UNWINDER,STACK_VALIDATION} so that all the objects are rebuilt when CONFIG_ORC_UNWINDER or CONFIG_STACK_VALIDATION is toggled. BTW, the correct option name is not CONFIG_ORC_UNWINDER, but CONFIG_UNWINDER_ORC. Commit 11af847446ed ("x86/unwind: Rename unwinder config options to 'CONFIG_UNWINDER_*'") missed to adjust this part. So, this dependency has been broken for a long time. As you can see in 'objtool_args', there are more CONFIG options that affect the objtool command line. Adding more and more include/config/* is ugly and unmaintainable. Another issue is that non-standard objects are needlessly rebuilt. Objects specified as OBJECT_FILES_NON_STANDARD is not processed by objtool, but they are rebuilt anyway when CONFIG_STACK_VALIDATION is toggled. This is not a big deal, but better to fix. A cleaner and more precise fix is to include the objtool command in *.cmd files so any command change is naturally detected by if_change. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers Reviewed-by: Kees Cook Acked-by: Josh Poimboeuf --- scripts/Makefile.build | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.build b/scripts/Makefile.build index e78096cd396b..021ae0146913 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -155,7 +155,7 @@ $(obj)/%.ll: $(src)/%.c FORCE # (See cmd_cc_o_c + relevant part of rule_cc_o_c) quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ - cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< + cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< $(cmd_objtool) ifdef CONFIG_MODVERSIONS # When module versioning is enabled the following steps are executed: @@ -243,7 +243,7 @@ ifndef CONFIG_LTO_CLANG # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file cmd_objtool = $(if $(patsubst y%,, \ $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \ - $(objtool) $(objtool_args) $@) + ; $(objtool) $(objtool_args) $@) objtool_obj = $(if $(patsubst y%,, \ $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \ $(objtool)) @@ -251,10 +251,8 @@ objtool_obj = $(if $(patsubst y%,, \ endif # CONFIG_LTO_CLANG endif # CONFIG_STACK_VALIDATION -# Rebuild all objects when objtool changes, or is enabled/disabled. -objtool_dep = $(objtool_obj) \ - $(wildcard include/config/ORC_UNWINDER \ - include/config/STACK_VALIDATION) +# Rebuild all objects when objtool changes +objtool_dep = $(objtool_obj) ifdef CONFIG_TRIM_UNUSED_KSYMS cmd_gen_ksymdeps = \ @@ -269,7 +267,6 @@ define rule_cc_o_c $(call cmd,gen_ksymdeps) $(call cmd,checksrc) $(call cmd,checkdoc) - $(call cmd,objtool) $(call cmd,modversions_c) $(call cmd,record_mcount) endef @@ -277,7 +274,6 @@ endef define rule_as_o_S $(call cmd_and_fixdep,as_o_S) $(call cmd,gen_ksymdeps) - $(call cmd,objtool) $(call cmd,modversions_S) endef @@ -365,7 +361,7 @@ $(obj)/%.s: $(src)/%.S FORCE $(call if_changed_dep,cpp_s_S) quiet_cmd_as_o_S = AS $(quiet_modtag) $@ - cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< + cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< $(cmd_objtool) ifdef CONFIG_ASM_MODVERSIONS -- cgit v1.2.3 From 918a6b7f68468ab80ec5e7ab7f3d2ef88905c20b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 31 Aug 2021 16:39:55 +0900 Subject: kbuild: factor out OBJECT_FILES_NON_STANDARD check into a macro The OBJECT_FILES_NON_STANDARD check is quite long. Factor it out into a new macro, objtool-enabled, to not repeat it. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers Reviewed-by: Kees Cook Acked-by: Josh Poimboeuf --- scripts/Makefile.build | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 021ae0146913..720a86642f48 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -241,12 +241,12 @@ ifndef CONFIG_LTO_CLANG # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file -cmd_objtool = $(if $(patsubst y%,, \ - $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \ - ; $(objtool) $(objtool_args) $@) -objtool_obj = $(if $(patsubst y%,, \ - $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \ - $(objtool)) + +objtool-enabled = $(if $(filter-out y%, \ + $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y) + +cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) +objtool_obj = $(if $(objtool-enabled), $(objtool)) endif # CONFIG_LTO_CLANG endif # CONFIG_STACK_VALIDATION -- cgit v1.2.3 From ef62588c2c8611c196b780561610921b7b864bb2 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 31 Aug 2021 16:39:56 +0900 Subject: kbuild: detect objtool update without using .SECONDEXPANSION Redo commit 8852c5524029 ("kbuild: Fix objtool dependency for 'OBJECT_FILES_NON_STANDARD_ := n'") to add the objtool dependency in a cleaner way. Using .SECONDEXPANSION ends up with unreadable code due to escaped dollars. Also, it is not efficient because the second half of Makefile.build is parsed twice every time. Append the objtool dependency to the *.cmd files at the build time. This is what fixdep and gen_ksymdeps.sh already do. So, following the same pattern seems a natural solution. This allows us to drop $$(objtool_dep) entirely. Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook Reviewed-by: Nick Desaulniers Acked-by: Josh Poimboeuf --- scripts/Makefile.build | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 720a86642f48..21b55f37a23f 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -246,14 +246,11 @@ objtool-enabled = $(if $(filter-out y%, \ $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y) cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) -objtool_obj = $(if $(objtool-enabled), $(objtool)) +cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd) endif # CONFIG_LTO_CLANG endif # CONFIG_STACK_VALIDATION -# Rebuild all objects when objtool changes -objtool_dep = $(objtool_obj) - ifdef CONFIG_TRIM_UNUSED_KSYMS cmd_gen_ksymdeps = \ $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd @@ -267,6 +264,7 @@ define rule_cc_o_c $(call cmd,gen_ksymdeps) $(call cmd,checksrc) $(call cmd,checkdoc) + $(call cmd,gen_objtooldep) $(call cmd,modversions_c) $(call cmd,record_mcount) endef @@ -274,12 +272,12 @@ endef define rule_as_o_S $(call cmd_and_fixdep,as_o_S) $(call cmd,gen_ksymdeps) + $(call cmd,gen_objtooldep) $(call cmd,modversions_S) endef # Built-in and composite module parts -.SECONDEXPANSION: -$(obj)/%.o: $(src)/%.c $(recordmcount_source) $$(objtool_dep) FORCE +$(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE $(call if_changed_rule,cc_o_c) $(call cmd,force_checksrc) @@ -380,7 +378,7 @@ cmd_modversions_S = \ fi endif -$(obj)/%.o: $(src)/%.S $$(objtool_dep) FORCE +$(obj)/%.o: $(src)/%.S FORCE $(call if_changed_rule,as_o_S) targets += $(filter-out $(subdir-builtin), $(real-obj-y)) -- cgit v1.2.3 From 90a353491e9f95516fcfd33ae7331d638557416c Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 31 Aug 2021 16:39:57 +0900 Subject: kbuild: reuse $(cmd_objtool) for cmd_cc_lto_link_modules For CONFIG_LTO_CLANG=y, the objtool processing is not possible at the compilation, hence postponed by the link time. Reuse $(cmd_objtool) for CONFIG_LTO_CLANG=y by defining objtool-enabled properly. For CONFIG_LTO_CLANG=y: objtool-enabled is off for %.o compilation objtool-enabled is on for %.lto link For CONFIG_LTO_CLANG=n: objtool-enabled is on for %.o compilation (but, it depends on OBJECT_FILE_NON_STANDARD) Set part-of-module := y for %.lto.o to avoid repeating --module. Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook Acked-by: Josh Poimboeuf --- scripts/Makefile.build | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 21b55f37a23f..78656b527fe5 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -236,20 +236,26 @@ objtool_args = \ $(if $(CONFIG_X86_SMAP), --uaccess) \ $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) -ifndef CONFIG_LTO_CLANG +cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) +cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd) + +endif # CONFIG_STACK_VALIDATION + +ifdef CONFIG_LTO_CLANG + +# Skip objtool for LLVM bitcode +$(obj)/%.o: objtool-enabled := + +else # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file -objtool-enabled = $(if $(filter-out y%, \ +$(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \ $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y) -cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) -cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd) - -endif # CONFIG_LTO_CLANG -endif # CONFIG_STACK_VALIDATION +endif ifdef CONFIG_TRIM_UNUSED_KSYMS cmd_gen_ksymdeps = \ @@ -289,13 +295,13 @@ cmd_cc_lto_link_modules = \ $(LD) $(ld_flags) -r -o $@ \ $(shell [ -s $(@:.lto.o=.o.symversions) ] && \ echo -T $(@:.lto.o=.o.symversions)) \ - --whole-archive $(filter-out FORCE,$^) + --whole-archive $(filter-out FORCE,$^) \ + $(cmd_objtool) -ifdef CONFIG_STACK_VALIDATION # objtool was skipped for LLVM bitcode, run it now that we have compiled # modules into native code -cmd_cc_lto_link_modules += ; $(objtool) $(objtool_args) --module $@ -endif +$(obj)/%.lto.o: objtool-enabled = y +$(obj)/%.lto.o: part-of-module := y $(obj)/%.lto.o: $(obj)/%.o FORCE $(call if_changed,cc_lto_link_modules) -- cgit v1.2.3 From d05377e184fc88e965e20606da93387b8fadf493 Mon Sep 17 00:00:00 2001 From: Ariel Marcovitch Date: Mon, 13 Sep 2021 19:45:14 +0300 Subject: kconfig: Create links to main menu items in search When one searches for a main menu item, links aren't created for it like with the rest of the symbols. This happens because we trace the item until we get to the rootmenu, but we don't include it in the path of the item. The rationale was probably that we don't want to show the main menu in the path of all items, because it is redundant. However, when an item has only the rootmenu in its path it should be included, because this way the user can jump to its location. Add a 'Main menu' entry in the 'Location:' section for the kconfig items. This makes the 'if (i > 0)' superfluous because each item with prompt will have at least one menu in its path. Signed-off-by: Ariel Marcovitch Signed-off-by: Masahiro Yamada --- scripts/kconfig/menu.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 606ba8a63c24..3d6f7cba8846 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -728,7 +728,7 @@ static void get_prompt_str(struct gstr *r, struct property *prop, get_dep_str(r, prop->visible.expr, " Visible if: "); menu = prop->menu->parent; - for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent) { + for (i = 0; menu && i < 8; menu = menu->parent) { bool accessible = menu_is_visible(menu); submenu[i++] = menu; @@ -758,21 +758,24 @@ static void get_prompt_str(struct gstr *r, struct property *prop, list_add_tail(&jump->entries, head); } - if (i > 0) { - str_printf(r, " Location:\n"); - for (j = 4; --i >= 0; j += 2) { - menu = submenu[i]; - if (jump && menu == location) - jump->offset = strlen(r->s); - str_printf(r, "%*c-> %s", j, ' ', - menu_get_prompt(menu)); - if (menu->sym) { - str_printf(r, " (%s [=%s])", menu->sym->name ? - menu->sym->name : "", - sym_get_string_value(menu->sym)); - } - str_append(r, "\n"); + str_printf(r, " Location:\n"); + for (j = 4; --i >= 0; j += 2) { + menu = submenu[i]; + if (jump && menu == location) + jump->offset = strlen(r->s); + + if (menu == &rootmenu) + /* The real rootmenu prompt is ugly */ + str_printf(r, "%*cMain menu", j, ' '); + else + str_printf(r, "%*c-> %s", j, ' ', menu_get_prompt(menu)); + + if (menu->sym) { + str_printf(r, " (%s [=%s])", menu->sym->name ? + menu->sym->name : "", + sym_get_string_value(menu->sym)); } + str_append(r, "\n"); } } -- cgit v1.2.3 From 65017d8381e2425a1b4cdc4681fadc179635c000 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 27 Sep 2021 21:54:36 +0900 Subject: kconfig: narrow the scope of variables in the lexer The variables, "ts" and "i", are used locally in the action of the [ \t]+ pattern in the start state. Define them where they are used. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lexer.l | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index 312cbad2d34d..efe487859308 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -85,7 +85,6 @@ n [A-Za-z0-9_-] %% int str = 0; - int ts, i; #.* /* ignore comment */ [ \t]* /* whitespaces */ @@ -196,6 +195,8 @@ n [A-Za-z0-9_-] { [ \t]+ { + int ts, i; + ts = 0; for (i = 0; i < yyleng; i++) { if (yytext[i] == '\t') -- cgit v1.2.3 From 6988f70cf105e70b4ea424d320521a9ed452fe46 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 27 Sep 2021 21:54:37 +0900 Subject: kconfig: rename a variable in the lexer to a clearer name In Kconfig, like Python, you can enclose a string by double-quotes or single-quotes. So, both "foo" and 'foo' are allowed. The variable, "str", is used to remember whether the string started with a double-quote or a single-quote because open/closing quotation marks must match. The name "str" is too generic to understand the intent. Rename it to "open_quote", which is easier to understand. The type should be 'char'. Signed-off-by: Masahiro Yamada Reviewed-by: Boris Kolpackov --- scripts/kconfig/lexer.l | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index efe487859308..cc386e443683 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -84,7 +84,7 @@ static void warn_ignored_character(char chr) n [A-Za-z0-9_-] %% - int str = 0; + char open_quote = 0; #.* /* ignore comment */ [ \t]* /* whitespaces */ @@ -133,7 +133,7 @@ n [A-Za-z0-9_-] ":=" return T_COLON_EQUAL; "+=" return T_PLUS_EQUAL; \"|\' { - str = yytext[0]; + open_quote = yytext[0]; new_string(); BEGIN(STRING); } @@ -170,7 +170,7 @@ n [A-Za-z0-9_-] append_string(yytext + 1, yyleng - 1); } \'|\" { - if (str == yytext[0]) { + if (open_quote == yytext[0]) { BEGIN(INITIAL); yylval.string = text; return T_WORD_QUOTE; -- cgit v1.2.3 From 229d0cfae5b21bfc42525cf43b0b4279243acc4e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 1 Oct 2021 14:32:44 +0900 Subject: kconfig: remove 'const' from the return type of sym_escape_string_value() sym_escape_string_value() returns a malloc'ed memory, but as (const char *). So, it must be casted to (void *) when it is free'd. This is odd. The return type of sym_escape_string_value() should be (char *). I exploited that free(NULL) has no effect. Signed-off-by: Masahiro Yamada --- scripts/kconfig/conf.c | 15 +++++++-------- scripts/kconfig/confdata.c | 27 ++++++++++++++------------- scripts/kconfig/lkc_proto.h | 2 +- scripts/kconfig/symbol.c | 3 ++- 4 files changed, 24 insertions(+), 23 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 5d84b44a2a2a..310fdd408793 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -647,17 +647,16 @@ static void check_conf(struct menu *menu) switch (input_mode) { case listnewconfig: if (sym->name) { - const char *str; + const char *val = sym_get_string_value(sym); + char *escaped = NULL; if (sym->type == S_STRING) { - str = sym_get_string_value(sym); - str = sym_escape_string_value(str); - printf("%s%s=%s\n", CONFIG_, sym->name, str); - free((void *)str); - } else { - str = sym_get_string_value(sym); - printf("%s%s=%s\n", CONFIG_, sym->name, str); + escaped = sym_escape_string_value(val); + val = escaped; } + + printf("%s%s=%s\n", CONFIG_, sym->name, val); + free(escaped); } break; case helpnewconfig: diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index cf72680cd769..9b2271eb43d6 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -728,21 +728,22 @@ static struct conf_printer header_printer_cb = static void conf_write_symbol(FILE *fp, struct symbol *sym, struct conf_printer *printer, void *printer_arg) { - const char *str; + const char *val; + char *escaped = NULL; - switch (sym->type) { - case S_UNKNOWN: - break; - case S_STRING: - str = sym_get_string_value(sym); - str = sym_escape_string_value(str); - printer->print_symbol(fp, sym, str, printer_arg); - free((void *)str); - break; - default: - str = sym_get_string_value(sym); - printer->print_symbol(fp, sym, str, printer_arg); + if (sym->type == S_UNKNOWN) + return; + + val = sym_get_string_value(sym); + + if (sym->type == S_STRING) { + escaped = sym_escape_string_value(val); + val = escaped; } + + printer->print_symbol(fp, sym, val, printer_arg); + + free(escaped); } static void diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index a11626bdc421..e6955df49973 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -18,7 +18,7 @@ extern struct symbol * symbol_hash[SYMBOL_HASHSIZE]; struct symbol * sym_lookup(const char *name, int flags); struct symbol * sym_find(const char *name); -const char * sym_escape_string_value(const char *in); +char *sym_escape_string_value(const char *in); struct symbol ** sym_re_search(const char *pattern); const char * sym_type_name(enum symbol_type type); void sym_calc_value(struct symbol *sym); diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 5844d636d38f..6bf8665a6a0f 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -871,7 +871,8 @@ struct symbol *sym_find(const char *name) return symbol; } -const char *sym_escape_string_value(const char *in) +/* The returned pointer must be freed on the caller side */ +char *sym_escape_string_value(const char *in) { const char *p; size_t reslen; -- cgit v1.2.3 From ca51b26b4a25b05c9b438ed85c4750bfb6f2d9ab Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 1 Oct 2021 14:32:45 +0900 Subject: kconfig: refactor conf_write_heading() All the call sites of conf_write_heading() pass NULL to the third argument, and it is not used in the function. Also, the print_comment hooks are doing much more complex than needed. Rewrite the code. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 95 ++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 62 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 9b2271eb43d6..83e324b9b5e5 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -161,7 +161,6 @@ static int conf_touch_dep(const char *name) struct conf_printer { void (*print_symbol)(FILE *, struct symbol *, const char *, void *); - void (*print_comment)(FILE *, const char *, void *); }; static void conf_warning(const char *fmt, ...) @@ -594,6 +593,36 @@ int conf_read(const char *name) return 0; } +struct comment_style { + const char *decoration; + const char *prefix; + const char *postfix; +}; + +static const struct comment_style comment_style_pound = { + .decoration = "#", + .prefix = "#", + .postfix = "#", +}; + +static const struct comment_style comment_style_c = { + .decoration = " *", + .prefix = "/*", + .postfix = " */", +}; + +static void conf_write_heading(FILE *fp, const struct comment_style *cs) +{ + fprintf(fp, "%s\n", cs->prefix); + + fprintf(fp, "%s Automatically generated file; DO NOT EDIT.\n", + cs->decoration); + + fprintf(fp, "%s %s\n", cs->decoration, rootmenu.prompt->text); + + fprintf(fp, "%s\n", cs->postfix); +} + /* * Kconfig configuration printer * @@ -625,30 +654,9 @@ kconfig_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, value); } -static void -kconfig_print_comment(FILE *fp, const char *value, void *arg) -{ - const char *p = value; - size_t l; - - for (;;) { - l = strcspn(p, "\n"); - fprintf(fp, "#"); - if (l) { - fprintf(fp, " "); - xfwrite(p, l, 1, fp); - p += l; - } - fprintf(fp, "\n"); - if (*p++ == '\0') - break; - } -} - static struct conf_printer kconfig_printer_cb = { .print_symbol = kconfig_print_symbol, - .print_comment = kconfig_print_comment, }; /* @@ -697,32 +705,9 @@ header_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) } -static void -header_print_comment(FILE *fp, const char *value, void *arg) -{ - const char *p = value; - size_t l; - - fprintf(fp, "/*\n"); - for (;;) { - l = strcspn(p, "\n"); - fprintf(fp, " *"); - if (l) { - fprintf(fp, " "); - xfwrite(p, l, 1, fp); - p += l; - } - fprintf(fp, "\n"); - if (*p++ == '\0') - break; - } - fprintf(fp, " */\n"); -} - static struct conf_printer header_printer_cb = { .print_symbol = header_print_symbol, - .print_comment = header_print_comment, }; static void conf_write_symbol(FILE *fp, struct symbol *sym, @@ -746,20 +731,6 @@ static void conf_write_symbol(FILE *fp, struct symbol *sym, free(escaped); } -static void -conf_write_heading(FILE *fp, struct conf_printer *printer, void *printer_arg) -{ - char buf[256]; - - snprintf(buf, sizeof(buf), - "\n" - "Automatically generated file; DO NOT EDIT.\n" - "%s\n", - rootmenu.prompt->text); - - printer->print_comment(fp, buf, printer_arg); -} - /* * Write out a minimal config. * All values that has default values are skipped as this is redundant. @@ -876,7 +847,7 @@ int conf_write(const char *name) if (!out) return 1; - conf_write_heading(out, &kconfig_printer_cb, NULL); + conf_write_heading(out, &comment_style_pound); if (!conf_get_changed()) sym_clear_all_valid(); @@ -1080,8 +1051,8 @@ int conf_write_autoconf(int overwrite) return 1; } - conf_write_heading(out, &kconfig_printer_cb, NULL); - conf_write_heading(out_h, &header_printer_cb, NULL); + conf_write_heading(out, &comment_style_pound); + conf_write_heading(out_h, &comment_style_c); for_all_symbols(i, sym) { sym_calc_value(sym); -- cgit v1.2.3 From 6ce45a91a9826532dde7c89cd2d6388c0bcb0cf7 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 1 Oct 2021 14:32:46 +0900 Subject: kconfig: refactor conf_write_symbol() I do not think 'struct conf_printer' is so useful. Add simple functions, print_symbol_for_*() to write out one symbol. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 136 +++++++++++++++++++-------------------------- 1 file changed, 57 insertions(+), 79 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 83e324b9b5e5..4e3fd194231b 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -159,10 +160,6 @@ static int conf_touch_dep(const char *name) return 0; } -struct conf_printer { - void (*print_symbol)(FILE *, struct symbol *, const char *, void *); -}; - static void conf_warning(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); @@ -629,91 +626,52 @@ static void conf_write_heading(FILE *fp, const struct comment_style *cs) * This printer is used when generating the resulting configuration after * kconfig invocation and `defconfig' files. Unset symbol might be omitted by * passing a non-NULL argument to the printer. - * */ -static void -kconfig_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) -{ - - switch (sym->type) { - case S_BOOLEAN: - case S_TRISTATE: - if (*value == 'n') { - bool skip_unset = (arg != NULL); - - if (!skip_unset) - fprintf(fp, "# %s%s is not set\n", - CONFIG_, sym->name); - return; - } - break; - default: - break; - } - - fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, value); -} +enum output_n { OUTPUT_N, OUTPUT_N_AS_UNSET, OUTPUT_N_NONE }; -static struct conf_printer kconfig_printer_cb = +static void __print_symbol(FILE *fp, struct symbol *sym, enum output_n output_n, + bool escape_string) { - .print_symbol = kconfig_print_symbol, -}; + const char *val; + char *escaped = NULL; -/* - * Header printer - * - * This printer is used when generating the `include/generated/autoconf.h' file. - */ -static void -header_print_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg) -{ + if (sym->type == S_UNKNOWN) + return; - switch (sym->type) { - case S_BOOLEAN: - case S_TRISTATE: { - const char *suffix = ""; + val = sym_get_string_value(sym); - switch (*value) { - case 'n': - break; - case 'm': - suffix = "_MODULE"; - /* fall through */ - default: - fprintf(fp, "#define %s%s%s 1\n", - CONFIG_, sym->name, suffix); - } - break; + if ((sym->type == S_BOOLEAN || sym->type == S_TRISTATE) && + output_n != OUTPUT_N && *val == 'n') { + if (output_n == OUTPUT_N_AS_UNSET) + fprintf(fp, "# %s%s is not set\n", CONFIG_, sym->name); + return; } - case S_HEX: { - const char *prefix = ""; - if (value[0] != '0' || (value[1] != 'x' && value[1] != 'X')) - prefix = "0x"; - fprintf(fp, "#define %s%s %s%s\n", - CONFIG_, sym->name, prefix, value); - break; - } - case S_STRING: - case S_INT: - fprintf(fp, "#define %s%s %s\n", - CONFIG_, sym->name, value); - break; - default: - break; + if (sym->type == S_STRING && escape_string) { + escaped = sym_escape_string_value(val); + val = escaped; } + fprintf(fp, "%s%s=%s\n", CONFIG_, sym->name, val); + + free(escaped); } -static struct conf_printer header_printer_cb = +static void print_symbol_for_dotconfig(FILE *fp, struct symbol *sym) { - .print_symbol = header_print_symbol, -}; + __print_symbol(fp, sym, OUTPUT_N_AS_UNSET, true); +} + +static void print_symbol_for_autoconf(FILE *fp, struct symbol *sym) +{ + __print_symbol(fp, sym, OUTPUT_N_NONE, true); +} -static void conf_write_symbol(FILE *fp, struct symbol *sym, - struct conf_printer *printer, void *printer_arg) +static void print_symbol_for_c(FILE *fp, struct symbol *sym) { const char *val; + const char *sym_suffix = ""; + const char *val_prefix = ""; char *escaped = NULL; if (sym->type == S_UNKNOWN) @@ -721,12 +679,32 @@ static void conf_write_symbol(FILE *fp, struct symbol *sym, val = sym_get_string_value(sym); - if (sym->type == S_STRING) { + switch (sym->type) { + case S_BOOLEAN: + case S_TRISTATE: + switch (*val) { + case 'n': + return; + case 'm': + sym_suffix = "_MODULE"; + /* fall through */ + default: + val = "1"; + } + break; + case S_HEX: + if (val[0] != '0' || (val[1] != 'x' && val[1] != 'X')) + val_prefix = "0x"; + break; + case S_STRING: escaped = sym_escape_string_value(val); val = escaped; + default: + break; } - printer->print_symbol(fp, sym, val, printer_arg); + fprintf(fp, "#define %s%s%s %s%s\n", CONFIG_, sym->name, sym_suffix, + val_prefix, val); free(escaped); } @@ -787,7 +765,7 @@ int conf_write_defconfig(const char *filename) goto next_menu; } } - conf_write_symbol(out, sym, &kconfig_printer_cb, NULL); + print_symbol_for_dotconfig(out, sym); } next_menu: if (menu->list != NULL) { @@ -874,7 +852,7 @@ int conf_write(const char *name) need_newline = false; } sym->flags |= SYMBOL_WRITTEN; - conf_write_symbol(out, sym, &kconfig_printer_cb, NULL); + print_symbol_for_dotconfig(out, sym); } next: @@ -1060,8 +1038,8 @@ int conf_write_autoconf(int overwrite) continue; /* write symbols to auto.conf and autoconf.h */ - conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1); - conf_write_symbol(out_h, sym, &header_printer_cb, NULL); + print_symbol_for_autoconf(out, sym); + print_symbol_for_c(out_h, sym); } fclose(out); fclose(out_h); -- cgit v1.2.3 From 51d792cb5de87fa8777b4769a33c302e4ad0580a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 1 Oct 2021 14:32:47 +0900 Subject: kconfig: refactor listnewconfig code We can reuse __print_symbol() helper to print symbols for listnewconfig. Only the difference is the format for "n" symbols. This prints "CONFIG_FOO=n" instead of "# CONFIG_FOO is not set". Signed-off-by: Masahiro Yamada --- scripts/kconfig/conf.c | 14 ++------------ scripts/kconfig/confdata.c | 5 +++++ scripts/kconfig/lkc_proto.h | 1 + 3 files changed, 8 insertions(+), 12 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 310fdd408793..971da3598fe4 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -646,18 +646,8 @@ static void check_conf(struct menu *menu) switch (input_mode) { case listnewconfig: - if (sym->name) { - const char *val = sym_get_string_value(sym); - char *escaped = NULL; - - if (sym->type == S_STRING) { - escaped = sym_escape_string_value(val); - val = escaped; - } - - printf("%s%s=%s\n", CONFIG_, sym->name, val); - free(escaped); - } + if (sym->name) + print_symbol_for_listconfig(sym); break; case helpnewconfig: printf("-----\n"); diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 4e3fd194231b..f17a2a9562ee 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -667,6 +667,11 @@ static void print_symbol_for_autoconf(FILE *fp, struct symbol *sym) __print_symbol(fp, sym, OUTPUT_N_NONE, true); } +void print_symbol_for_listconfig(struct symbol *sym) +{ + __print_symbol(stdout, sym, OUTPUT_N, true); +} + static void print_symbol_for_c(FILE *fp, struct symbol *sym) { const char *val; diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index e6955df49973..ec4a01bb60ce 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -19,6 +19,7 @@ extern struct symbol * symbol_hash[SYMBOL_HASHSIZE]; struct symbol * sym_lookup(const char *name, int flags); struct symbol * sym_find(const char *name); char *sym_escape_string_value(const char *in); +void print_symbol_for_listconfig(struct symbol *sym); struct symbol ** sym_re_search(const char *pattern); const char * sym_type_name(enum symbol_type type); void sym_calc_value(struct symbol *sym); -- cgit v1.2.3 From 80f7bc7737630fb1b2c4f440fc7627337bd2f605 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 1 Oct 2021 14:32:48 +0900 Subject: kconfig: move sym_escape_string_value() to confdata.c Now that sym_escape_string_value() is only used in confdata.c it can be a 'static' function. Rename it escape_string_value() because it is agnostic about (struct sym *). Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 47 +++++++++++++++++++++++++++++++++++++++++++-- scripts/kconfig/lkc_proto.h | 1 - scripts/kconfig/symbol.c | 44 ------------------------------------------ 3 files changed, 45 insertions(+), 47 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index f17a2a9562ee..26b39d34e2be 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -620,6 +620,49 @@ static void conf_write_heading(FILE *fp, const struct comment_style *cs) fprintf(fp, "%s\n", cs->postfix); } +/* The returned pointer must be freed on the caller side */ +static char *escape_string_value(const char *in) +{ + const char *p; + char *out; + size_t len; + + len = strlen(in) + strlen("\"\"") + 1; + + p = in; + while (1) { + p += strcspn(p, "\"\\"); + + if (p[0] == '\0') + break; + + len++; + p++; + } + + out = xmalloc(len); + out[0] = '\0'; + + strcat(out, "\""); + + p = in; + while (1) { + len = strcspn(p, "\"\\"); + strncat(out, p, len); + p += len; + + if (p[0] == '\0') + break; + + strcat(out, "\\"); + strncat(out, p++, 1); + } + + strcat(out, "\""); + + return out; +} + /* * Kconfig configuration printer * @@ -648,7 +691,7 @@ static void __print_symbol(FILE *fp, struct symbol *sym, enum output_n output_n, } if (sym->type == S_STRING && escape_string) { - escaped = sym_escape_string_value(val); + escaped = escape_string_value(val); val = escaped; } @@ -702,7 +745,7 @@ static void print_symbol_for_c(FILE *fp, struct symbol *sym) val_prefix = "0x"; break; case S_STRING: - escaped = sym_escape_string_value(val); + escaped = escape_string_value(val); val = escaped; default: break; diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index ec4a01bb60ce..edd1e617b25c 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -18,7 +18,6 @@ extern struct symbol * symbol_hash[SYMBOL_HASHSIZE]; struct symbol * sym_lookup(const char *name, int flags); struct symbol * sym_find(const char *name); -char *sym_escape_string_value(const char *in); void print_symbol_for_listconfig(struct symbol *sym); struct symbol ** sym_re_search(const char *pattern); const char * sym_type_name(enum symbol_type type); diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 6bf8665a6a0f..0572330bf8a7 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -871,50 +871,6 @@ struct symbol *sym_find(const char *name) return symbol; } -/* The returned pointer must be freed on the caller side */ -char *sym_escape_string_value(const char *in) -{ - const char *p; - size_t reslen; - char *res; - size_t l; - - reslen = strlen(in) + strlen("\"\"") + 1; - - p = in; - for (;;) { - l = strcspn(p, "\"\\"); - p += l; - - if (p[0] == '\0') - break; - - reslen++; - p++; - } - - res = xmalloc(reslen); - res[0] = '\0'; - - strcat(res, "\""); - - p = in; - for (;;) { - l = strcspn(p, "\"\\"); - strncat(res, p, l); - p += l; - - if (p[0] == '\0') - break; - - strcat(res, "\\"); - strncat(res, p++, 1); - } - - strcat(res, "\""); - return res; -} - struct sym_match { struct symbol *sym; off_t so, eo; -- cgit v1.2.3 From 8499f2dd57ef099290fa5411c4498bccc9c407d9 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 1 Oct 2021 14:32:49 +0900 Subject: kconfig: add conf_get_autoheader_name() For consistency with conf_get_autoconfig_name() Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 26b39d34e2be..acf3d5a2973e 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -223,6 +223,13 @@ static const char *conf_get_autoconfig_name(void) return name ? name : "include/config/auto.conf"; } +static const char *conf_get_autoheader_name(void) +{ + char *name = getenv("KCONFIG_AUTOHEADER"); + + return name ? name : "include/generated/autoconf.h"; +} + static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p) { char *p2; @@ -1092,9 +1099,7 @@ int conf_write_autoconf(int overwrite) fclose(out); fclose(out_h); - name = getenv("KCONFIG_AUTOHEADER"); - if (!name) - name = "include/generated/autoconf.h"; + name = conf_get_autoheader_name(); if (make_parent_dir(name)) return 1; if (rename(".tmpconfig.h", name)) -- cgit v1.2.3 From 57ddd07c456053dfdabebc6a2d030c57cd3fb75b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 1 Oct 2021 14:32:50 +0900 Subject: kconfig: refactor conf_write_autoconf() This function does similar for auto.conf and autoconf.h Create __conf_write_autoconf() helper to factor out the common code. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 94 ++++++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 37 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index acf3d5a2973e..7301f4b2f4d5 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -1058,13 +1058,53 @@ static int conf_touch_deps(void) return 0; } +static int __conf_write_autoconf(const char *filename, + void (*print_symbol)(FILE *, struct symbol *), + const struct comment_style *comment_style) +{ + char tmp[PATH_MAX]; + FILE *file; + struct symbol *sym; + int ret, i; + + if (make_parent_dir(filename)) + return -1; + + ret = snprintf(tmp, sizeof(tmp), "%s.tmp", filename); + if (ret >= sizeof(tmp)) /* check truncation */ + return -1; + + file = fopen(tmp, "w"); + if (!file) { + perror("fopen"); + return -1; + } + + conf_write_heading(file, comment_style); + + for_all_symbols(i, sym) + if ((sym->flags & SYMBOL_WRITE) && sym->name) + print_symbol(file, sym); + + /* check possible errors in conf_write_heading() and print_symbol() */ + if (ferror(file)) + return -1; + + fclose(file); + + if (rename(tmp, filename)) { + perror("rename"); + return -1; + } + + return 0; +} + int conf_write_autoconf(int overwrite) { struct symbol *sym; - const char *name; const char *autoconf_name = conf_get_autoconfig_name(); - FILE *out, *out_h; - int i; + int ret, i; if (!overwrite && is_present(autoconf_name)) return 0; @@ -1074,45 +1114,25 @@ int conf_write_autoconf(int overwrite) if (conf_touch_deps()) return 1; - out = fopen(".tmpconfig", "w"); - if (!out) - return 1; - - out_h = fopen(".tmpconfig.h", "w"); - if (!out_h) { - fclose(out); - return 1; - } - - conf_write_heading(out, &comment_style_pound); - conf_write_heading(out_h, &comment_style_c); - - for_all_symbols(i, sym) { + for_all_symbols(i, sym) sym_calc_value(sym); - if (!(sym->flags & SYMBOL_WRITE) || !sym->name) - continue; - /* write symbols to auto.conf and autoconf.h */ - print_symbol_for_autoconf(out, sym); - print_symbol_for_c(out_h, sym); - } - fclose(out); - fclose(out_h); - - name = conf_get_autoheader_name(); - if (make_parent_dir(name)) - return 1; - if (rename(".tmpconfig.h", name)) - return 1; + ret = __conf_write_autoconf(conf_get_autoheader_name(), + print_symbol_for_c, + &comment_style_c); + if (ret) + return ret; - if (make_parent_dir(autoconf_name)) - return 1; /* - * This must be the last step, kbuild has a dependency on auto.conf - * and this marks the successful completion of the previous steps. + * Create include/config/auto.conf. This must be the last step because + * Kbuild has a dependency on auto.conf and this marks the successful + * completion of the previous steps. */ - if (rename(".tmpconfig", autoconf_name)) - return 1; + ret = __conf_write_autoconf(conf_get_autoconfig_name(), + print_symbol_for_autoconf, + &comment_style_pound); + if (ret) + return ret; return 0; } -- cgit v1.2.3 From 00d674cb35362dd30df7ff1e0003ad6d6c3ebf3a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 1 Oct 2021 14:32:51 +0900 Subject: kconfig: refactor conf_write_dep() The if ... else inside the for-loop is unneeded because one empty line is placed after printing the last element of deps_config. Currently, all errors in conf_write_dep() are ignored. Add proper error checks. Rename it to conf_write_autoconf_cmd(), which is more intuitive. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 54 +++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 17 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 7301f4b2f4d5..6ac53bf7aa64 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -957,32 +957,50 @@ next: } /* write a dependency file as used by kbuild to track dependencies */ -static int conf_write_dep(const char *name) +static int conf_write_autoconf_cmd(const char *autoconf_name) { + char name[PATH_MAX], tmp[PATH_MAX]; struct file *file; FILE *out; + int ret; - out = fopen("..config.tmp", "w"); - if (!out) - return 1; - fprintf(out, "deps_config := \\\n"); - for (file = file_list; file; file = file->next) { - if (file->next) - fprintf(out, "\t%s \\\n", file->name); - else - fprintf(out, "\t%s\n", file->name); + ret = snprintf(name, sizeof(name), "%s.cmd", autoconf_name); + if (ret >= sizeof(name)) /* check truncation */ + return -1; + + if (make_parent_dir(name)) + return -1; + + ret = snprintf(tmp, sizeof(tmp), "%s.cmd.tmp", autoconf_name); + if (ret >= sizeof(tmp)) /* check truncation */ + return -1; + + out = fopen(tmp, "w"); + if (!out) { + perror("fopen"); + return -1; } - fprintf(out, "\n%s: \\\n" - "\t$(deps_config)\n\n", conf_get_autoconfig_name()); - env_write_dep(out, conf_get_autoconfig_name()); + fprintf(out, "deps_config := \\\n"); + for (file = file_list; file; file = file->next) + fprintf(out, "\t%s \\\n", file->name); + + fprintf(out, "\n%s: $(deps_config)\n\n", autoconf_name); + + env_write_dep(out, autoconf_name); fprintf(out, "\n$(deps_config): ;\n"); + + if (ferror(out)) /* error check for all fprintf() calls */ + return -1; + fclose(out); - if (make_parent_dir(name)) - return 1; - rename("..config.tmp", name); + if (rename(tmp, name)) { + perror("rename"); + return -1; + } + return 0; } @@ -1109,7 +1127,9 @@ int conf_write_autoconf(int overwrite) if (!overwrite && is_present(autoconf_name)) return 0; - conf_write_dep("include/config/auto.conf.cmd"); + ret = conf_write_autoconf_cmd(autoconf_name); + if (ret) + return -1; if (conf_touch_deps()) return 1; -- cgit v1.2.3 From fee762d69ad5968dfd0ecbc300810f185ee5c5b8 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 1 Oct 2021 14:32:52 +0900 Subject: kconfig: refactor conf_touch_dep() If this function fails to touch a dummy header due to missing parent directory, then it creates it and touches the file again. This was needed because CONFIG_FOO_BAR was previously tracked by include/config/foo/bar.h. (include/config/foo/ may not exist here) This is no longer the case since commit 0e0345b77ac4 ("kbuild: redo fake deps at include/config/*.h"); now all the fake headers are placed right under include/config/, like include/config/FOO_BAR. Do not try to create parent directory, include/config/, which already exists. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 6ac53bf7aa64..42bc56ee238c 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -130,31 +130,17 @@ static size_t depfile_prefix_len; /* touch depfile for symbol 'name' */ static int conf_touch_dep(const char *name) { - int fd, ret; - char *d; + int fd; /* check overflow: prefix + name + '\0' must fit in buffer. */ if (depfile_prefix_len + strlen(name) + 1 > sizeof(depfile_path)) return -1; - d = depfile_path + depfile_prefix_len; - strcpy(d, name); + strcpy(depfile_path + depfile_prefix_len, name); - /* Assume directory path already exists. */ fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (fd == -1) { - if (errno != ENOENT) - return -1; - - ret = make_parent_dir(depfile_path); - if (ret) - return ret; - - /* Try it again. */ - fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (fd == -1) - return -1; - } + if (fd == -1) + return -1; close(fd); return 0; -- cgit v1.2.3 From 2216cf68cf56808323bff44d43083422a1c4e2f9 Mon Sep 17 00:00:00 2001 From: Hui Su Date: Fri, 8 Oct 2021 19:24:38 +0800 Subject: scripts: update the comments of kallsyms support update the comments of kallsyms support. Fixes: af73d78bd384 ("kbuild: Remove debug info from kallsyms linking") Signed-off-by: Hui Su Signed-off-by: Masahiro Yamada --- scripts/link-vmlinux.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index d74cee5c4326..a98c4f045302 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -369,14 +369,14 @@ if [ -n "${CONFIG_KALLSYMS}" ]; then # kallsyms support # Generate section listing all symbols and add it into vmlinux # It's a three step process: - # 1) Link .tmp_vmlinux1 so it has all symbols and sections, + # 1) Link .tmp_vmlinux.kallsyms1 so it has all symbols and sections, # but __kallsyms is empty. # Running kallsyms on that gives us .tmp_kallsyms1.o with # the right size - # 2) Link .tmp_vmlinux2 so it now has a __kallsyms section of + # 2) Link .tmp_vmlinux.kallsyms2 so it now has a __kallsyms section of # the right size, but due to the added section, some # addresses have shifted. - # From here, we generate a correct .tmp_kallsyms2.o + # From here, we generate a correct .tmp_vmlinux.kallsyms2.o # 3) That link may have expanded the kernel image enough that # more linker branch stubs / trampolines had to be added, which # introduces new names, which further expands kallsyms. Do another -- cgit v1.2.3 From 88f5e1e66253fc4acd3f68eb4d356fa4653a7bf9 Mon Sep 17 00:00:00 2001 From: Paweł Jasiak Date: Fri, 8 Oct 2021 13:37:59 +0200 Subject: kbuild: Add make tarzst-pkg build option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add tarzst-pkg and perf-tarzst-src-pkg targets to build zstd compressed tarballs. Signed-off-by: Paweł Jasiak Signed-off-by: Masahiro Yamada --- scripts/Makefile.package | 10 +++++++--- scripts/package/buildtar | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.package b/scripts/Makefile.package index b74c65284fb2..77b612183c08 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -103,7 +103,7 @@ snap-pkg: # tarball targets # --------------------------------------------------------------------------- -tar-pkgs := dir-pkg tar-pkg targz-pkg tarbz2-pkg tarxz-pkg +tar-pkgs := dir-pkg tar-pkg targz-pkg tarbz2-pkg tarxz-pkg tarzst-pkg PHONY += $(tar-pkgs) $(tar-pkgs): $(MAKE) -f $(srctree)/Makefile @@ -130,10 +130,12 @@ $(if $(findstring tar-src,$@),, \ $(if $(findstring bz2,$@),$(KBZIP2), \ $(if $(findstring gz,$@),$(KGZIP), \ $(if $(findstring xz,$@),$(XZ), \ -$(error unknown target $@)))) \ +$(if $(findstring zst,$@),$(ZSTD), \ +$(error unknown target $@))))) \ -f -9 $(perf-tar).tar) -perf-tar-pkgs := perf-tar-src-pkg perf-targz-src-pkg perf-tarbz2-src-pkg perf-tarxz-src-pkg +perf-tar-pkgs := perf-tar-src-pkg perf-targz-src-pkg perf-tarbz2-src-pkg \ + perf-tarxz-src-pkg perf-tarzst-src-pkg PHONY += $(perf-tar-pkgs) $(perf-tar-pkgs): $(call cmd,perf_tar) @@ -153,9 +155,11 @@ help: @echo ' targz-pkg - Build the kernel as a gzip compressed tarball' @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball' @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball' + @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball' @echo ' perf-tar-src-pkg - Build $(perf-tar).tar source tarball' @echo ' perf-targz-src-pkg - Build $(perf-tar).tar.gz source tarball' @echo ' perf-tarbz2-src-pkg - Build $(perf-tar).tar.bz2 source tarball' @echo ' perf-tarxz-src-pkg - Build $(perf-tar).tar.xz source tarball' + @echo ' perf-tarzst-src-pkg - Build $(perf-tar).tar.zst source tarball' .PHONY: $(PHONY) diff --git a/scripts/package/buildtar b/scripts/package/buildtar index 221aa7df008d..cb54c7f1aa80 100755 --- a/scripts/package/buildtar +++ b/scripts/package/buildtar @@ -39,6 +39,10 @@ case "${1}" in opts="-I ${XZ}" tarball=${tarball}.xz ;; + tarzst-pkg) + opts="-I ${ZSTD}" + tarball=${tarball}.zst + ;; *) echo "Unknown tarball target \"${1}\" requested, please add it to ${0}." >&2 exit 1 -- cgit v1.2.3 From 6947fd96ae9bbe8c8c473a2199fd3edfd8b9f8c8 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 12 Oct 2021 12:25:03 +0900 Subject: kbuild: split DEBUG_CFLAGS out to scripts/Makefile.debug To slim down the top Makefile, split out the code block surrounded by ifdef CONFIG_DEBUG_INFO ... endif. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers Reviewed-by: Sedat Dilek --- Makefile | 39 +-------------------------------------- scripts/Makefile.debug | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 38 deletions(-) create mode 100644 scripts/Makefile.debug (limited to 'scripts') diff --git a/Makefile b/Makefile index ee5896261d2f..8e3224470dc1 100644 --- a/Makefile +++ b/Makefile @@ -847,44 +847,6 @@ ifdef CONFIG_ZERO_CALL_USED_REGS KBUILD_CFLAGS += -fzero-call-used-regs=used-gpr endif -DEBUG_CFLAGS := - -ifdef CONFIG_DEBUG_INFO - -ifdef CONFIG_DEBUG_INFO_SPLIT -DEBUG_CFLAGS += -gsplit-dwarf -else -DEBUG_CFLAGS += -g -endif - -ifndef CONFIG_AS_IS_LLVM -KBUILD_AFLAGS += -Wa,-gdwarf-2 -endif - -ifndef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT -dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4 -dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5 -DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y) -endif - -ifdef CONFIG_DEBUG_INFO_REDUCED -DEBUG_CFLAGS += -fno-var-tracking -ifdef CONFIG_CC_IS_GCC -DEBUG_CFLAGS += -femit-struct-debug-baseonly -endif -endif - -ifdef CONFIG_DEBUG_INFO_COMPRESSED -DEBUG_CFLAGS += -gz=zlib -KBUILD_AFLAGS += -gz=zlib -KBUILD_LDFLAGS += --compress-debug-sections=zlib -endif - -endif # CONFIG_DEBUG_INFO - -KBUILD_CFLAGS += $(DEBUG_CFLAGS) -export DEBUG_CFLAGS - ifdef CONFIG_FUNCTION_TRACER ifdef CONFIG_FTRACE_MCOUNT_USE_CC CC_FLAGS_FTRACE += -mrecord-mcount @@ -1033,6 +995,7 @@ KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) # include additional Makefiles when needed include-y := scripts/Makefile.extrawarn +include-$(CONFIG_DEBUG_INFO) += scripts/Makefile.debug include-$(CONFIG_KASAN) += scripts/Makefile.kasan include-$(CONFIG_KCSAN) += scripts/Makefile.kcsan include-$(CONFIG_UBSAN) += scripts/Makefile.ubsan diff --git a/scripts/Makefile.debug b/scripts/Makefile.debug new file mode 100644 index 000000000000..9f39b0130551 --- /dev/null +++ b/scripts/Makefile.debug @@ -0,0 +1,33 @@ +DEBUG_CFLAGS := + +ifdef CONFIG_DEBUG_INFO_SPLIT +DEBUG_CFLAGS += -gsplit-dwarf +else +DEBUG_CFLAGS += -g +endif + +ifndef CONFIG_AS_IS_LLVM +KBUILD_AFLAGS += -Wa,-gdwarf-2 +endif + +ifndef CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF4) := 4 +dwarf-version-$(CONFIG_DEBUG_INFO_DWARF5) := 5 +DEBUG_CFLAGS += -gdwarf-$(dwarf-version-y) +endif + +ifdef CONFIG_DEBUG_INFO_REDUCED +DEBUG_CFLAGS += -fno-var-tracking +ifdef CONFIG_CC_IS_GCC +DEBUG_CFLAGS += -femit-struct-debug-baseonly +endif +endif + +ifdef CONFIG_DEBUG_INFO_COMPRESSED +DEBUG_CFLAGS += -gz=zlib +KBUILD_AFLAGS += -gz=zlib +KBUILD_LDFLAGS += --compress-debug-sections=zlib +endif + +KBUILD_CFLAGS += $(DEBUG_CFLAGS) +export DEBUG_CFLAGS -- cgit v1.2.3