From e3fd9b5384f37e55261ebd261ad97951a44ece50 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 4 Jul 2018 10:59:23 +0900 Subject: scripts/dtc: consolidate include path options in Makefile It is tedious to specify extra compiler options for every file. HOST_EXTRACFLAGS is useful to add options to all files in a directory. -I$(src)/libfdt is needed for all the files in this directory to include libfdt_env.h etc. from scripts/dtc/libfdt/. On the other hand, -I$(src) is used to include check-in headers from generated C files. Thus, I added it only to dtc-lexer.lex.o and dtc-parser.tab.o . Signed-off-by: Masahiro Yamada Reviewed-by: Rob Herring --- scripts/dtc/Makefile | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'scripts') diff --git a/scripts/dtc/Makefile b/scripts/dtc/Makefile index 9cac65b7419c..1c943e03eaf2 100644 --- a/scripts/dtc/Makefile +++ b/scripts/dtc/Makefile @@ -9,21 +9,11 @@ dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \ dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o # Source files need to get at the userspace version of libfdt_env.h to compile +HOST_EXTRACFLAGS := -I$(src)/libfdt -HOSTCFLAGS_DTC := -I$(src) -I$(src)/libfdt - -HOSTCFLAGS_checks.o := $(HOSTCFLAGS_DTC) -HOSTCFLAGS_data.o := $(HOSTCFLAGS_DTC) -HOSTCFLAGS_dtc.o := $(HOSTCFLAGS_DTC) -HOSTCFLAGS_flattree.o := $(HOSTCFLAGS_DTC) -HOSTCFLAGS_fstree.o := $(HOSTCFLAGS_DTC) -HOSTCFLAGS_livetree.o := $(HOSTCFLAGS_DTC) -HOSTCFLAGS_srcpos.o := $(HOSTCFLAGS_DTC) -HOSTCFLAGS_treesource.o := $(HOSTCFLAGS_DTC) -HOSTCFLAGS_util.o := $(HOSTCFLAGS_DTC) - -HOSTCFLAGS_dtc-lexer.lex.o := $(HOSTCFLAGS_DTC) -HOSTCFLAGS_dtc-parser.tab.o := $(HOSTCFLAGS_DTC) +# Generated files need one more search path to include headers in source tree +HOSTCFLAGS_dtc-lexer.lex.o := -I$(src) +HOSTCFLAGS_dtc-parser.tab.o := -I$(src) # dependencies on generated files need to be listed explicitly $(obj)/dtc-lexer.lex.o: $(obj)/dtc-parser.tab.h -- cgit v1.2.3-59-g8ed1b From 4bf6a9af0e9107926d1fb0112e7f9acb0d798cb4 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Tue, 14 Aug 2018 17:36:49 -0700 Subject: kconfig: add build-only configurator targets Add build-only targets for build_menuconfig, build_nconfig, build_xconfig, and build_gconfig. (targets must end in "config" to qualify in top-level Makefile) This allows these target to be built without execution (e.g., to look for errors or warnings) and/or to be built and checked by sparse. Signed-off-by: Randy Dunlap Signed-off-by: Masahiro Yamada --- scripts/kconfig/Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index 8d8791069abf..f7bdcc9a6433 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile @@ -3,7 +3,8 @@ # Kernel configuration targets # These targets are used from top-level makefile -PHONY += xconfig gconfig menuconfig config localmodconfig localyesconfig +PHONY += xconfig gconfig menuconfig config localmodconfig localyesconfig \ + build_menuconfig build_nconfig build_gconfig build_xconfig ifdef KBUILD_KCONFIG Kconfig := $(KBUILD_KCONFIG) @@ -33,6 +34,14 @@ config: $(obj)/conf nconfig: $(obj)/nconf $< $(silent) $(Kconfig) +build_menuconfig: $(obj)/mconf + +build_nconfig: $(obj)/nconf + +build_gconfig: $(obj)/gconf + +build_xconfig: $(obj)/qconf + localyesconfig localmodconfig: $(obj)/conf $(Q)perl $(srctree)/$(src)/streamline_config.pl --$@ $(srctree) $(Kconfig) > .tmp.config $(Q)if [ -f .config ]; then \ -- cgit v1.2.3-59-g8ed1b From f1575595d15657bd78c139978107deabec5a3959 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 15 Aug 2018 14:59:43 +0900 Subject: kconfig: error out when seeing recursive dependency Originally, recursive dependency was a fatal error for Kconfig because Kconfig cannot compute symbol values in such a situation. Commit d595cea62403 ("kconfig: print more info when we see a recursive dependency") changed it to a warning, which I guess was not intentional. Get it back to an error again. Also, rename the unit test directory "warn_recursive_dep" to "err_recursive_dep" so that it matches to the behavior. Signed-off-by: Masahiro Yamada Tested-by: Dirk Gouders --- scripts/kconfig/symbol.c | 3 -- scripts/kconfig/tests/err_recursive_dep/Kconfig | 62 ++++++++++++++++++++++ .../kconfig/tests/err_recursive_dep/__init__.py | 10 ++++ .../tests/err_recursive_dep/expected_stderr | 30 +++++++++++ scripts/kconfig/tests/warn_recursive_dep/Kconfig | 62 ---------------------- .../kconfig/tests/warn_recursive_dep/__init__.py | 9 ---- .../tests/warn_recursive_dep/expected_stderr | 30 ----------- 7 files changed, 102 insertions(+), 104 deletions(-) create mode 100644 scripts/kconfig/tests/err_recursive_dep/Kconfig create mode 100644 scripts/kconfig/tests/err_recursive_dep/__init__.py create mode 100644 scripts/kconfig/tests/err_recursive_dep/expected_stderr delete mode 100644 scripts/kconfig/tests/warn_recursive_dep/Kconfig delete mode 100644 scripts/kconfig/tests/warn_recursive_dep/__init__.py delete mode 100644 scripts/kconfig/tests/warn_recursive_dep/expected_stderr (limited to 'scripts') diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 4ec8b1f0d42c..688f487ff454 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -1248,9 +1248,6 @@ struct symbol *sym_check_deps(struct symbol *sym) sym->flags &= ~SYMBOL_CHECK; } - if (sym2 && sym2 == sym) - sym2 = NULL; - return sym2; } diff --git a/scripts/kconfig/tests/err_recursive_dep/Kconfig b/scripts/kconfig/tests/err_recursive_dep/Kconfig new file mode 100644 index 000000000000..a65bfcb7137e --- /dev/null +++ b/scripts/kconfig/tests/err_recursive_dep/Kconfig @@ -0,0 +1,62 @@ +# depends on itself + +config A + bool "A" + depends on A + +# select itself + +config B + bool + select B + +# depends on each other + +config C1 + bool "C1" + depends on C2 + +config C2 + bool "C2" + depends on C1 + +# depends on and select + +config D1 + bool "D1" + depends on D2 + select D2 + +config D2 + bool + +# depends on and imply +# This is not recursive dependency + +config E1 + bool "E1" + depends on E2 + imply E2 + +config E2 + bool "E2" + +# property + +config F1 + bool "F1" + default F2 + +config F2 + bool "F2" + depends on F1 + +# menu + +menu "menu depending on its content" + depends on G + +config G + bool "G" + +endmenu diff --git a/scripts/kconfig/tests/err_recursive_dep/__init__.py b/scripts/kconfig/tests/err_recursive_dep/__init__.py new file mode 100644 index 000000000000..5f3821b43ce6 --- /dev/null +++ b/scripts/kconfig/tests/err_recursive_dep/__init__.py @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 +""" +Detect recursive dependency error. + +Recursive dependency should be treated as an error. +""" + +def test(conf): + assert conf.oldaskconfig() == 1 + assert conf.stderr_contains('expected_stderr') diff --git a/scripts/kconfig/tests/err_recursive_dep/expected_stderr b/scripts/kconfig/tests/err_recursive_dep/expected_stderr new file mode 100644 index 000000000000..3de807dd9cb2 --- /dev/null +++ b/scripts/kconfig/tests/err_recursive_dep/expected_stderr @@ -0,0 +1,30 @@ +Kconfig:9:error: recursive dependency detected! +Kconfig:9: symbol B is selected by B +For a resolution refer to Documentation/kbuild/kconfig-language.txt +subsection "Kconfig recursive dependency limitations" + +Kconfig:3:error: recursive dependency detected! +Kconfig:3: symbol A depends on A +For a resolution refer to Documentation/kbuild/kconfig-language.txt +subsection "Kconfig recursive dependency limitations" + +Kconfig:15:error: recursive dependency detected! +Kconfig:15: symbol C1 depends on C2 +Kconfig:19: symbol C2 depends on C1 +For a resolution refer to Documentation/kbuild/kconfig-language.txt +subsection "Kconfig recursive dependency limitations" + +Kconfig:30:error: recursive dependency detected! +Kconfig:30: symbol D2 is selected by D1 +Kconfig:25: symbol D1 depends on D2 +For a resolution refer to Documentation/kbuild/kconfig-language.txt +subsection "Kconfig recursive dependency limitations" + +Kconfig:59:error: recursive dependency detected! +Kconfig:59: symbol G depends on G +For a resolution refer to Documentation/kbuild/kconfig-language.txt +subsection "Kconfig recursive dependency limitations" + +Kconfig:50:error: recursive dependency detected! +Kconfig:50: symbol F2 depends on F1 +Kconfig:48: symbol F1 default value contains F2 diff --git a/scripts/kconfig/tests/warn_recursive_dep/Kconfig b/scripts/kconfig/tests/warn_recursive_dep/Kconfig deleted file mode 100644 index a65bfcb7137e..000000000000 --- a/scripts/kconfig/tests/warn_recursive_dep/Kconfig +++ /dev/null @@ -1,62 +0,0 @@ -# depends on itself - -config A - bool "A" - depends on A - -# select itself - -config B - bool - select B - -# depends on each other - -config C1 - bool "C1" - depends on C2 - -config C2 - bool "C2" - depends on C1 - -# depends on and select - -config D1 - bool "D1" - depends on D2 - select D2 - -config D2 - bool - -# depends on and imply -# This is not recursive dependency - -config E1 - bool "E1" - depends on E2 - imply E2 - -config E2 - bool "E2" - -# property - -config F1 - bool "F1" - default F2 - -config F2 - bool "F2" - depends on F1 - -# menu - -menu "menu depending on its content" - depends on G - -config G - bool "G" - -endmenu diff --git a/scripts/kconfig/tests/warn_recursive_dep/__init__.py b/scripts/kconfig/tests/warn_recursive_dep/__init__.py deleted file mode 100644 index adb21951ba41..000000000000 --- a/scripts/kconfig/tests/warn_recursive_dep/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -""" -Warn recursive inclusion. - -Recursive dependency should be warned. -""" - -def test(conf): - assert conf.oldaskconfig() == 0 - assert conf.stderr_contains('expected_stderr') diff --git a/scripts/kconfig/tests/warn_recursive_dep/expected_stderr b/scripts/kconfig/tests/warn_recursive_dep/expected_stderr deleted file mode 100644 index 3de807dd9cb2..000000000000 --- a/scripts/kconfig/tests/warn_recursive_dep/expected_stderr +++ /dev/null @@ -1,30 +0,0 @@ -Kconfig:9:error: recursive dependency detected! -Kconfig:9: symbol B is selected by B -For a resolution refer to Documentation/kbuild/kconfig-language.txt -subsection "Kconfig recursive dependency limitations" - -Kconfig:3:error: recursive dependency detected! -Kconfig:3: symbol A depends on A -For a resolution refer to Documentation/kbuild/kconfig-language.txt -subsection "Kconfig recursive dependency limitations" - -Kconfig:15:error: recursive dependency detected! -Kconfig:15: symbol C1 depends on C2 -Kconfig:19: symbol C2 depends on C1 -For a resolution refer to Documentation/kbuild/kconfig-language.txt -subsection "Kconfig recursive dependency limitations" - -Kconfig:30:error: recursive dependency detected! -Kconfig:30: symbol D2 is selected by D1 -Kconfig:25: symbol D1 depends on D2 -For a resolution refer to Documentation/kbuild/kconfig-language.txt -subsection "Kconfig recursive dependency limitations" - -Kconfig:59:error: recursive dependency detected! -Kconfig:59: symbol G depends on G -For a resolution refer to Documentation/kbuild/kconfig-language.txt -subsection "Kconfig recursive dependency limitations" - -Kconfig:50:error: recursive dependency detected! -Kconfig:50: symbol F2 depends on F1 -Kconfig:48: symbol F1 default value contains F2 -- cgit v1.2.3-59-g8ed1b From 5e8c5299d31519e0327be1020f309fa62dc53036 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 15 Aug 2018 14:59:44 +0900 Subject: kconfig: report recursive dependency involving 'imply' Currently, Kconfig does not complain about the recursive dependency where 'imply' keywords are involved. [Test Code] config A bool "a" config B bool "b" imply A depends on A In the code above, Kconfig cannot calculate the symbol values correctly due to the circular dependency. For example, allyesconfig followed by syncconfig results in an odd behavior because CONFIG_B becomes visible in syncconfig. $ make allyesconfig scripts/kconfig/conf --allyesconfig Kconfig # # configuration written to .config # $ cat .config # # Automatically generated file; DO NOT EDIT. # Main menu # CONFIG_A=y $ make syncconfig scripts/kconfig/conf --syncconfig Kconfig * * Restart config... * * * Main menu * a (A) [Y/n/?] y b (B) [N/y/?] (NEW) To detect this correctly, sym_check_expr_deps() should recurse to not only sym->rev_dep.expr but also sym->implied.expr . At this moment, sym_check_print_recursive() cannot distinguish 'select' and 'imply' since it does not know the precise context where the recursive dependency has been hit. This will be solved by the next commit. In fact, even the document and the unit-test are confused. Using 'imply' does not solve recursive dependency since 'imply' addresses the unmet direct dependency, which 'select' could cause. Signed-off-by: Masahiro Yamada Tested-by: Dirk Gouders --- Documentation/kbuild/kconfig-language.txt | 3 +- scripts/kconfig/symbol.c | 9 +++-- scripts/kconfig/tests/err_recursive_dep/Kconfig | 3 +- .../tests/err_recursive_dep/expected_stderr | 38 +++++++++++++--------- 4 files changed, 33 insertions(+), 20 deletions(-) (limited to 'scripts') diff --git a/Documentation/kbuild/kconfig-language.txt b/Documentation/kbuild/kconfig-language.txt index c54cb7cb9ff4..864e740811da 100644 --- a/Documentation/kbuild/kconfig-language.txt +++ b/Documentation/kbuild/kconfig-language.txt @@ -545,7 +545,7 @@ make KBUILD_KCONFIG=Documentation/kbuild/Kconfig.recursion-issue-02 allnoconfig Practical solutions to kconfig recursive issue ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Developers who run into the recursive Kconfig issue have three options +Developers who run into the recursive Kconfig issue have two options at their disposal. We document them below and also provide a list of historical issues resolved through these different solutions. @@ -553,7 +553,6 @@ historical issues resolved through these different solutions. b) Match dependency semantics: b1) Swap all "select FOO" to "depends on FOO" or, b2) Swap all "depends on FOO" to "select FOO" - c) Consider the use of "imply" instead of "select" The resolution to a) can be tested with the sample Kconfig file Documentation/kbuild/Kconfig.recursion-issue-01 through the removal diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 688f487ff454..90e706096af8 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -1098,7 +1098,7 @@ static void sym_check_print_recursive(struct symbol *last_sym) sym->name ? sym->name : "", next_sym->name ? next_sym->name : ""); } else { - fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n", + fprintf(stderr, "%s:%d:\tsymbol %s is selected or implied by %s\n", prop->file->name, prop->lineno, sym->name ? sym->name : "", next_sym->name ? next_sym->name : ""); @@ -1161,8 +1161,13 @@ static struct symbol *sym_check_sym_deps(struct symbol *sym) if (sym2) goto out; + sym2 = sym_check_expr_deps(sym->implied.expr); + if (sym2) + goto out; + for (prop = sym->prop; prop; prop = prop->next) { - if (prop->type == P_CHOICE || prop->type == P_SELECT) + if (prop->type == P_CHOICE || prop->type == P_SELECT || + prop->type == P_IMPLY) continue; stack.prop = prop; sym2 = sym_check_expr_deps(prop->visible.expr); diff --git a/scripts/kconfig/tests/err_recursive_dep/Kconfig b/scripts/kconfig/tests/err_recursive_dep/Kconfig index a65bfcb7137e..ebdb3ffd8717 100644 --- a/scripts/kconfig/tests/err_recursive_dep/Kconfig +++ b/scripts/kconfig/tests/err_recursive_dep/Kconfig @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + # depends on itself config A @@ -31,7 +33,6 @@ config D2 bool # depends on and imply -# This is not recursive dependency config E1 bool "E1" diff --git a/scripts/kconfig/tests/err_recursive_dep/expected_stderr b/scripts/kconfig/tests/err_recursive_dep/expected_stderr index 3de807dd9cb2..2eb25288db8c 100644 --- a/scripts/kconfig/tests/err_recursive_dep/expected_stderr +++ b/scripts/kconfig/tests/err_recursive_dep/expected_stderr @@ -1,30 +1,38 @@ -Kconfig:9:error: recursive dependency detected! -Kconfig:9: symbol B is selected by B +Kconfig:11:error: recursive dependency detected! +Kconfig:11: symbol B is selected or implied by B For a resolution refer to Documentation/kbuild/kconfig-language.txt subsection "Kconfig recursive dependency limitations" -Kconfig:3:error: recursive dependency detected! -Kconfig:3: symbol A depends on A +Kconfig:5:error: recursive dependency detected! +Kconfig:5: symbol A depends on A For a resolution refer to Documentation/kbuild/kconfig-language.txt subsection "Kconfig recursive dependency limitations" -Kconfig:15:error: recursive dependency detected! -Kconfig:15: symbol C1 depends on C2 -Kconfig:19: symbol C2 depends on C1 +Kconfig:17:error: recursive dependency detected! +Kconfig:17: symbol C1 depends on C2 +Kconfig:21: symbol C2 depends on C1 For a resolution refer to Documentation/kbuild/kconfig-language.txt subsection "Kconfig recursive dependency limitations" -Kconfig:30:error: recursive dependency detected! -Kconfig:30: symbol D2 is selected by D1 -Kconfig:25: symbol D1 depends on D2 +Kconfig:32:error: recursive dependency detected! +Kconfig:32: symbol D2 is selected or implied by D1 +Kconfig:27: symbol D1 depends on D2 For a resolution refer to Documentation/kbuild/kconfig-language.txt subsection "Kconfig recursive dependency limitations" -Kconfig:59:error: recursive dependency detected! -Kconfig:59: symbol G depends on G +Kconfig:37:error: recursive dependency detected! +Kconfig:37: symbol E1 depends on E2 +Kconfig:42: symbol E2 is selected or implied by E1 For a resolution refer to Documentation/kbuild/kconfig-language.txt subsection "Kconfig recursive dependency limitations" -Kconfig:50:error: recursive dependency detected! -Kconfig:50: symbol F2 depends on F1 -Kconfig:48: symbol F1 default value contains F2 +Kconfig:60:error: recursive dependency detected! +Kconfig:60: symbol G depends on G +For a resolution refer to Documentation/kbuild/kconfig-language.txt +subsection "Kconfig recursive dependency limitations" + +Kconfig:51:error: recursive dependency detected! +Kconfig:51: symbol F2 depends on F1 +Kconfig:49: symbol F1 default value contains F2 +For a resolution refer to Documentation/kbuild/kconfig-language.txt +subsection "Kconfig recursive dependency limitations" -- cgit v1.2.3-59-g8ed1b From f498926c47aa7d4f1b6d08af2ba16f3cf8fcb151 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 15 Aug 2018 14:59:45 +0900 Subject: kconfig: improve the recursive dependency report This commit improves the messages of the recursive dependency. Currently, sym->dir_dep.expr is not checked. Hence, any dependency in property visibility is regarded as the dependency of the symbol. [Test Code 1] config A bool "a" depends on B config B bool "b" depends on A [Test Code 2] config A bool "a" if B config B bool "b" depends on A For both cases above, the same message is displayed: symbol B depends on A symbol A depends on B This commit changes the message for the latter, like this: symbol B depends on A symbol A prompt is visible depending on B Also, 'select' and 'imply' are distinguished. Signed-off-by: Masahiro Yamada Tested-by: Dirk Gouders --- scripts/kconfig/symbol.c | 48 +++++++++++++++------- .../tests/err_recursive_dep/expected_stderr | 6 +-- 2 files changed, 37 insertions(+), 17 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 90e706096af8..703b9b899ee9 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -1011,7 +1011,7 @@ static struct dep_stack { struct dep_stack *prev, *next; struct symbol *sym; struct property *prop; - struct expr *expr; + struct expr **expr; } *check_top; static void dep_stack_insert(struct dep_stack *stack, struct symbol *sym) @@ -1076,31 +1076,42 @@ static void sym_check_print_recursive(struct symbol *last_sym) fprintf(stderr, "%s:%d:error: recursive dependency detected!\n", prop->file->name, prop->lineno); - if (stack->expr) { - fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n", - prop->file->name, prop->lineno, + if (sym_is_choice(sym)) { + fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n", + menu->file->name, menu->lineno, + sym->name ? sym->name : "", + next_sym->name ? next_sym->name : ""); + } else if (sym_is_choice_value(sym)) { + fprintf(stderr, "%s:%d:\tsymbol %s is part of choice %s\n", + menu->file->name, menu->lineno, sym->name ? sym->name : "", - prop_get_type_name(prop->type), next_sym->name ? next_sym->name : ""); - } else if (stack->prop) { + } else if (stack->expr == &sym->dir_dep.expr) { fprintf(stderr, "%s:%d:\tsymbol %s depends on %s\n", prop->file->name, prop->lineno, sym->name ? sym->name : "", next_sym->name ? next_sym->name : ""); - } else if (sym_is_choice(sym)) { - fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n", - menu->file->name, menu->lineno, + } else if (stack->expr == &sym->rev_dep.expr) { + fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n", + prop->file->name, prop->lineno, sym->name ? sym->name : "", next_sym->name ? next_sym->name : ""); - } else if (sym_is_choice_value(sym)) { - fprintf(stderr, "%s:%d:\tsymbol %s is part of choice %s\n", - menu->file->name, menu->lineno, + } else if (stack->expr == &sym->implied.expr) { + fprintf(stderr, "%s:%d:\tsymbol %s is implied by %s\n", + prop->file->name, prop->lineno, sym->name ? sym->name : "", next_sym->name ? next_sym->name : ""); + } else if (stack->expr) { + fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n", + prop->file->name, prop->lineno, + sym->name ? sym->name : "", + prop_get_type_name(prop->type), + next_sym->name ? next_sym->name : ""); } else { - fprintf(stderr, "%s:%d:\tsymbol %s is selected or implied by %s\n", + fprintf(stderr, "%s:%d:\tsymbol %s %s is visible depending on %s\n", prop->file->name, prop->lineno, sym->name ? sym->name : "", + prop_get_type_name(prop->type), next_sym->name ? next_sym->name : ""); } } @@ -1157,14 +1168,23 @@ static struct symbol *sym_check_sym_deps(struct symbol *sym) dep_stack_insert(&stack, sym); + stack.expr = &sym->dir_dep.expr; + sym2 = sym_check_expr_deps(sym->dir_dep.expr); + if (sym2) + goto out; + + stack.expr = &sym->rev_dep.expr; sym2 = sym_check_expr_deps(sym->rev_dep.expr); if (sym2) goto out; + stack.expr = &sym->implied.expr; sym2 = sym_check_expr_deps(sym->implied.expr); if (sym2) goto out; + stack.expr = NULL; + for (prop = sym->prop; prop; prop = prop->next) { if (prop->type == P_CHOICE || prop->type == P_SELECT || prop->type == P_IMPLY) @@ -1175,7 +1195,7 @@ static struct symbol *sym_check_sym_deps(struct symbol *sym) break; if (prop->type != P_DEFAULT || sym_is_choice(sym)) continue; - stack.expr = prop->expr; + stack.expr = &prop->expr; sym2 = sym_check_expr_deps(prop->expr); if (sym2) break; diff --git a/scripts/kconfig/tests/err_recursive_dep/expected_stderr b/scripts/kconfig/tests/err_recursive_dep/expected_stderr index 2eb25288db8c..84679b104655 100644 --- a/scripts/kconfig/tests/err_recursive_dep/expected_stderr +++ b/scripts/kconfig/tests/err_recursive_dep/expected_stderr @@ -1,5 +1,5 @@ Kconfig:11:error: recursive dependency detected! -Kconfig:11: symbol B is selected or implied by B +Kconfig:11: symbol B is selected by B For a resolution refer to Documentation/kbuild/kconfig-language.txt subsection "Kconfig recursive dependency limitations" @@ -15,14 +15,14 @@ For a resolution refer to Documentation/kbuild/kconfig-language.txt subsection "Kconfig recursive dependency limitations" Kconfig:32:error: recursive dependency detected! -Kconfig:32: symbol D2 is selected or implied by D1 +Kconfig:32: symbol D2 is selected by D1 Kconfig:27: symbol D1 depends on D2 For a resolution refer to Documentation/kbuild/kconfig-language.txt subsection "Kconfig recursive dependency limitations" Kconfig:37:error: recursive dependency detected! Kconfig:37: symbol E1 depends on E2 -Kconfig:42: symbol E2 is selected or implied by E1 +Kconfig:42: symbol E2 is implied by E1 For a resolution refer to Documentation/kbuild/kconfig-language.txt subsection "Kconfig recursive dependency limitations" -- cgit v1.2.3-59-g8ed1b From 1f3aa9002dc6a0d59a4b599b4fc8f01cf43ef014 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Wed, 15 Aug 2018 12:30:38 -0700 Subject: scripts: modpost: check memory allocation results Fix missing error check for memory allocation functions in scripts/mod/modpost.c. Fixes kernel bugzilla #200319: https://bugzilla.kernel.org/show_bug.cgi?id=200319 Signed-off-by: Randy Dunlap Cc: Yuexing Wang Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index dc6d714e4dcb..0d998c54564d 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -672,7 +672,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info, if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER) break; if (symname[0] == '.') { - char *munged = strdup(symname); + char *munged = NOFAIL(strdup(symname)); munged[0] = '_'; munged[1] = toupper(munged[1]); symname = munged; @@ -1318,7 +1318,7 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr, static char *sec2annotation(const char *s) { if (match(s, init_exit_sections)) { - char *p = malloc(20); + char *p = NOFAIL(malloc(20)); char *r = p; *p++ = '_'; @@ -1338,7 +1338,7 @@ static char *sec2annotation(const char *s) strcat(p, " "); return r; } else { - return strdup(""); + return NOFAIL(strdup("")); } } @@ -2036,7 +2036,7 @@ void buf_write(struct buffer *buf, const char *s, int len) { if (buf->size - buf->pos < len) { buf->size += len + SZ; - buf->p = realloc(buf->p, buf->size); + buf->p = NOFAIL(realloc(buf->p, buf->size)); } strncpy(buf->p + buf->pos, s, len); buf->pos += len; -- cgit v1.2.3-59-g8ed1b From b5f8cb9e908f46feaa5d0ddbf3e2e1b8d85d1a65 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Wed, 15 Aug 2018 17:13:50 -0700 Subject: kbuild: Add a space after `!` to prevent parsing as file pattern Some shells use !(pattern|...|pattern) to match file names not containing the specified patterns. This may result in output like $ ./scripts/clang-version.sh gcc ./scripts/clang-version.sh[18]: COPYING: not found printf: %d __clang_major__: conversion error printf: %d __clang_minor__: conversion error printf: %d __clang_patchlevel__: conversion error 00000 $ and set CONFIG_CLANG_VERSION to the invalid value '00000'. POSIX says[0] If the pipeline begins with the reserved word ! and command1 is a subshell command, the application shall ensure that the ( operator at the beginning of command1 is separated from the ! by one or more characters. The behavior of the reserved word ! immediately followed by the ( operator is unspecified. So, just add a to prevent this. [0] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_02 Signed-off-by: Michael Forney Signed-off-by: Masahiro Yamada --- scripts/clang-version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/clang-version.sh b/scripts/clang-version.sh index dbf0a31eb111..e65fbc3079d4 100755 --- a/scripts/clang-version.sh +++ b/scripts/clang-version.sh @@ -12,7 +12,7 @@ compiler="$*" -if !( $compiler --version | grep -q clang) ; then +if ! ( $compiler --version | grep -q clang) ; then echo 0 exit 1 fi -- cgit v1.2.3-59-g8ed1b From 98a4afbfafd226636cd6bb6a1208b3693daff2b1 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 16 Aug 2018 13:36:48 +0900 Subject: kconfig: fix "Can't open ..." in parallel build If you run "make menuconfig" or "make nconfig" with -j option in a fresh source tree, you will see several "Can't open ..." messages: $ make -j8 menuconfig HOSTCC scripts/basic/fixdep YACC scripts/kconfig/zconf.tab.c LEX scripts/kconfig/zconf.lex.c /bin/sh: 1: .: Can't open scripts/kconfig/.mconf-cfg /bin/sh: 1: .: Can't open scripts/kconfig/.mconf-cfg /bin/sh: 1: .: Can't open scripts/kconfig/.mconf-cfg /bin/sh: 1: .: HOSTCC scripts/kconfig/lxdialog/checklist.o Can't open scripts/kconfig/.mconf-cfg /bin/sh: 1: .: Can't open scripts/kconfig/.mconf-cfg /bin/sh: 1: .: Can't open scripts/kconfig/.mconf-cfg /bin/sh: 1: .: Can't open scripts/kconfig/.mconf-cfg HOSTCC scripts/kconfig/lxdialog/inputbox.o /bin/sh: 1: .: Can't open scripts/kconfig/.mconf-cfg /bin/sh: 1: .: Can't open scripts/kconfig/.mconf-cfg /bin/sh: 1: .: Can't open scripts/kconfig/.mconf-cfg UPD scripts/kconfig/.mconf-cfg /bin/sh: 1: .: Can't open scripts/kconfig/.mconf-cfg HOSTCC scripts/kconfig/lxdialog/menubox.o HOSTCC scripts/kconfig/lxdialog/textbox.o HOSTCC scripts/kconfig/lxdialog/util.o HOSTCC scripts/kconfig/lxdialog/yesno.o HOSTCC scripts/kconfig/mconf.o HOSTCC scripts/kconfig/zconf.tab.o HOSTLD scripts/kconfig/mconf Correct dependencies to fix this problem. Fixes: 1c5af5cf9308 ("kconfig: refactor ncurses package checks for building mconf and nconf") Cc: linux-stable # v4.18 Reported-by: Borislav Petkov Signed-off-by: Masahiro Yamada Tested-by: Borislav Petkov --- scripts/kconfig/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index f7bdcc9a6433..4a7bd2192073 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile @@ -178,7 +178,7 @@ HOSTLDLIBS_nconf = $(shell . $(obj)/.nconf-cfg && echo $$libs) HOSTCFLAGS_nconf.o = $(shell . $(obj)/.nconf-cfg && echo $$cflags) HOSTCFLAGS_nconf.gui.o = $(shell . $(obj)/.nconf-cfg && echo $$cflags) -$(obj)/nconf.o: $(obj)/.nconf-cfg +$(obj)/nconf.o $(obj)/nconf.gui.o: $(obj)/.nconf-cfg # mconf: Used for the menuconfig target based on lxdialog hostprogs-y += mconf @@ -189,7 +189,8 @@ HOSTLDLIBS_mconf = $(shell . $(obj)/.mconf-cfg && echo $$libs) $(foreach f, mconf.o $(lxdialog), \ $(eval HOSTCFLAGS_$f = $$(shell . $(obj)/.mconf-cfg && echo $$$$cflags))) -$(addprefix $(obj)/, mconf.o $(lxdialog)): $(obj)/.mconf-cfg +$(obj)/mconf.o: $(obj)/.mconf-cfg +$(addprefix $(obj)/lxdialog/, $(lxdialog)): $(obj)/.mconf-cfg # qconf: Used for the xconfig target based on Qt hostprogs-y += qconf -- cgit v1.2.3-59-g8ed1b From 9a9ddcf478319bff313837ca235c557d16133b3d Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 16 Aug 2018 16:48:26 +0900 Subject: kconfig: suppress "configuration written to .config" for syncconfig The top-level Makefile invokes "make syncconfig" when necessary. Then, Kconfig displays the following message when .config is updated. # # configuration written to .config # It is distracting because "make syncconfig" happens during the build stage, and does nothing important in most cases. Suggested-by: Linus Torvalds Signed-off-by: Masahiro Yamada --- scripts/kconfig/conf.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'scripts') diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index b35cc9303979..7b2b37260669 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -508,6 +508,11 @@ int main(int ac, char **av) input_mode = (enum input_mode)opt; switch (opt) { case syncconfig: + /* + * syncconfig is invoked during the build stage. + * Suppress distracting "configuration written to ..." + */ + conf_set_message_callback(NULL); sync_kconfig = 1; break; case defconfig: -- cgit v1.2.3-59-g8ed1b From f55f2328bb28a8517620518c5d124f5194673309 Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Fri, 17 Aug 2018 14:03:19 +0200 Subject: kbuild: make sorting initramfs contents independent of locale Some LANG values (e.g. pl_PL.UTF-8) cause the sort command to output files before their parent directories, which makes them inaccessible for the kernel. In other words, when the kernel populates the rootfs, it is unable to create files whose parent directories have not been yet created. This patch makes sorting use the default (LANG=C) locale, which results in correctly laid out initramfs images (parent directories before files). Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Masahiro Yamada --- scripts/gen_initramfs_list.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/gen_initramfs_list.sh b/scripts/gen_initramfs_list.sh index 10e528b3a08f..0aad760fcd8c 100755 --- a/scripts/gen_initramfs_list.sh +++ b/scripts/gen_initramfs_list.sh @@ -174,7 +174,7 @@ dir_filelist() { ${dep_list}header "$1" srcdir=$(echo "$1" | sed -e 's://*:/:g') - dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" | sort) + dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" | LANG=C sort) # If $dirlist is only one line, then the directory is empty if [ "$(echo "${dirlist}" | wc -l)" -gt 1 ]; then -- cgit v1.2.3-59-g8ed1b From 6fbd856950b41345ad5c893613efebdc0c356bc7 Mon Sep 17 00:00:00 2001 From: zhong jiang Date: Sat, 18 Aug 2018 21:51:12 +0800 Subject: Coccinelle: remove pci_alloc_consistent semantic to detect in zalloc-simple.cocci Because pci_alloc_consistent has been deprecated. We prefer to use dma_alloc_coherent directly. Therefore, we should remove pci_alloc_consistent to increase the confidence. Acked-by: Julia Lawall Acked-by: Himanshu Jha Signed-off-by: zhong jiang Signed-off-by: Masahiro Yamada --- scripts/coccinelle/api/alloc/zalloc-simple.cocci | 41 +----------------------- 1 file changed, 1 insertion(+), 40 deletions(-) (limited to 'scripts') diff --git a/scripts/coccinelle/api/alloc/zalloc-simple.cocci b/scripts/coccinelle/api/alloc/zalloc-simple.cocci index 92b20913055f..d819275b7fde 100644 --- a/scripts/coccinelle/api/alloc/zalloc-simple.cocci +++ b/scripts/coccinelle/api/alloc/zalloc-simple.cocci @@ -35,8 +35,7 @@ statement S; * x = (T)\(kmalloc(E1, ...)\|vmalloc(E1)\|dma_alloc_coherent(...,E1,...)\| kmalloc_node(E1, ...)\|kmem_cache_alloc(...)\|kmem_alloc(E1, ...)\| - devm_kmalloc(...,E1,...)\|kvmalloc(E1, ...)\|pci_alloc_consistent(...,E1,...)\| - kvmalloc_node(E1,...)\); + devm_kmalloc(...,E1,...)\|kvmalloc(E1, ...)\|kvmalloc_node(E1,...)\); if ((x==NULL) || ...) S * memset((T2)x,0,E1); @@ -124,15 +123,6 @@ statement S; - x = (T)kvmalloc(E1,E2); + x = (T)kvzalloc(E1,E2); | -- x = pci_alloc_consistent(E2,E1,E3); -+ x = pci_zalloc_consistent(E2,E1,E3); -| -- x = (T *)pci_alloc_consistent(E2,E1,E3); -+ x = pci_zalloc_consistent(E2,E1,E3); -| -- x = (T)pci_alloc_consistent(E2,E1,E3); -+ x = (T)pci_zalloc_consistent(E2,E1,E3); -| - x = kvmalloc_node(E1,E2,E3); + x = kvzalloc_node(E1,E2,E3); | @@ -388,35 +378,6 @@ x << r7.x; msg="WARNING: kvzalloc should be used for %s, instead of kvmalloc/memset" % (x) coccilib.report.print_report(p[0], msg) -//----------------------------------------------------------------- -@r8 depends on org || report@ -type T, T2; -expression x; -expression E1,E2,E3; -statement S; -position p; -@@ - - x = (T)pci_alloc_consistent@p(E2,E1,E3); - if ((x==NULL) || ...) S - memset((T2)x,0,E1); - -@script:python depends on org@ -p << r8.p; -x << r8.x; -@@ - -msg="%s" % (x) -msg_safe=msg.replace("[","@(").replace("]",")") -coccilib.org.print_todo(p[0], msg_safe) - -@script:python depends on report@ -p << r8.p; -x << r8.x; -@@ - -msg="WARNING: pci_zalloc_consistent should be used for %s, instead of pci_alloc_consistent/memset" % (x) -coccilib.report.print_report(p[0], msg) //----------------------------------------------------------------- @r9 depends on org || report@ type T, T2; -- cgit v1.2.3-59-g8ed1b From f6f57a46435d7253a52a1a07a58183678ad266a0 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 21 Aug 2018 00:29:51 +0900 Subject: initramfs: move gen_initramfs_list.sh from scripts/ to usr/ scripts/gen_initramfs_list.sh is only invoked from usr/Makefile. Move it so that all tools to create initramfs are self-contained in the usr/ directory. Signed-off-by: Masahiro Yamada --- Documentation/early-userspace/README | 6 +- .../filesystems/ramfs-rootfs-initramfs.txt | 2 +- scripts/gen_initramfs_list.sh | 328 --------------------- usr/Makefile | 2 +- usr/gen_initramfs_list.sh | 328 +++++++++++++++++++++ 5 files changed, 333 insertions(+), 333 deletions(-) delete mode 100755 scripts/gen_initramfs_list.sh create mode 100755 usr/gen_initramfs_list.sh (limited to 'scripts') diff --git a/Documentation/early-userspace/README b/Documentation/early-userspace/README index 2c00b072a4c8..1e1057958dd3 100644 --- a/Documentation/early-userspace/README +++ b/Documentation/early-userspace/README @@ -66,17 +66,17 @@ early userspace image can be built by an unprivileged user. As a technical note, when directories and files are specified, the entire CONFIG_INITRAMFS_SOURCE is passed to -scripts/gen_initramfs_list.sh. This means that CONFIG_INITRAMFS_SOURCE +usr/gen_initramfs_list.sh. This means that CONFIG_INITRAMFS_SOURCE can really be interpreted as any legal argument to gen_initramfs_list.sh. If a directory is specified as an argument then the contents are scanned, uid/gid translation is performed, and usr/gen_init_cpio file directives are output. If a directory is -specified as an argument to scripts/gen_initramfs_list.sh then the +specified as an argument to usr/gen_initramfs_list.sh then the contents of the file are simply copied to the output. All of the output directives from directory scanning and file contents copying are processed by usr/gen_init_cpio. -See also 'scripts/gen_initramfs_list.sh -h'. +See also 'usr/gen_initramfs_list.sh -h'. Where's this all leading? ========================= diff --git a/Documentation/filesystems/ramfs-rootfs-initramfs.txt b/Documentation/filesystems/ramfs-rootfs-initramfs.txt index b176928e6963..79637d227e85 100644 --- a/Documentation/filesystems/ramfs-rootfs-initramfs.txt +++ b/Documentation/filesystems/ramfs-rootfs-initramfs.txt @@ -164,7 +164,7 @@ Documentation/early-userspace/README for more details.) The kernel does not depend on external cpio tools. If you specify a directory instead of a configuration file, the kernel's build infrastructure creates a configuration file from that directory (usr/Makefile calls -scripts/gen_initramfs_list.sh), and proceeds to package up that directory +usr/gen_initramfs_list.sh), and proceeds to package up that directory using the config file (by feeding it to usr/gen_init_cpio, which is created from usr/gen_init_cpio.c). The kernel's build-time cpio creation code is entirely self-contained, and the kernel's boot-time extractor is also diff --git a/scripts/gen_initramfs_list.sh b/scripts/gen_initramfs_list.sh deleted file mode 100755 index 0aad760fcd8c..000000000000 --- a/scripts/gen_initramfs_list.sh +++ /dev/null @@ -1,328 +0,0 @@ -#!/bin/sh -# Copyright (C) Martin Schlemmer -# Copyright (C) 2006 Sam Ravnborg -# -# Released under the terms of the GNU GPL -# -# Generate a cpio packed initramfs. It uses gen_init_cpio to generate -# the cpio archive, and then compresses it. -# The script may also be used to generate the inputfile used for gen_init_cpio -# This script assumes that gen_init_cpio is located in usr/ directory - -# error out on errors -set -e - -usage() { -cat << EOF -Usage: -$0 [-o ] [-u ] [-g ] {-d | } ... - -o Create compressed initramfs file named using - gen_init_cpio and compressor depending on the extension - -u User ID to map to user ID 0 (root). - is only meaningful if is a - directory. "squash" forces all files to uid 0. - -g Group ID to map to group ID 0 (root). - is only meaningful if is a - directory. "squash" forces all files to gid 0. - File list or directory for cpio archive. - If is a .cpio file it will be used - as direct input to initramfs. - -d Output the default cpio list. - -All options except -o and -l may be repeated and are interpreted -sequentially and immediately. -u and -g states are preserved across - options so an explicit "-u 0 -g 0" is required -to reset the root/group mapping. -EOF -} - -# awk style field access -# $1 - field number; rest is argument string -field() { - shift $1 ; echo $1 -} - -list_default_initramfs() { - # echo usr/kinit/kinit - : -} - -default_initramfs() { - cat <<-EOF >> ${output} - # This is a very simple, default initramfs - - dir /dev 0755 0 0 - nod /dev/console 0600 0 0 c 5 1 - dir /root 0700 0 0 - # file /kinit usr/kinit/kinit 0755 0 0 - # slink /init kinit 0755 0 0 - EOF -} - -filetype() { - local argv1="$1" - - # symlink test must come before file test - if [ -L "${argv1}" ]; then - echo "slink" - elif [ -f "${argv1}" ]; then - echo "file" - elif [ -d "${argv1}" ]; then - echo "dir" - elif [ -b "${argv1}" -o -c "${argv1}" ]; then - echo "nod" - elif [ -p "${argv1}" ]; then - echo "pipe" - elif [ -S "${argv1}" ]; then - echo "sock" - else - echo "invalid" - fi - return 0 -} - -list_print_mtime() { - : -} - -print_mtime() { - local my_mtime="0" - - if [ -e "$1" ]; then - my_mtime=$(find "$1" -printf "%T@\n" | sort -r | head -n 1) - fi - - echo "# Last modified: ${my_mtime}" >> ${output} - echo "" >> ${output} -} - -list_parse() { - if [ -L "$1" ]; then - return - fi - echo "$1" | sed 's/:/\\:/g; s/$/ \\/' -} - -# for each file print a line in following format -# -# for links, devices etc the format differs. See gen_init_cpio for details -parse() { - local location="$1" - local name="/${location#${srcdir}}" - # change '//' into '/' - name=$(echo "$name" | sed -e 's://*:/:g') - local mode="$2" - local uid="$3" - local gid="$4" - local ftype=$(filetype "${location}") - # remap uid/gid to 0 if necessary - [ "$root_uid" = "squash" ] && uid=0 || [ "$uid" -eq "$root_uid" ] && uid=0 - [ "$root_gid" = "squash" ] && gid=0 || [ "$gid" -eq "$root_gid" ] && gid=0 - local str="${mode} ${uid} ${gid}" - - [ "${ftype}" = "invalid" ] && return 0 - [ "${location}" = "${srcdir}" ] && return 0 - - case "${ftype}" in - "file") - str="${ftype} ${name} ${location} ${str}" - ;; - "nod") - local dev=`LC_ALL=C ls -l "${location}"` - local maj=`field 5 ${dev}` - local min=`field 6 ${dev}` - maj=${maj%,} - - [ -b "${location}" ] && dev="b" || dev="c" - - str="${ftype} ${name} ${str} ${dev} ${maj} ${min}" - ;; - "slink") - local target=`readlink "${location}"` - str="${ftype} ${name} ${target} ${str}" - ;; - *) - str="${ftype} ${name} ${str}" - ;; - esac - - echo "${str}" >> ${output} - - return 0 -} - -unknown_option() { - printf "ERROR: unknown option \"$arg\"\n" >&2 - printf "If the filename validly begins with '-', " >&2 - printf "then it must be prefixed\n" >&2 - printf "by './' so that it won't be interpreted as an option." >&2 - printf "\n" >&2 - usage >&2 - exit 1 -} - -list_header() { - : -} - -header() { - printf "\n#####################\n# $1\n" >> ${output} -} - -# process one directory (incl sub-directories) -dir_filelist() { - ${dep_list}header "$1" - - srcdir=$(echo "$1" | sed -e 's://*:/:g') - dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" | LANG=C sort) - - # If $dirlist is only one line, then the directory is empty - if [ "$(echo "${dirlist}" | wc -l)" -gt 1 ]; then - ${dep_list}print_mtime "$1" - - echo "${dirlist}" | \ - while read x; do - ${dep_list}parse ${x} - done - fi -} - -# if only one file is specified and it is .cpio file then use it direct as fs -# if a directory is specified then add all files in given direcotry to fs -# if a regular file is specified assume it is in gen_initramfs format -input_file() { - source="$1" - if [ -f "$1" ]; then - ${dep_list}header "$1" - is_cpio="$(echo "$1" | sed 's/^.*\.cpio\(\..*\)\{0,1\}/cpio/')" - if [ $2 -eq 0 -a ${is_cpio} = "cpio" ]; then - cpio_file=$1 - echo "$1" | grep -q '^.*\.cpio\..*' && is_cpio_compressed="compressed" - [ ! -z ${dep_list} ] && echo "$1" - return 0 - fi - if [ -z ${dep_list} ]; then - print_mtime "$1" >> ${output} - cat "$1" >> ${output} - else - echo "$1 \\" - cat "$1" | while read type dir file perm ; do - if [ "$type" = "file" ]; then - echo "$file \\"; - fi - done - fi - elif [ -d "$1" ]; then - dir_filelist "$1" - else - echo " ${prog}: Cannot open '$1'" >&2 - exit 1 - fi -} - -prog=$0 -root_uid=0 -root_gid=0 -dep_list= -cpio_file= -cpio_list= -output="/dev/stdout" -output_file="" -is_cpio_compressed= -compr="gzip -n -9 -f" - -arg="$1" -case "$arg" in - "-l") # files included in initramfs - used by kbuild - dep_list="list_" - echo "deps_initramfs := $0 \\" - shift - ;; - "-o") # generate compressed cpio image named $1 - shift - output_file="$1" - cpio_list="$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)" - output=${cpio_list} - echo "$output_file" | grep -q "\.gz$" \ - && [ -x "`which gzip 2> /dev/null`" ] \ - && compr="gzip -n -9 -f" - echo "$output_file" | grep -q "\.bz2$" \ - && [ -x "`which bzip2 2> /dev/null`" ] \ - && compr="bzip2 -9 -f" - echo "$output_file" | grep -q "\.lzma$" \ - && [ -x "`which lzma 2> /dev/null`" ] \ - && compr="lzma -9 -f" - echo "$output_file" | grep -q "\.xz$" \ - && [ -x "`which xz 2> /dev/null`" ] \ - && compr="xz --check=crc32 --lzma2=dict=1MiB" - echo "$output_file" | grep -q "\.lzo$" \ - && [ -x "`which lzop 2> /dev/null`" ] \ - && compr="lzop -9 -f" - echo "$output_file" | grep -q "\.lz4$" \ - && [ -x "`which lz4 2> /dev/null`" ] \ - && compr="lz4 -l -9 -f" - echo "$output_file" | grep -q "\.cpio$" && compr="cat" - shift - ;; -esac -while [ $# -gt 0 ]; do - arg="$1" - shift - case "$arg" in - "-u") # map $1 to uid=0 (root) - root_uid="$1" - [ "$root_uid" = "-1" ] && root_uid=$(id -u || echo 0) - shift - ;; - "-g") # map $1 to gid=0 (root) - root_gid="$1" - [ "$root_gid" = "-1" ] && root_gid=$(id -g || echo 0) - shift - ;; - "-d") # display default initramfs list - default_list="$arg" - ${dep_list}default_initramfs - ;; - "-h") - usage - exit 0 - ;; - *) - case "$arg" in - "-"*) - unknown_option - ;; - *) # input file/dir - process it - input_file "$arg" "$#" - ;; - esac - ;; - esac -done - -# If output_file is set we will generate cpio archive and compress it -# we are careful to delete tmp files -if [ ! -z ${output_file} ]; then - if [ -z ${cpio_file} ]; then - timestamp= - if test -n "$KBUILD_BUILD_TIMESTAMP"; then - timestamp="$(date -d"$KBUILD_BUILD_TIMESTAMP" +%s || :)" - if test -n "$timestamp"; then - timestamp="-t $timestamp" - fi - fi - cpio_tfile="$(mktemp ${TMPDIR:-/tmp}/cpiofile.XXXXXX)" - usr/gen_init_cpio $timestamp ${cpio_list} > ${cpio_tfile} - else - cpio_tfile=${cpio_file} - fi - rm ${cpio_list} - if [ "${is_cpio_compressed}" = "compressed" ]; then - cat ${cpio_tfile} > ${output_file} - else - (cat ${cpio_tfile} | ${compr} - > ${output_file}) \ - || (rm -f ${output_file} ; false) - fi - [ -z ${cpio_file} ] && rm ${cpio_tfile} -fi -exit 0 diff --git a/usr/Makefile b/usr/Makefile index 237a028693ce..748f6a60bb1e 100644 --- a/usr/Makefile +++ b/usr/Makefile @@ -24,7 +24,7 @@ $(obj)/initramfs_data.o: $(obj)/$(datafile_y) FORCE # Generate the initramfs cpio archive hostprogs-y := gen_init_cpio -initramfs := $(CONFIG_SHELL) $(srctree)/scripts/gen_initramfs_list.sh +initramfs := $(CONFIG_SHELL) $(srctree)/$(src)/gen_initramfs_list.sh ramfs-input := $(if $(filter-out "",$(CONFIG_INITRAMFS_SOURCE)), \ $(shell echo $(CONFIG_INITRAMFS_SOURCE)),-d) ramfs-args := \ diff --git a/usr/gen_initramfs_list.sh b/usr/gen_initramfs_list.sh new file mode 100755 index 000000000000..0aad760fcd8c --- /dev/null +++ b/usr/gen_initramfs_list.sh @@ -0,0 +1,328 @@ +#!/bin/sh +# Copyright (C) Martin Schlemmer +# Copyright (C) 2006 Sam Ravnborg +# +# Released under the terms of the GNU GPL +# +# Generate a cpio packed initramfs. It uses gen_init_cpio to generate +# the cpio archive, and then compresses it. +# The script may also be used to generate the inputfile used for gen_init_cpio +# This script assumes that gen_init_cpio is located in usr/ directory + +# error out on errors +set -e + +usage() { +cat << EOF +Usage: +$0 [-o ] [-u ] [-g ] {-d | } ... + -o Create compressed initramfs file named using + gen_init_cpio and compressor depending on the extension + -u User ID to map to user ID 0 (root). + is only meaningful if is a + directory. "squash" forces all files to uid 0. + -g Group ID to map to group ID 0 (root). + is only meaningful if is a + directory. "squash" forces all files to gid 0. + File list or directory for cpio archive. + If is a .cpio file it will be used + as direct input to initramfs. + -d Output the default cpio list. + +All options except -o and -l may be repeated and are interpreted +sequentially and immediately. -u and -g states are preserved across + options so an explicit "-u 0 -g 0" is required +to reset the root/group mapping. +EOF +} + +# awk style field access +# $1 - field number; rest is argument string +field() { + shift $1 ; echo $1 +} + +list_default_initramfs() { + # echo usr/kinit/kinit + : +} + +default_initramfs() { + cat <<-EOF >> ${output} + # This is a very simple, default initramfs + + dir /dev 0755 0 0 + nod /dev/console 0600 0 0 c 5 1 + dir /root 0700 0 0 + # file /kinit usr/kinit/kinit 0755 0 0 + # slink /init kinit 0755 0 0 + EOF +} + +filetype() { + local argv1="$1" + + # symlink test must come before file test + if [ -L "${argv1}" ]; then + echo "slink" + elif [ -f "${argv1}" ]; then + echo "file" + elif [ -d "${argv1}" ]; then + echo "dir" + elif [ -b "${argv1}" -o -c "${argv1}" ]; then + echo "nod" + elif [ -p "${argv1}" ]; then + echo "pipe" + elif [ -S "${argv1}" ]; then + echo "sock" + else + echo "invalid" + fi + return 0 +} + +list_print_mtime() { + : +} + +print_mtime() { + local my_mtime="0" + + if [ -e "$1" ]; then + my_mtime=$(find "$1" -printf "%T@\n" | sort -r | head -n 1) + fi + + echo "# Last modified: ${my_mtime}" >> ${output} + echo "" >> ${output} +} + +list_parse() { + if [ -L "$1" ]; then + return + fi + echo "$1" | sed 's/:/\\:/g; s/$/ \\/' +} + +# for each file print a line in following format +# +# for links, devices etc the format differs. See gen_init_cpio for details +parse() { + local location="$1" + local name="/${location#${srcdir}}" + # change '//' into '/' + name=$(echo "$name" | sed -e 's://*:/:g') + local mode="$2" + local uid="$3" + local gid="$4" + local ftype=$(filetype "${location}") + # remap uid/gid to 0 if necessary + [ "$root_uid" = "squash" ] && uid=0 || [ "$uid" -eq "$root_uid" ] && uid=0 + [ "$root_gid" = "squash" ] && gid=0 || [ "$gid" -eq "$root_gid" ] && gid=0 + local str="${mode} ${uid} ${gid}" + + [ "${ftype}" = "invalid" ] && return 0 + [ "${location}" = "${srcdir}" ] && return 0 + + case "${ftype}" in + "file") + str="${ftype} ${name} ${location} ${str}" + ;; + "nod") + local dev=`LC_ALL=C ls -l "${location}"` + local maj=`field 5 ${dev}` + local min=`field 6 ${dev}` + maj=${maj%,} + + [ -b "${location}" ] && dev="b" || dev="c" + + str="${ftype} ${name} ${str} ${dev} ${maj} ${min}" + ;; + "slink") + local target=`readlink "${location}"` + str="${ftype} ${name} ${target} ${str}" + ;; + *) + str="${ftype} ${name} ${str}" + ;; + esac + + echo "${str}" >> ${output} + + return 0 +} + +unknown_option() { + printf "ERROR: unknown option \"$arg\"\n" >&2 + printf "If the filename validly begins with '-', " >&2 + printf "then it must be prefixed\n" >&2 + printf "by './' so that it won't be interpreted as an option." >&2 + printf "\n" >&2 + usage >&2 + exit 1 +} + +list_header() { + : +} + +header() { + printf "\n#####################\n# $1\n" >> ${output} +} + +# process one directory (incl sub-directories) +dir_filelist() { + ${dep_list}header "$1" + + srcdir=$(echo "$1" | sed -e 's://*:/:g') + dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" | LANG=C sort) + + # If $dirlist is only one line, then the directory is empty + if [ "$(echo "${dirlist}" | wc -l)" -gt 1 ]; then + ${dep_list}print_mtime "$1" + + echo "${dirlist}" | \ + while read x; do + ${dep_list}parse ${x} + done + fi +} + +# if only one file is specified and it is .cpio file then use it direct as fs +# if a directory is specified then add all files in given direcotry to fs +# if a regular file is specified assume it is in gen_initramfs format +input_file() { + source="$1" + if [ -f "$1" ]; then + ${dep_list}header "$1" + is_cpio="$(echo "$1" | sed 's/^.*\.cpio\(\..*\)\{0,1\}/cpio/')" + if [ $2 -eq 0 -a ${is_cpio} = "cpio" ]; then + cpio_file=$1 + echo "$1" | grep -q '^.*\.cpio\..*' && is_cpio_compressed="compressed" + [ ! -z ${dep_list} ] && echo "$1" + return 0 + fi + if [ -z ${dep_list} ]; then + print_mtime "$1" >> ${output} + cat "$1" >> ${output} + else + echo "$1 \\" + cat "$1" | while read type dir file perm ; do + if [ "$type" = "file" ]; then + echo "$file \\"; + fi + done + fi + elif [ -d "$1" ]; then + dir_filelist "$1" + else + echo " ${prog}: Cannot open '$1'" >&2 + exit 1 + fi +} + +prog=$0 +root_uid=0 +root_gid=0 +dep_list= +cpio_file= +cpio_list= +output="/dev/stdout" +output_file="" +is_cpio_compressed= +compr="gzip -n -9 -f" + +arg="$1" +case "$arg" in + "-l") # files included in initramfs - used by kbuild + dep_list="list_" + echo "deps_initramfs := $0 \\" + shift + ;; + "-o") # generate compressed cpio image named $1 + shift + output_file="$1" + cpio_list="$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)" + output=${cpio_list} + echo "$output_file" | grep -q "\.gz$" \ + && [ -x "`which gzip 2> /dev/null`" ] \ + && compr="gzip -n -9 -f" + echo "$output_file" | grep -q "\.bz2$" \ + && [ -x "`which bzip2 2> /dev/null`" ] \ + && compr="bzip2 -9 -f" + echo "$output_file" | grep -q "\.lzma$" \ + && [ -x "`which lzma 2> /dev/null`" ] \ + && compr="lzma -9 -f" + echo "$output_file" | grep -q "\.xz$" \ + && [ -x "`which xz 2> /dev/null`" ] \ + && compr="xz --check=crc32 --lzma2=dict=1MiB" + echo "$output_file" | grep -q "\.lzo$" \ + && [ -x "`which lzop 2> /dev/null`" ] \ + && compr="lzop -9 -f" + echo "$output_file" | grep -q "\.lz4$" \ + && [ -x "`which lz4 2> /dev/null`" ] \ + && compr="lz4 -l -9 -f" + echo "$output_file" | grep -q "\.cpio$" && compr="cat" + shift + ;; +esac +while [ $# -gt 0 ]; do + arg="$1" + shift + case "$arg" in + "-u") # map $1 to uid=0 (root) + root_uid="$1" + [ "$root_uid" = "-1" ] && root_uid=$(id -u || echo 0) + shift + ;; + "-g") # map $1 to gid=0 (root) + root_gid="$1" + [ "$root_gid" = "-1" ] && root_gid=$(id -g || echo 0) + shift + ;; + "-d") # display default initramfs list + default_list="$arg" + ${dep_list}default_initramfs + ;; + "-h") + usage + exit 0 + ;; + *) + case "$arg" in + "-"*) + unknown_option + ;; + *) # input file/dir - process it + input_file "$arg" "$#" + ;; + esac + ;; + esac +done + +# If output_file is set we will generate cpio archive and compress it +# we are careful to delete tmp files +if [ ! -z ${output_file} ]; then + if [ -z ${cpio_file} ]; then + timestamp= + if test -n "$KBUILD_BUILD_TIMESTAMP"; then + timestamp="$(date -d"$KBUILD_BUILD_TIMESTAMP" +%s || :)" + if test -n "$timestamp"; then + timestamp="-t $timestamp" + fi + fi + cpio_tfile="$(mktemp ${TMPDIR:-/tmp}/cpiofile.XXXXXX)" + usr/gen_init_cpio $timestamp ${cpio_list} > ${cpio_tfile} + else + cpio_tfile=${cpio_file} + fi + rm ${cpio_list} + if [ "${is_cpio_compressed}" = "compressed" ]; then + cat ${cpio_tfile} > ${output_file} + else + (cat ${cpio_tfile} | ${compr} - > ${output_file}) \ + || (rm -f ${output_file} ; false) + fi + [ -z ${cpio_file} ] && rm ${cpio_tfile} +fi +exit 0 -- cgit v1.2.3-59-g8ed1b From 87a32e624037e8b6e8538ed864dc9994853acc4d Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 24 Aug 2018 08:20:38 +0900 Subject: kbuild: pass LDFLAGS to recordmcount.pl Since commit 0fbe9a245c60 ("microblaze: add endianness options to LDFLAGS instead of LD"), you cannot build the kernel for microblaze with CONFIG_DYNAMIC_FTRACE. Fixes: 0fbe9a245c60 ("microblaze: add endianness options to LDFLAGS instead of LD") Signed-off-by: Masahiro Yamada --- scripts/Makefile.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 93b8e24b0e15..f5d7612696d0 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -220,7 +220,7 @@ sub_cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \ "$(if $(CONFIG_64BIT),64,32)" \ "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CFLAGS)" \ - "$(LD)" "$(NM)" "$(RM)" "$(MV)" \ + "$(LD) $(LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \ "$(if $(part-of-module),1,0)" "$(@)"; recordmcount_source := $(srctree)/scripts/recordmcount.pl endif # BUILD_C_RECORDMCOUNT -- cgit v1.2.3-59-g8ed1b From d503ac531a5246e4d910f971b213807fea925956 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 24 Aug 2018 08:20:39 +0900 Subject: kbuild: rename LDFLAGS to KBUILD_LDFLAGS Commit a0f97e06a43c ("kbuild: enable 'make CFLAGS=...' to add additional options to CC") renamed CFLAGS to KBUILD_CFLAGS. Commit 222d394d30e7 ("kbuild: enable 'make AFLAGS=...' to add additional options to AS") renamed AFLAGS to KBUILD_AFLAGS. Commit 06c5040cdb13 ("kbuild: enable 'make CPPFLAGS=...' to add additional options to CPP") renamed CPPFLAGS to KBUILD_CPPFLAGS. For some reason, LDFLAGS was not renamed. Using a well-known variable like LDFLAGS may result in accidental override of the variable. Kbuild generally uses KBUILD_ prefixed variables for the internally appended options, so here is one more conversion to sanitize the naming convention. I did not touch Makefiles under tools/ since the tools build system is a different world. Signed-off-by: Masahiro Yamada Acked-by: Kirill A. Shutemov Reviewed-by: Palmer Dabbelt --- Makefile | 6 +++--- arch/arc/Makefile | 2 +- arch/arm/Makefile | 4 ++-- arch/arm64/Makefile | 4 ++-- arch/c6x/Makefile | 3 +-- arch/h8300/Makefile | 2 +- arch/hexagon/Makefile | 4 +--- arch/m68k/Makefile | 2 +- arch/microblaze/Makefile | 4 ++-- arch/mips/Makefile | 2 +- arch/mips/boot/compressed/Makefile | 2 +- arch/mips/lasat/image/Makefile | 2 +- arch/nds32/Makefile | 4 ++-- arch/powerpc/Makefile | 6 +++--- arch/riscv/Makefile | 4 ++-- arch/s390/Makefile | 2 +- arch/sh/Makefile | 4 ++-- arch/sparc/Makefile | 4 ++-- arch/um/Makefile | 2 +- arch/x86/Makefile | 4 ++-- arch/x86/Makefile.um | 4 ++-- arch/x86/boot/compressed/Makefile | 6 +++--- arch/xtensa/Makefile | 2 +- arch/xtensa/boot/boot-elf/Makefile | 2 +- scripts/Kbuild.include | 4 ++-- scripts/Makefile.build | 6 +++--- scripts/Makefile.lib | 2 +- scripts/Makefile.modpost | 2 +- scripts/link-vmlinux.sh | 4 ++-- 29 files changed, 48 insertions(+), 51 deletions(-) (limited to 'scripts') diff --git a/Makefile b/Makefile index 1623b8b6e8f5..2e2b0095131c 100644 --- a/Makefile +++ b/Makefile @@ -440,7 +440,7 @@ KBUILD_CFLAGS_KERNEL := KBUILD_AFLAGS_MODULE := -DMODULE KBUILD_CFLAGS_MODULE := -DMODULE KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds -LDFLAGS := +KBUILD_LDFLAGS := GCC_PLUGINS_CFLAGS := export ARCH SRCARCH CONFIG_SHELL HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC @@ -448,7 +448,7 @@ export CPP AR NM STRIP OBJCOPY OBJDUMP KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS export MAKE LEX YACC AWK GENKSYMS INSTALLKERNEL PERL PYTHON PYTHON2 PYTHON3 UTS_MACHINE export HOSTCXX KBUILD_HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS -export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS +export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE @@ -1020,7 +1020,7 @@ ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) # Final link of vmlinux with optional arch pass after final link cmd_link-vmlinux = \ - $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) ; \ + $(CONFIG_SHELL) $< $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_vmlinux) ; \ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE diff --git a/arch/arc/Makefile b/arch/arc/Makefile index 6c1b20dd76ad..fb026196aaab 100644 --- a/arch/arc/Makefile +++ b/arch/arc/Makefile @@ -95,7 +95,7 @@ KBUILD_CFLAGS_MODULE += -mlong-calls -mno-millicode # Finally dump eveything into kernel build system KBUILD_CFLAGS += $(cflags-y) KBUILD_AFLAGS += $(KBUILD_CFLAGS) -LDFLAGS += $(ldflags-y) +KBUILD_LDFLAGS += $(ldflags-y) head-y := arch/arc/kernel/head.o diff --git a/arch/arm/Makefile b/arch/arm/Makefile index e7d703d8fac3..360f80aeb9ff 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -43,12 +43,12 @@ ifeq ($(CONFIG_CPU_BIG_ENDIAN),y) KBUILD_CPPFLAGS += -mbig-endian CHECKFLAGS += -D__ARMEB__ AS += -EB -LDFLAGS += -EB +KBUILD_LDFLAGS += -EB else KBUILD_CPPFLAGS += -mlittle-endian CHECKFLAGS += -D__ARMEL__ AS += -EL -LDFLAGS += -EL +KBUILD_LDFLAGS += -EL endif # diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index efe61a2e4b5e..106039d25e2f 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -62,14 +62,14 @@ CHECKFLAGS += -D__AARCH64EB__ AS += -EB # Prefer the baremetal ELF build target, but not all toolchains include # it so fall back to the standard linux version if needed. -LDFLAGS += -EB $(call ld-option, -maarch64elfb, -maarch64linuxb) +KBUILD_LDFLAGS += -EB $(call ld-option, -maarch64elfb, -maarch64linuxb) UTS_MACHINE := aarch64_be else KBUILD_CPPFLAGS += -mlittle-endian CHECKFLAGS += -D__AARCH64EL__ AS += -EL # Same as above, prefer ELF but fall back to linux target if needed. -LDFLAGS += -EL $(call ld-option, -maarch64elf, -maarch64linux) +KBUILD_LDFLAGS += -EL $(call ld-option, -maarch64elf, -maarch64linux) UTS_MACHINE := aarch64 endif diff --git a/arch/c6x/Makefile b/arch/c6x/Makefile index 6ab942e6c534..3fe8a948e94c 100644 --- a/arch/c6x/Makefile +++ b/arch/c6x/Makefile @@ -23,8 +23,7 @@ ifdef CONFIG_CPU_BIG_ENDIAN KBUILD_CFLAGS += -mbig-endian KBUILD_AFLAGS += -mbig-endian LINKFLAGS += -mbig-endian -KBUILD_LDFLAGS += -mbig-endian -LDFLAGS += -EB +KBUILD_LDFLAGS += -mbig-endian -EB CHECKFLAGS += -D_BIG_ENDIAN endif diff --git a/arch/h8300/Makefile b/arch/h8300/Makefile index e1c02ca230cb..f9cbbb13853f 100644 --- a/arch/h8300/Makefile +++ b/arch/h8300/Makefile @@ -20,7 +20,7 @@ KBUILD_CFLAGS += -mint32 -fno-builtin KBUILD_CFLAGS += -D__linux__ KBUILD_CFLAGS += -DUTS_SYSNAME=\"uClinux\" KBUILD_AFLAGS += $(aflags-y) -LDFLAGS += $(ldflags-y) +KBUILD_LDFLAGS += $(ldflags-y) ifeq ($(CROSS_COMPILE),) CROSS_COMPILE := h8300-unknown-linux- diff --git a/arch/hexagon/Makefile b/arch/hexagon/Makefile index 2efaa18e995a..4c5858b80f0e 100644 --- a/arch/hexagon/Makefile +++ b/arch/hexagon/Makefile @@ -22,9 +22,7 @@ ldflags-y += $(call cc-option,-mv${CONFIG_HEXAGON_ARCH_VERSION}) KBUILD_CFLAGS += $(cflags-y) KBUILD_AFLAGS += $(aflags-y) - -# no KBUILD_LDFLAGS? -LDFLAGS += $(ldflags-y) +KBUILD_LDFLAGS += $(ldflags-y) # Thread-info register will be r19. This value is not configureable; # it is hard-coded in several files. diff --git a/arch/m68k/Makefile b/arch/m68k/Makefile index f0dd9fc84002..997c9f20ea0f 100644 --- a/arch/m68k/Makefile +++ b/arch/m68k/Makefile @@ -69,7 +69,7 @@ KBUILD_CFLAGS += -D__uClinux__ KBUILD_AFLAGS += -D__uClinux__ endif -LDFLAGS := -m m68kelf +KBUILD_LDFLAGS := -m m68kelf KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/m68k/kernel/module.lds ifdef CONFIG_SUN3 diff --git a/arch/microblaze/Makefile b/arch/microblaze/Makefile index 73330360a8e6..4f3ab5707265 100644 --- a/arch/microblaze/Makefile +++ b/arch/microblaze/Makefile @@ -40,11 +40,11 @@ CPUFLAGS-$(CONFIG_XILINX_MICROBLAZE0_USE_PCMP_INSTR) += -mxl-pattern-compare ifdef CONFIG_CPU_BIG_ENDIAN KBUILD_CFLAGS += -mbig-endian KBUILD_AFLAGS += -mbig-endian -LDFLAGS += -EB +KBUILD_LDFLAGS += -EB else KBUILD_CFLAGS += -mlittle-endian KBUILD_AFLAGS += -mlittle-endian -LDFLAGS += -EL +KBUILD_LDFLAGS += -EL endif CPUFLAGS-1 += $(call cc-option,-mcpu=v$(CPU_VER)) diff --git a/arch/mips/Makefile b/arch/mips/Makefile index 5425df002a6b..d74b3742fa5d 100644 --- a/arch/mips/Makefile +++ b/arch/mips/Makefile @@ -309,7 +309,7 @@ endif # instead of .eh_frame so we don't discard them. KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -LDFLAGS += -m $(ld-emul) +KBUILD_LDFLAGS += -m $(ld-emul) ifdef CONFIG_MIPS CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile index abe77add8789..3c453a1f1ff1 100644 --- a/arch/mips/boot/compressed/Makefile +++ b/arch/mips/boot/compressed/Makefile @@ -92,7 +92,7 @@ UIMAGE_LOADADDR = $(VMLINUZ_LOAD_ADDRESS) vmlinuzobjs-y += $(obj)/piggy.o quiet_cmd_zld = LD $@ - cmd_zld = $(LD) $(LDFLAGS) -Ttext $(VMLINUZ_LOAD_ADDRESS) -T $< $(vmlinuzobjs-y) -o $@ + cmd_zld = $(LD) $(KBUILD_LDFLAGS) -Ttext $(VMLINUZ_LOAD_ADDRESS) -T $< $(vmlinuzobjs-y) -o $@ quiet_cmd_strip = STRIP $@ cmd_strip = $(STRIP) -s $@ vmlinuz: $(src)/ld.script $(vmlinuzobjs-y) $(obj)/calc_vmlinuz_load_addr diff --git a/arch/mips/lasat/image/Makefile b/arch/mips/lasat/image/Makefile index 9ab1326f57c9..78ce4cff1012 100644 --- a/arch/mips/lasat/image/Makefile +++ b/arch/mips/lasat/image/Makefile @@ -38,7 +38,7 @@ $(obj)/rom.bin: $(obj)/rom # Rule to make the bootloader $(obj)/rom: $(addprefix $(obj)/,$(OBJECTS)) - $(LD) $(LDFLAGS) $(LDSCRIPT) -o $@ $^ + $(LD) $(KBUILD_LDFLAGS) $(LDSCRIPT) -o $@ $^ $(obj)/%.o: $(obj)/%.gz $(LD) -r -o $@ -b binary $< diff --git a/arch/nds32/Makefile b/arch/nds32/Makefile index 031c676821ff..63f4f173e5f4 100644 --- a/arch/nds32/Makefile +++ b/arch/nds32/Makefile @@ -33,12 +33,12 @@ endif ifdef CONFIG_CPU_LITTLE_ENDIAN KBUILD_CFLAGS += $(call cc-option, -EL) KBUILD_AFLAGS += $(call cc-option, -EL) -LDFLAGS += $(call cc-option, -EL) +KBUILD_LDFLAGS += $(call cc-option, -EL) CHECKFLAGS += -D__NDS32_EL__ else KBUILD_CFLAGS += $(call cc-option, -EB) KBUILD_AFLAGS += $(call cc-option, -EB) -LDFLAGS += $(call cc-option, -EB) +KBUILD_LDFLAGS += $(call cc-option, -EB) CHECKFLAGS += -D__NDS32_EB__ endif diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile index 8397c7bd5880..11a1acba164a 100644 --- a/arch/powerpc/Makefile +++ b/arch/powerpc/Makefile @@ -76,14 +76,14 @@ endif ifdef CONFIG_CPU_LITTLE_ENDIAN KBUILD_CFLAGS += -mlittle-endian -LDFLAGS += -EL +KBUILD_LDFLAGS += -EL LDEMULATION := lppc GNUTARGET := powerpcle MULTIPLEWORD := -mno-multiple KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-save-toc-indirect) else KBUILD_CFLAGS += $(call cc-option,-mbig-endian) -LDFLAGS += -EB +KBUILD_LDFLAGS += -EB LDEMULATION := ppc GNUTARGET := powerpc MULTIPLEWORD := -mmultiple @@ -108,7 +108,7 @@ aflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mlittle-endian ifeq ($(HAS_BIARCH),y) KBUILD_CFLAGS += -m$(BITS) KBUILD_AFLAGS += -m$(BITS) -Wl,-a$(BITS) -LDFLAGS += -m elf$(BITS)$(LDEMULATION) +KBUILD_LDFLAGS += -m elf$(BITS)$(LDEMULATION) KBUILD_ARFLAGS += --target=elf$(BITS)-$(GNUTARGET) endif diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 9ddd88bb30b7..61ec42405ec9 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -29,7 +29,7 @@ ifeq ($(CONFIG_ARCH_RV64I),y) KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0500, -DCONFIG_ARCH_SUPPORTS_INT128) KBUILD_MARCH = rv64im - LDFLAGS += -melf64lriscv + KBUILD_LDFLAGS += -melf64lriscv else BITS := 32 UTS_MACHINE := riscv32 @@ -37,7 +37,7 @@ else KBUILD_CFLAGS += -mabi=ilp32 KBUILD_AFLAGS += -mabi=ilp32 KBUILD_MARCH = rv32im - LDFLAGS += -melf32lriscv + KBUILD_LDFLAGS += -melf32lriscv endif KBUILD_CFLAGS += -Wall diff --git a/arch/s390/Makefile b/arch/s390/Makefile index ba6d122526fb..ee65185bbc80 100644 --- a/arch/s390/Makefile +++ b/arch/s390/Makefile @@ -11,7 +11,7 @@ # LD_BFD := elf64-s390 -LDFLAGS := -m elf64_s390 +KBUILD_LDFLAGS := -m elf64_s390 KBUILD_AFLAGS_MODULE += -fPIC KBUILD_CFLAGS_MODULE += -fPIC KBUILD_AFLAGS += -m64 diff --git a/arch/sh/Makefile b/arch/sh/Makefile index 65300193b99f..c521ade2557c 100644 --- a/arch/sh/Makefile +++ b/arch/sh/Makefile @@ -122,11 +122,11 @@ endif ifdef CONFIG_CPU_LITTLE_ENDIAN ld-bfd := elf32-$(UTS_MACHINE)-linux LDFLAGS_vmlinux += --defsym jiffies=jiffies_64 --oformat $(ld-bfd) -LDFLAGS += -EL +KBUILD_LDFLAGS += -EL else ld-bfd := elf32-$(UTS_MACHINE)big-linux LDFLAGS_vmlinux += --defsym jiffies=jiffies_64+4 --oformat $(ld-bfd) -LDFLAGS += -EB +KBUILD_LDFLAGS += -EB endif export ld-bfd BITS diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile index 966a13d2b127..8ece494ea0f9 100644 --- a/arch/sparc/Makefile +++ b/arch/sparc/Makefile @@ -21,7 +21,7 @@ ifeq ($(CONFIG_SPARC32),y) # CHECKFLAGS += -D__sparc__ -LDFLAGS := -m elf32_sparc +KBUILD_LDFLAGS := -m elf32_sparc export BITS := 32 UTS_MACHINE := sparc @@ -40,7 +40,7 @@ else # CHECKFLAGS += -D__sparc__ -D__sparc_v9__ -D__arch64__ -LDFLAGS := -m elf64_sparc +KBUILD_LDFLAGS := -m elf64_sparc export BITS := 64 UTS_MACHINE := sparc64 diff --git a/arch/um/Makefile b/arch/um/Makefile index 44ddc3e8fa66..ab1066c38944 100644 --- a/arch/um/Makefile +++ b/arch/um/Makefile @@ -133,7 +133,7 @@ export LDS_ELF_FORMAT := $(ELF_FORMAT) # The wrappers will select whether using "malloc" or the kernel allocator. LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc -LD_FLAGS_CMDLINE = $(foreach opt,$(LDFLAGS),-Wl,$(opt)) +LD_FLAGS_CMDLINE = $(foreach opt,$(KBUILD_LDFLAGS),-Wl,$(opt)) # Used by link-vmlinux.sh which has special support for um link export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 7e3c07d6ad42..94859241bc3e 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -219,7 +219,7 @@ sha256_ni_instr :=$(call as-instr,sha256msg1 %xmm0$(comma)%xmm1,-DCONFIG_AS_SHA2 KBUILD_AFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr) KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr) -LDFLAGS := -m elf_$(UTS_MACHINE) +KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE) # # The 64-bit kernel must be aligned to 2MB. Pass -z max-page-size=0x200000 to @@ -227,7 +227,7 @@ LDFLAGS := -m elf_$(UTS_MACHINE) # by the linker. # ifdef CONFIG_X86_64 -LDFLAGS += $(call ld-option, -z max-page-size=0x200000) +KBUILD_LDFLAGS += $(call ld-option, -z max-page-size=0x200000) endif # Speed up the build diff --git a/arch/x86/Makefile.um b/arch/x86/Makefile.um index 5296f8c9e7f0..91085a08de6c 100644 --- a/arch/x86/Makefile.um +++ b/arch/x86/Makefile.um @@ -4,7 +4,7 @@ core-y += arch/x86/crypto/ ifeq ($(CONFIG_X86_32),y) START := 0x8048000 -LDFLAGS += -m elf_i386 +KBUILD_LDFLAGS += -m elf_i386 ELF_ARCH := i386 ELF_FORMAT := elf32-i386 CHECKFLAGS += -D__i386__ @@ -43,7 +43,7 @@ KBUILD_CFLAGS += -fno-builtin -m64 CHECKFLAGS += -m64 -D__x86_64__ KBUILD_AFLAGS += -m64 -LDFLAGS += -m elf_x86_64 +KBUILD_LDFLAGS += -m elf_x86_64 KBUILD_CPPFLAGS += -m64 ELF_ARCH := i386:x86-64 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 169c2feda14a..28764dacf018 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -42,16 +42,16 @@ KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ GCOV_PROFILE := n UBSAN_SANITIZE :=n -LDFLAGS := -m elf_$(UTS_MACHINE) +KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE) # Compressed kernel should be built as PIE since it may be loaded at any # address by the bootloader. ifeq ($(CONFIG_X86_32),y) -LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker) +KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker) else # To build 64-bit compressed kernel as PIE, we disable relocation # overflow check to avoid relocation overflow error with a new linker # command-line option, -z noreloc-overflow. -LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \ +KBUILD_LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \ && echo "-z noreloc-overflow -pie --no-dynamic-linker") endif LDFLAGS_vmlinux := -T diff --git a/arch/xtensa/Makefile b/arch/xtensa/Makefile index 3a934b72a272..295c120ed099 100644 --- a/arch/xtensa/Makefile +++ b/arch/xtensa/Makefile @@ -49,7 +49,7 @@ KBUILD_CFLAGS += $(call cc-option,-mno-serialize-volatile,) KBUILD_AFLAGS += -mlongcalls -mtext-section-literals ifneq ($(CONFIG_LD_NO_RELAX),) -LDFLAGS := --no-relax +KBUILD_LDFLAGS := --no-relax endif ifeq ($(shell echo __XTENSA_EB__ | $(CC) -E - | grep -v "\#"),1) diff --git a/arch/xtensa/boot/boot-elf/Makefile b/arch/xtensa/boot/boot-elf/Makefile index 521471981356..12ae1e91cb75 100644 --- a/arch/xtensa/boot/boot-elf/Makefile +++ b/arch/xtensa/boot/boot-elf/Makefile @@ -25,7 +25,7 @@ $(obj)/Image.o: vmlinux.bin $(OBJS) $(OBJS) $@ $(obj)/../Image.elf: $(obj)/Image.o $(obj)/boot.lds - $(Q)$(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) \ + $(Q)$(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_vmlinux) \ -T $(obj)/boot.lds \ --build-id=none \ -o $@ $(obj)/Image.o diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 7c98f60e2266..c75413d05a63 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -163,8 +163,8 @@ cc-ldoption = $(call try-run,\ $(CC) $(1) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2)) # ld-option -# Usage: LDFLAGS += $(call ld-option, -X, -Y) -ld-option = $(call try-run, $(LD) $(LDFLAGS) $(1) -v,$(1),$(2),$(3)) +# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y) +ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3)) # ar-option # Usage: KBUILD_ARFLAGS := $(call ar-option,D) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index f5d7612696d0..1c48572223d1 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -190,7 +190,7 @@ cmd_modversions_c = \ $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ > $(@D)/.tmp_$(@F:.o=.ver); \ \ - $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ + $(LD) $(KBUILD_LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ -T $(@D)/.tmp_$(@F:.o=.ver); \ rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \ else \ @@ -220,7 +220,7 @@ sub_cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \ "$(if $(CONFIG_64BIT),64,32)" \ "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CFLAGS)" \ - "$(LD) $(LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \ + "$(LD) $(KBUILD_LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \ "$(if $(part-of-module),1,0)" "$(@)"; recordmcount_source := $(srctree)/scripts/recordmcount.pl endif # BUILD_C_RECORDMCOUNT @@ -394,7 +394,7 @@ cmd_modversions_S = \ $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ > $(@D)/.tmp_$(@F:.o=.ver); \ \ - $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ + $(LD) $(KBUILD_LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ -T $(@D)/.tmp_$(@F:.o=.ver); \ rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \ else \ diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index df0fff252619..61e596650ed3 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -162,7 +162,7 @@ a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ $(__cpp_flags) -ld_flags = $(LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) +ld_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) DTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index dd92dbbbaa68..7d4af0d0accb 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -120,7 +120,7 @@ ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) # Step 6), final link of the modules with optional arch pass after final link quiet_cmd_ld_ko_o = LD [M] $@ cmd_ld_ko_o = \ - $(LD) -r $(LDFLAGS) \ + $(LD) -r $(KBUILD_LDFLAGS) \ $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ -o $@ $(filter-out FORCE,$^) ; \ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 4bf811c09f59..c8cf45362bd6 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -75,7 +75,7 @@ modpost_link() ${KBUILD_VMLINUX_LIBS} \ --end-group" - ${LD} ${LDFLAGS} -r -o ${1} ${objects} + ${LD} ${KBUILD_LDFLAGS} -r -o ${1} ${objects} } # Link of vmlinux @@ -95,7 +95,7 @@ vmlinux_link() --end-group \ ${1}" - ${LD} ${LDFLAGS} ${LDFLAGS_vmlinux} -o ${2} \ + ${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} -o ${2} \ -T ${lds} ${objects} else objects="-Wl,--whole-archive \ -- cgit v1.2.3-59-g8ed1b