Skip to content
Snippets Groups Projects
  1. Nov 27, 2024
  2. Oct 07, 2024
  3. Sep 20, 2024
    • Kris Van Hees's avatar
      kbuild: generate offset range data for builtin modules · 5f5e7344
      Kris Van Hees authored
      
      Create file module.builtin.ranges that can be used to find where
      built-in modules are located by their addresses. This will be useful for
      tracing tools to find what functions are for various built-in modules.
      
      The offset range data for builtin modules is generated using:
       - modules.builtin: associates object files with module names
       - vmlinux.map: provides load order of sections and offset of first member
          per section
       - vmlinux.o.map: provides offset of object file content per section
       - .*.cmd: build cmd file with KBUILD_MODFILE
      
      The generated data will look like:
      
      .text 00000000-00000000 = _text
      .text 0000baf0-0000cb10 amd_uncore
      .text 0009bd10-0009c8e0 iosf_mbi
      ...
      .text 00b9f080-00ba011a intel_skl_int3472_discrete
      .text 00ba0120-00ba03c0 intel_skl_int3472_discrete intel_skl_int3472_tps68470
      .text 00ba03c0-00ba08d6 intel_skl_int3472_tps68470
      ...
      .data 00000000-00000000 = _sdata
      .data 0000f020-0000f680 amd_uncore
      
      For each ELF section, it lists the offset of the first symbol.  This can
      be used to determine the base address of the section at runtime.
      
      Next, it lists (in strict ascending order) offset ranges in that section
      that cover the symbols of one or more builtin modules.  Multiple ranges
      can apply to a single module, and ranges can be shared between modules.
      
      The CONFIG_BUILTIN_MODULE_RANGES option controls whether offset range data
      is generated for kernel modules that are built into the kernel image.
      
      How it works:
      
       1. The modules.builtin file is parsed to obtain a list of built-in
          module names and their associated object names (the .ko file that
          the module would be in if it were a loadable module, hereafter
          referred to as <kmodfile>).  This object name can be used to
          identify objects in the kernel compile because any C or assembler
          code that ends up into a built-in module will have the option
          -DKBUILD_MODFILE=<kmodfile> present in its build command, and those
          can be found in the .<obj>.cmd file in the kernel build tree.
      
          If an object is part of multiple modules, they will all be listed
          in the KBUILD_MODFILE option argument.
      
          This allows us to conclusively determine whether an object in the
          kernel build belong to any modules, and which.
      
       2. The vmlinux.map is parsed next to determine the base address of each
          top level section so that all addresses into the section can be
          turned into offsets.  This makes it possible to handle sections
          getting loaded at different addresses at system boot.
      
          We also determine an 'anchor' symbol at the beginning of each
          section to make it possible to calculate the true base address of
          a section at runtime (i.e. symbol address - symbol offset).
      
          We collect start addresses of sections that are included in the top
          level section.  This is used when vmlinux is linked using vmlinux.o,
          because in that case, we need to look at the vmlinux.o linker map to
          know what object a symbol is found in.
      
          And finally, we process each symbol that is listed in vmlinux.map
          (or vmlinux.o.map) based on the following structure:
      
          vmlinux linked from vmlinux.a:
      
            vmlinux.map:
              <top level section>
                <included section>  -- might be same as top level section)
                  <object>          -- built-in association known
                    <symbol>        -- belongs to module(s) object belongs to
                    ...
      
          vmlinux linked from vmlinux.o:
      
            vmlinux.map:
              <top level section>
                <included section>  -- might be same as top level section)
                  vmlinux.o         -- need to use vmlinux.o.map
                    <symbol>        -- ignored
                    ...
      
            vmlinux.o.map:
              <section>
                  <object>          -- built-in association known
                    <symbol>        -- belongs to module(s) object belongs to
                    ...
      
       3. As sections, objects, and symbols are processed, offset ranges are
          constructed in a straight-forward way:
      
            - If the symbol belongs to one or more built-in modules:
                - If we were working on the same module(s), extend the range
                  to include this object
                - If we were working on another module(s), close that range,
                  and start the new one
            - If the symbol does not belong to any built-in modules:
                - If we were working on a module(s) range, close that range
      
      Signed-off-by: default avatarKris Van Hees <kris.van.hees@oracle.com>
      Reviewed-by: default avatarNick Alcock <nick.alcock@oracle.com>
      Reviewed-by: default avatarAlan Maguire <alan.maguire@oracle.com>
      Reviewed-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Tested-by: default avatarSam James <sam@gentoo.org>
      Reviewed-by: default avatarSami Tolvanen <samitolvanen@google.com>
      Tested-by: default avatarSami Tolvanen <samitolvanen@google.com>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      5f5e7344
  4. Sep 01, 2024
    • Masahiro Yamada's avatar
      kbuild: remove *.symversions left-over · 87af9388
      Masahiro Yamada authored
      
      Commit 5ce2176b ("genksyms: adjust the output format to modpost")
      stopped generating *.symversions files.
      
      Remove the left-over from the .gitignore file and the 'clean' rule.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: default avatarNathan Chancellor <nathan@kernel.org>
      87af9388
    • Laurent Pinchart's avatar
      Remove *.orig pattern from .gitignore · 76be4f5a
      Laurent Pinchart authored
      
      Commit 3f1b0e1f (".gitignore update") added *.orig and *.rej
      patterns to .gitignore in v2.6.23. The commit message didn't give a
      rationale. Later on, commit 1f5d3a6b ("Remove *.rej pattern from
      .gitignore") removed the *.rej pattern in v2.6.26, on the rationale that
      *.rej files indicated something went really wrong and should not be
      ignored.
      
      The *.rej files are now shown by `git status`, which helps located
      conflicts when applying patches and lowers the probability that they
      will go unnoticed. It is however still easy to overlook the *.orig files
      which slowly polute the source tree. That's not as big of a deal as not
      noticing a conflict, but it's still not nice.
      
      Drop the *.orig pattern from .gitignore to avoid this and help keep the
      source tree clean.
      
      Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
      [masahiroy@kernel.org:
      I do not have a strong opinion about this. Perhaps some people may have
      a different opinion.
      
      If you are someone who wants to ignore *.orig, it is likely you would
      want to do so across all projects. Then, $XDG_CONFIG_HOME/git/ignore
      would be more suitable for your needs. gitignore(5) suggests, "Patterns
      which a user wants Git to ignore in all situations generally go into a
      file specified by core.excludesFile in the user's ~/.gitconfig".
      
      Please note that you cannot do the opposite; if *.orig is ignored by
      the project's .gitignore, you cannot override the decision because
      $XDG_CONFIG_HOME/git/ignore has a lower priority.
      
      If *.orig is sitting on the fence, I'd leave it to the users. ]
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      76be4f5a
  5. Aug 09, 2024
  6. Jul 21, 2024
  7. Feb 19, 2024
    • Masahiro Yamada's avatar
      kbuild: create a list of all built DTB files · 24507871
      Masahiro Yamada authored
      
      It is useful to have a list of all *.dtb and *.dtbo files generated
      from the current build.
      
      With this commit, 'make dtbs' creates arch/*/boot/dts/dtbs-list, which
      lists the dtb(o) files created in the current build. It maintains the
      order of the dtb-y additions in Makefiles although the order is not
      important for DTBs. It is a (good) side effect through the reuse of the
      modules.order rule.
      
      Please note this list only includes the files directly added to dtb-y.
      
      For example, consider this case:
      
          foo-dtbs := foo_base.dtb foo_overlay.dtbo
          dtb-y := foo.dtb
      
      In this example, the list will include foo.dtb, but not foo_base.dtb
      or foo_overlay.dtbo.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      24507871
  8. Dec 28, 2023
  9. Oct 03, 2023
  10. Jul 24, 2023
  11. Jul 04, 2023
  12. 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
  13. Apr 20, 2023
  14. Apr 05, 2023
  15. Mar 16, 2023
  16. Feb 05, 2023
  17. 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
  18. Dec 30, 2022
  19. Nov 18, 2022
  20. Sep 28, 2022
  21. 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
  22. May 01, 2021
  23. 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
  24. Feb 04, 2021
  25. Jan 14, 2021
  26. Sep 10, 2020
  27. Jul 31, 2020
  28. Jul 05, 2020
  29. 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
  30. Mar 25, 2020
  31. Mar 02, 2020
  32. Feb 20, 2020
  33. Nov 11, 2019
  34. Sep 10, 2019
  35. Aug 21, 2019
Loading