1. 11 Jul, 2019 1 commit
    • Masahiro Yamada's avatar
      kbuild: use -- separater intead of $(filter-out ...) for cc-cross-prefix · d4a74bbf
      Masahiro Yamada authored
      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: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      d4a74bbf
  2. 10 Jul, 2019 5 commits
  3. 09 Jul, 2019 7 commits
    • Masahiro Yamada's avatar
      scripts/tags.sh: remove unused environment variables from comments · b3b3eb9d
      Masahiro Yamada authored
      This script has no reference to ${ARCH}, ${src}, ${obj}.
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      b3b3eb9d
    • Masahiro Yamada's avatar
      scripts/tags.sh: drop SUBARCH support for ARM · d1db881d
      Masahiro Yamada authored
      Our goal is to have more and more sub-architectures to join the
      ARM multi-platform, and support them in a single configuration.
      
      Remove the ARM SUBARCH support because it is ugly.
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      d1db881d
    • Masahiro Yamada's avatar
      kbuild: compile-test kernel headers to ensure they are self-contained · 43c78d88
      Masahiro Yamada authored
      The headers in include/ are globally used in the kernel source tree
      to provide common APIs. They are included from external modules, too.
      
      It will be useful to make as many headers self-contained as possible
      so that we do not have to rely on a specific include order.
      
      There are more than 4000 headers in include/. In my rough analysis,
      70% of them are already self-contained. With efforts, most of them
      can be self-contained.
      
      For now, we must exclude more than 1000 headers just because they
      cannot be compiled as standalone units. I added them to header-test-.
      The blacklist was mostly generated by a script, so the reason of the
      breakage should be checked later.
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Tested-by: default avatarJani Nikula <jani.nikula@intel.com>
      Reviewed-by: default avatarJoel Fernandes (Google) <joel@joelfernandes.org>
      43c78d88
    • Masahiro Yamada's avatar
      kheaders: include only headers into kheaders_data.tar.xz · 7199ff7d
      Masahiro Yamada authored
      Currently, kheaders_data.tar.xz contains some build scripts as well as
      headers. None of them is needed in the header archive.
      
      For ARCH=x86, this commit excludes the following from the archive:
      
        arch/x86/include/asm/Kbuild
        arch/x86/include/uapi/asm/Kbuild
        include/asm-generic/Kbuild
        include/config/auto.conf
        include/config/kernel.release
        include/config/tristate.conf
        include/uapi/asm-generic/Kbuild
        include/uapi/Kbuild
        kernel/gen_kheaders.sh
      
      This change is actually motivated for the planned header compile-testing
      because it will generate more build artifacts, which should not be
      included in the archive.
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Reviewed-by: default avatarJoel Fernandes (Google) <joel@joelfernandes.org>
      7199ff7d
    • Masahiro Yamada's avatar
      kheaders: remove meaningless -R option of 'ls' · b60b7c2e
      Masahiro Yamada authored
      The -R option of 'ls' is supposed to be used for directories.
      
         -R, --recursive
                list subdirectories recursively
      
      Since 'find ... -type f' only matches to regular files, we do not
      expect directories passed to the 'ls' command here.
      
      Giving -R is harmless at least, but unneeded.
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Reviewed-by: default avatarJoel Fernandes (Google) <joel@joelfernandes.org>
      b60b7c2e
    • Masahiro Yamada's avatar
      kbuild: support header-test-pattern-y · 1e21cbfa
      Masahiro Yamada authored
      In my view, most of headers can be self-contained. So, it would be
      tedious to add every header to header-test-y explicitly. We usually
      end up with "all headers with some exceptions".
      
      There are two types in exceptions:
      
      [1] headers that are never compiled as standalone units
      
        For examples, include/linux/compiler-gcc.h is not intended for
        direct inclusion. We should always exclude such ones.
      
      [2] headers that are conditionally compiled as standalone units
      
        Some headers can be compiled only for particular architectures.
        For example, include/linux/arm-cci.h can be compiled only for
        arm/arm64 because it requires <asm/arm-cci.h> to exist.
        Clang can compile include/soc/nps/mtm.h only for arc because
        it contains an arch-specific register in inline assembler.
      
      So, you can write Makefile like this:
      
        header-test-                += linux/compiler-gcc.h
        header-test-$(CONFIG_ARM)   += linux/arm-cci.h
        header-test-$(CONFIG_ARM64) += linux/arm-cci.h
        header-test-$(CONFIG_ARC)   += soc/nps/mtm.h
      
      The new syntax header-test-pattern-y will be useful to specify
      "the rest".
      
      The typical usage is like this:
      
        header-test-pattern-y += */*.h
      
      This will add all the headers in sub-directories to the test coverage,
      excluding $(header-test-). In this regards, header-test-pattern-y
      behaves like a weaker variant of header-test-y.
      
      Caveat:
      The patterns in header-test-pattern-y are prefixed with $(srctree)/$(src)/
      but not $(objtree)/$(obj)/. Stale generated headers are often left over
      when you traverse the git history without cleaning. Wildcard patterns for
      $(objtree) may match to stale headers, which could fail to compile.
      One pitfall is $(srctree)/$(src)/ and $(objtree)/$(obj)/ point to the
      same directory for in-tree building. So, header-test-pattern-y should
      be used with care since it can potentially match to stale headers.
      
      Caveat2:
      You could use wildcard for header-test-. For example,
      
        header-test- += asm-generic/%
      
      ... will exclude headers in asm-generic directory. Unfortunately, the
      wildcard character is '%' instead of '*' here because this is evaluated
      by $(filter-out ...) whereas header-test-pattern-y is evaluated by
      $(wildcard ...). This is a kludge, but seems useful in some places...
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Tested-by: default avatarJani Nikula <jani.nikula@intel.com>
      1e21cbfa
    • Masahiro Yamada's avatar
      kbuild: do not create wrappers for header-test-y · c93a0368
      Masahiro Yamada authored
      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: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Acked-by: default avatarJani Nikula <jani.nikula@intel.com>
      Tested-by: default avatarJani Nikula <jani.nikula@intel.com>
      c93a0368
  4. 08 Jul, 2019 1 commit
    • Masahiro Yamada's avatar
      kbuild: compile-test exported headers to ensure they are self-contained · d6fc9fcb
      Masahiro Yamada authored
      Multiple people have suggested compile-testing UAPI headers to ensure
      they can be really included from user-space. "make headers_check" is
      obviously not enough to catch bugs, and we often leak unresolved
      references to user-space.
      
      Use the new header-test-y syntax to implement it. Please note exported
      headers are compile-tested with a completely different set of compiler
      flags. The header search path is set to $(objtree)/usr/include since
      exported headers should not include unexported ones.
      
      We use -std=gnu89 for the kernel space since the kernel code highly
      depends on GNU extensions. On the other hand, UAPI headers should be
      written in more standardized C, so they are compiled with -std=c90.
      This will emit errors if C++ style comments, the keyword 'inline', etc.
      are used. Please use C style comments (/* ... */), '__inline__', etc.
      in UAPI headers.
      
      There is additional compiler requirement to enable this test because
      many of UAPI headers include <stdlib.h>, <sys/ioctl.h>, <sys/time.h>,
      etc. directly or indirectly. You cannot use kernel.org pre-built
      toolchains [1] since they lack <stdlib.h>.
      
      I reused CONFIG_CC_CAN_LINK to check the system header availability.
      The intention is slightly different, but a compiler that can link
      userspace programs provide system headers.
      
      For now, a lot of headers need to be excluded because they cannot
      be compiled standalone, but this is a good start point.
      
      [1] https://mirrors.edge.kernel.org/pub/tools/crosstool/index.htmlSigned-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Reviewed-by: default avatarSam Ravnborg <sam@ravnborg.org>
      d6fc9fcb
  5. 07 Jul, 2019 7 commits
  6. 03 Jul, 2019 1 commit
  7. 01 Jul, 2019 6 commits
    • Masahiro Yamada's avatar
      fixdep: check return value of printf() and putchar() · 6f9ac9f4
      Masahiro Yamada authored
      When there is not enough space on your storage device, the build will
      fail with 'No space left on device' error message.
      
      The reason is obvious from the message, so you will free up some disk
      space, then you will resume the build.
      
      However, sometimes you may still see a mysterious error message:
      
        unterminated call to function 'wildcard': missing ')'.
      
      If you run out of the disk space, fixdep may end up with generating
      incomplete .*.cmd files.
      
      For example, if the disk-full error occurs while fixdep is running
      print_dep(), the .*.cmd might be truncated like this:
      
         $(wildcard include/config/
      
      When you run 'make' next time, this broken .*.cmd will be included,
      then Make will terminate parsing since it is a wrong syntax.
      
      Once this happens, you need to run 'make clean' or delete the broken
      .*.cmd file manually.
      
      Even if you do not see any error message, the .*.cmd files after any
      error could be potentially incomplete, and unreliable. You may miss
      the re-compilation due to missing header dependency.
      
      If printf() cannot output the string for disk shortage or whatever
      reason, it returns a negative value, but currently fixdep does not
      check it at all. Consequently, fixdep *successfully* generates a
      broken .*.cmd file. Make never notices that since fixdep exits with 0,
      which means success.
      
      Given the intended usage of fixdep, it must respect the return value
      of not only malloc(), but also printf() and putchar().
      
      This seems a long-standing issue since the introduction of fixdep.
      
      In old days, Kbuild tried to provide an extra safety by letting fixdep
      output to a temporary file and renaming it after everything is done:
      
        scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp;\
        rm -f $(depfile);                                                    \
        mv -f $(dot-target).tmp $(dot-target).cmd)
      
      It was no help to avoid the current issue; fixdep successfully created
      a truncated tmp file, which would be renamed to a .*.cmd file.
      
      This problem should be fixed by propagating the error status to the
      build system because:
      
      [1] Since commit 9c2af1c7 ("kbuild: add .DELETE_ON_ERROR special
          target"), Make will delete the target automatically on any failure
          in the recipe.
      
      [2] Since commit 392885ee ("kbuild: let fixdep directly write to
          .*.cmd files"), .*.cmd file is included only when the corresponding
          target already exists.
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      6f9ac9f4
    • Masahiro Yamada's avatar
      kbuild: split modules.order build rule out of 'modules' target · 68980b47
      Masahiro Yamada authored
      modules.order is a real target. Split its build rule out like
      modules.builtin
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      68980b47
    • Masahiro Yamada's avatar
      kbuild: fix missed rebuild of modules.builtin · 50ef0cdf
      Masahiro Yamada authored
      Unlike modules.order, modules.builtin is not rebuilt every time.
      Once modules.builtin is created, it will not be updated until
      auto.conf or tristate.conf is changed.
      
      So, it does not  notice a change in Makefile, for example, the rename
      of modules.
      
      Kbuild must always descend into directories for modules.builtin too.
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      50ef0cdf
    • Masahiro Yamada's avatar
      kbuild: save $(strip ...) for calling if_changed and friends · c2341e2a
      Masahiro Yamada authored
      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: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      c2341e2a
    • Masahiro Yamada's avatar
      kbuild: save $(strip ...) for calling any-prepreq · 93f31bbd
      Masahiro Yamada authored
      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: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      93f31bbd
    • Masahiro Yamada's avatar
      kbuild: rename arg-check to cmd-check · 50bcca6a
      Masahiro Yamada authored
      I prefer 'cmd-check' for consistency.
      
      We have 'echo-cmd', 'cmd', 'cmd_and_fixdep', etc. in this file.
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      50bcca6a
  8. 23 Jun, 2019 7 commits
  9. 15 Jun, 2019 5 commits