Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
  1. Sep 24, 2020
  2. Aug 26, 2020
    • Nathan Huckleberry's avatar
      Makefile: Add clang-tidy and static analyzer support to makefile · 6ad7cbc0
      Nathan Huckleberry authored
      This patch adds clang-tidy and the clang static-analyzer as make
      targets. The goal of this patch is to make static analysis tools
      usable and extendable by any developer or researcher who is familiar
      with basic c++.
      
      The current static analysis tools require intimate knowledge of the
      internal workings of the static analysis. Clang-tidy and the clang
      static analyzers expose an easy to use api and allow users unfamiliar
      with clang to write new checks with relative ease.
      
      ===Clang-tidy===
      
      Clang-tidy is an easily extendable 'linter' that runs on the AST.
      Clang-tidy checks are easy to write and understand. A check consists of
      two parts, a matcher and a checker. The matcher is created using a
      domain specific language that acts on the AST
      (https://clang.llvm.org/docs/LibASTMatchersReference.html).  When AST
      nodes are found by the matcher a callback is made to the checker. The
      checker can then execute additional checks and issue warnings.
      
      Here is a...
      6ad7cbc0
    • Masahiro Yamada's avatar
      kbuild: wire up the build rule of compile_commands.json to Makefile · 3d32285f
      Masahiro Yamada authored
      Currently, you need to manually run scripts/gen_compile_commands.py
      to create compile_commands.json. It parses all the .*.cmd files found
      under the specified directory.
      
      If you rebuild the kernel over again without 'make clean',
      .*.cmd files from older builds will create stale entries in
      compile_commands.json.
      
      This commit wires up the compile_commands.json rule to Makefile, and
      makes it parse only the .*.cmd files involved in the current build.
      
      Pass $(KBUILD_VMLINUX_OBJS), $(KBUILD_VMLINUX_LIBS), and modules.order
      to the script. The objects or archives linked to vmlinux are listed in
      $(KBUILD_VMLINUX_OBJS) or $(KBUILD_VMLINUX_LIBS). All the modules are
      listed in modules.order.
      
      You can create compile_commands.json from Make:
      
        $ make -j$(nproc) CC=clang compile_commands.json
      
      You can also build vmlinux, modules, and compile_commands.json all
      together in a single command:
      
        $ make -j$(nproc) CC=clang all compile_commands.json
      
      It works for M= builds as well. In this case, compile_commands.json
      is created in the top directory of the external module.
      
      This is convenient, but it has a drawback; the coverage of the
      compile_commands.json is reduced because only the objects linked to
      vmlinux or modules are handled. For example, the following C files are
      not included in the compile_commands.json:
      
       - Decompressor source files (arch/*/boot/)
       - VDSO source files
       - C files used to generate intermediates (e.g. kernel/bounds.c)
       - Standalone host programs
      
      I think it is fine for most developers because our main interest is
      the kernel-space code.
      
      If you want to cover all the compiled C files, please build the kernel,
      then run the script manually as you did before:
      
        $ make clean    # if you want to remove stale .cmd files [optional]
        $ make -j$(nproc) CC=clang
        $ scripts/gen_compile_commands.py
      
      Here is a note for out-of-tree builds. 'make compile_commands.json'
      works with O= option, but please notice compile_commands.json is
      created in the object tree instead of the source tree.
      
      Some people may want to have compile_commands.json in the source tree
      because Clang Tools searches for it through all parent paths of the
      first input source file.
      
      However, you cannot do this for O= builds. Kbuild should never generate
      any build artifact in the source tree when O= is given because the
      source tree might be read-only. Any write attempt to the source tree
      is monitored and the violation may be reported. See the commit log of
      8ef14c2c
      
      .
      
      So, the only possible way is to create compile_commands.json in the
      object tree, then specify '-p <build-path>' when you use clang-check,
      clang-tidy, etc.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Acked-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      3d32285f
    • Masahiro Yamada's avatar
      kbuild: hide commands to run Kconfig, and show short log for syncconfig · 23cd88c9
      Masahiro Yamada authored
      
      Some targets (localyesconfig, localmodconfig, defconfig) hide the
      command running, but the others do not.
      
      Users know which Kconfig flavor they are running, so it is OK to hide
      the command. Add $(Q) to all commands consistently. If you want to see
      the full command running, pass V=1 from the command line.
      
      syncconfig is the exceptional case, which occurs without explicit
      command invocation by the user. Display the Kbuild-style log for it.
      The ugly bare log will go away.
      
      [Before]
      
      scripts/kconfig/conf  --syncconfig Kconfig
      
      [After]
      
        SYNC    include/config/auto.conf
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      23cd88c9
    • Sedat Dilek's avatar
      kbuild: Simplify DEBUG_INFO Kconfig handling · 695afd3d
      Sedat Dilek authored
      While playing with [1] I saw that the handling
      of CONFIG_DEBUG_INFO can be simplified.
      
      [1] https://patchwork.kernel.org/patch/11716107/
      
      
      
      Signed-off-by: default avatarSedat Dilek <sedat.dilek@gmail.com>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      695afd3d
  3. Aug 23, 2020
  4. Aug 18, 2020
  5. Aug 16, 2020
  6. Aug 12, 2020
  7. Aug 09, 2020
    • Masahiro Yamada's avatar
      kbuild: stop filtering out $(GCC_PLUGINS_CFLAGS) from cc-option base · 132305b3
      Masahiro Yamada authored
      Commit d26e9414
      
       ("kbuild: no gcc-plugins during cc-option tests")
      was neeeded because scripts/Makefile.gcc-plugins was too early.
      
      This is unneeded by including scripts/Makefile.gcc-plugins last,
      and being careful to not add cc-option tests after it.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      132305b3
    • Masahiro Yamada's avatar
      kbuild: include scripts/Makefile.* only when relevant CONFIG is enabled · e0fe0bbe
      Masahiro Yamada authored
      
      Currently, the top Makefile includes all of scripts/Makefile.<feature>
      even if the associated CONFIG option is disabled.
      
      Do not include unneeded Makefiles in order to slightly optimize the
      parse stage.
      
      Include $(include-y), and ignore $(include-).
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      e0fe0bbe
    • Masahiro Yamada's avatar
      kbuild: do not export LDFLAGS_vmlinux · 3ec8a5b3
      Masahiro Yamada authored
      When you clean the build tree for ARCH=arm, you may see the following
      error message from 'nm' command:
      
      $ make -j24 ARCH=arm clean
        CLEAN   arch/arm/crypto
        CLEAN   arch/arm/kernel
        CLEAN   arch/arm/mach-at91
        CLEAN   arch/arm/mach-omap2
        CLEAN   arch/arm/vdso
        CLEAN   certs
        CLEAN   lib
        CLEAN   usr
        CLEAN   net/wireless
        CLEAN   drivers/firmware/efi/libstub
      nm: 'arch/arm/boot/compressed/../../../../vmlinux': No such file
      /bin/sh: 1: arithmetic expression: expecting primary: " "
        CLEAN   arch/arm/boot/compressed
        CLEAN   drivers/scsi
        CLEAN   drivers/tty/vt
        CLEAN   arch/arm/boot
        CLEAN   vmlinux.symvers modules.builtin modules.builtin.modinfo
      
      Even if you rerun the same command, the error message will not be
      shown despite vmlinux is already gone.
      
      To reproduce it, the parallel option -j is needed. Single thread
      cleaning always executes 'archclean', 'vmlinuxclean' in this order,
      so vmlinux still exists when arch/arm/boot/compressed/ is cleaned.
      
      Looking at arch/arm/boot/compressed/Makefile does not help understand
      the reason of the error message. Both KBSS_SZ and LDFLAGS_vmlinux are
      assigned with '=' operator, hence, they are not expanded unless used.
      Obviously, 'make clean' does not use them.
      
      In fact, the root cause exists in the top Makefile:
      
        export LDFLAGS_vmlinux
      
      Since LDFLAGS_vmlinux is an exported variable, LDFLAGS_vmlinux in
      arch/arm/boot/compressed/Makefile is expanded when scripts/Makefile.clean
      has a command to execute. This is why the error message shows up only
      when there exist build artifacts in arch/arm/boot/compressed/.
      
      Adding 'unexport LDFLAGS_vmlinux' to arch/arm/boot/compressed/Makefile
      will fix it as far as ARCH=arm is concerned, but I think the proper fix
      is to get rid of 'export LDFLAGS_vmlinux' from the top Makefile.
      
      LDFLAGS_vmlinux in the top Makefile contains linker flags for the top
      vmlinux. LDFLAGS_vmlinux in arch/arm/boot/compressed/Makefile is for
      arch/arm/boot/compressed/vmlinux. They just happen to have the same
      variable name, but are used for different purposes. Stop shadowing
      LDFLAGS_vmlinux.
      
      This commit passes LDFLAGS_vmlinux to scripts/link-vmlinux.sh via a
      command line parameter instead of via an environment variable. LD and
      KBUILD_LDFLAGS are exported, but I did the same for consistency. Anyway,
      they must be included in cmd_link-vmlinux to allow if_changed to detect
      the changes in LD or KBUILD_LDFLAGS.
      
      The following Makefiles are not affected:
      
        arch/arm/boot/compressed/Makefile
        arch/h8300/boot/compressed/Makefile
        arch/nios2/boot/compressed/Makefile
        arch/parisc/boot/compressed/Makefile
        arch/s390/boot/compressed/Makefile
        arch/sh/boot/compressed/Makefile
        arch/sh/boot/romimage/Makefile
        arch/x86/boot/compressed/Makefile
      
      They use ':=' or '=' to clear the LDFLAGS_vmlinux inherited from the
      top Makefile.
      
      We need to take a closer look at the impact to unicore32 and xtensa.
      
      arch/unicore32/boot/compressed/Makefile only uses '+=' operator for
      LDFLAGS_vmlinux. So, the decompressor previously inherited the linker
      flags from the top Makefile.
      
      However, commit 70fac51f ("unicore32 additional architecture files:
      boot process") was merged before commit 1f2bfbd0 ("kbuild: link of
      vmlinux moved to a script"). So, I rather consider this is a bug fix of
      1f2bfbd0.
      
      arch/xtensa/boot/boot-elf/Makefile is also affected, but this is also
      considered a fix for the same reason. It did not inherit LDFLAGS_vmlinux
      when commit 4bedea94
      
       ("[PATCH] xtensa: Architecture support for
      Tensilica Xtensa Part 2") was merged. I deleted $(LDFLAGS_vmlinux),
      which is now empty.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Tested-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      3ec8a5b3
  8. Aug 02, 2020
  9. Jul 31, 2020
  10. Jul 26, 2020
  11. Jul 22, 2020
  12. Jul 19, 2020
  13. Jul 13, 2020
  14. Jul 12, 2020
  15. Jul 11, 2020
  16. Jul 06, 2020
  17. Jul 05, 2020
  18. Jul 01, 2020
  19. Jun 28, 2020
  20. Jun 21, 2020
  21. Jun 16, 2020
    • glider@google.com's avatar
      security: allow using Clang's zero initialization for stack variables · f0fe00d4
      glider@google.com authored
      In addition to -ftrivial-auto-var-init=pattern (used by
      CONFIG_INIT_STACK_ALL now) Clang also supports zero initialization for
      locals enabled by -ftrivial-auto-var-init=zero. The future of this flag
      is still being debated (see https://bugs.llvm.org/show_bug.cgi?id=45497
      
      ).
      Right now it is guarded by another flag,
      -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang,
      which means it may not be supported by future Clang releases. Another
      possible resolution is that -ftrivial-auto-var-init=zero will persist
      (as certain users have already started depending on it), but the name
      of the guard flag will change.
      
      In the meantime, zero initialization has proven itself as a good
      production mitigation measure against uninitialized locals. Unlike pattern
      initialization, which has a higher chance of triggering existing bugs,
      zero initialization provides safe defaults for strings, pointers, indexes,
      and sizes. On the other hand, pattern initialization remains safer for
      return values. Chrome OS and Android are moving to using zero
      initialization for production builds.
      
      Performance-wise, the difference between pattern and zero initialization
      is usually negligible, although the generated code for zero
      initialization is more compact.
      
      This patch renames CONFIG_INIT_STACK_ALL to CONFIG_INIT_STACK_ALL_PATTERN
      and introduces another config option, CONFIG_INIT_STACK_ALL_ZERO, that
      enables zero initialization for locals if the corresponding flags are
      supported by Clang.
      
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Nick Desaulniers <ndesaulniers@google.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarAlexander Potapenko <glider@google.com>
      Link: https://lore.kernel.org/r/20200616083435.223038-1-glider@google.com
      
      
      Reviewed-by: default avatarMaciej Żenczykowski <maze@google.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      f0fe00d4
  22. Jun 14, 2020
    • Arvind Sankar's avatar
      Makefile: Improve compressed debug info support detection · 7b169944
      Arvind Sankar authored
      Commit
        10e68b02
      
       ("Makefile: support compressed debug info")
      added support for compressed debug sections.
      
      Support is detected by checking
      - does the compiler support -gz=zlib
      - does the assembler support --compressed-debug-sections=zlib
      - does the linker support --compressed-debug-sections=zlib
      
      However, the gcc driver's support for this option is somewhat
      convoluted. The driver's builtin specs are set based on the version of
      binutils that it was configured with. It reports an error if the
      configure-time linker/assembler (i.e., not necessarily the actual
      assembler that will be run) do not support the option, but only if the
      assembler (or linker) is actually invoked when -gz=zlib is passed.
      
      The cc-option check in scripts/Kconfig.include does not invoke the
      assembler, so the gcc driver reports success even if it does not support
      the option being passed to the assembler.
      
      Because the as-option check passes the option directly to the assembler
      via -Wa,--compressed-debug-sections=zlib, the gcc driver does not see
      this option and will never report an error.
      
      Combined with an installed version of binutils that is more recent than
      the one the compiler was built with, it is possible for all three tests
      to succeed, yet an actual compilation with -gz=zlib to fail.
      
      Moreover, it is unnecessary to explicitly pass
      --compressed-debug-sections=zlib to the assembler via -Wa, since the
      driver will do that automatically when it supports -gz=zlib.
      
      Convert the as-option to just -gz=zlib, simplifying it as well as
      performing a better test of the gcc driver's capabilities.
      
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Signed-off-by: default avatarArvind Sankar <nivedita@alum.mit.edu>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      7b169944
    • Linus Torvalds's avatar
      Linux 5.8-rc1 · b3a9e3b9
      Linus Torvalds authored
      v5.8-rc1
      b3a9e3b9
  23. Jun 11, 2020
  24. Jun 06, 2020
    • Denis Efremov's avatar
      kbuild: add variables for compression tools · 8dfb61dc
      Denis Efremov authored
      
      Allow user to use alternative implementations of compression tools,
      such as pigz, pbzip2, pxz. For example, multi-threaded tools to
      speed up the build:
      $ make GZIP=pigz BZIP2=pbzip2
      
      Variables _GZIP, _BZIP2, _LZOP are used internally because original env
      vars are reserved by the tools. The use of GZIP in gzip tool is obsolete
      since 2015. However, alternative implementations (e.g., pigz) still rely
      on it. BZIP2, BZIP, LZOP vars are not obsolescent.
      
      The credit goes to @grsecurity.
      
      As a sidenote, for multi-threaded lzma, xz compression one can use:
      $ export XZ_OPT="--threads=0"
      
      Signed-off-by: default avatarDenis Efremov <efremov@linux.com>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      8dfb61dc
    • Jonas Zeiger's avatar
      Makefile: install modules.builtin even if CONFIG_MODULES=n · e0b250b5
      Jonas Zeiger authored
      
      Many applications check for available kernel features via:
      
        - /proc/modules (loaded modules, present if CONFIG_MODULES=y)
        - $(MODLIB)/modules.builtin (builtin modules)
      
      They fail to detect features if the kernel was built with CONFIG_MODULES=n
      and modules.builtin isn't installed.
      
      Therefore, add the target "_builtin_inst_" and make "install" and
      "modules_install" depend on it.
      
      Tests results:
      
        - make install: kernel image is copied as before, modules.builtin copied
        - make modules_install: (CONFIG_MODULES=n) nothing is copied, exit 1
      
      Signed-off-by: default avatarJonas Zeiger <jonas.zeiger@talpidae.net>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      e0b250b5
    • Masahiro Yamada's avatar
      modpost: show warning if any of symbol dump files is missing · 48a0f727
      Masahiro Yamada authored
      
      If modpost fails to load a symbol dump file, it cannot check unresolved
      symbols, hence module dependency will not be added. Nor CRCs can be added.
      
      Currently, external module builds check only $(objtree)/Module.symvers,
      but it should check files specified by KBUILD_EXTRA_SYMBOLS as well.
      
      Move the warning message from the top Makefile to scripts/Makefile.modpost
      and print the warning if any dump file is missing.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      48a0f727
    • Masahiro Yamada's avatar
      modpost: generate vmlinux.symvers and reuse it for the second modpost · 269a535c
      Masahiro Yamada authored
      
      The full build runs modpost twice, first for vmlinux.o and second for
      modules.
      
      The first pass dumps all the vmlinux symbols into Module.symvers, but
      the second pass parses vmlinux again instead of reusing the dump file,
      presumably because it needs to avoid accumulating stale symbols.
      
      Loading symbol info from a dump file is faster than parsing an ELF object.
      Besides, modpost deals with various issues to parse vmlinux in the second
      pass.
      
      A solution is to make the first pass dumps symbols into a separate file,
      vmlinux.symvers. The second pass reads it, and parses module .o files.
      The merged symbol information is dumped into Module.symvers in the same
      way as before.
      
      This makes further modpost cleanups possible.
      
      Also, it fixes the problem of 'make vmlinux', which previously overwrote
      Module.symvers, throwing away module symbols.
      
      I slightly touched scripts/link-vmlinux.sh so that vmlinux is re-linked
      when you cross this commit. Otherwise, vmlinux.symvers would not be
      generated.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      269a535c
  25. Jun 03, 2020
  26. Jun 01, 2020