1. 17 6月, 2020 1 次提交
    • M
      kbuild: improve cc-option to clean up all temporary files · f2f02ebd
      Masahiro Yamada 提交于
      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 .<pid>.tmp, here <pid> 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 .<pid>.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_<pid>/tmp, and
      removes .tmp_<pid> 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
      <base-name-of-object>.gcno
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      f2f02ebd
  2. 12 5月, 2020 1 次提交
    • M
      kbuild: use -MMD instead of -MD to exclude system headers from dependency · 30a77297
      Masahiro Yamada 提交于
      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 <stdarg.h>. 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 <stdarg.h>
      is included from every file. So, I implemented a more reliable way in
      the previous commit.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      30a77297
  3. 15 1月, 2020 1 次提交
    • M
      kbuild: remove *.tmp file when filechk fails · 88fe89a4
      Masahiro Yamada 提交于
      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 <file>..." 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: NBartosz Golaszewski <bgolaszewski@baylibre.com>
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      88fe89a4
  4. 07 1月, 2020 2 次提交
    • M
      kbuild: create modules.builtin without Makefile.modbuiltin or tristate.conf · 8b41fc44
      Masahiro Yamada 提交于
      Commit bc081dd6 ("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 <linux/module.h>. 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: NMasahiro Yamada <masahiroy@kernel.org>
      8b41fc44
    • M
      kbuild: add stringify helper to quote a string passed to C files · 7e826c44
      Masahiro Yamada 提交于
      Make $(squote)$(quote)...$(quote)$(squote) a helper macro.
      I will reuse it in the next commit.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      7e826c44
  5. 11 11月, 2019 2 次提交
    • M
      kbuild: rename any-prereq to newer-prereqs · eba19032
      Masahiro Yamada 提交于
      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: NMasahiro Yamada <yamada.masahiro@socionext.com>
      eba19032
    • M
      kbuild: drop $(wildcard $^) check in if_changed* for faster rebuild · 2d3b1b8f
      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 <kai@tp1.ruhr-uni-bochum.de>
      | 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 <file> ...")
      |
      |     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 <file> ..." 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 4f193362 ("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 8e9b61b2 ("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 8e9b61b2 ("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: NMasahiro Yamada <yamada.masahiro@socionext.com>
      2d3b1b8f
  6. 01 10月, 2019 1 次提交
  7. 27 7月, 2019 1 次提交
  8. 17 7月, 2019 1 次提交
  9. 11 7月, 2019 1 次提交
    • M
      kbuild: use -- separater intead of $(filter-out ...) for cc-cross-prefix · d4a74bbf
      Masahiro Yamada 提交于
      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 913ab978 ("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: NMasahiro Yamada <yamada.masahiro@socionext.com>
      d4a74bbf
  10. 01 7月, 2019 3 次提交
    • M
      kbuild: save $(strip ...) for calling if_changed and friends · c2341e2a
      Masahiro Yamada 提交于
      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: NMasahiro Yamada <yamada.masahiro@socionext.com>
      c2341e2a
    • M
      kbuild: save $(strip ...) for calling any-prepreq · 93f31bbd
      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: NMasahiro Yamada <yamada.masahiro@socionext.com>
      93f31bbd
    • M
      kbuild: rename arg-check to cmd-check · 50bcca6a
      Masahiro Yamada 提交于
      I prefer 'cmd-check' for consistency.
      
      We have 'echo-cmd', 'cmd', 'cmd_and_fixdep', etc. in this file.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      50bcca6a
  11. 15 6月, 2019 2 次提交
  12. 07 6月, 2019 1 次提交
    • M
      kbuild: use more portable 'command -v' for cc-cross-prefix · 913ab978
      Masahiro Yamada 提交于
      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 bd55f96f ("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 <psmith@gnu.org>
      | 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 <nbowler@draconx.ca>.
      
      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: bd55f96f ("kbuild: refactor cc-cross-prefix implementation")
      Cc: linux-stable <stable@vger.kernel.org> # 5.1
      Reported-by: NAlexey Brodkin <abrodkin@synopsys.com>
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      Tested-by: NAlexey Brodkin <abrodkin@synopsys.com>
      913ab978
  13. 31 5月, 2019 1 次提交
  14. 20 5月, 2019 1 次提交
  15. 18 5月, 2019 1 次提交
  16. 04 3月, 2019 1 次提交
    • M
      kbuild: remove cc-version macro · d3a918c6
      Masahiro Yamada 提交于
      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 <major><minor>, while CONFIG_GCC_VERSION
      <major><minor><patch>. I adjusted cc-ifversion for the difference of
      the number of digits.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      d3a918c6
  17. 27 2月, 2019 1 次提交
    • M
      kbuild: refactor cc-cross-prefix implementation · bd55f96f
      Masahiro Yamada 提交于
      - $(word 1, <text>) is equivalent to $(firstword <text>)
      
       - 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: NMasahiro Yamada <yamada.masahiro@socionext.com>
      bd55f96f
  18. 28 1月, 2019 1 次提交
    • M
      kbuild: add real-prereqs shorthand for $(filter-out FORCE,$^) · afa974b7
      Masahiro Yamada 提交于
      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
      69ea912f ("kbuild: remove unneeded link_multi_deps"). I added some
      comment to avoid accidental breakage.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      Acked-by: NRob Herring <robh@kernel.org>
      afa974b7
  19. 14 1月, 2019 1 次提交
  20. 06 1月, 2019 2 次提交
  21. 19 12月, 2018 1 次提交
  22. 02 12月, 2018 1 次提交
    • M
      kbuild: move .SECONDARY special target to Kbuild.include · 8e9b61b2
      Masahiro Yamada 提交于
      In commit 54a702f7 ("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: NMasahiro Yamada <yamada.masahiro@socionext.com>
      8e9b61b2
  23. 01 12月, 2018 5 次提交
    • M
      kbuild: refactor if_changed · 67126965
      Masahiro Yamada 提交于
      '@set -e; $(echo-cmd) $(cmd_$(1)' can be replaced with '$(cmd)'.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      67126965
    • M
      kbuild: remove trailing semicolon from cmd_* passed to if_changed_rule · e5d28910
      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: NMasahiro Yamada <yamada.masahiro@socionext.com>
      e5d28910
    • M
      kbuild: change if_changed_rule for multi-line recipe · 3a2429e1
      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: NMasahiro Yamada <yamada.masahiro@socionext.com>
      3a2429e1
    • M
      kbuild: simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS · bbda5ec6
      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: NMasahiro Yamada <yamada.masahiro@socionext.com>
      Reviewed-by: NNicolas Pitre <nico@linaro.org>
      bbda5ec6
    • M
      kbuild: let fixdep directly write to .*.cmd files · 392885ee
      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 9c2af1c7 ("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 2982c953 ("kbuild: remove redundant
      $(wildcard ...) for cmd_files calculation"), and commit 00d78ab2
      ("kbuild: remove dead code in cmd_files calculation in top Makefile")
      because now we must check the presence of targets.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      392885ee
  24. 02 11月, 2018 1 次提交
    • M
      kbuild: remove cc-name variable · 99516742
      Masahiro Yamada 提交于
      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: NMasahiro Yamada <yamada.masahiro@socionext.com>
      99516742
  25. 01 11月, 2018 1 次提交
  26. 04 10月, 2018 1 次提交
    • N
      kbuild/Makefile: Prepare for using macros in inline assembly code to work... · 77b0bf55
      Nadav Amit 提交于
      kbuild/Makefile: Prepare for using macros in inline assembly code to work around asm() related GCC inlining bugs
      
      Using macros in inline assembly allows us to work around bugs
      in GCC's inlining decisions.
      
      Compile macros.S and use it to assemble all C files.
      Currently only x86 will use it.
      
      Background:
      
      The inlining pass of GCC doesn't include an assembler, so it's not aware
      of basic properties of the generated code, such as its size in bytes,
      or that there are such things as discontiuous blocks of code and data
      due to the newfangled linker feature called 'sections' ...
      
      Instead GCC uses a lazy and fragile heuristic: it does a linear count of
      certain syntactic and whitespace elements in inlined assembly block source
      code, such as a count of new-lines and semicolons (!), as a poor substitute
      for "code size and complexity".
      
      Unsurprisingly this heuristic falls over and breaks its neck whith certain
      common types of kernel code that use inline assembly, such as the frequent
      practice of putting useful information into alternative sections.
      
      As a result of this fresh, 20+ years old GCC bug, GCC's inlining decisions
      are effectively disabled for inlined functions that make use of such asm()
      blocks, because GCC thinks those sections of code are "large" - when in
      reality they are often result in just a very low number of machine
      instructions.
      
      This absolute lack of inlining provess when GCC comes across such asm()
      blocks both increases generated kernel code size and causes performance
      overhead, which is particularly noticeable on paravirt kernels, which make
      frequent use of these inlining facilities in attempt to stay out of the
      way when running on baremetal hardware.
      
      Instead of fixing the compiler we use a workaround: we set an assembly macro
      and call it from the inlined assembly block. As a result GCC considers the
      inline assembly block as a single instruction. (Which it often isn't but I digress.)
      
      This uglifies and bloats the source code - for example just the refcount
      related changes have this impact:
      
       Makefile                 |    9 +++++++--
       arch/x86/Makefile        |    7 +++++++
       arch/x86/kernel/macros.S |    7 +++++++
       scripts/Kbuild.include   |    4 +++-
       scripts/mod/Makefile     |    2 ++
       5 files changed, 26 insertions(+), 3 deletions(-)
      
      Yay readability and maintainability, it's not like assembly code is hard to read
      and maintain ...
      
      We also hope that GCC will eventually get fixed, but we are not holding
      our breath for that. Yet we are optimistic, it might still happen, any decade now.
      
      [ mingo: Wrote new changelog describing the background. ]
      Tested-by: NKees Cook <keescook@chromium.org>
      Signed-off-by: NNadav Amit <namit@vmware.com>
      Acked-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      Acked-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Brian Gerst <brgerst@gmail.com>
      Cc: Denys Vlasenko <dvlasenk@redhat.com>
      Cc: H. Peter Anvin <hpa@zytor.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Michal Marek <michal.lkml@markovi.net>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Sam Ravnborg <sam@ravnborg.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-kbuild@vger.kernel.org
      Link: http://lkml.kernel.org/r/20181003213100.189959-3-namit@vmware.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
      77b0bf55
  27. 12 9月, 2018 1 次提交
  28. 30 8月, 2018 1 次提交
  29. 24 8月, 2018 1 次提交
  30. 28 7月, 2018 1 次提交