Skip to content
Snippets Groups Projects
  1. Dec 28, 2023
  2. Oct 03, 2023
  3. Jul 24, 2023
  4. Jul 04, 2023
  5. Jun 22, 2023
    • Masahiro Yamada's avatar
      kbuild: implement CONFIG_TRIM_UNUSED_KSYMS without recursion · 5e9e95cc
      Masahiro Yamada authored
      When CONFIG_TRIM_UNUSED_KSYMS is enabled, Kbuild recursively traverses
      the directory tree to determine which EXPORT_SYMBOL to trim. If an
      EXPORT_SYMBOL turns out to be unused by anyone, Kbuild begins the
      second traverse, where some source files are recompiled with their
      EXPORT_SYMBOL() tuned into a no-op.
      
      Linus stated negative opinions about this slowness in commits:
      
       - 5cf0fd59 ("Kbuild: disable TRIM_UNUSED_KSYMS option")
       - a555bdd0 ("Kbuild: enable TRIM_UNUSED_KSYMS again, with some guarding")
      
      We can do this better now. The final data structures of EXPORT_SYMBOL
      are generated by the modpost stage, so modpost can selectively emit
      KSYMTAB entries that are really used by modules.
      
      Commit f73edc89 ("kbuild: unify two modpost invocations") is another
      ground-work to do this in a one-pass algorithm. With the list of modules,
      modpost sets sym->used if it is used by a module. modpost emits KSYMTAB
      only for symbols with sym->used==true.
      
      BTW, Nicolas explained why the trimming was implemented with recursion:
      
        https://lore.kernel.org/all/2o2rpn97-79nq-p7s2-nq5-8p83391473r@syhkavp.arg/
      
      
      
      Actually, we never achieved that level of optimization where the chain
      reaction of trimming comes into play because:
      
       - CONFIG_LTO_CLANG cannot remove any unused symbols
       - CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is enabled only for vmlinux,
         but not modules
      
      If deeper trimming is required, we need to revisit this, but I guess
      that is unlikely to happen.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      5e9e95cc
  6. Apr 20, 2023
  7. Apr 05, 2023
  8. Mar 16, 2023
  9. Feb 05, 2023
  10. Jan 22, 2023
    • Masahiro Yamada's avatar
      .gitignore: update the command to check tracked files being ignored · b8a9ddca
      Masahiro Yamada authored
      
      Recent git versions do not accept the noted command.
      
        $ git ls-files -i --exclude-standard
        fatal: ls-files -i must be used with either -o or -c
      
      The -c was implied before, but we need to make it explicit since
      git commit b338e9f66873 ("ls-files: error out on -i unless -o or -c
      are specified").
      
      Also, replace --exclude-standard with --exclude-per-directory=.gitignore
      so that everyone will get consistent results.
      
      git-ls-files(1) says:
      
        --exclude-standard
            Add the standard Git exclusions: .git/info/exclude, .gitignore in
            each directory, and the user's global exclusion file.
      
      We cannot predict what is locally added to .git/info/exclude or the
      user's global exclusion file.
      
      We can only manage .gitignore files committed to the repository.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: default avatarMiguel Ojeda <ojeda@kernel.org>
      b8a9ddca
  11. Dec 30, 2022
  12. Nov 18, 2022
  13. Sep 28, 2022
  14. May 07, 2022
    • Masahiro Yamada's avatar
      kbuild: split the second line of *.mod into *.usyms · 9413e764
      Masahiro Yamada authored
      
      The *.mod files have two lines; the first line lists the member objects
      of the module, and the second line, if CONFIG_TRIM_UNUSED_KSYMS=y, lists
      the undefined symbols.
      
      Currently, we generate *.mod after constructing composite modules,
      otherwise, we cannot compute the second line. No prerequisite is
      required to print the first line.
      
      They are orthogonal. Splitting them into separate commands will ease
      further cleanups.
      
      This commit splits the list of undefined symbols out to *.usyms files.
      
      Previously, the list of undefined symbols ended up with a very long
      line, but now it has one symbol per line.
      
      Use sed like we did before commit 7d32358b ("kbuild: avoid split
      lines in .mod files").
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: default avatarNicolas Schier <nicolas@fjasle.eu>
      9413e764
  15. May 01, 2021
  16. Apr 24, 2021
    • Masahiro Yamada's avatar
      kbuild: generate Module.symvers only when vmlinux exists · 69bc8d38
      Masahiro Yamada authored
      
      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: default avatarMasahiro Yamada <masahiroy@kernel.org>
      69bc8d38
    • 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
  17. Feb 04, 2021
  18. Jan 14, 2021
  19. Sep 10, 2020
  20. Jul 31, 2020
  21. Jul 05, 2020
  22. 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
  23. Mar 25, 2020
  24. Mar 02, 2020
  25. Feb 20, 2020
  26. Nov 11, 2019
  27. Sep 10, 2019
  28. Aug 21, 2019
  29. Jul 27, 2019
  30. Jul 17, 2019
    • Masahiro Yamada's avatar
      kbuild: create *.mod with full directory path and remove MODVERDIR · b7dca6dd
      Masahiro Yamada authored
      While descending directories, Kbuild produces objects for modules,
      but do not link final *.ko files; it is done in the modpost.
      
      To keep track of modules, Kbuild creates a *.mod file in $(MODVERDIR)
      for every module it is building. Some post-processing steps read the
      necessary information from *.mod files. This avoids descending into
      directories again. This mechanism was introduced in 2003 or so.
      
      Later, commit 551559e1 ("kbuild: implement modules.order") added
      modules.order. So, we can simply read it out to know all the modules
      with directory paths. This is easier than parsing the first line of
      *.mod files.
      
      $(MODVERDIR) has a flat directory structure, that is, *.mod files
      are named only with base names. This is based on the assumption that
      the module name is unique across the tree. This assumption is really
      fragile.
      
      Stephen Rothwell reported a race condition caused by a module name
      conflict:
      
        https://lkml.org/lkml/2019/5/13/991
      
      
      
      In parallel building, two different threads could write to the same
      $(MODVERDIR)/*.mod simultaneously.
      
      Non-unique module names are the source of all kind of troubles, hence
      commit 3a48a919 ("kbuild: check uniqueness of module names")
      introduced a new checker script.
      
      However, it is still fragile in the build system point of view because
      this race happens before scripts/modules-check.sh is invoked. If it
      happens again, the modpost will emit unclear error messages.
      
      To fix this issue completely, create *.mod with full directory path
      so that two threads never attempt to write to the same file.
      
      $(MODVERDIR) is no longer needed.
      
      Since modules with directory paths are listed in modules.order, Kbuild
      is still able to find *.mod files without additional descending.
      
      I also killed cmd_secanalysis; scripts/mod/sumversion.c computes MD4 hash
      for modules with MODULE_VERSION(). When CONFIG_DEBUG_SECTION_MISMATCH=y,
      it occurs not only in the modpost stage, but also during directory
      descending, where sumversion.c may parse stale *.mod files. It would emit
      'No such file or directory' warning when an object consisting a module is
      renamed, or when a single-obj module is turned into a multi-obj module or
      vice versa.
      
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Acked-by: default avatarNicolas Pitre <nico@fluxnic.net>
      b7dca6dd
  31. Jul 09, 2019
    • 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
  32. Jun 15, 2019
  33. May 18, 2019
  34. May 08, 2019
  35. May 07, 2019
    • Alexey Gladkov's avatar
      moduleparam: Save information about built-in modules in separate file · 898490c0
      Alexey Gladkov authored
      
      Problem:
      
      When a kernel module is compiled as a separate module, some important
      information about the kernel module is available via .modinfo section of
      the module.  In contrast, when the kernel module is compiled into the
      kernel, that information is not available.
      
      Information about built-in modules is necessary in the following cases:
      
      1. When it is necessary to find out what additional parameters can be
      passed to the kernel at boot time.
      
      2. When you need to know which module names and their aliases are in
      the kernel. This is very useful for creating an initrd image.
      
      Proposal:
      
      The proposed patch does not remove .modinfo section with module
      information from the vmlinux at the build time and saves it into a
      separate file after kernel linking. So, the kernel does not increase in
      size and no additional information remains in it. Information is stored
      in the same format as in the separate modules (null-terminated string
      array). Because the .modinfo section is already exported with a separate
      modules, we are not creating a new API.
      
      It can be easily read in the userspace:
      
      $ tr '\0' '\n' < modules.builtin.modinfo
      ext4.softdep=pre: crc32c
      ext4.license=GPL
      ext4.description=Fourth Extended Filesystem
      ext4.author=Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others
      ext4.alias=fs-ext4
      ext4.alias=ext3
      ext4.alias=fs-ext3
      ext4.alias=ext2
      ext4.alias=fs-ext2
      md_mod.alias=block-major-9-*
      md_mod.alias=md
      md_mod.description=MD RAID framework
      md_mod.license=GPL
      md_mod.parmtype=create_on_open:bool
      md_mod.parmtype=start_dirty_degraded:int
      ...
      
      Co-Developed-by: default avatarGleb Fotengauer-Malinovskiy <glebfm@altlinux.org>
      Signed-off-by: default avatarGleb Fotengauer-Malinovskiy <glebfm@altlinux.org>
      Signed-off-by: default avatarAlexey Gladkov <gladkov.alexey@gmail.com>
      Acked-by: default avatarJessica Yu <jeyu@kernel.org>
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      898490c0
    • Masahiro Yamada's avatar
      .gitignore: add leading and trailing slashes to generated directories · 1e35663e
      Masahiro Yamada authored
      
      Clarify these directory paths are relative to the top of the source
      tree.
      
      Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      1e35663e
Loading