20 Oct, 2020

1 commit

  • After commit 43fee2b23895 ("kbuild: do not redirect the first
    prerequisite for filechk"), the rule is no longer automatically passed
    $< as stdin, so remove the stale comment.

    Fixes: 43fee2b23895 ("kbuild: do not redirect the first prerequisite for filechk")
    Signed-off-by: Rasmus Villemoes
    Signed-off-by: Masahiro Yamada

    Rasmus Villemoes
     

10 Aug, 2020

1 commit


17 Jun, 2020

1 commit

  • When cc-option and friends evaluate compiler flags, the temporary file
    $$TMP is created as an output object, and automatically cleaned up.
    The actual file path of $$TMP is ..tmp, here is the process
    ID of $(shell ...) invoked from cc-option. (Please note $$$$ is the
    escape sequence of $$).

    Such garbage files are cleaned up in most cases, but some compiler flags
    create additional output files.

    For example, -gsplit-dwarf creates a .dwo file.

    When CONFIG_DEBUG_INFO_SPLIT=y, you will see a bunch of ..dwo files
    left in the top of build directories. You may not notice them unless you
    do 'ls -a', but the garbage files will increase every time you run 'make'.

    This commit changes the temporary object path to .tmp_/tmp, and
    removes .tmp_ directory when exiting. Separate build artifacts such
    as *.dwo will be cleaned up all together because their file paths are
    usually determined based on the base name of the object.

    Another example is -ftest-coverage, which outputs the coverage data into
    .gcno

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

12 May, 2020

1 commit

  • This omits system headers from the generated header dependency.

    System headers are not updated unless you upgrade the compiler. Nor do
    they contain CONFIG options, so fixdep does not need to parse them.

    Having said that, the effect of this optimization will be quite small
    because the kernel code generally does not include system headers
    except . Host programs include a lot of system headers,
    but there are not so many in the kernel tree.

    At first, keeping system headers in .*.cmd files might be useful to
    detect the compiler update, but there is no guarantee that
    is included from every file. So, I implemented a more reliable way in
    the previous commit.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

15 Jan, 2020

1 commit

  • Bartosz Golaszewski reports that when "make {menu,n,g,x}config" fails
    due to missing packages, a temporary file is left over, which is not
    ignored by git.

    For example, if GTK+ is not installed:

    $ make gconfig
    *
    * Unable to find the GTK+ installation. Please make sure that
    * the GTK+ 2.0 development package is correctly installed.
    * You need gtk+-2.0 gmodule-2.0 libglade-2.0
    *
    scripts/kconfig/Makefile:208: recipe for target 'scripts/kconfig/gconf-cfg' failed
    make[1]: *** [scripts/kconfig/gconf-cfg] Error 1
    Makefile:567: recipe for target 'gconfig' failed
    make: *** [gconfig] Error 2
    $ git status
    HEAD detached at v5.4
    Untracked files:
    (use "git add ..." to include in what will be committed)

    scripts/kconfig/gconf-cfg.tmp

    nothing added to commit but untracked files present (use "git add" to track)

    This is because the check scripts are run with filechk, which misses
    to clean up the temporary file on failure.

    When the line

    { $(filechk_$(1)); } > $@.tmp;

    ... fails, it exits immediately due to the 'set -e'. Use trap to make
    sure to delete the temporary file on exit.

    For extra safety, I replaced $@.tmp with $(dot-target).tmp to make it
    a hidden file.

    Reported-by: Bartosz Golaszewski
    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

07 Jan, 2020

2 commits

  • Commit bc081dd6e9f6 ("kbuild: generate modules.builtin") added
    infrastructure to generate modules.builtin, the list of all
    builtin modules.

    Basically, it works like this:

    - Kconfig generates include/config/tristate.conf, the list of
    tristate CONFIG options with a value in a capital letter.

    - scripts/Makefile.modbuiltin makes Kbuild descend into
    directories to collect the information of builtin modules.

    I am not a big fan of it because Kbuild ends up with traversing
    the source tree twice.

    I am not sure how perfectly it should work, but this approach cannot
    avoid false positives; even if the relevant CONFIG option is tristate,
    some Makefiles forces obj-m to obj-y.

    Some examples are:

    arch/powerpc/platforms/powermac/Makefile:
    obj-$(CONFIG_NVRAM:m=y) += nvram.o

    net/ipv6/Makefile:
    obj-$(subst m,y,$(CONFIG_IPV6)) += inet6_hashtables.o

    net/netlabel/Makefile:
    obj-$(subst m,y,$(CONFIG_IPV6)) += netlabel_calipso.o

    Nobody has complained about (or noticed) it, so it is probably fine to
    have false positives in modules.builtin.

    This commit simplifies the implementation. Let's exploit the fact
    that every module has MODULE_LICENSE(). (modpost shows a warning if
    MODULE_LICENSE is missing. If so, 0-day bot would already have blocked
    such a module.)

    I added MODULE_FILE to . When the code is being compiled
    as builtin, it will be filled with the file path of the module, and
    collected into modules.builtin.info. Then, scripts/link-vmlinux.sh
    extracts the list of builtin modules out of it.

    This new approach fixes the false-positives above, but adds another
    type of false-positives; non-modular code may have MODULE_LICENSE()
    by mistake. This is not a big deal, it is just the code is always
    orphan. We can clean it up if we like. You can see cleanup examples by:

    $ git log --grep='make.* explicitly non-modular'

    To sum up, this commits deletes lots of code, but still produces almost
    equivalent results. Please note it does not increase the vmlinux size at
    all. As you can see in include/asm-generic/vmlinux.lds.h, the .modinfo
    section is discarded in the link stage.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     
  • Make $(squote)$(quote)...$(quote)$(squote) a helper macro.
    I will reuse it in the next commit.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

11 Nov, 2019

2 commits

  • GNU Make manual says:

    $?
    The names of all the prerequisites that are newer than the target,
    with spaces between them.

    To reflect this, rename any-prereq to newer-prereqs, which is clearer
    and more intuitive.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     
  • The incremental build of Linux kernel is pretty slow when lots of
    objects are compiled. The rebuild of allmodconfig may take a few
    minutes even when none of the objects needs to be rebuilt.

    The time-consuming part in the incremental build is the evaluation of
    if_changed* macros since they are used in the recipes to compile C and
    assembly source files into objects.

    I notice the following code in if_changed* is expensive:

    $(filter-out $(PHONY) $(wildcard $^),$^)

    In the incremental build, every object has its .*.cmd file, which
    contains the auto-generated list of included headers. So, $^ are
    expanded into the long list of the source file + included headers,
    and $(wildcard $^) checks whether they exist.

    It may not be clear why this check exists there.

    Here is the record of my research.

    [1] The first code addition into Kbuild

    This code dates back to 2002. It is the pre-git era. So, I copy-pasted
    it from the historical git tree.

    | commit 4a6db0791528c220655b063cf13fefc8470dbfee (HEAD)
    | Author: Kai Germaschewski
    | Date: Mon Jun 17 00:22:37 2002 -0500
    |
    | kbuild: Handle removed headers
    |
    | New and old way to handle dependencies would choke when a file
    | #include'd by other files was removed, since the dependency on it was
    | still recorded, but since it was gone, make has no idea what to do about
    | it (and would complain with "No rule to make ...")
    |
    | We now add targets for all the previously included files, so make will
    | just ignore them if they disappear.
    |
    | diff --git a/Rules.make b/Rules.make
    | index 6ef827d3df39..7db5301ea7db 100644
    | --- a/Rules.make
    | +++ b/Rules.make
    | @@ -446,7 +446,7 @@ if_changed = $(if $(strip $? \
    | # execute the command and also postprocess generated .d dependencies
    | # file
    |
    | -if_changed_dep = $(if $(strip $? \
    | +if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\
    | $(filter-out $(cmd_$(1)),$(cmd_$@))\
    | $(filter-out $(cmd_$@),$(cmd_$(1)))),\
    | @set -e; \
    | diff --git a/scripts/fixdep.c b/scripts/fixdep.c
    | index b5d7bee8efc7..db45bd1888c0 100644
    | --- a/scripts/fixdep.c
    | +++ b/scripts/fixdep.c
    | @@ -292,7 +292,7 @@ void parse_dep_file(void *map, size_t len)
    | exit(1);
    | }
    | memcpy(s, m, p-m); s[p-m] = 0;
    | - printf("%s: \\\n", target);
    | + printf("deps_%s := \\\n", target);
    | m = p+1;
    |
    | clear_config();
    | @@ -314,7 +314,8 @@ void parse_dep_file(void *map, size_t len)
    | }
    | m = p + 1;
    | }
    | - printf("\n");
    | + printf("\n%s: $(deps_%s)\n\n", target, target);
    | + printf("$(deps_%s):\n", target);
    | }
    |
    | void print_deps(void)

    The "No rule to make ..." error can be solved by passing -MP to
    the compiler, but I think the detection of header removal is a good
    feature. When a header is removed, all source files that previously
    included it should be re-compiled. This makes sure we has correctly
    got rid of #include directives of it.

    This is also related with the behavior of $?. The GNU Make manual says:

    $?
    The names of all the prerequisites that are newer than the target,
    with spaces between them.

    This does not explain whether a non-existent prerequisite is considered
    to be newer than the target.

    At this point of time, GNU Make 3.7x was used, where the $? did not
    include non-existent prerequisites. Therefore,

    $(filter-out FORCE $(wildcard $^),$^)

    was useful to detect the header removal, and to rebuild the related
    objects if it is the case.

    [2] Change of $? behavior

    Later, the behavior of $? was changed (fixed) to include prerequisites
    that did not exist.

    First, GNU Make commit 64e16d6c00a5 ("Various changes getting ready for
    the release of 3.81.") changed it, but in the release test of 3.81, it
    turned out to break the kernel build.

    See these:

    - http://lists.gnu.org/archive/html/bug-make/2006-03/msg00003.html
    - https://savannah.gnu.org/bugs/?16002
    - https://savannah.gnu.org/bugs/?16051

    Then, GNU Make commit 6d8d9b74d9c5 ("Numerous updates to tests for
    issues found on Cygwin and Windows.") reverted it for the 3.81 release
    to give Linux kernel time to adjust to the new behavior.

    After the 3.81 release, GNU Make commit 7595f38f62af ("Fixed a number
    of documentation bugs, plus some build/install issues:") re-added it.

    [3] Adjustment to the new $? behavior on Kbuild side

    Meanwhile, the kernel build was changed by commit 4f1933620f57 ("kbuild:
    change kbuild to not rely on incorrect GNU make behavior") to adjust to
    the new $? behavior.

    [4] GNU Make 3.82 released in 2010

    GNU Make 3.82 was the first release that integrated the correct $?
    behavior. At this point, Kbuild dealt with GNU Make versions with
    different $? behaviors.

    3.81 or older:
    $? does not contain any non-existent prerequisite.
    $(filter-out $(PHONY) $(wildcard $^),$^) was useful to detect
    removed include headers.

    3.82 or newer:
    $? contains non-existent prerequisites. When a header is removed,
    it appears in $?. $(filter-out $(PHONY) $(wildcard $^),$^) became
    a redundant check.

    With the correct $? behavior, we could have dropped the expensive
    check for 3.82 or later, but we did not. (Maybe nobody noticed this
    optimization.)

    [5] The .SECONDARY special target trips up $?

    Some time later, I noticed $? did not work as expected under some
    circumstances. As above, $? should contain non-existent prerequisites,
    but the ones specified as SECONDARY do not appear in $?.

    I asked this in GNU Make ML, and it seems a bug:

    https://lists.gnu.org/archive/html/bug-make/2019-01/msg00001.html

    Since commit 8e9b61b293d9 ("kbuild: move .SECONDARY special target to
    Kbuild.include"), all files, including headers listed in .*.cmd files,
    are treated as secondary.

    So, we are back into the incorrect $? behavior.

    If we Kbuild want to react to the header removal, we need to keep
    $(filter-out $(PHONY) $(wildcard $^),$^) but this makes the rebuild
    so slow.

    [Summary]

    - I believe noticing the header removal and recompiling related objects
    is a nice feature for the build system.

    - If $? worked correctly, $(filter-out $(PHONY),$?) would be enough
    to detect the header removal.

    - Currently, $? does not work correctly when used with .SECONDARY,
    and Kbuild is hit by this bug.

    - I filed a bug report for this, but not fixed yet as of writing.

    - Currently, the header removal is detected by the following expensive
    code:

    $(filter-out $(PHONY) $(wildcard $^),$^)

    - I do not want to revert commit 8e9b61b293d9 ("kbuild: move
    .SECONDARY special target to Kbuild.include"). Specifying
    .SECONDARY globally is clean, and it matches to the Kbuild policy.

    This commit proactively removes the expensive check since it makes the
    incremental build faster. A downside is Kbuild will no longer be able
    to notice the header removal.

    You can confirm it by the full-build followed by a header removal, and
    then re-build.

    $ make defconfig all
    [ full build ]
    $ rm include/linux/device.h
    $ make
    CALL scripts/checksyscalls.sh
    CALL scripts/atomic/check-atomics.sh
    DESCEND objtool
    CHK include/generated/compile.h
    Kernel: arch/x86/boot/bzImage is ready (#11)
    Building modules, stage 2.
    MODPOST 12 modules

    Previously, Kbuild noticed a missing header and emits a build error.
    Now, Kbuild is fine with it. This is an unusual corner-case, not a big
    deal. Once the $? bug is fixed in GNU Make, everything will work fine.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

01 Oct, 2019

1 commit


27 Jul, 2019

1 commit


17 Jul, 2019

1 commit


13 Jul, 2019

1 commit

  • Pull Kbuild updates from Masahiro Yamada:

    - remove headers_{install,check}_all targets

    - remove unreasonable 'depends on !UML' from CONFIG_SAMPLES

    - re-implement 'make headers_install' more cleanly

    - add new header-test-y syntax to compile-test headers

    - compile-test exported headers to ensure they are compilable in
    user-space

    - compile-test headers under include/ to ensure they are self-contained

    - remove -Waggregate-return, -Wno-uninitialized, -Wno-unused-value
    flags

    - add -Werror=unknown-warning-option for Clang

    - add 128-bit built-in types support to genksyms

    - fix missed rebuild of modules.builtin

    - propagate 'No space left on device' error in fixdep to Make

    - allow Clang to use its integrated assembler

    - improve some coccinelle scripts

    - add a new flag KBUILD_ABS_SRCTREE to request Kbuild to use absolute
    path for $(srctree).

    - do not ignore errors when compression utility is missing

    - misc cleanups

    * tag 'kbuild-v5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (49 commits)
    kbuild: use -- separater intead of $(filter-out ...) for cc-cross-prefix
    kbuild: Inform user to pass ARCH= for make mrproper
    kbuild: fix compression errors getting ignored
    kbuild: add a flag to force absolute path for srctree
    kbuild: replace KBUILD_SRCTREE with boolean building_out_of_srctree
    kbuild: remove src and obj from the top Makefile
    scripts/tags.sh: remove unused environment variables from comments
    scripts/tags.sh: drop SUBARCH support for ARM
    kbuild: compile-test kernel headers to ensure they are self-contained
    kheaders: include only headers into kheaders_data.tar.xz
    kheaders: remove meaningless -R option of 'ls'
    kbuild: support header-test-pattern-y
    kbuild: do not create wrappers for header-test-y
    kbuild: compile-test exported headers to ensure they are self-contained
    init/Kconfig: add CONFIG_CC_CAN_LINK
    kallsyms: exclude kasan local symbols on s390
    kbuild: add more hints about SUBDIRS replacement
    coccinelle: api/stream_open: treat all wait_.*() calls as blocking
    coccinelle: put_device: Add a cast to an expression for an assignment
    coccinelle: put_device: Adjust a message construction
    ...

    Linus Torvalds
     

11 Jul, 2019

1 commit

  • arch/mips/Makefile passes prefixes that start with '-' to cc-cross-prefix
    when $(tool-archpref) evaluates to the empty string.

    They are filtered-out before the $(shell ...) invocation. Otherwise,
    'command -v' would be confused.

    $ command -v -linux-gcc
    bash: command: -l: invalid option
    command: usage: command [-pVv] command [arg ...]

    Since commit 913ab9780fc0 ("kbuild: use more portable 'command -v' for
    cc-cross-prefix"), cc-cross-prefix throws away the stderr output, so
    the console is not polluted in any way.

    This is not a big deal in practice, but I see a slightly better taste
    in adding '--' to teach it that '-linux-gcc' is an argument instead of
    a command option.

    This will cause extra forking of subshell, but it will not be noticeable
    performance regression.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

01 Jul, 2019

3 commits

  • The string returned by $(filter-out ...) does not contain any leading
    or trailing spaces.

    With the previous commit, 'any-prereq' no longer contains any
    excessive spaces.

    Nor does 'cmd-check' since it expands to a $(filter-out ...) call.

    So, only the space that matters is the one between 'any-prereq'
    and 'cmd-check'.

    By removing it from the code, we can save $(strip ...) evaluation.
    This refactoring is possible because $(any-prereq)$(cmd-check) is only
    passed to the first argument of $(if ...), so we are only interested
    in whether or not it is empty.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     
  • The string returned by $(filter-out ...) does not contain any leading
    or trailing spaces.

    So, only the space that matters is the one between

    $(filter-out $(PHONY),$?)

    and

    $(filter-out $(PHONY) $(wildcard $^),$^)

    By removing it from the code, we can save $(strip ...) evaluation.
    This refactoring is possible because $(any-prereq) is only passed to
    the first argument of $(if ...), so we are only interested in whether
    or not it is empty.

    This is also the prerequisite for the next commit.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     
  • I prefer 'cmd-check' for consistency.

    We have 'echo-cmd', 'cmd', 'cmd_and_fixdep', etc. in this file.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

15 Jun, 2019

2 commits

  • Now that hdr-inst is used only in the top Makefile, move it there
    from scripts/Kbuild.include.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     
  • The kbuild documentation clearly shows that the documents
    there are written at different times: some use markdown,
    some use their own peculiar logic to split sections.

    Convert everything to ReST without affecting too much
    the author's style and avoiding adding uneeded markups.

    The conversion is actually:
    - add blank lines and identation in order to identify paragraphs;
    - fix tables markups;
    - add some lists markups;
    - mark literal blocks;
    - adjust title markups.

    At its new index.rst, let's add a :orphan: while this is not linked to
    the main index.rst file, in order to avoid build warnings.

    Signed-off-by: Mauro Carvalho Chehab
    Signed-off-by: Jonathan Corbet

    Mauro Carvalho Chehab
     

07 Jun, 2019

1 commit

  • To print the pathname that will be used by shell in the current
    environment, 'command -v' is a standardized way. [1]

    'which' is also often used in scripts, but it is less portable.

    When I worked on commit bd55f96fa9fc ("kbuild: refactor cc-cross-prefix
    implementation"), I was eager to use 'command -v' but it did not work.
    (The reason is explained below.)

    I kept 'which' as before but got rid of '> /dev/null 2>&1' as I
    thought it was no longer needed. Sorry, I was wrong.

    It works well on my Ubuntu machine, but Alexey Brodkin reports noisy
    warnings on CentOS7 when 'which' fails to find the given command in
    the PATH environment.

    $ which foo
    which: no foo in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin)

    Given that behavior of 'which' depends on system (and it may not be
    installed by default), I want to try 'command -v' once again.

    The specification [1] clearly describes the behavior of 'command -v'
    when the given command is not found:

    Otherwise, no output shall be written and the exit status shall reflect
    that the name was not found.

    However, we need a little magic to use 'command -v' from Make.

    $(shell ...) passes the argument to a subshell for execution, and
    returns the standard output of the command.

    Here is a trick. GNU Make may optimize this by executing the command
    directly instead of forking a subshell, if no shell special characters
    are found in the command and omitting the subshell will not change the
    behavior.

    In this case, no shell special character is used. So, Make will try
    to run it directly. However, 'command' is a shell-builtin command,
    then Make would fail to find it in the PATH environment:

    $ make ARCH=m68k defconfig
    make: command: Command not found
    make: command: Command not found
    make: command: Command not found

    In fact, Make has a table of shell-builtin commands because it must
    ask the shell to execute them.

    Until recently, 'command' was missing in the table.

    This issue was fixed by the following commit:

    | commit 1af314465e5dfe3e8baa839a32a72e83c04f26ef
    | Author: Paul Smith
    | Date: Sun Nov 12 18:10:28 2017 -0500
    |
    | * job.c: Add "command" as a known shell built-in.
    |
    | This is not a POSIX shell built-in but it's common in UNIX shells.
    | Reported by Nick Bowler .

    Because the latest release is GNU Make 4.2.1 in 2016, this commit is
    not included in any released versions. (But some distributions may
    have back-ported it.)

    We need to trick Make to spawn a subshell. There are various ways to
    do so:

    1) Use a shell special character '~' as dummy

    $(shell : ~; command -v $(c)gcc)

    2) Use a variable reference that always expands to the empty string
    (suggested by David Laight)

    $(shell command$${x:+} -v $(c)gcc)

    3) Use redirect

    $(shell command -v $(c)gcc 2>/dev/null)

    I chose 3) to not confuse people. The stderr would not be polluted
    anyway, but it will provide extra safety, and is easy to understand.

    Tested on Make 3.81, 3.82, 4.0, 4.1, 4.2, 4.2.1

    [1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html

    Fixes: bd55f96fa9fc ("kbuild: refactor cc-cross-prefix implementation")
    Cc: linux-stable # 5.1
    Reported-by: Alexey Brodkin
    Signed-off-by: Masahiro Yamada
    Tested-by: Alexey Brodkin

    Masahiro Yamada
     

31 May, 2019

1 commit

  • Add SPDX license identifiers to all Make/Kconfig files which:

    - Have no license information of any form

    These files fall under the project license, GPL v2 only. The resulting SPDX
    license identifier is:

    GPL-2.0

    Reported-by: Masahiro Yamada
    Signed-off-by: Greg Kroah-Hartman
    Reviewed-by: Kate Stewart
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

20 May, 2019

1 commit

  • If you want to see if your linker supports a certain flag, then ask the
    linker directly with ld-option (not the compiler with cc-ldoption).
    Checking for linker flag support is an antipattern that complicates the
    usage of various linkers other than bfd via -fuse-ld={bfd|gold|lld}.

    Cc: clang-built-linux@googlegroups.com
    Suggested-by: Masahiro Yamada
    Signed-off-by: Nick Desaulniers
    Signed-off-by: Masahiro Yamada

    Nick Desaulniers
     

18 May, 2019

1 commit

  • The 'addtree' and 'flags' in scripts/Kbuild.include are so compilecated
    and ugly.

    As I mentioned in [1], Kbuild should stop automatic prefixing of header
    search path options.

    I fixed up (almost) all Makefiles in the kernel. Now 'addtree' and
    'flags' have been removed.

    Kbuild still caters to add $(srctree)/$(src) and $(objtree)/$(obj)
    to the header search path for O= building, but never touches extra
    compiler options from ccflags-y etc.

    [1]: https://patchwork.kernel.org/patch/9632347/

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

04 Mar, 2019

1 commit

  • There is no more direct user of this macro; it is only used by
    cc-ifversion.

    Calling this macro is not efficient since it invokes the compiler to
    get the compiler version. CONFIG_GCC_VERSION is already calculated in
    the Kconfig stage, so Makefile can reuse it.

    Here is a note about the slight difference between cc-version and
    CONFIG_GCC_VERSION:

    When using Clang, cc-version is evaluated to '0402' because Clang
    defines __GNUC__ and __GNUC__MINOR__, and looks like GCC 4.2 in the
    version point of view. On the other hand, CONFIG_GCC_VERSION=0
    when $(CC) is clang.

    There are currently two users of cc-ifversion:
    arch/mips/loongson64/Platform
    arch/powerpc/Makefile

    They are not affected by this change.

    The format of cc-version is , while CONFIG_GCC_VERSION
    . I adjusted cc-ifversion for the difference of
    the number of digits.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

27 Feb, 2019

1 commit

  • - $(word 1, ) is equivalent to $(firstword )

    - hardcode "gcc" instead of $(CC)

    - minimize the shell script part

    A little more notes in case $(filter-out -%, ...) is not clear.

    arch/mips/Makefile passes prefixes depending on the configuration.

    CROSS_COMPILE := $(call cc-cross-prefix, $(tool-archpref)-linux- \
    $(tool-archpref)-linux-gnu- $(tool-archpref)-unknown-linux-gnu-)

    In the Kconfig stage (e.g. when you run 'make defconfig'), neither
    CONFIG_32BIT nor CONFIG_64BIT is defined. So, $(tool-archpref) is
    empty. As a result, "-linux -linux-gnu- -unknown-linux-gnu" is passed
    into cc-cross-prefix. The command 'which' assumes arguments starting
    with a hyphen as command options, then emits the following messages:

    Illegal option -l
    Illegal option -l
    Illegal option -u

    I think it is strange to define CROSS_COMPILE depending on the CONFIG
    options since you need to feed $(CC) to Kconfig, but it is how MIPS
    Makefile currently works. Anyway, it would not hurt to filter-out
    invalid strings beforehand.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

28 Jan, 2019

1 commit

  • In Kbuild, if_changed and friends must have FORCE as a prerequisite.

    Hence, $(filter-out FORCE,$^) or $(filter-out $(PHONY),$^) is a common
    idiom to get the names of all the prerequisites except phony targets.

    Add real-prereqs as a shorthand.

    Note:
    We cannot replace $(filter %.o,$^) in cmd_link_multi-m because $^ may
    include auto-generated dependencies from the .*.cmd file when a single
    object module is changed into a multi object module. Refer to commit
    69ea912fda74 ("kbuild: remove unneeded link_multi_deps"). I added some
    comment to avoid accidental breakage.

    Signed-off-by: Masahiro Yamada
    Acked-by: Rob Herring

    Masahiro Yamada
     

14 Jan, 2019

1 commit


06 Jan, 2019

2 commits


30 Dec, 2018

1 commit

  • Pull Kbuild updates from Masahiro Yamada:
    "Kbuild core:
    - remove unneeded $(call cc-option,...) switches
    - consolidate Clang compiler flags into CLANG_FLAGS
    - announce the deprecation of SUBDIRS
    - fix single target build for external module
    - simplify the dependencies of 'prepare' stage targets
    - allow fixdep to directly write to .*.cmd files
    - simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS
    - change if_changed_rule to accept multi-line recipe
    - move .SECONDARY special target to scripts/Kbuild.include
    - remove redundant 'set -e'
    - improve parallel execution for CONFIG_HEADERS_CHECK
    - misc cleanups

    Treewide fixes and cleanups
    - set Clang flags correctly for PowerPC boot images
    - fix UML build error with CONFIG_GCC_PLUGINS
    - remove unneeded patterns from .gitignore files
    - refactor firmware/Makefile
    - remove unneeded rules for *offsets.s
    - avoid unneeded regeneration of intermediate .s files
    - clean up ./Kbuild

    Modpost:
    - remove unused -M, -K options
    - fix false positive warnings about section mismatch
    - use simple devtable lookup instead of linker magic
    - misc cleanups

    Coccinelle:
    - relax boolinit.cocci checks for overall consistency
    - fix warning messages of boolinit.cocci

    Other tools:
    - improve -dirty check of scripts/setlocalversion
    - add a tool to generate compile_commands.json from .*.cmd files"

    * tag 'kbuild-v4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (51 commits)
    kbuild: remove unused cmd_gentimeconst
    kbuild: remove $(obj)/ prefixes in ./Kbuild
    treewide: add intermediate .s files to targets
    treewide: remove explicit rules for *offsets.s
    firmware: refactor firmware/Makefile
    firmware: remove unnecessary patterns from .gitignore
    scripts: remove unnecessary ihex2fw and check-lc_ctypes from .gitignore
    um: remove unused filechk_gen_header in Makefile
    scripts: add a tool to produce a compile_commands.json file
    kbuild: add -Werror=implicit-int flag unconditionally
    kbuild: add -Werror=strict-prototypes flag unconditionally
    kbuild: add -fno-PIE flag unconditionally
    scripts: coccinelle: Correct warning message
    scripts: coccinelle: only suggest true/false in files that already use them
    kbuild: handle part-of-module correctly for *.ll and *.symtypes
    kbuild: refactor part-of-module
    kbuild: refactor quiet_modtag
    kbuild: remove redundant quiet_modtag for $(obj-m)
    kbuild: refactor Makefile.asm-generic
    user/Makefile: Fix typo and capitalization in comment section
    ...

    Linus Torvalds
     

19 Dec, 2018

1 commit

  • …k around asm() related GCC inlining bugs"

    This reverts commit 77b0bf55bc675233d22cd5df97605d516d64525e.

    See this commit for details about the revert:

    e769742d3584 ("Revert "x86/jump-labels: Macrofy inline assembly code to work around GCC inlining bugs"")

    Conflicts:
    arch/x86/Makefile

    Reported-by: Masahiro Yamada <yamada.masahiro@socionext.com>
    Reviewed-by: Borislav Petkov <bp@alien8.de>
    Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
    Cc: Juergen Gross <jgross@suse.com>
    Cc: Richard Biener <rguenther@suse.de>
    Cc: Kees Cook <keescook@chromium.org>
    Cc: Segher Boessenkool <segher@kernel.crashing.org>
    Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Josh Poimboeuf <jpoimboe@redhat.com>
    Cc: Nadav Amit <namit@vmware.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Ingo Molnar <mingo@kernel.org>

    Ingo Molnar
     

02 Dec, 2018

1 commit

  • In commit 54a702f70589 ("kbuild: mark $(targets) as .SECONDARY and
    remove .PRECIOUS markers"), I missed one important feature of the
    .SECONDARY target:

    .SECONDARY with no prerequisites causes all targets to be
    treated as secondary.

    ... which agrees with the policy of Kbuild.

    Let's move it to scripts/Kbuild.include, with no prerequisites.

    Note:
    If an intermediate file is generated by $(call if_changed,...), you
    still need to add it to "targets" so its .*.cmd file is included.

    The arm/arm64 crypto files are generated by $(call cmd,shipped),
    so they do not need to be added to "targets", but need to be added
    to "clean-files" so "make clean" can properly clean them away.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

01 Dec, 2018

5 commits

  • '@set -e; $(echo-cmd) $(cmd_$(1)' can be replaced with '$(cmd)'.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     
  • With the change of rule_cc_o_c / rule_as_o_S in the last commit, each
    command is executed in a separate subshell. Rip off unneeded semicolons.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     
  • The 'define' ... 'endef' directive is useful to confine a series of
    shell commands into a single macro:

    define foo
    [action1]
    [action2]
    [action3]
    endif

    Each action is executed in a separate subshell.

    However, rule_cc_o_c and rule_as_o_S in scripts/Makefile.build are
    written as follows (with a trailing semicolon in each cmd_*):

    define rule_cc_o_c
    [action1] ; \
    [action2] ; \
    [action3] ;
    endef

    All shell commands are concatenated with '; \' so that it looks like
    a single command from the Makefile point of view. This does not
    exploit the benefits of 'define' ... 'endef' form because a single
    shell command can be more simply written, like this:

    rule_cc_o_c = \
    [action1] ; \
    [action2] ; \
    [action3] ;

    I guess the intention for the command concatenation was to let the
    '@set -e' in if_changed_rule cover all the commands.

    We can improve the readability by moving '@set -e' to the 'cmd' macro.
    The combo of $(call echo-cmd,*) $(cmd_*) in rule_cc_o_c and rule_as_o_S
    have been replaced with $(call cmd,*). The trailing back-slashes have
    been removed.

    Here is a note about the performance: the commands in rule_cc_o_c and
    rule_as_o_S were previously executed all together in a single subshell,
    but now each line in a separate subshell. This means Make will spawn
    extra subshells [1]. I measured the build performance for
    x86_64_defconfig + CONFIG_MODVERSIONS + CONFIG_TRIM_UNUSED_KSYMS
    and I saw slight performance regression, but I believe code readability
    and maintainability wins.

    [1] Precisely, GNU Make may optimize this by executing the command
    directly instead of forking a subshell, if no shell special
    characters are found in the command line and omitting the subshell
    will not change the behavior.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     
  • My main motivation of this commit is to clean up scripts/Kbuild.include
    and scripts/Makefile.build.

    Currently, CONFIG_TRIM_UNUSED_KSYMS works with a tricky gimmick;
    possibly exported symbols are detected by letting $(CPP) replace
    EXPORT_SYMBOL* with a special string '=== __KSYM_*===', which is
    post-processed by sed, and passed to fixdep. The extra preprocessing
    is costly, and hacking cmd_and_fixdep is ugly.

    I came up with a new way to find exported symbols; insert a dummy
    symbol __ksym_marker_* to each potentially exported symbol. Those
    dummy symbols are picked up by $(NM), post-processed by sed, then
    appended to .*.cmd files. I collected the post-process part to a
    new shell script scripts/gen_ksymdeps.sh for readability. The dummy
    symbols are put into the .discard.* section so that the linker
    script rips them off the final vmlinux or modules.

    A nice side-effect is building with CONFIG_TRIM_UNUSED_KSYMS will
    be much faster.

    Signed-off-by: Masahiro Yamada
    Reviewed-by: Nicolas Pitre

    Masahiro Yamada
     
  • Currently, fixdep writes dependencies to .*.tmp, which is renamed to
    .*.cmd after everything succeeds. This is a very safe way to avoid
    corrupted .*.cmd files. The if_changed_dep has carried this safety
    mechanism since it was added in 2002.

    If fixdep fails for some reasons or a user terminates the build while
    fixdep is running, the incomplete output from the fixdep could be
    troublesome.

    This is my insight about some bad scenarios:

    [1] If the compiler succeeds to generate *.o file, but fixdep fails
    to write necessary dependencies to .*.cmd file, Make will miss
    to rebuild the object when headers or CONFIG options are changed.
    In this case, fixdep should not generate .*.cmd file at all so
    that 'arg-check' will surely trigger the rebuild of the object.

    [2] A partially constructed .*.cmd file may not be a syntactically
    correct makefile. The next time Make runs, it would include it,
    then fail to parse it. Once this happens, 'make clean' is be the
    only way to fix it.

    In fact, [1] is no longer a problem since commit 9c2af1c7377a ("kbuild:
    add .DELETE_ON_ERROR special target"). Make deletes a target file on
    any failure in its recipe. Because fixdep is a part of the recipe of
    *.o target, if it fails, the *.o is deleted anyway. However, I am a
    bit worried about the slight possibility of [2].

    So, here is a solution. Let fixdep directly write to a .*.cmd file,
    but allow makefiles to include it only when its corresponding target
    exists.

    This effectively reverts commit 2982c953570b ("kbuild: remove redundant
    $(wildcard ...) for cmd_files calculation"), and commit 00d78ab2ba75
    ("kbuild: remove dead code in cmd_files calculation in top Makefile")
    because now we must check the presence of targets.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

02 Nov, 2018

1 commit

  • There is one more user of $(cc-name) in the top Makefile. It is supposed
    to detect Clang before invoking Kconfig, so it should still be there
    in the $(shell ...) form. All the other users of $(cc-name) have been
    replaced with $(CONFIG_CC_IS_CLANG). Hence, scripts/Kbuild.include does
    not need to define cc-name any more.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

01 Nov, 2018

1 commit


29 Oct, 2018

1 commit

  • Pull Kbuild updates from Masahiro Yamada:

    - optimize kallsyms slightly

    - remove check for old CFLAGS usage

    - add some compiler flags unconditionally instead of evaluating
    $(call cc-option,...)

    - fix variable shadowing in host tools

    - refactor scripts/mkmakefile

    - refactor various makefiles

    * tag 'kbuild-v4.20' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild:
    modpost: Create macro to avoid variable shadowing
    ASN.1: Remove unnecessary shadowed local variable
    kbuild: use 'else ifeq' for checksrc to improve readability
    kbuild: remove unneeded link_multi_deps
    kbuild: add -Wno-unused-but-set-variable flag unconditionally
    kbuild: add -Wdeclaration-after-statement flag unconditionally
    kbuild: add -Wno-pointer-sign flag unconditionally
    modpost: remove leftover symbol prefix handling for module device table
    kbuild: simplify command line creation in scripts/mkmakefile
    kbuild: do not pass $(objtree) to scripts/mkmakefile
    kbuild: remove user ID check in scripts/mkmakefile
    kbuild: remove VERSION and PATCHLEVEL from $(objtree)/Makefile
    kbuild: add --include-dir flag only for out-of-tree build
    kbuild: remove dead code in cmd_files calculation in top Makefile
    kbuild: hide most of targets when running config or mixed targets
    kbuild: remove old check for CFLAGS use
    kbuild: prefix Makefile.dtbinst path with $(srctree) unconditionally
    kallsyms: remove left-over Blackfin code
    kallsyms: reduce size a little on 64-bit

    Linus Torvalds