1. 20 6月, 2022 1 次提交
  2. 05 6月, 2022 2 次提交
  3. 01 6月, 2022 1 次提交
    • M
      kbuild: check static EXPORT_SYMBOL* by script instead of modpost · 31cb50b5
      Masahiro Yamada 提交于
      The 'static' specifier and EXPORT_SYMBOL() are an odd combination.
      
      Commit 15bfc234 ("modpost: check for static EXPORT_SYMBOL*
      functions") tried to detect it, but this check has false negatives.
      
      Here is the sample code.
      
        Makefile:
      
          obj-y += foo1.o foo2.o
      
        foo1.c:
      
          #include <linux/export.h>
          static void foo(void) {}
          EXPORT_SYMBOL(foo);
      
        foo2.c:
      
          void foo(void) {}
      
      foo1.c exports the static symbol 'foo', but modpost cannot catch it
      because it is fooled by foo2.c, which has a global symbol with the
      same name.
      
      s->is_static is cleared if a global symbol with the same name is found
      somewhere, but EXPORT_SYMBOL() and the global symbol do not necessarily
      belong to the same compilation unit.
      
      This check should be done per compilation unit, but I do not know how
      to do it in modpost. modpost runs against vmlinux.o or modules, which
      merges multiple objects, then forgets their origin.
      
      modpost cannot parse individual objects because they may not be ELF but
      LLVM IR when CONFIG_LTO_CLANG=y.
      
      Add a simple bash script to parse the output from ${NM}. This works for
      CONFIG_LTO_CLANG=y because llvm-nm can dump symbols of LLVM IR files.
      
      Revert 15bfc234.
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: NNick Desaulniers <ndesaulniers@google.com>
      Tested-by: NNathan Chancellor <nathan@kernel.org>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
      31cb50b5
  4. 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
  5. 27 5月, 2022 5 次提交
  6. 24 5月, 2022 1 次提交
    • M
      kbuild: link symbol CRCs at final link, removing CONFIG_MODULE_REL_CRCS · 7b453719
      Masahiro Yamada 提交于
      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: NMasahiro Yamada <masahiroy@kernel.org>
      Tested-by: NNathan Chancellor <nathan@kernel.org>
      Tested-by: NNicolas Schier <nicolas@fjasle.eu>
      Reviewed-by: NNicolas Schier <nicolas@fjasle.eu>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
      7b453719
  7. 23 5月, 2022 2 次提交
    • M
      modpost: extract symbol versions from *.cmd files · f292d875
      Masahiro Yamada 提交于
      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: 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)
      f292d875
    • M
      modpost: add sym_find_with_module() helper · 69c4cc99
      Masahiro Yamada 提交于
      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: NMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: NNicolas Schier <nicolas@fjasle.eu>
      Tested-by: NNathan Chancellor <nathan@kernel.org>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
      69c4cc99
  8. 11 5月, 2022 3 次提交
  9. 08 5月, 2022 21 次提交
  10. 03 4月, 2022 1 次提交
  11. 23 3月, 2022 1 次提交
  12. 13 3月, 2022 1 次提交
    • M
      Kbuild: use -Wdeclaration-after-statement · 4d94f910
      Mark Rutland 提交于
      The kernel is moving from using `-std=gnu89` to `-std=gnu11`, permitting
      the use of additional C11 features such as for-loop initial declarations.
      
      One contentious aspect of C99 is that it permits mixed declarations and
      code, and for now at least, it seems preferable to enforce that
      declarations must come first.
      
      These warnings were already enabled in the kernel itself, but not
      for KBUILD_USERCFLAGS or the compat VDSO on arch/arm64, which uses
      a separate set of CFLAGS.
      
      This patch fixes an existing violation in modpost.c, which is not
      reported because of the missing flag in KBUILD_USERCFLAGS:
      
      | scripts/mod/modpost.c: In function ‘match’:
      | scripts/mod/modpost.c:837:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
      |   837 |   const char *endp = p + strlen(p) - 1;
      |       |   ^~~~~
      Signed-off-by: NMark Rutland <mark.rutland@arm.com>
      [arnd: don't add a duplicate flag to the default set, update changelog]
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Reviewed-by: NNathan Chancellor <nathan@kernel.org>
      Reviewed-by: NNick Desaulniers <ndesaulniers@google.com>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang v13.0.0 (x86-64)
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      4d94f910