Skip to content
  1. Sep 06, 2019
    • Masahiro Yamada's avatar
      kbuild: rename KBUILD_ENABLE_EXTRA_GCC_CHECKS to KBUILD_EXTRA_WARN · e27128db
      Masahiro Yamada authored
      
      
      KBUILD_ENABLE_EXTRA_GCC_CHECKS started as a switch to add extra warning
      options for GCC, but now it is a historical misnomer since we use it
      also for Clang, DTC, and even kernel-doc.
      
      Rename it to more sensible, shorter KBUILD_EXTRA_WARN.
      
      For the backward compatibility, KBUILD_ENABLE_EXTRA_GCC_CHECKS is still
      supported (but not advertised in the documentation).
      
      I also fixed up 'make help', and updated the documentation.
      
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Reviewed-by: default avatarNathan Chancellor <natechancellor@gmail.com>
      Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Reviewed-by: default avatarSedat Dilek <sedat.dilek@gmail.com>
      e27128db
    • Masahiro Yamada's avatar
      kbuild: refactor scripts/Makefile.extrawarn · 64a91907
      Masahiro Yamada authored
      Instead of the warning-[123] magic, let's accumulate compiler options
      to KBUILD_CFLAGS directly as the top Makefile does. I think this makes
      it easier to understand what is going on in this file.
      
      This commit slightly changes the behavior, I think all of which are OK.
      
      [1] Currently, cc-option calls are needlessly evaluated. For example,
            warning-3 += $(call cc-option, -Wpacked-bitfield-compat)
          needs evaluating only when W=3, but it is actually evaluated for
          W=1, W=2 as well. With this commit, only relevant cc-option calls
          will be evaluated. This is a slight optimization.
      
      [2] Currently, unsupported level like W=4 is checked by:
            $(error W=$(KBUILD_ENABLE_EXTRA_GCC_CHECKS) is unknown)
          This will no longer be checked, but I do not think it is a big
          deal.
      
      [3] Currently, 4 Clang warnings (Winitializer-overrides, Wformat,
          Wsign-compare, Wformat-zero-length) are shown by any of W=1, W=2,
          and W=3. With this commit, they will be warned only by W=1. I
          think this is a more correct behavior since each warning belongs
          to only one group.
      
      For understanding this commit correctly:
      
      We have 3 warning groups, W=1, W=2, and W=3. You may think W=3 has a
      higher level than W=1, but they are actually independent. If you like,
      you can combine them like W=13. To enable all the warnings, you can
      pass W=123. It is shown by 'make help', but not noticed much. Since we
      support W= combination, there should not exist intersection among the
      three groups. If we enable Winitializer-overrides for W=1, we do not
      need to for W=2 or W=3. This is the reason why I think the change [3]
      makes sense.
      
      The documentation says -Winitializer-overrides is enabled by default.
      (https://clang.llvm.org/docs/DiagnosticsReference.html#winitializer-overrides
      
      )
      We negate it by passing -Wno-initializer-overrides for the normal
      build, but we do not do that for W=1. This means, W=1 effectively
      enables -Winitializer-overrides by the clang's default. The same for
      the other three.
      
      Add comments in case people are confused with the code.
      
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Reviewed-by: default avatarNathan Chancellor <natechancellor@gmail.com>
      Tested-by: default avatarSedat Dilek <sedat.dilek@gmail.com>
      Acked-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Acked-by: default avatarMiguel Ojeda <miguel.ojeda.sandonis@gmail.com>
      64a91907
  2. Sep 04, 2019
    • Guillaume Tucker's avatar
      merge_config.sh: ignore unwanted grep errors · 60bef52c
      Guillaume Tucker authored
      
      
      The merge_config.sh script verifies that all the config options have
      their expected value in the resulting file and prints any issues as
      warnings.  These checks aren't intended to be treated as errors given
      the current implementation.  However, since "set -e" was added, if the
      grep command to look for a config option does not find it the script
      will then abort prematurely.
      
      Handle the case where the grep exit status is non-zero by setting
      ACTUAL_VAL to an empty string to restore previous functionality.
      
      Fixes: cdfca821 ("merge_config.sh: Check error codes from make")
      Signed-off-by: default avatarGuillaume Tucker <guillaume.tucker@collabora.com>
      Acked-by: default avatarJon Hunter <jonathanh@nvidia.com>
      Tested-by: default avatarJon Hunter <jonathanh@nvidia.com>
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      60bef52c
    • Masahiro Yamada's avatar
      kbuild: change *FLAGS_<basetarget>.o to take the path relative to $(obj) · 54b8ae66
      Masahiro Yamada authored
      
      
      Kbuild provides per-file compiler flag addition/removal:
      
        CFLAGS_<basetarget>.o
        CFLAGS_REMOVE_<basetarget>.o
        AFLAGS_<basetarget>.o
        AFLAGS_REMOVE_<basetarget>.o
        CPPFLAGS_<basetarget>.lds
        HOSTCFLAGS_<basetarget>.o
        HOSTCXXFLAGS_<basetarget>.o
      
      The <basetarget> is the filename of the target with its directory and
      suffix stripped.
      
      This syntax comes into a trouble when two files with the same basename
      appear in one Makefile, for example:
      
        obj-y += foo.o
        obj-y += dir/foo.o
        CFLAGS_foo.o := <some-flags>
      
      Here, the <some-flags> applies to both foo.o and dir/foo.o
      
      The real world problem is:
      
        scripts/kconfig/util.c
        scripts/kconfig/lxdialog/util.c
      
      Both files are compiled into scripts/kconfig/mconf, but only the
      latter should be given with the ncurses flags.
      
      It is more sensible to use the relative path to the Makefile, like this:
      
        obj-y += foo.o
        CFLAGS_foo.o := <some-flags>
        obj-y += dir/foo.o
        CFLAGS_dir/foo.o := <other-flags>
      
      At first, I attempted to replace $(basetarget) with $*. The $* variable
      is replaced with the stem ('%') part in a pattern rule. This works with
      most of cases, but does not for explicit rules.
      
      For example, arch/ia64/lib/Makefile reuses rule_as_o_S in its own
      explicit rules, so $* will be empty, resulting in ignoring the per-file
      AFLAGS.
      
      I introduced a new variable, target-stem, which can be used also from
      explicit rules.
      
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Acked-by: default avatarMarc Zyngier <maz@kernel.org>
      54b8ae66
    • Denis Efremov's avatar
      modpost: add NOFAIL to strndup · 6f02bdfc
      Denis Efremov authored
      
      
      Add NOFAIL check for the strndup call, because the function
      allocates memory and can return NULL. All calls to strdup in
      modpost are checked with NOFAIL.
      
      Signed-off-by: default avatarDenis Efremov <efremov@linux.com>
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      6f02bdfc
    • Heikki Krogerus's avatar
      modpost: add guid_t type definition · 389c9af7
      Heikki Krogerus authored
      
      
      Since guid_t is the recommended data type for UUIDs in
      kernel (and I guess uuid_le is meant to be ultimately
      replaced with it), it should be made available here as
      well.
      
      Signed-off-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      389c9af7
    • Masahiro Yamada's avatar
      kbuild: add $(BASH) to run scripts with bash-extension · 858805b3
      Masahiro Yamada authored
      
      
      CONFIG_SHELL falls back to sh when bash is not installed on the system,
      but nobody is testing such a case since bash is usually installed.
      So, shell scripts invoked by CONFIG_SHELL are only tested with bash.
      
      It makes it difficult to test whether the hashbang #!/bin/sh is real.
      For example, #!/bin/sh in arch/powerpc/kernel/prom_init_check.sh is
      false. (I fixed it up)
      
      Besides, some shell scripts invoked by CONFIG_SHELL use bash-extension
      and #!/bin/bash is specified as the hashbang, while CONFIG_SHELL may
      not always be set to bash.
      
      Probably, the right thing to do is to introduce BASH, which is bash by
      default, and always set CONFIG_SHELL to sh. Replace $(CONFIG_SHELL)
      with $(BASH) for bash scripts.
      
      If somebody tries to add bash-extension to a #!/bin/sh script, it will
      be caught in testing because /bin/sh is a symlink to dash on some major
      distributions.
      
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      858805b3
    • Masahiro Yamada's avatar
      kbuild: remove ARCH_{CPP,A,C}FLAGS · 8cc7af75
      Masahiro Yamada authored
      
      
      These flags were added by commit 61754c18 ("kbuild: Allow arch
      Makefiles to override {cpp,ld,c}flags") to allow ARC to override -O2.
      
      We did not see any other usage after all. Now that ARC switched to
      CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3, there is no more user of
      these variables.
      
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      8cc7af75
    • Masahiro Yamada's avatar
      kbuild,arc: add CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3 for ARC · 15f5db60
      Masahiro Yamada authored
      
      
      arch/arc/Makefile overrides -O2 with -O3. This is the only user of
      ARCH_CFLAGS. There is no user of ARCH_CPPFLAGS or ARCH_AFLAGS.
      My plan is to remove ARCH_{CPP,A,C}FLAGS after refactoring the ARC
      Makefile.
      
      Currently, ARC has no way to enable -Wmaybe-uninitialized because both
      -O3 and -Os disable it. Enabling it will be useful for compile-testing.
      This commit allows allmodconfig (, which defaults to -O2) to enable it.
      
      Add CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=y to all the defconfig files
      in arch/arc/configs/ in order to keep the current config settings.
      
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Acked-by: default avatarVineet Gupta <vgupta@synopsys.com>
      15f5db60
  3. Aug 30, 2019
  4. Aug 29, 2019
  5. Aug 25, 2019
  6. Aug 22, 2019
  7. Aug 21, 2019
    • Masahiro Yamada's avatar
      kbuild: rebuild modules when module linker scripts are updated · 10df0638
      Masahiro Yamada authored
      
      
      Currently, the timestamp of module linker scripts are not checked.
      Add them to the dependency of modules so they are correctly rebuilt.
      
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      10df0638
    • Masahiro Yamada's avatar
      kbuild: move KBUILD_LDS, KBUILD_VMLINUX_{OBJS,LIBS} to makefiles.rst · 888f0c34
      Masahiro Yamada authored
      
      
      These three variables are not intended to be tweaked by users.
      Move them from kbuild.rst to makefiles.rst.
      
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      888f0c34
    • Masahiro Yamada's avatar
      treewide: remove dummy Makefiles for single targets · cbdf59ad
      Masahiro Yamada authored
      
      
      Now that the single target build descends into sub-directories in the
      same way as the normal build, these dummy Makefiles are not needed
      any more.
      
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      cbdf59ad
    • Masahiro Yamada's avatar
      kbuild: make single targets work more correctly · 394053f4
      Masahiro Yamada authored
      
      
      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: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      394053f4
    • Kees Cook's avatar
      kbuild: Parameterize kallsyms generation and correct reporting · 8959e392
      Kees Cook authored
      
      
      When kallsyms generation happens, temporary vmlinux outputs are linked
      but the quiet make output didn't report it, giving the impression that
      the prior command is taking longer than expected.
      
      Instead, report the linking step explicitly. While at it, this
      consolidates the repeated "kallsyms generation step" into a single
      function and removes the existing copy/pasting.
      
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      8959e392
    • Masahiro Yamada's avatar
      kbuild: re-implement detection of CONFIG options leaked to user-space · c7c0eecf
      Masahiro Yamada authored
      
      
      scripts/headers_check.pl can detect references to CONFIG options in
      exported headers, but it has been disabled for more than a decade.
      
      Reverting commit 7e3fa561 ("kbuild: drop check for CONFIG_ in
      headers_check") would emit the following warnings for headers_check
      on x86:
      
      usr/include/mtd/ubi-user.h:283: leaks CONFIG_MTD_UBI_BEB_LIMIT to userspace where it is not valid
      usr/include/linux/cm4000_cs.h:26: leaks CONFIG_COMPAT to userspace where it is not valid
      usr/include/linux/pkt_cls.h:301: leaks CONFIG_NET_CLS_ACT to userspace where it is not valid
      usr/include/linux/videodev2.h:2465: leaks CONFIG_VIDEO_ADV_DEBUG to userspace where it is not valid
      usr/include/linux/bpf.h:249: leaks CONFIG_EFFICIENT_UNALIGNED_ACCESS to userspace where it is not valid
      usr/include/linux/bpf.h:819: leaks CONFIG_CGROUP_NET_CLASSID to userspace where it is not valid
      usr/include/linux/bpf.h:1011: leaks CONFIG_IP_ROUTE_CLASSID to userspace where it is not valid
      usr/include/linux/bpf.h:1742: leaks CONFIG_BPF_KPROBE_OVERRIDE to userspace where it is not valid
      usr/include/linux/bpf.h:1747: leaks CONFIG_FUNCTION_ERROR_INJECTION to userspace where it is not valid
      usr/include/linux/bpf.h:1936: leaks CONFIG_XFRM to userspace where it is not valid
      usr/include/linux/bpf.h:2184: leaks CONFIG_BPF_LIRC_MODE2 to userspace where it is not valid
      usr/include/linux/bpf.h:2210: leaks CONFIG_BPF_LIRC_MODE2 to userspace where it is not valid
      usr/include/linux/bpf.h:2227: leaks CONFIG_SOCK_CGROUP_DATA to userspace where it is not valid
      usr/include/linux/bpf.h:2311: leaks CONFIG_NET to userspace where it is not valid
      usr/include/linux/bpf.h:2348: leaks CONFIG_NET to userspace where it is not valid
      usr/include/linux/bpf.h:2422: leaks CONFIG_BPF_LIRC_MODE2 to userspace where it is not valid
      usr/include/linux/bpf.h:2528: leaks CONFIG_NET to userspace where it is not valid
      usr/include/linux/pktcdvd.h:37: leaks CONFIG_CDROM_PKTCDVD_WCACHE to userspace where it is not valid
      usr/include/linux/hw_breakpoint.h:27: leaks CONFIG_HAVE_MIXED_BREAKPOINTS_REGS to userspace where it is not valid
      usr/include/linux/raw.h:17: leaks CONFIG_MAX_RAW_DEVS to userspace where it is not valid
      usr/include/linux/elfcore.h:62: leaks CONFIG_BINFMT_ELF_FDPIC to userspace where it is not valid
      usr/include/linux/eventpoll.h:82: leaks CONFIG_PM_SLEEP to userspace where it is not valid
      usr/include/linux/atmdev.h:104: leaks CONFIG_COMPAT to userspace where it is not valid
      usr/include/asm-generic/unistd.h:651: leaks CONFIG_MMU to userspace where it is not valid
      usr/include/asm-generic/bitsperlong.h:9: leaks CONFIG_64BIT to userspace where it is not valid
      usr/include/asm-generic/fcntl.h:119: leaks CONFIG_64BIT to userspace where it is not valid
      usr/include/asm/auxvec.h:14: leaks CONFIG_IA32_EMULATION to userspace where it is not valid
      usr/include/asm/e820.h:14: leaks CONFIG_NODES_SHIFT to userspace where it is not valid
      usr/include/asm/e820.h:39: leaks CONFIG_X86_PMEM_LEGACY to userspace where it is not valid
      usr/include/asm/e820.h:49: leaks CONFIG_INTEL_TXT to userspace where it is not valid
      usr/include/asm/mman.h:7: leaks CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS to userspace where it is not valid
      
      Most of these are false positives because scripts/headers_check.pl
      parses comment lines.
      
      It is also false negative. arch/x86/include/uapi/asm/auxvec.h contains
      CONFIG_IA32_EMULATION and CONFIG_X86_64, but the only former is reported.
      
      It would be possible to fix scripts/headers_check.pl, of course.
      However, we already have some duplicated checks between headers_check
      and CONFIG_UAPI_HEADER_TEST. At this moment of time, there are still
      dozens of headers excluded from the header test (usr/include/Makefile),
      but we might be able to remove headers_check eventually.
      
      I re-implemented it in scripts/headers_install.sh by using sed because
      the most of code in scripts/headers_install.sh is written in sed.
      
      This patch works like this:
      
      [1] Run scripts/unifdef first because we need to drop the code
          surrounded by #ifdef __KERNEL__ ... #endif
      
      [2] Remove all C style comments. The sed code is somewhat complicated
          since we need to deal with both single and multi line comments.
      
          Precisely speaking, a comment block is replaced with a space just
          in case.
      
            CONFIG_FOO/* this is a comment */CONFIG_BAR
      
          should be converted into:
      
            CONFIG_FOO CONFIG_BAR
      
          instead of:
      
            CONFIG_FOOCONFIG_BAR
      
      [3] Match CONFIG_... pattern. It correctly matches to all CONFIG
          options that appear in a single line.
      
      After this commit, this would detect the following warnings, all of
      which are real ones.
      
      warning: include/uapi/linux/pktcdvd.h: leak CONFIG_CDROM_PKTCDVD_WCACHE to user-space
      warning: include/uapi/linux/hw_breakpoint.h: leak CONFIG_HAVE_MIXED_BREAKPOINTS_REGS to user-space
      warning: include/uapi/linux/raw.h: leak CONFIG_MAX_RAW_DEVS to user-space
      warning: include/uapi/linux/elfcore.h: leak CONFIG_BINFMT_ELF_FDPIC to user-space
      warning: include/uapi/linux/eventpoll.h: leak CONFIG_PM_SLEEP to user-space
      warning: include/uapi/linux/atmdev.h: leak CONFIG_COMPAT to user-space
      warning: include/uapi/asm-generic/fcntl.h: leak CONFIG_64BIT to user-space
      warning: arch/x86/include/uapi/asm/auxvec.h: leak CONFIG_IA32_EMULATION to user-space
      warning: arch/x86/include/uapi/asm/auxvec.h: leak CONFIG_X86_64 to user-space
      warning: arch/x86/include/uapi/asm/mman.h: leak CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS to user-space
      
      However, it is not nice to show them right now. I created a list of
      existing leakages. They are not warned, but a new leakage will be
      blocked by the 0-day bot.
      
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Acked-by: default avatarSam Ravnborg <sam@ravnborg.org>
      c7c0eecf