1. 30 12月, 2022 1 次提交
    • S
      kbuild: Fix running modpost with musl libc · 63ffe00d
      Samuel Holland 提交于
      commit 3d57e1b7 ("kbuild: refactor the prerequisites of the modpost
      rule") moved 'vmlinux.o' inside modpost-args, possibly before some of
      the other options. However, getopt() in musl libc follows POSIX and
      stops looking for options upon reaching the first non-option argument.
      As a result, the '-T' option is misinterpreted as a positional argument,
      and the build fails:
      
        make -f ./scripts/Makefile.modpost
           scripts/mod/modpost   -E   -o Module.symvers vmlinux.o -T modules.order
        -T: No such file or directory
        make[1]: *** [scripts/Makefile.modpost:137: Module.symvers] Error 1
        make: *** [Makefile:1960: modpost] Error 2
      
      The fix is to move all options before 'vmlinux.o' in modpost-args.
      
      Fixes: 3d57e1b7 ("kbuild: refactor the prerequisites of the modpost rule")
      Signed-off-by: NSamuel Holland <samuel@sholland.org>
      Reviewed-by: NNathan Chancellor <nathan@kernel.org>
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      63ffe00d
  2. 14 12月, 2022 2 次提交
  3. 22 11月, 2022 1 次提交
  4. 27 10月, 2022 1 次提交
  5. 14 10月, 2022 1 次提交
  6. 02 10月, 2022 1 次提交
  7. 29 9月, 2022 3 次提交
  8. 29 5月, 2022 1 次提交
    • M
      kbuild: do not create *.prelink.o for Clang LTO or IBT · c25e1c55
      Masahiro Yamada 提交于
      When CONFIG_LTO_CLANG=y, additional intermediate *.prelink.o is created
      for each module. Also, objtool is postponed until LLVM IR is converted
      to ELF.
      
      CONFIG_X86_KERNEL_IBT works in a similar way to postpone objtool until
      objects are merged together.
      
      This commit stops generating *.prelink.o, so the build flow will look
      similar with/without LTO.
      
      The following figures show how the LTO build currently works, and
      how this commit is changing it.
      
      Current build flow
      ==================
      
       [1] single-object module
      
                                            $(LD)
                 $(CC)                     +objtool              $(LD)
          foo.c --------------------> foo.o -----> foo.prelink.o -----> foo.ko
                                    (LLVM IR)          (ELF)       |    (ELF)
                                                                   |
                                                       foo.mod.o --/
                                                       (LLVM IR)
      
       [2] multi-object module
                                            $(LD)
                 $(CC)         $(AR)       +objtool               $(LD)
          foo1.c -----> foo1.o -----> foo.o -----> foo.prelink.o -----> foo.ko
                                 |  (archive)          (ELF)       |    (ELF)
          foo2.c -----> foo2.o --/                                 |
                       (LLVM IR)                       foo.mod.o --/
                                                       (LLVM IR)
      
        One confusion is that foo.o in multi-object module is an archive
        despite of its suffix.
      
      New build flow
      ==============
      
       [1] single-object module
      
        Since there is only one object, there is no need to keep the LLVM IR.
        Use $(CC)+$(LD) to generate an ELF object in one build rule. When LTO
        is disabled, $(LD) is unneeded because $(CC) produces an ELF object.
      
                     $(CC)+$(LD)+objtool              $(LD)
          foo.c ----------------------------> foo.o ---------> foo.ko
                                              (ELF)     |      (ELF)
                                                        |
                                            foo.mod.o --/
                                            (LLVM IR)
      
       [2] multi-object module
      
        Previously, $(AR) was used to combine LLVM IR files into an archive,
        but there was no technical reason to do so. Use $(LD) to merge them
        into a single ELF object.
      
                                     $(LD)
                   $(CC)            +objtool          $(LD)
          foo1.c ---------> foo1.o ---------> foo.o ---------> foo.ko
                                       |      (ELF)     |      (ELF)
          foo2.c ---------> foo2.o ----/                |
                           (LLVM IR)        foo.mod.o --/
                                            (LLVM IR)
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: NNicolas Schier <nicolas@fjasle.eu>
      Tested-by: NNathan Chancellor <nathan@kernel.org>
      Reviewed-by: NSami Tolvanen <samitolvanen@google.com>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
      Acked-by: NJosh Poimboeuf <jpoimboe@kernel.org>
      c25e1c55
  9. 27 5月, 2022 2 次提交
  10. 19 9月, 2021 1 次提交
  11. 03 9月, 2021 1 次提交
  12. 25 4月, 2021 3 次提交
    • M
      kbuild: fix false-positive modpost warning when all symbols are trimmed · 4475dff5
      Masahiro Yamada 提交于
      Nathan reports that the mips defconfig emits the following warning:
      
        WARNING: modpost: Symbol info of vmlinux is missing. Unresolved symbol check will be entirely skipped.
      
      This false-positive happens when CONFIG_TRIM_UNUSED_KSYMS is enabled,
      but no CONFIG option is set to 'm'.
      
      Commit a0590473 ("nfs: fix PNFS_FLEXFILE_LAYOUT Kconfig default")
      turned the last 'm' into 'y' for the mips defconfig, and uncovered
      this issue.
      
      In this case, the module feature itself is enabled, but we have no
      module to build. As a result, CONFIG_TRIM_UNUSED_KSYMS drops all the
      instances of EXPORT_SYMBOL. Then, modpost wrongly assumes vmlinux is
      missing because vmlinux.symvers is empty. (As another false-positive
      case, you can create a module that does not use any symbol of vmlinux).
      
      The current behavior is to entirely suppress the unresolved symbol
      warnings when vmlinux is missing just because there are too many.
      I found the origin of this code in the historical git tree. [1]
      
      If this is a matter of noisiness, I think modpost can display the
      first 10 warnings, and the number of suppressed warnings at the end.
      
      You will get a bit noisier logs when you run 'make modules' without
      vmlinux, but such warnings are better to show because you never know
      the resulting modules are actually loadable or not.
      
      This commit changes the following:
      
       - If any of input *.symver files is missing, pass -w option to let
         the module build keep going with warnings instead of errors.
      
       - If there are too many (10+) unresolved symbol warnings, show only
         the first 10, and also the number of suppressed warnings.
      
      [1]: https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=1cc0e0529569bf6a94f6d49770aa6d4b599d2c46Reported-by: NNathan Chancellor <nathan@kernel.org>
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      4475dff5
    • M
      kbuild: do not set -w for vmlinux.o modpost · 5ab70ff4
      Masahiro Yamada 提交于
      The -w option is meaningless for the first pass of modpost (vmlinux.o).
      
      We know there are unresolved symbols in vmlinux.o, hence we skip
      check_exports() and other checks when mod->is_vmlinux is set.
      
      See the following part in the for-loop.
      
          if (mod->is_vmlinux || mod->from_dump)
                  continue;
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      5ab70ff4
    • M
      kbuild: generate Module.symvers only when vmlinux exists · 69bc8d38
      Masahiro Yamada 提交于
      The external module build shows the following warning if Module.symvers
      is missing in the kernel tree.
      
        WARNING: Symbol version dump "Module.symvers" is missing.
                 Modules may not have dependencies or modversions.
      
      I think this is an important heads-up because the resulting modules may
      not work as expected. This happens when you did not build the entire
      kernel tree, for example, you might have prepared the minimal setups
      for external modules by 'make defconfig && make modules_preapre'.
      
      A problem is that 'make modules' creates Module.symvers even without
      vmlinux. In this case, that warning is suppressed since Module.symvers
      already exists in spite of its incomplete content.
      
      The incomplete (i.e. invalid) Module.symvers should not be created.
      
      This commit changes the second pass of modpost to dump symbols into
      modules-only.symvers. The final Module.symvers is created by
      concatenating vmlinux.symvers and modules-only.symvers if both exist.
      
      Module.symvers is supposed to collect symbols from both vmlinux and
      modules. It might be a bit confusing, and I am not quite sure if it
      is an official interface, but presumably it is difficult to rename it
      because some tools (e.g. kmod) parse it.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      69bc8d38
  13. 15 3月, 2021 1 次提交
    • M
      kbuild: prefix $(srctree)/ to some included Makefiles · 3204a7fb
      Masahiro Yamada 提交于
      VPATH is used in Kbuild to make pattern rules search for prerequisites
      in both $(objtree) and $(srctree). Some of *.c, *.S files are not real
      sources, but generated by tools such as flex, bison, perl.
      
      In contrast, I doubt the benefit of --include-dir=$(abs_srctree) because
      it is always clear which Makefiles are real sources, and which are not.
      
      So, my hope is to add $(srctree)/ prefix to all check-in Makefiles,
      then remove --include-dir=$(abs_srctree) flag in the future.
      
      I am touching only some Kbuild core parts for now. Treewide fixes will
      be needed to achieve this goal.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      3204a7fb
  14. 15 1月, 2021 2 次提交
  15. 02 8月, 2020 1 次提交
  16. 06 6月, 2020 9 次提交
  17. 03 6月, 2020 3 次提交
    • M
      modpost: pass -N option only for modules modpost · 4e5ab74c
      Masahiro Yamada 提交于
      The built-in only code is not required to have MODULE_IMPORT_NS() to
      use symbols. So, the namespace is not checked for vmlinux(.o).
      
      Do not pass the meaningless -N option to the first pass of modpost.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      4e5ab74c
    • M
      modpost: move -T option close to the modpost command · 89d61176
      Masahiro Yamada 提交于
      The '-T -' option reads the file list from stdin.
      
      It is clearer to put it close to the piped command.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      89d61176
    • M
      modpost: fix -i (--ignore-errors) MAKEFLAGS detection · 91e6ee58
      Masahiro Yamada 提交于
      $(filter -i,$(MAKEFLAGS)) works only in limited use-cases.
      
      The representation of $(MAKEFLAGS) depends on various factors:
        - GNU Make version (version 3.8x or version 4.x)
        - The presence of other flags like -j
      
      In my experiments, $(MAKEFLAGS) is expanded as follows:
      
        * GNU Make 3.8x:
      
          * without -j option:
            --no-print-directory -Rri
      
          * with -j option:
            --no-print-directory -Rr --jobserver-fds=3,4 -j -i
      
        * GNU Make 4.x:
      
          * without -j option:
            irR --no-print-directory
      
          * with -j option:
            irR -j --jobserver-fds=3,4 --no-print-directory
      
      For GNU Make 4.x, the flags are grouped as 'irR', which does not work.
      
      For the single thread build with GNU Make 3.8x, the flags are grouped
      as '-Rri', which does not work either.
      
      To make it work for all cases, do likewise as commit 6f0fa58e
      ("kbuild: simplify silent build (-s) detection").
      
      BTW, since commit ff9b45c5 ("kbuild: modpost: read modules.order
      instead of $(MODVERDIR)/*.mod"), you also need to pass -k option to
      build final *.ko files. 'make -i -k' ignores compile errors in modules,
      and build as many remaining *.ko as possible.
      
      Please note this feature is kind of dangerous if other modules depend
      on the broken module because the generated modules will lack the correct
      module dependency or CRC. Honestly, I am not a big fan of it, but I am
      keeping this feature.
      
      Fixes: eed380f3 ("modpost: Optionally ignore secondary errors seen if a single module build fails")
      Cc: Guenter Roeck <linux@roeck-us.net>
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      91e6ee58
  18. 29 5月, 2020 1 次提交
    • M
      kbuild: disallow multi-word in M= or KBUILD_EXTMOD · e9e81b63
      Masahiro Yamada 提交于
      $(firstword ...) in scripts/Makefile.modpost was added by commit
      3f3fd3c0 ("[PATCH] kbuild: allow multi-word $M in Makefile.modpost")
      to build multiple external module directories.
      
      It was a solution to resolve symbol dependencies when an external
      module depends on another external module.
      
      Commit 0d96fb20 ("kbuild: Add new Kbuild variable
      KBUILD_EXTRA_SYMBOLS") introduced another solution by passing symbol
      info via KBUILD_EXTRA_SYMBOLS, then broke the multi-word M= support.
      
        include $(if $(wildcard $(KBUILD_EXTMOD)/Kbuild), \
                     $(KBUILD_EXTMOD)/Kbuild, $(KBUILD_EXTMOD)/Makefile)
      
      ... does not work if KBUILD_EXTMOD contains multiple words.
      
      This feature has been broken for more than a decade. Remove the
      bitrotten code, and stop parsing if M or KBUILD_EXTMOD contains
      multiple words.
      
      As Documentation/kbuild/modules.rst explains, if your module depends
      on another one, there are two solutions:
        - add a common top-level Kbuild file
        - use KBUILD_EXTRA_SYMBOLS
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      e9e81b63
  19. 13 3月, 2020 1 次提交
  20. 16 1月, 2020 1 次提交
  21. 11 11月, 2019 3 次提交