From 0d989ac2c90b5f51fe12102d3cddf54b959f2014 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 12 May 2021 15:52:01 +0900 Subject: kbuild: remove libelf checks from top Makefile I do not see a good reason why only the libelf development package must be so carefully checked. Kbuild generally does not check host tools or libraries. For example, x86_64 defconfig fails to build with no libssl development package installed. scripts/extract-cert.c:21:10: fatal error: openssl/bio.h: No such file or directory 21 | #include | ^~~~~~~~~~~~~~~ To solve the build error, you need to install libssl-dev or openssl-devel package, depending on your distribution. 'apt-file search', 'dnf provides', etc. is your frined to find a proper package to install. This commit removes all the libelf checks from the top Makefile. If libelf is missing, objtool will fail to build in a similar pattern: .../linux/tools/objtool/include/objtool/elf.h:10:10: fatal error: gelf.h: No such file or directory 10 | #include You need to install libelf-dev, libelf-devel, or elfutils-libelf-devel to proceed. Another remarkable change is, CONFIG_STACK_VALIDATION (without CONFIG_UNWINDER_ORC) previously continued to build with a warning, but now it will treat missing libelf as an error. This is just a one-time installation, so it should not hurt to break a build and make a user install the package. BTW, the traditional way to handle such checks is autotool, but according to [1], I do not expect the kernel build would have similar scripting like './configure' does. [1]: https://lore.kernel.org/lkml/CA+55aFzr2HTZVOuzpHYDwmtRJLsVzE-yqg2DHpHi_9ePsYp5ug@mail.gmail.com/ Signed-off-by: Masahiro Yamada Acked-by: Andrii Nakryiko --- scripts/Makefile.build | 2 -- scripts/Makefile.modfinal | 2 -- 2 files changed, 4 deletions(-) (limited to 'scripts') diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 949f723efe53..7adc3a2c3c31 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -219,7 +219,6 @@ endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT ifdef CONFIG_STACK_VALIDATION ifndef CONFIG_LTO_CLANG -ifneq ($(SKIP_STACK_VALIDATION),1) __objtool_obj := $(objtree)/tools/objtool/objtool @@ -233,7 +232,6 @@ objtool_obj = $(if $(patsubst y%,, \ $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \ $(__objtool_obj)) -endif # SKIP_STACK_VALIDATION endif # CONFIG_LTO_CLANG endif # CONFIG_STACK_VALIDATION diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index dd87cea9fba7..bdee3babc5cf 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -39,12 +39,10 @@ prelink-ext := .lto # so let's now process the prelinked binary before we link the module. ifdef CONFIG_STACK_VALIDATION -ifneq ($(SKIP_STACK_VALIDATION),1) cmd_ld_ko_o += \ $(objtree)/tools/objtool/objtool $(objtool_args) \ $(@:.ko=$(prelink-ext).o); -endif # SKIP_STACK_VALIDATION endif # CONFIG_STACK_VALIDATION endif # CONFIG_LTO_CLANG -- cgit v1.2.3-70-g09d2 From 2728fcfa4fcc0c4152629c48d49c3bd5f9008329 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 17 May 2021 16:03:11 +0900 Subject: kbuild: merge scripts/mkmakefile to top Makefile scripts/mkmakefile is simple enough to be merged in the Makefile. Use $(call cmd,...) to show the log instead of doing it in the shell script. Signed-off-by: Masahiro Yamada --- Makefile | 11 +++++++++-- scripts/mkmakefile | 17 ----------------- 2 files changed, 9 insertions(+), 19 deletions(-) delete mode 100755 scripts/mkmakefile (limited to 'scripts') diff --git a/Makefile b/Makefile index 4dcfe9c48d60..504327207d66 100644 --- a/Makefile +++ b/Makefile @@ -544,14 +544,21 @@ scripts_basic: $(Q)rm -f .tmp_quiet_recordmcount PHONY += outputmakefile +ifdef building_out_of_srctree # Before starting out-of-tree build, make sure the source tree is clean. # outputmakefile generates a Makefile in the output directory, if using a # separate output directory. This allows convenient use of make in the # output directory. # At the same time when output Makefile generated, generate .gitignore to # ignore whole output directory + +quiet_cmd_makefile = GEN Makefile + cmd_makefile = { \ + echo "\# Automatically generated by $(srctree)/Makefile: don't edit"; \ + echo "include $(srctree)/Makefile"; \ + } > Makefile + outputmakefile: -ifdef building_out_of_srctree $(Q)if [ -f $(srctree)/.config -o \ -d $(srctree)/include/config -o \ -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \ @@ -562,7 +569,7 @@ ifdef building_out_of_srctree false; \ fi $(Q)ln -fsn $(srctree) source - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree) + $(call cmd,makefile) $(Q)test -e .gitignore || \ { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore endif diff --git a/scripts/mkmakefile b/scripts/mkmakefile deleted file mode 100755 index 1cb174751429..000000000000 --- a/scripts/mkmakefile +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 -# Generates a small Makefile used in the root of the output -# directory, to allow make to be started from there. -# The Makefile also allow for more convinient build of external modules - -# Usage -# $1 - Kernel src directory - -if [ "${quiet}" != "silent_" ]; then - echo " GEN Makefile" -fi - -cat << EOF > Makefile -# Automatically generated by $0: don't edit -include $1/Makefile -EOF -- cgit v1.2.3-70-g09d2 From 174a1dcc96429efce4ef7eb2f5c4506480da2182 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 17 May 2021 16:03:13 +0900 Subject: kbuild: sink stdout from cmd for silent build When building with 'make -s', no output to stdout should be printed. As Arnd Bergmann reported [1], mkimage shows the detailed information of the generated images. I think this should be suppressed by the 'cmd' macro instead of by individual scripts. Insert 'exec >/dev/null;' in order to redirect stdout to /dev/null for silent builds. [Note about this implementation] 'exec >/dev/null;' may look somewhat tricky, but this has a reason. Appending '>/dev/null' at the end of command line is a common way for redirection, so I first tried this: cmd = @set -e; $(echo-cmd) $(cmd_$(1)) >/dev/null ... but it would not work if $(cmd_$(1)) itself contains a redirection. For example, cmd_wrap in scripts/Makefile.asm-generic redirects the output from the 'echo' command into the target file. It would be expanded into: echo "#include " > $@ >/dev/null Then, the target file gets empty because the string will go to /dev/null instead of $@. Next, I tried this: cmd = @set -e; $(echo-cmd) { $(cmd_$(1)); } >/dev/null The form above would be expanded into: { echo "#include " > $@; } >/dev/null This works as expected. However, it would be a syntax error if $(cmd_$(1)) is empty. When CONFIG_TRIM_UNUSED_KSYMS is disabled, $(call cmd,gen_ksymdeps) in scripts/Makefile.build would be expanded into: set -e; { ; } >/dev/null ..., which causes an syntax error. I also tried this: cmd = @set -e; $(echo-cmd) ( $(cmd_$(1)) ) >/dev/null ... but this causes a syntax error for the same reason. So, finally I adopted: cmd = @set -e; $(echo-cmd) exec >/dev/null; $(cmd_$(1)) [1]: https://lore.kernel.org/lkml/20210514135752.2910387-1-arnd@kernel.org/ Signed-off-by: Masahiro Yamada --- scripts/Kbuild.include | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 82dd1b65b7a8..f247e691562d 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -90,8 +90,13 @@ clean := -f $(srctree)/scripts/Makefile.clean obj echo-cmd = $(if $($(quiet)cmd_$(1)),\ echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';) +# sink stdout for 'make -s' + redirect := + quiet_redirect := +silent_redirect := exec >/dev/null; + # printing commands -cmd = @set -e; $(echo-cmd) $(cmd_$(1)) +cmd = @set -e; $(echo-cmd) $($(quiet)redirect) $(cmd_$(1)) ### # if_changed - execute command if any prerequisite is newer than -- cgit v1.2.3-70-g09d2 From c39013ee64b5083ec3202aae8a418e9c70baff7a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 17 May 2021 16:03:14 +0900 Subject: kbuild: clean up ${quiet} checks in shell scripts There were efforts to make 'make -s' really silent when it is a warning-free build. The conventional way was to let a shell script check ${quiet}, and if it is 'silent_', suppress the stdout by itself. With the previous commit, the 'cmd' takes care of it now. The 'cmd' is also invoked from if_changed, if_changed_dep, and if_changed_rule. You can omit ${quiet} checks in shell scripts when they are invoked from the 'cmd' macro. Signed-off-by: Masahiro Yamada --- kernel/gen_kheaders.sh | 4 +--- scripts/link-vmlinux.sh | 4 +--- scripts/mkcompile_h | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) (limited to 'scripts') diff --git a/kernel/gen_kheaders.sh b/kernel/gen_kheaders.sh index 34a1dc2abc7d..1966a749e0d9 100755 --- a/kernel/gen_kheaders.sh +++ b/kernel/gen_kheaders.sh @@ -56,9 +56,7 @@ if [ -f kernel/kheaders.md5 ] && exit fi -if [ "${quiet}" != "silent_" ]; then - echo " GEN $tarfile" -fi +echo " GEN $tarfile" rm -rf $cpio_dir mkdir $cpio_dir diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index f4de4c97015b..3b342b0b0b38 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -38,9 +38,7 @@ LDFLAGS_vmlinux="$3" # Will be supressed by "make -s" info() { - if [ "${quiet}" != "silent_" ]; then - printf " %-7s %s\n" "${1}" "${2}" - fi + printf " %-7s %s\n" "${1}" "${2}" } # Generate a linker script to ensure correct ordering of initcalls. diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h index 4ae735039daf..06bbf4c2c66c 100755 --- a/scripts/mkcompile_h +++ b/scripts/mkcompile_h @@ -9,8 +9,6 @@ PREEMPT_RT=$5 CC_VERSION="$6" LD=$7 -vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; } - # Do not expand names set -f @@ -82,7 +80,7 @@ if [ -r $TARGET ] && \ cmp -s .tmpver.1 .tmpver.2; then rm -f .tmpcompile else - vecho " UPD $TARGET" + echo " UPD $TARGET" mv -f .tmpcompile $TARGET fi rm -f .tmpver.1 .tmpver.2 -- cgit v1.2.3-70-g09d2 From 2a73cce2dad3b6e0aa705b376bb736358b6b5e8e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 23 May 2021 12:14:24 +0900 Subject: scripts/setlocalversion: remove mercurial, svn and git-svn supports The mercurial, svn, git-svn supports were added by the following commits: - 3dce174cfcba ("kbuild: support mercurial in setlocalversion") - ba3d05fb6369 ("kbuild: add svn revision information to setlocalversion") - ff80aa97c9b4 ("setlocalversion: add git-svn support") They did not explain why they are useful for the kernel source tree. Let's revert all of them, and see if somebody will complain about it. Signed-off-by: Masahiro Yamada Reviewed-by: Greg Kroah-Hartman Reviewed-by: Nico Schottelius --- scripts/setlocalversion | 41 ----------------------------------------- 1 file changed, 41 deletions(-) (limited to 'scripts') diff --git a/scripts/setlocalversion b/scripts/setlocalversion index db941f6d9591..879cba956e60 100755 --- a/scripts/setlocalversion +++ b/scripts/setlocalversion @@ -79,11 +79,6 @@ scm_version() fi fi - # Is this git on svn? - if git config --get svn-remote.svn.url >/dev/null; then - printf -- '-svn%s' "$(git svn find-rev $head)" - fi - # Check for uncommitted changes. # First, with git-status, but --no-optional-locks is only # supported in git >= 2.14, so fall back to git-diff-index if @@ -96,42 +91,6 @@ scm_version() } | grep -qvE '^(.. )?scripts/package'; then printf '%s' -dirty fi - - # All done with git - return - fi - - # Check for mercurial and a mercurial repo. - if test -d .hg && hgid=$(hg id 2>/dev/null); then - # Do we have an tagged version? If so, latesttagdistance == 1 - if [ "$(hg log -r . --template '{latesttagdistance}')" = "1" ]; then - id=$(hg log -r . --template '{latesttag}') - printf '%s%s' -hg "$id" - else - tag=$(printf '%s' "$hgid" | cut -d' ' -f2) - if [ -z "$tag" -o "$tag" = tip ]; then - id=$(printf '%s' "$hgid" | sed 's/[+ ].*//') - printf '%s%s' -hg "$id" - fi - fi - - # Are there uncommitted changes? - # These are represented by + after the changeset id. - case "$hgid" in - *+|*+\ *) printf '%s' -dirty ;; - esac - - # All done with mercurial - return - fi - - # Check for svn and a svn repo. - if rev=$(LC_ALL=C svn info 2>/dev/null | grep '^Last Changed Rev'); then - rev=$(echo $rev | awk '{print $NF}') - printf -- '-svn%s' "$rev" - - # All done with svn - return fi } -- cgit v1.2.3-70-g09d2 From a2be76a352f1035a2e5f914a409743d65dc514c5 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 23 May 2021 12:14:25 +0900 Subject: scripts/setlocalversion: remove workaround for old make-kpkg This reverts commit b052ce4c840e ("kbuild: fix false positive -dirty tag caused by make-kpkg"). If I understand correctly, this problem occurred in very old versions of make-kpkg. When I tried a newer version, make-kpkg did not touch scripts/package/Makefile. Anyway, Debian uses 'make deb-pkg' instead of make-kpkg these days. Debian handbook [1] mentions it as "the good old days": "CULTURE The good old days of kernel-package Before the Linux build system gained the ability to build proper Debian packages, the recommended way to build such packages was to use make-kpkg from the kernel-package package." [1]: https://debian-handbook.info/browse/stable/sect.kernel-compilation.html Signed-off-by: Masahiro Yamada Reviewed-by: Greg Kroah-Hartman Reviewed-by: Nico Schottelius --- scripts/setlocalversion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/setlocalversion b/scripts/setlocalversion index 879cba956e60..f3084d6bbb22 100755 --- a/scripts/setlocalversion +++ b/scripts/setlocalversion @@ -88,7 +88,7 @@ scm_version() if { git --no-optional-locks status -uno --porcelain 2>/dev/null || git diff-index --name-only HEAD - } | grep -qvE '^(.. )?scripts/package'; then + } | read dummy; then printf '%s' -dirty fi fi -- cgit v1.2.3-70-g09d2 From ffaf62a8050b5f7995083ee93526b57d8d79fec4 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 23 May 2021 12:14:26 +0900 Subject: scripts/setlocalversion: add more comments to -dirty flag detection This script stumbled on the read-only source tree over again: - a2bb90a08cb3 ("kbuild: fix delay in setlocalversion on readonly source") - cdf2bc632ebc ("scripts/setlocalversion on write-protected source tree") - 8ef14c2c41d9 ("Revert "scripts/setlocalversion: git: Make -dirty check more robust"") - ff64dd485730 ("scripts/setlocalversion: Improve -dirty check with git-status --no-optional-locks") Add comments to clarify that this script should never ever try to write to the source tree. 'git describe --dirty' might look as a simple solution for appending the -dirty string, but we cannot use it because it creates the .git/index.lock file. Signed-off-by: Masahiro Yamada Reviewed-by: Greg Kroah-Hartman Reviewed-by: Nico Schottelius --- scripts/setlocalversion | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'scripts') diff --git a/scripts/setlocalversion b/scripts/setlocalversion index f3084d6bbb22..6865df6699c8 100755 --- a/scripts/setlocalversion +++ b/scripts/setlocalversion @@ -80,6 +80,10 @@ scm_version() fi # Check for uncommitted changes. + # This script must avoid any write attempt to the source tree, + # which might be read-only. + # You cannot use 'git describe --dirty' because it tries to + # create .git/index.lock . # First, with git-status, but --no-optional-locks is only # supported in git >= 2.14, so fall back to git-diff-index if # it fails. Note that git-diff-index does not refresh the -- cgit v1.2.3-70-g09d2 From 630ff0faf84eac6448c851961d4865471a792160 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 23 May 2021 12:14:27 +0900 Subject: scripts/setlocalversion: factor out 12-chars hash construction Both of if and else parts append exactly 12 hex chars, but in different ways. Factor out the else part because we need to support it without relying on git-describe. Remove the --abbrev=12 option since we do not use the hash from git-describe anyway. Signed-off-by: Masahiro Yamada Reviewed-by: Greg Kroah-Hartman Reviewed-by: Nico Schottelius --- scripts/setlocalversion | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'scripts') diff --git a/scripts/setlocalversion b/scripts/setlocalversion index 6865df6699c8..62c0bcce1575 100755 --- a/scripts/setlocalversion +++ b/scripts/setlocalversion @@ -59,24 +59,12 @@ scm_version() fi # If we are past a tagged commit (like # "v2.6.30-rc5-302-g72357d5"), we pretty print it. - # - # Ensure the abbreviated sha1 has exactly 12 - # hex characters, to make the output - # independent of git version, local - # core.abbrev settings and/or total number of - # objects in the current repository - passing - # --abbrev=12 ensures a minimum of 12, and the - # awk substr() then picks the 'g' and first 12 - # hex chars. - if atag="$(git describe --abbrev=12 2>/dev/null)"; then - echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),substr($(NF),0,13))}' - - # If we don't have a tag at all we print -g{commitish}, - # again using exactly 12 hex chars. - else - head="$(echo $head | cut -c1-12)" - printf '%s%s' -g $head + if atag="$(git describe 2>/dev/null)"; then + echo "$atag" | awk -F- '{printf("-%05d", $(NF-1))}' fi + + # Add -g and exactly 12 hex chars. + printf '%s%s' -g "$(echo $head | cut -c1-12)" fi # Check for uncommitted changes. -- cgit v1.2.3-70-g09d2 From 042da426f8ebde012be9429ff705232af7ad7469 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 23 May 2021 12:14:28 +0900 Subject: scripts/setlocalversion: simplify the short version part Reduce the indentation. Signed-off-by: Masahiro Yamada Reviewed-by: Greg Kroah-Hartman Reviewed-by: Nico Schottelius --- scripts/setlocalversion | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/setlocalversion b/scripts/setlocalversion index 62c0bcce1575..151f04971faa 100755 --- a/scripts/setlocalversion +++ b/scripts/setlocalversion @@ -131,15 +131,13 @@ res="${res}${CONFIG_LOCALVERSION}${LOCALVERSION}" if test "$CONFIG_LOCALVERSION_AUTO" = "y"; then # full scm version string res="$res$(scm_version)" -else +elif [ -z "${LOCALVERSION}" ]; then # append a plus sign if the repository is not in a clean # annotated or signed tagged state (as git describe only # looks at signed or annotated tags - git tag -a/-s) and # LOCALVERSION= is not specified - if test "${LOCALVERSION+set}" != "set"; then - scm=$(scm_version --short) - res="$res${scm:++}" - fi + scm=$(scm_version --short) + res="$res${scm:++}" fi echo "$res" -- cgit v1.2.3-70-g09d2 From 43ac711053fc6d94a3f16141c4efe20059a9d918 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 29 May 2021 02:13:21 +0900 Subject: kconfig: constify long_opts getopt_long() does not modify the long_opts structure. Signed-off-by: Masahiro Yamada --- scripts/kconfig/conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index bfa1ea8f5f98..5d84b44a2a2a 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -678,7 +678,7 @@ static void check_conf(struct menu *menu) check_conf(child); } -static struct option long_opts[] = { +static const struct option long_opts[] = { {"help", no_argument, NULL, 'h'}, {"silent", no_argument, NULL, 's'}, {"oldaskconfig", no_argument, &input_mode_opt, oldaskconfig}, -- cgit v1.2.3-70-g09d2 From 4a6795933a890d41504c6df04527d1e093a4cbe6 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Mon, 7 Jun 2021 15:02:06 +0100 Subject: kbuild: modpost: Explicitly warn about unprototyped symbols One common cause of modpost version generation failures is a failure to prototype exported assembly functions - the tooling requires this for exported functions even if they are not and should not be called from C code in order to do the version mangling for symbols. Unfortunately the error message is currently rather abstruse, simply saying that "version generation failed" and even diving into the code doesn't directly show what's going on since there's several steps between the problem and it being observed. Provide an explicit hint as to the likely cause of a version generation failure to help anyone who runs into this in future more readily diagnose and fix the problem. Signed-off-by: Mark Brown Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 3e623ccc020b..270a7df898e2 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -660,8 +660,11 @@ static void handle_modversion(const struct module *mod, unsigned int crc; if (sym->st_shndx == SHN_UNDEF) { - warn("EXPORT symbol \"%s\" [%s%s] version generation failed, symbol will not be versioned.\n", - symname, mod->name, mod->is_vmlinux ? "" : ".ko"); + warn("EXPORT symbol \"%s\" [%s%s] version ...\n" + "Is \"%s\" prototyped in ?\n", + symname, mod->name, mod->is_vmlinux ? "" : ".ko", + symname); + return; } -- cgit v1.2.3-70-g09d2 From a979522a1a88556e42a22ce61bccc58e304cb361 Mon Sep 17 00:00:00 2001 From: Matthias Maennich Date: Sat, 12 Jun 2021 15:18:38 +0100 Subject: kbuild: mkcompile_h: consider timestamp if KBUILD_BUILD_TIMESTAMP is set To avoid unnecessary recompilations, mkcompile_h does not regenerate compile.h if just the timestamp changed. Though, if KBUILD_BUILD_TIMESTAMP is set, an explicit timestamp for the build was requested, in which case we should not ignore it. If a user follows the documentation for reproducible builds [1] and defines KBUILD_BUILD_TIMESTAMP as the git commit timestamp, a clean build will have the correct timestamp. A subsequent cherry-pick (or amend) changes the commit timestamp and if an incremental build is done with a different KBUILD_BUILD_TIMESTAMP now, that new value is not taken into consideration. But it should for reproducibility. Hence, whenever KBUILD_BUILD_TIMESTAMP is explicitly set, do not ignore UTS_VERSION when making a decision about whether the regenerated version of compile.h should be moved into place. [1] https://www.kernel.org/doc/html/latest/kbuild/reproducible-builds.html Signed-off-by: Matthias Maennich Signed-off-by: Masahiro Yamada --- scripts/mkcompile_h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h index 06bbf4c2c66c..6a2a04d92f42 100755 --- a/scripts/mkcompile_h +++ b/scripts/mkcompile_h @@ -68,15 +68,23 @@ UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)" # Only replace the real compile.h if the new one is different, # in order to preserve the timestamp and avoid unnecessary # recompilations. -# We don't consider the file changed if only the date/time changed. +# We don't consider the file changed if only the date/time changed, +# unless KBUILD_BUILD_TIMESTAMP was explicitly set (e.g. for +# reproducible builds with that value referring to a commit timestamp). # A kernel config change will increase the generation number, thus # causing compile.h to be updated (including date/time) due to the # changed comment in the # first line. +if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then + IGNORE_PATTERN="UTS_VERSION" +else + IGNORE_PATTERN="NOT_A_PATTERN_TO_BE_MATCHED" +fi + if [ -r $TARGET ] && \ - grep -v 'UTS_VERSION' $TARGET > .tmpver.1 && \ - grep -v 'UTS_VERSION' .tmpcompile > .tmpver.2 && \ + grep -v $IGNORE_PATTERN $TARGET > .tmpver.1 && \ + grep -v $IGNORE_PATTERN .tmpcompile > .tmpver.2 && \ cmp -s .tmpver.1 .tmpver.2; then rm -f .tmpcompile else -- cgit v1.2.3-70-g09d2 From c6a3a81d19b834e3aed819027f022c5938fca2ec Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 5 Jul 2021 15:06:54 +0900 Subject: scripts: check duplicated syscall number in syscall table Currently, syscall{hdr,tbl}.sh sorts the entire syscall table, but you can assume it is already sorted by the syscall number. The generated syscall table does not work if the same syscall number appears twice. Check it in the script. Signed-off-by: Masahiro Yamada --- scripts/syscallhdr.sh | 2 +- scripts/syscalltbl.sh | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/syscallhdr.sh b/scripts/syscallhdr.sh index 848ac2735115..22e34cd46b9b 100755 --- a/scripts/syscallhdr.sh +++ b/scripts/syscallhdr.sh @@ -69,7 +69,7 @@ guard=_UAPI_ASM_$(basename "$outfile" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \ -e 's/[^A-Z0-9_]/_/g' -e 's/__/_/g') -grep -E "^[0-9A-Fa-fXx]+[[:space:]]+$abis" "$infile" | sort -n | { +grep -E "^[0-9A-Fa-fXx]+[[:space:]]+$abis" "$infile" | { echo "#ifndef $guard" echo "#define $guard" echo diff --git a/scripts/syscalltbl.sh b/scripts/syscalltbl.sh index aa6ab156301c..6abe143889ef 100755 --- a/scripts/syscalltbl.sh +++ b/scripts/syscalltbl.sh @@ -52,10 +52,15 @@ outfile="$2" nxt=0 -grep -E "^[0-9]+[[:space:]]+$abis" "$infile" | sort -n | { +grep -E "^[0-9]+[[:space:]]+$abis" "$infile" | { while read nr abi name native compat ; do + if [ $nxt -gt $nr ]; then + echo "error: $infile: syscall table is not sorted or duplicates the same syscall number" >&2 + exit 1 + fi + while [ $nxt -lt $nr ]; do echo "__SYSCALL($nxt, sys_ni_syscall)" nxt=$((nxt + 1)) -- cgit v1.2.3-70-g09d2 From 27932b6a2088eac7a5afa5471963b926cfbb4de7 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 6 Jul 2021 15:15:29 +0900 Subject: scripts: add generic syscallnr.sh Like syscallhdr.sh and syscalltbl.sh, add a simple script to generate the __NR_syscalls, which should not be exported to userspace. This script is useful to replace arch/mips/kernel/syscalls/syscallnr.sh, refactor arch/s390/kernel/syscalls/syscalltbl, and eliminate the code surrounded by #ifdef __KERNEL__ / #endif from exported uapi/asm/unistd_*.h files. Signed-off-by: Masahiro Yamada --- scripts/syscallnr.sh | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 scripts/syscallnr.sh (limited to 'scripts') diff --git a/scripts/syscallnr.sh b/scripts/syscallnr.sh new file mode 100644 index 000000000000..3aa29e0dcc52 --- /dev/null +++ b/scripts/syscallnr.sh @@ -0,0 +1,74 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only +# +# Generate a syscall number header. +# +# Each line of the syscall table should have the following format: +# +# NR ABI NAME [NATIVE] [COMPAT] +# +# NR syscall number +# ABI ABI name +# NAME syscall name +# NATIVE native entry point (optional) +# COMPAT compat entry point (optional) +set -e + +usage() { + echo >&2 "usage: $0 [--abis ABIS] [--prefix PREFIX] INFILE OUTFILE" >&2 + echo >&2 + echo >&2 " INFILE input syscall table" + echo >&2 " OUTFILE output header file" + echo >&2 + echo >&2 "options:" + echo >&2 " --abis ABIS ABI(s) to handle (By default, all lines are handled)" + echo >&2 " --prefix PREFIX The prefix to the macro like __NR_" + exit 1 +} + +# default unless specified by options +abis= +prefix= + +while [ $# -gt 0 ] +do + case $1 in + --abis) + abis=$(echo "($2)" | tr ',' '|') + shift 2;; + --prefix) + prefix=$2 + shift 2;; + -*) + echo "$1: unknown option" >&2 + usage;; + *) + break;; + esac +done + +if [ $# -ne 2 ]; then + usage +fi + +infile="$1" +outfile="$2" + +guard=_ASM_$(basename "$outfile" | + sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \ + -e 's/[^A-Z0-9_]/_/g' -e 's/__/_/g') + +grep -E "^[0-9A-Fa-fXx]+[[:space:]]+$abis" "$infile" | sort -n | { + echo "#ifndef $guard" + echo "#define $guard" + echo + + max=0 + while read nr abi name native compat ; do + max=$nr + done + + echo "#define __NR_${prefix}syscalls $(($max + 1))" + echo + echo "#endif /* $guard */" +} > "$outfile" -- cgit v1.2.3-70-g09d2