Skip to content
  1. May 24, 2022
    • Masahiro Yamada's avatar
      kbuild: link symbol CRCs at final link, removing CONFIG_MODULE_REL_CRCS · 7b453719
      Masahiro Yamada authored
      
      
      include/{linux,asm-generic}/export.h defines a weak symbol, __crc_*
      as a placeholder.
      
      Genksyms writes the version CRCs into the linker script, which will be
      used for filling the __crc_* symbols. The linker script format depends
      on CONFIG_MODULE_REL_CRCS. If it is enabled, __crc_* holds the offset
      to the reference of CRC.
      
      It is time to get rid of this complexity.
      
      Now that modpost parses text files (.*.cmd) to collect all the CRCs,
      it can generate C code that will be linked to the vmlinux or modules.
      
      Generate a new C file, .vmlinux.export.c, which contains the CRCs of
      symbols exported by vmlinux. It is compiled and linked to vmlinux in
      scripts/link-vmlinux.sh.
      
      Put the CRCs of symbols exported by modules into the existing *.mod.c
      files. No additional build step is needed for modules. As before,
      *.mod.c are compiled and linked to *.ko in scripts/Makefile.modfinal.
      
      No linker magic is used here. The new C implementation works in the
      same way, whether CONFIG_RELOCATABLE is enabled or not.
      CONFIG_MODULE_REL_CRCS is no longer needed.
      
      Previously, Kbuild invoked additional $(LD) to update the CRCs in
      objects, but this step is unneeded too.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Tested-by: default avatarNathan Chancellor <nathan@kernel.org>
      Tested-by: default avatarNicolas Schier <nicolas@fjasle.eu>
      Reviewed-by: default avatarNicolas Schier <nicolas@fjasle.eu>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
      7b453719
  2. May 23, 2022
    • Masahiro Yamada's avatar
      modpost: extract symbol versions from *.cmd files · f292d875
      Masahiro Yamada authored
      
      
      Currently, CONFIG_MODVERSIONS needs extra link to embed the symbol
      versions into ELF objects. Then, modpost extracts the version CRCs
      from them.
      
      The following figures show how it currently works, and how I am trying
      to change it.
      
      Current implementation
      ======================
                                                                 |----------|
                       embed CRC      -------------------------->| final    |
             $(CC)       $(LD)       /  |---------|              | link for |
             -----> *.o -------> *.o -->| modpost |              | vmlinux  |
            /              /            |         |-- *.mod.c -->| or       |
           / genksyms     /             |---------|              | module   |
        *.c ------> *.symversions                                |----------|
      
      Genksyms outputs the calculated CRCs in the form of linker script
      (*.symversions), which is used by $(LD) to update the object.
      
      If CONFIG_LTO_CLANG=y, the build process is much more complex. Embedding
      the CRCs is postponed until the LLVM bitcode is converted into ELF,
      creating another intermediate *.prelink.o.
      
      However, this complexity is unneeded. There is no reason why we must
      embed version CRCs in objects so early.
      
      There is final link stage for vmlinux (scripts/link-vmlinux.sh) and
      modules (scripts/Makefile.modfinal). We can link CRCs at the very last
      moment.
      
      New implementation
      ==================
                                                                 |----------|
                         --------------------------------------->| final    |
             $(CC)      /    |---------|                         | link for |
             -----> *.o ---->|         |                         | vmlinux  |
            /                | modpost |--- .vmlinux.export.c -->| or       |
           / genksyms        |         |--- *.mod.c ------------>| module   |
        *.c ------> *.cmd -->|---------|                         |----------|
      
      Pass the symbol versions to modpost as separate text data, which are
      available in *.cmd files.
      
      This commit changes modpost to extract CRCs from *.cmd files instead of
      from ELF objects.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: default avatarNicolas Schier <nicolas@fjasle.eu>
      Tested-by: default avatarNathan Chancellor <nathan@kernel.org>
      Reviewed-by: default avatarSami Tolvanen <samitolvanen@google.com>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
      f292d875
    • Masahiro Yamada's avatar
      modpost: add sym_find_with_module() helper · 69c4cc99
      Masahiro Yamada authored
      
      
      find_symbol() returns the first symbol found in the hash table. This
      table is global, so it may return a symbol from an unexpected module.
      
      There is a case where we want to search for a symbol with a given name
      in a specified module.
      
      Add sym_find_with_module(), which receives the module pointer as the
      second argument. It is equivalent to find_module() if NULL is passed
      as the module pointer.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: default avatarNicolas Schier <nicolas@fjasle.eu>
      Tested-by: default avatarNathan Chancellor <nathan@kernel.org>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
      69c4cc99
  3. May 11, 2022
  4. May 08, 2022