1. 22 8月, 2019 2 次提交
  2. 21 8月, 2019 1 次提交
    • M
      kbuild: make single targets work more correctly · 394053f4
      Masahiro Yamada 提交于
      Currently, the single target build directly descends into the directory
      of the target. For example,
      
        $ make foo/bar/baz.o
      
      ... directly descends into foo/bar/.
      
      On the other hand, the normal build usually descends one directory at
      a time, i.e. descends into foo/, and then foo/bar/.
      
      This difference causes some problems.
      
      [1] miss subdir-asflags-y, subdir-ccflags-y in upper Makefiles
      
          The options in subdir-{as,cc}flags-y take effect in the current
          and its sub-directories. In other words, they are inherited
          downward. In the example above, the single target will miss
          subdir-{as,cc}flags-y if they are defined in foo/Makefile.
      
      [2] could be built in a different directory
      
          As Documentation/kbuild/modules.rst section 4.3 says, Kbuild can
          handle files that are spread over several sub-directories.
      
          The build rule of foo/bar/baz.o may not necessarily be specified in
          foo/bar/Makefile. It might be specifies in foo/Makefile as follows:
      
          [foo/Makefile]
          obj-y := bar/baz.o
      
          This often happens when a module is so big that its source files
          are divided into sub-directories.
      
          In this case, there is no Makefile in the foo/bar/ directory, yet
          the single target descends into foo/bar/, then fails due to the
          missing Makefile. You can still do 'make foo/bar/' for partial
          building, but cannot do 'make foo/bar/baz.s'. I believe the single
          target '%.s' is a useful feature for inspecting the compiler output.
      
          Some modules work around this issue by putting an empty Makefile
          in every sub-directory.
      
      This commit fixes those problems by making the single target build
      descend in the same way as the normal build does.
      
      Another change is the single target build will observe the CONFIG
      options. Previously, it allowed users to build the foo.o even when
      the corresponding CONFIG_FOO is disabled:
      
         obj-$(CONFIG_FOO) += foo.o
      
      In the new behavior, the single target build will just fail and show
      "No rule to make target ..." (or "Nothing to be done for ..." if the
      stale object already exists, but cannot be updated).
      
      The disadvantage of this commit is the build speed. Now that the
      single target build visits every directory and parses lots of
      Makefiles, it is slower than before. (But, I hope it will not be
      too slow.)
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      394053f4
  3. 15 8月, 2019 2 次提交
  4. 14 8月, 2019 1 次提交
    • M
      kbuild: use $(basename ...) for cmd_asn1_compiler · 49d5089d
      Masahiro Yamada 提交于
      $(basename ...) trims the last suffix. Using it is more intuitive in
      my opinion.
      
      This pattern rule makes %.asn1.c and %.asn1.h at the same time.
      Previously, the short log showed only either of them, depending on
      the target file in question.
      
      To clarify that two files are being generated by the single recipe,
      I changed the log as follows:
      
      Before:
      
        ASN.1   crypto/asymmetric_keys/x509.asn1.c
      
      After:
      
        ASN.1   crypto/asymmetric_keys/x509.asn1.[ch]
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      49d5089d
  5. 10 8月, 2019 3 次提交
    • M
      kbuild: show hint if subdir-y/m is used to visit module Makefile · c07d8d47
      Masahiro Yamada 提交于
      Since commit ff9b45c5 ("kbuild: modpost: read modules.order instead
      of $(MODVERDIR)/*.mod"), a module is no longer built in the following
      pattern:
      
        [Makefile]
        subdir-y := some-module
      
        [some-module/Makefile]
        obj-m := some-module.o
      
      You cannot write Makefile this way in upstream because modules.order is
      not correctly generated. subdir-y is used to descend to a sub-directory
      that builds tools, device trees, etc.
      
      For external modules, the modules order does not matter. So, the
      Makefile above was known to work.
      
      I believe the Makefile should be re-written as follows:
      
        [Makefile]
        obj-m := some-module/
      
        [some-module/Makefile]
        obj-m := some-module.o
      
      However, people will have no idea if their Makefile suddenly stops
      working. In fact, I received questions from multiple people.
      
      Show a warning for a while if obj-m is specified in a Makefile visited
      by subdir-y or subdir-m.
      
      I touched the %/ rule to avoid false-positive warnings for the single
      target.
      
      Cc: Jan Kiszka <jan.kiszka@siemens.com>
      Cc: Tom Stonecypher <thomas.edwardx.stonecypher@intel.com>
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      Tested-by: NJan Kiszka <jan.kiszka@siemens.com>
      c07d8d47
    • M
      kbuild: generate modules.order only in directories visited by obj-y/m · 4f2c8f30
      Masahiro Yamada 提交于
      The modules.order files in directories visited by the chain of obj-y
      or obj-m are merged to the upper-level ones, and become parts of the
      top-level modules.order. On the other hand, there is no need to
      generate modules.order in directories visited by subdir-y or subdir-m
      since they would become orphan anyway.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      4f2c8f30
    • M
      kbuild: fix false-positive need-builtin calculation · d9f78edf
      Masahiro Yamada 提交于
      The current implementation of need-builtin is false-positive,
      for example, in the following Makefile:
      
        obj-m := foo/
        obj-y := foo/bar/
      
      ..., where foo/built-in.a is not required.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      d9f78edf
  6. 18 7月, 2019 3 次提交
    • M
      kbuild: split out *.mod out of {single,multi}-used-m rules · 9f69a496
      Masahiro Yamada 提交于
      Currently, *.mod is created as a side-effect of obj-m.
      
      Split out *.mod as a dedicated build rule, which allows to unify
      the %.c -> %.o rule, and remove the single-used-m rule.
      
      This also makes the incremental build of allmodconfig faster because
      it saves $(NM) invocation when there is no change in the module.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      9f69a496
    • M
      kbuild: remove the first line of *.mod files · 60ae1b19
      Masahiro Yamada 提交于
      The current format of *.mod is like this:
      
        line 1: directory path to the .ko file
        line 2: a list of objects linked into this module
        line 3: unresolved symbols (only when CONFIG_TRIM_UNUSED_KSYMS=y)
      
      Now that *.mod and *.ko are created in the same directory, the line 1
      provides no valuable information. It can be derived by replacing the
      extension .mod with .ko. In fact, nobody uses the first line any more.
      
      Cut down the first line.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      60ae1b19
    • M
      kbuild: create *.mod with full directory path and remove MODVERDIR · b7dca6dd
      Masahiro Yamada 提交于
      While descending directories, Kbuild produces objects for modules,
      but do not link final *.ko files; it is done in the modpost.
      
      To keep track of modules, Kbuild creates a *.mod file in $(MODVERDIR)
      for every module it is building. Some post-processing steps read the
      necessary information from *.mod files. This avoids descending into
      directories again. This mechanism was introduced in 2003 or so.
      
      Later, commit 551559e1 ("kbuild: implement modules.order") added
      modules.order. So, we can simply read it out to know all the modules
      with directory paths. This is easier than parsing the first line of
      *.mod files.
      
      $(MODVERDIR) has a flat directory structure, that is, *.mod files
      are named only with base names. This is based on the assumption that
      the module name is unique across the tree. This assumption is really
      fragile.
      
      Stephen Rothwell reported a race condition caused by a module name
      conflict:
      
        https://lkml.org/lkml/2019/5/13/991
      
      In parallel building, two different threads could write to the same
      $(MODVERDIR)/*.mod simultaneously.
      
      Non-unique module names are the source of all kind of troubles, hence
      commit 3a48a919 ("kbuild: check uniqueness of module names")
      introduced a new checker script.
      
      However, it is still fragile in the build system point of view because
      this race happens before scripts/modules-check.sh is invoked. If it
      happens again, the modpost will emit unclear error messages.
      
      To fix this issue completely, create *.mod with full directory path
      so that two threads never attempt to write to the same file.
      
      $(MODVERDIR) is no longer needed.
      
      Since modules with directory paths are listed in modules.order, Kbuild
      is still able to find *.mod files without additional descending.
      
      I also killed cmd_secanalysis; scripts/mod/sumversion.c computes MD4 hash
      for modules with MODULE_VERSION(). When CONFIG_DEBUG_SECTION_MISMATCH=y,
      it occurs not only in the modpost stage, but also during directory
      descending, where sumversion.c may parse stale *.mod files. It would emit
      'No such file or directory' warning when an object consisting a module is
      renamed, or when a single-obj module is turned into a multi-obj module or
      vice versa.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      Acked-by: NNicolas Pitre <nico@fluxnic.net>
      b7dca6dd
  7. 17 7月, 2019 4 次提交
    • M
      kbuild: remove duplication from modules.order in sub-directories · e0e1b1ec
      Masahiro Yamada 提交于
      Currently, only the top-level modules.order drops duplicated entries.
      
      The modules.order files in sub-directories potentially contain
      duplication. To list out the paths of all modules, I want to use
      modules.order instead of parsing *.mod files in $(MODVERDIR).
      
      To achieve this, I want to rip off duplication from modules.order
      of external modules too.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      e0e1b1ec
    • M
      kbuild: get rid of kernel/ prefix from in-tree modules.{order,builtin} · 1bd9a468
      Masahiro Yamada 提交于
      Removing the 'kernel/' prefix will make our life easier because we can
      simply do 'cat modules.order' to get all built modules with full paths.
      
      Currently, we parse the first line of '*.mod' files in $(MODVERDIR).
      Since we have duplicated functionality here, I plan to remove MODVERDIR
      entirely.
      
      In fact, modules.order is generated also for external modules in a
      broken format. It adds the 'kernel/' prefix to the absolute path of
      the module, like this:
      
        kernel//path/to/your/external/module/foo.ko
      
      This is fine for now since modules.order is not used for external
      modules. However, I want to sanitize the format everywhere towards
      the goal of removing MODVERDIR.
      
      We cannot change the format of installed module.{order,builtin}.
      So, 'make modules_install' will add the 'kernel/' prefix while copying
      them to $(MODLIB)/.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      1bd9a468
    • M
      kbuild: do not create empty modules.order in the prepare stage · 7e131918
      Masahiro Yamada 提交于
      Currently, $(objtree)/modules.order is touched in two places.
      
      In the 'prepare0' rule, scripts/Makefile.build creates an empty
      modules.order while processing 'obj=.'
      
      In the 'modules' rule, the top-level Makefile overwrites it with
      the correct list of modules.
      
      While this might be a good side-effect that modules.order is made
      empty every time (probably this is not intended functionality),
      I personally do not like this behavior.
      
      Create modules.order only when it is sensible to do so.
      
      This avoids creating the following pointless files:
      
        scripts/basic/modules.order
        scripts/dtc/modules.order
        scripts/gcc-plugins/modules.order
        scripts/genksyms/modules.order
        scripts/mod/modules.order
        scripts/modules.order
        scripts/selinux/genheaders/modules.order
        scripts/selinux/mdp/modules.order
        scripts/selinux/modules.order
      
      Going forward, $(objtree)/modules.order lists the modules that
      was built in the last successful build.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      7e131918
    • M
      kbuild: compile-test headers listed in header-test-m as well · 4bd01de8
      Masahiro Yamada 提交于
      It will be useful to control the header-test by a tristate option.
      
      If CONFIG_FOO is a tristate option, you can write like this:
      
        header-test-$(CONFIG_FOO) += foo.h
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      4bd01de8
  8. 10 7月, 2019 1 次提交
  9. 09 7月, 2019 1 次提交
    • M
      kbuild: do not create wrappers for header-test-y · c93a0368
      Masahiro Yamada 提交于
      header-test-y does not work with headers in sub-directories.
      
      For example, you may want to write a Makefile, like this:
      
      include/linux/Kbuild:
      
        header-test-y += mtd/nand.h
      
      This entry will create a wrapper include/linux/mtd/nand.hdrtest.c
      with the following content:
      
        #include "mtd/nand.h"
      
      To make this work, we need to add $(srctree)/include/linux to the
      header search path. It would be tedious to add ccflags-y.
      
      Instead, we could change the *.hdrtest.c rule to wrap:
      
        #include "nand.h"
      
      This works for in-tree build since #include "..." searches in the
      relative path from the header with this directive. For O=... build,
      we need to add $(srctree)/include/linux/mtd to the header search path,
      which will be even more tedious.
      
      After all, I thought it would be handier to compile headers directly
      without creating wrappers.
      
      I added a new build rule to compile %.h into %.h.s
      
      The target is %.h.s instead of %.h.o because it is slightly faster.
      Also, as for GCC, an empty assembly is smaller than an empty object.
      
      I wrote the build rule:
      
        $(CC) $(c_flags) -S -o $@ -x c /dev/null -include $<
      
      instead of:
      
        $(CC) $(c_flags) -S -o $@ -x c $<
      
      Both work fine with GCC, but the latter is bad for Clang.
      
      This comes down to the difference in the -Wunused-function policy.
      GCC does not warn about unused 'static inline' functions at all.
      Clang does not warn about the ones in included headers, but does
      about the ones in the source. So, we should handle headers as
      headers, not as source files.
      
      In fact, this has been hidden since commit abb2ea7d ("compiler,
      clang: suppress warning for unused static inline functions"), but we
      should not rely on that.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      Acked-by: NJani Nikula <jani.nikula@intel.com>
      Tested-by: NJani Nikula <jani.nikula@intel.com>
      c93a0368
  10. 15 6月, 2019 1 次提交
  11. 03 4月, 2019 1 次提交
    • P
      objtool: Add UACCESS validation · ea24213d
      Peter Zijlstra 提交于
      It is important that UACCESS regions are as small as possible;
      furthermore the UACCESS state is not scheduled, so doing anything that
      might directly call into the scheduler will cause random code to be
      ran with UACCESS enabled.
      
      Teach objtool too track UACCESS state and warn about any CALL made
      while UACCESS is enabled. This very much includes the __fentry__()
      and __preempt_schedule() calls.
      
      Note that exceptions _do_ save/restore the UACCESS state, and therefore
      they can drive preemption. This also means that all exception handlers
      must have an otherwise redundant UACCESS disable instruction;
      therefore ignore this warning for !STT_FUNC code (exception handlers
      are not normal functions).
      Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Acked-by: NJosh Poimboeuf <jpoimboe@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: NIngo Molnar <mingo@kernel.org>
      ea24213d
  12. 02 4月, 2019 1 次提交
    • M
      kbuild: use $(srctree) instead of KBUILD_SRC to check out-of-tree build · a9a49c2a
      Masahiro Yamada 提交于
      KBUILD_SRC was conventionally used for some different purposes:
       [1] To remember the source tree path
       [2] As a flag to check if sub-make is already done
       [3] As a flag to check if Kbuild runs out of tree
      
      For [1], we do not need to remember it because the top Makefile
      can compute it by $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
      
      [2] has been replaced with self-commenting 'sub_make_done'.
      
      For [3], we can distinguish in-tree/out-of-tree by comparing
      $(srctree) and '.'
      
      This commit converts [3] to prepare for the KBUILD_SRC removal.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      a9a49c2a
  13. 28 3月, 2019 1 次提交
    • J
      kbuild: strip whitespace in cmd_record_mcount findstring · 1a49b2fd
      Joe Lawrence 提交于
      CC_FLAGS_FTRACE may contain trailing whitespace that interferes with
      findstring.
      
      For example, commit 6977f95e ("powerpc: avoid -mno-sched-epilog on
      GCC 4.9 and newer") introduced a change such that on my ppc64le box,
      CC_FLAGS_FTRACE="-pg -mprofile-kernel ".  (Note the trailing space.)
      When cmd_record_mcount is now invoked, findstring fails as the ftrace
      flags were found at very end of _c_flags, without the trailing space.
      
        _c_flags=" ... -pg -mprofile-kernel"
        CC_FLAGS_FTRACE="-pg -mprofile-kernel "
                                             ^
          findstring is looking for this extra space
      
      Remove the redundant whitespaces from CC_FLAGS_FTRACE in
      cmd_record_mcount to avoid this problem.
      
      [masahiro.yamada: This issue only happens in the released versions
      of GNU Make. CC_FLAGS_FTRACE will not contain the trailing space if
      you use the latest GNU Make, which contains commit b90fabc8d6f3
      ("* NEWS: Do not insert a space during '+=' if the value is empty.") ]
      
      Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com> (refactoring)
      Fixes: 6977f95e ("powerpc: avoid -mno-sched-epilog on GCC 4.9 and newer").
      Signed-off-by: NJoe Lawrence <joe.lawrence@redhat.com>
      Acked-by: NSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      1a49b2fd
  14. 14 3月, 2019 1 次提交
  15. 27 2月, 2019 1 次提交
    • M
      kbuild: hardcode genksyms path and remove GENKSYMS variable · 88110713
      Masahiro Yamada 提交于
      The genksyms source was integrated into the kernel tree in 2003.
      
      I do not expect anybody still using the external /sbin/genksyms.
      Kbuild does not need to provide the ability to override GENKSYMS.
      
      Let's remove the GENKSYMS variable, and use the hardcoded path.
      
      Since it occurred in the pre-git era, I attached the commit message
      in case somebody is interested in the historical background.
      
        | Author: Kai Germaschewski <kai@tp1.ruhr-uni-bochum.de>
        | Date:   Wed Feb 19 04:17:28 2003 -0600
        |
        | kbuild: [PATCH] put genksyms in scripts dir
        |
        | This puts genksyms into scripts/genksyms/.
        |
        | genksyms used to be maintained externally, though the only possible user
        | was the kernel build. Moving it into the kernel sources makes it easier to
        | keep it uptodate, like for example updating it to generate linker scripts
        | directly instead of postprocessing the generated header file fragments
        | with sed, as we do currently.
        |
        | Also, genksyms does not handle __typeof__, which needs to be fixed since
        | some of the exported symbol in the kernel are defined using __typeof__.
        |
        | (Rusty Russell/me)
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      88110713
  16. 20 2月, 2019 2 次提交
    • M
      kbuild: generate modules.order only when CONFIG_MODULES=y · 1d8001ef
      Masahiro Yamada 提交于
      Do not generate pointless modules.order when the module support is
      disabled.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      1d8001ef
    • M
      kbuild: Disable extra debugging info in .s output · 1e88e415
      Masahiro Yamada 提交于
      Modern gcc adds view assignments, reset assertion checking in .loc
      directives and a couple more additional debug markers, which clutters
      the asm output unnecessarily:
      
      For example:
      
        bsp_resume:
        .LFB3466:
                .loc 1 1868 1 is_stmt 1 view -0
                .cfi_startproc
                .loc 1 1869 2 view .LVU73
        # arch/x86/kernel/cpu/common.c:1869:    if (this_cpu->c_bsp_resume)
                .loc 1 1869 14 is_stmt 0 view .LVU74
                movq    this_cpu(%rip), %rax    # this_cpu, this_cpu
                movq    64(%rax), %rax  # this_cpu.94_1->c_bsp_resume, _2
        # arch/x86/kernel/cpu/common.c:1869:    if (this_cpu->c_bsp_resume)
                .loc 1 1869 5 view .LVU75
                testq   %rax, %rax      # _2
                je      .L8     #,
                .loc 1 1870 3 is_stmt 1 view .LVU76
                movq    $boot_cpu_data, %rdi    #,
                jmp     __x86_indirect_thunk_rax
      
      or
              .loc 2 57 9 view .LVU478
              .loc 2 57 9 view .LVU479
              .loc 2 57 9 view .LVU480
              .loc 2 57 9 view .LVU481
        .LBB1385:
        .LBB1383:
        .LBB1379:
        .LBB1377:
        .LBB1375:
              .loc 2 57 9 view .LVU482
              .loc 2 57 9 view .LVU483
              movl	%edi, %edx	# cpu, cpu
        .LVL87:
              .loc 2 57 9 is_stmt 0 view .LVU484
      
      That MOV in there is drowned in debugging information and latter makes
      it hard to follow the asm. And that DWARF info is not really needed for
      asm output staring.
      
      Disable the debug information generation which clutters the asm output
      unnecessarily:
      
        bsp_resume:
        # arch/x86/kernel/cpu/common.c:1869:    if (this_cpu->c_bsp_resume)
                movq    this_cpu(%rip), %rax    # this_cpu, this_cpu
                movq    64(%rax), %rax  # this_cpu.94_1->c_bsp_resume, _2
        # arch/x86/kernel/cpu/common.c:1869:    if (this_cpu->c_bsp_resume)
                testq   %rax, %rax      # _2
                je      .L8     #,
        # arch/x86/kernel/cpu/common.c:1870:            this_cpu->c_bsp_resume(&boot_cpu_data);
                movq    $boot_cpu_data, %rdi    #,
                jmp     __x86_indirect_thunk_rax
        .L8:
        # arch/x86/kernel/cpu/common.c:1871: }
                rep ret
                .size   bsp_resume, .-bsp_resume
      
        [ bp: write commit message. ]
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      Signed-off-by: NBorislav Petkov <bp@suse.de>
      1e88e415
  17. 28 1月, 2019 3 次提交
  18. 16 12月, 2018 4 次提交
  19. 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
  20. 01 12月, 2018 6 次提交
    • M
      kbuild: remove redundant 'set -e' from cmd_* defines · 5439f09f
      Masahiro Yamada 提交于
      These three cmd_* are invoked in the $(call cmd,*) form.
      
      Now that 'set -e' moved to the 'cmd' macro, they do not need to
      explicitly give 'set -e'.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      5439f09f
    • 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: refactor modversions build rules · ee3e46b7
      Masahiro Yamada 提交于
      Let $(CC) compile objects into normal files *.o instead of .tmp_*.o
      whether CONFIG_MODVERSIONS is enabled or not. With this, the input
      file for objtool is always *.o so objtool_o can go away.
      
      I guess the reason of using .tmp_*.o for intermediate objects was
      to avoid leaving incomplete *.o file (, whose timestamp says it is
      up-to-date) when the genksyms tool failed for some reasons.
      
      It no longer matters because any targets are deleted on errors since
      commit 9c2af1c7 ("kbuild: add .DELETE_ON_ERROR special target").
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      ee3e46b7
    • M
      kbuild: remove redundant 'set -e' from sub_cmd_record_mcount · 4317ee3b
      Masahiro Yamada 提交于
      This is executed inside the if_changed_rule, which already sets
      'set -e'.
      Signed-off-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      4317ee3b