Skip to content
Snippets Groups Projects
  1. Apr 22, 2022
  2. Apr 19, 2022
  3. Apr 01, 2022
  4. Mar 15, 2022
  5. Jan 13, 2022
  6. Jan 08, 2022
    • Masahiro Yamada's avatar
      kbuild: do not include include/config/auto.conf from shell scripts · 7d153696
      Masahiro Yamada authored
      Richard Weinberger pointed out the risk of sourcing the kernel config
      from shell scripts [1], and proposed some patches [2], [3]. It is a good
      point, but it took a long time because I was wondering how to fix this.
      
      This commit goes with simple grep approach because there are only a few
      scripts including the kernel configuration.
      
      scripts/link_vmlinux.sh has references to a bunch of CONFIG options,
      all of which are boolean. I added is_enabled() helper as
      scripts/package/{mkdebian,builddeb} do.
      
      scripts/gen_autoksyms.sh uses 'eval', stating "to expand the whitelist
      path". I removed it since it is the issue we are trying to fix.
      
      I was a bit worried about the cost of invoking the grep command over
      again. I extracted the grep parts from it, and measured the cost. It
      was approximately 0.03 sec, which I hope is acceptable.
      
      [test code]
      
        $ cat test-grep.sh
        #!/bin/sh
      
        is_enabled() {
                grep -q "^$1=y" include/config/auto.conf
        }
      
        is_enabled CONFIG_LTO_CLANG
        is_enabled CONFIG_LTO_CLANG
        is_enabled CONFIG_STACK_VALIDATION
        is_enabled CONFIG_UNWINDER_ORC
        is_enabled CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
        is_enabled CONFIG_VMLINUX_VALIDATION
        is_enabled CONFIG_FRAME_POINTER
        is_enabled CONFIG_GCOV_KERNEL
        is_enabled CONFIG_LTO_CLANG
        is_enabled CONFIG_RETPOLINE
        is_enabled CONFIG_X86_SMAP
        is_enabled CONFIG_LTO_CLANG
        is_enabled CONFIG_VMLINUX_MAP
        is_enabled CONFIG_KALLSYMS_ALL
        is_enabled CONFIG_KALLSYMS_ABSOLUTE_PERCPU
        is_enabled CONFIG_KALLSYMS_BASE_RELATIVE
        is_enabled CONFIG_DEBUG_INFO_BTF
        is_enabled CONFIG_KALLSYMS
        is_enabled CONFIG_DEBUG_INFO_BTF
        is_enabled CONFIG_BPF
        is_enabled CONFIG_BUILDTIME_TABLE_SORT
        is_enabled CONFIG_KALLSYMS
      
        $ time ./test-grep.sh
        real    0m0.036s
        user    0m0.027s
        sys     m0.009s
      
      [1]: https://lore.kernel.org/all/1919455.eZKeABUfgV@blindfold/
      [2]: https://lore.kernel.org/all/20180219092245.26404-1-richard@nod.at/
      [3]: https://lore.kernel.org/all/20210920213957.1064-2-richard@nod.at/
      
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: default avatarNicolas Schier <n.schier@avm.de>
      7d153696
  7. Dec 09, 2021
  8. Nov 02, 2021
  9. Oct 12, 2021
  10. Sep 02, 2021
  11. Jun 29, 2021
  12. May 27, 2021
    • Javier Martinez Canillas's avatar
      kbuild: Quote OBJCOPY var to avoid a pahole call break the build · ff2e6efd
      Javier Martinez Canillas authored
      
      The ccache tool can be used to speed up cross-compilation, by calling the
      compiler and binutils through ccache. For example, following should work:
      
          $ export ARCH=arm64 CROSS_COMPILE="ccache aarch64-linux-gnu-"
      
          $ make M=drivers/gpu/drm/rockchip/
      
      but pahole fails to extract the BTF info from DWARF, breaking the build:
      
            CC [M]  drivers/gpu/drm/rockchip//rockchipdrm.mod.o
            LD [M]  drivers/gpu/drm/rockchip//rockchipdrm.ko
            BTF [M] drivers/gpu/drm/rockchip//rockchipdrm.ko
          aarch64-linux-gnu-objcopy: invalid option -- 'J'
          Usage: aarch64-linux-gnu-objcopy [option(s)] in-file [out-file]
           Copies a binary file, possibly transforming it in the process
          ...
          make[1]: *** [scripts/Makefile.modpost:156: __modpost] Error 2
          make: *** [Makefile:1866: modules] Error 2
      
      this fails because OBJCOPY is set to "ccache aarch64-linux-gnu-copy" and
      later pahole is executed with the following command line:
      
          LLVM_OBJCOPY=$(OBJCOPY) $(PAHOLE) -J --btf_base vmlinux $@
      
      which gets expanded to:
      
          LLVM_OBJCOPY=ccache aarch64-linux-gnu-objcopy pahole -J ...
      
      instead of:
      
          LLVM_OBJCOPY="ccache aarch64-linux-gnu-objcopy" pahole -J ...
      
      Fixes: 5f9ae91f ("kbuild: Build kernel module BTFs if BTF is enabled and pahole supports it")
      Signed-off-by: default avatarJavier Martinez Canillas <javierm@redhat.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Acked-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Acked-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Link: https://lore.kernel.org/bpf/20210526215228.3729875-1-javierm@redhat.com
      ff2e6efd
  13. May 26, 2021
    • Masahiro Yamada's avatar
      kbuild: clean up ${quiet} checks in shell scripts · c39013ee
      Masahiro Yamada authored
      
      There were efforts to make 'make -s' really silent when it is a
      warning-free build.
      
      The conventional way was to let a shell script check ${quiet}, and if
      it is 'silent_', suppress the stdout by itself.
      
      With the previous commit, the 'cmd' takes care of it now. The 'cmd' is
      also invoked from if_changed, if_changed_dep, and if_changed_rule.
      
      You can omit ${quiet} checks in shell scripts when they are invoked
      from the 'cmd' macro.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      c39013ee
  14. May 05, 2021
  15. Apr 24, 2021
    • Rasmus Villemoes's avatar
      kbuild: apply fixdep logic to link-vmlinux.sh · 0b956e20
      Rasmus Villemoes authored
      
      The patch adding CONFIG_VMLINUX_MAP revealed a small defect in the
      build system: link-vmlinux.sh takes decisions based on CONFIG_*
      options, but changing one of those does not always lead to vmlinux
      being linked again.
      
      For most of the CONFIG_* knobs referenced previously, this has
      probably been hidden by those knobs also affecting some object file,
      hence indirectly also vmlinux.
      
      But CONFIG_VMLINUX_MAP is only handled inside link-vmlinux.sh, and
      changing CONFIG_VMLINUX_MAP=n to CONFIG_VMLINUX_MAP=y does not cause
      the build system to re-link (and hence have vmlinux.map
      emitted). Since that map file is mostly a debugging aid, this is
      merely a nuisance which is easily worked around by just deleting
      vmlinux and building again.
      
      But one could imagine other (possibly future) CONFIG options that
      actually do affect the vmlinux binary but which are not captured
      through some object file dependency.
      
      To fix this, make link-vmlinux.sh emit a .vmlinux.d file in the same
      format as the dependency files generated by gcc, and apply the fixdep
      logic to that. I've tested that this correctly works with both in-tree
      and out-of-tree builds.
      
      Signed-off-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      0b956e20
    • Rasmus Villemoes's avatar
      kbuild: add CONFIG_VMLINUX_MAP expert option · 5cc12472
      Rasmus Villemoes authored
      
      It can be quite useful to have ld emit a link map file, in order to
      debug or verify that special sections end up where they are supposed
      to, and to see what LD_DEAD_CODE_DATA_ELIMINATION manages to get rid
      of.
      
      The only reason I'm not just adding this unconditionally is that the
      .map file can be rather large (several MB), and that's a waste of
      space when one isn't interested in these things. Also make it depend
      on CONFIG_EXPERT.
      
      Signed-off-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      5cc12472
  16. Apr 13, 2021
  17. Feb 23, 2021
  18. Jan 14, 2021
  19. Oct 09, 2020
    • Masahiro Yamada's avatar
      kbuild: split the build log of kallsyms · 08beb669
      Masahiro Yamada authored
      
      Currently, the build log shows KSYM + object name.
      
      Precisely speaking, kallsyms generates a .S file and then the compiler
      compiles it into a .o file. Split the build log into two.
      
      [Before]
      
        GEN     modules.builtin
        LD      .tmp_vmlinux.kallsyms1
        KSYM    .tmp_vmlinux.kallsyms1.o
        LD      .tmp_vmlinux.kallsyms2
        KSYM    .tmp_vmlinux.kallsyms2.o
        LD      vmlinux
      
      [After]
      
        GEN     modules.builtin
        LD      .tmp_vmlinux.kallsyms1
        KSYMS   .tmp_vmlinux.kallsyms1.S
        AS      .tmp_vmlinux.kallsyms1.o
        LD      .tmp_vmlinux.kallsyms2
        KSYMS   .tmp_vmlinux.kallsyms2.S
        AS      .tmp_vmlinux.kallsyms2.o
        LD      vmlinux
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      08beb669
  20. Sep 23, 2020
  21. Aug 09, 2020
    • 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
  22. Jul 13, 2020
  23. Jun 09, 2020
  24. Jun 06, 2020
    • 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. Apr 22, 2020
  26. Mar 19, 2020
  27. Mar 04, 2020
    • Kees Cook's avatar
      kbuild: Remove debug info from kallsyms linking · af73d78b
      Kees Cook authored
      
      When CONFIG_DEBUG_INFO is enabled, the two kallsyms linking steps spend
      time collecting and writing the dwarf sections to the temporary output
      files. kallsyms does not need this information, and leaving it off
      halves their linking time. This is especially noticeable without
      CONFIG_DEBUG_INFO_REDUCED. The BTF linking stage, however, does still
      need those details.
      
      Refactor the BTF and kallsyms generation stages slightly for more
      regularized temporary names. Skip debug during kallsyms links.
      Additionally move "info BTF" to the correct place since commit
      8959e392 ("kbuild: Parameterize kallsyms generation and correct
      reporting"), which added "info LD ..." to vmlinux_link calls.
      
      For a full debug info build with BTF, my link time goes from 1m06s to
      0m54s, saving about 12 seconds, or 18%.
      
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Link: https://lore.kernel.org/bpf/202003031814.4AEA3351@keescook
      af73d78b
  28. Feb 10, 2020
    • Masahiro Yamada's avatar
      kbuild: fix mismatch between .version and include/generated/compile.h · 083bc0e1
      Masahiro Yamada authored
      
      Since commit 56d58936 ("kbuild: do not create orphan built-in.a or
      obj-y objects"), scripts/link-vmlinux.sh does nothing when descending
      into init/.
      
      Once the version number becomes out of sync between .version and
      include/generated/compile.h, it is not self-healing.
      
      [How to reproduce]
      
       $ echo 100 > .version
       $ make
      
      You will see the number in the .version is always bigger than that in
      compile.h by one. After this, every time you run 'make', the vmlinux is
      re-linked even when none of source files is updated.
      
      Fixes: 56d58936 ("kbuild: do not create orphan built-in.a or obj-y objects")
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      083bc0e1
  29. Jan 22, 2020
  30. Jan 06, 2020
    • Masahiro Yamada's avatar
      kbuild: create modules.builtin without Makefile.modbuiltin or tristate.conf · 8b41fc44
      Masahiro Yamada authored
      
      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: default avatarMasahiro Yamada <masahiroy@kernel.org>
      8b41fc44
  31. Dec 13, 2019
Loading