Skip to content
Snippets Groups Projects
  1. Apr 17, 2023
  2. Apr 08, 2023
  3. Nov 13, 2022
    • Zhen Lei's avatar
      kallsyms: Correctly sequence symbols when CONFIG_LTO_CLANG=y · 010a0aad
      Zhen Lei authored
      
      LLVM appends various suffixes for local functions and variables, suffixes
      observed:
       - foo.llvm.[0-9a-f]+
       - foo.[0-9a-f]+
      
      Therefore, when CONFIG_LTO_CLANG=y, kallsyms_lookup_name() needs to
      truncate the suffix of the symbol name before comparing the local function
      or variable name.
      
      Old implementation code:
      -	if (strcmp(namebuf, name) == 0)
      -		return kallsyms_sym_address(i);
      -	if (cleanup_symbol_name(namebuf) && strcmp(namebuf, name) == 0)
      -		return kallsyms_sym_address(i);
      
      The preceding process is traversed by address from low to high. That is,
      for those with the same name after the suffix is removed, the one with
      the smallest address is returned first. Therefore, when sorting in the
      tool, if the raw names are the same, they should be sorted by address in
      ascending order.
      
      ASCII[.]   = 2e
      ASCII[0-9] = 30,39
      ASCII[A-Z] = 41,5a
      ASCII[_]   = 5f
      ASCII[a-z] = 61,7a
      
      According to the preceding ASCII code values, the following sorting result
      is strictly followed.
       ---------------------------------
      |    main-key     |    sub-key    |
      |---------------------------------|
      |                 |  addr_lowest  |
      | <name>          |      ...      |
      | <name>.<suffix> |      ...      |
      |                 |  addr_highest |
      |---------------------------------|
      | <name>?<others> |               |   //? is [_A-Za-z0-9]
       ---------------------------------
      
      Signed-off-by: default avatarZhen Lei <thunder.leizhen@huawei.com>
      Signed-off-by: default avatarLuis Chamberlain <mcgrof@kernel.org>
      010a0aad
  4. Oct 02, 2022
  5. Sep 28, 2022
    • Masahiro Yamada's avatar
      kbuild: unify two modpost invocations · f73edc89
      Masahiro Yamada authored
      
      Currently, modpost is executed twice; first for vmlinux, second
      for modules.
      
      This commit merges them.
      
      Current build flow
      ==================
      
        1) build obj-y and obj-m objects
          2) link vmlinux.o
            3) modpost for vmlinux
              4) link vmlinux
                5) modpost for modules
                  6) link modules (*.ko)
      
      The build steps 1) through 6) are serialized, that is, modules are
      built after vmlinux. You do not get benefits of parallel builds when
      scripts/link-vmlinux.sh is being run.
      
      New build flow
      ==============
      
        1) build obj-y and obj-m objects
          2) link vmlinux.o
            3) modpost for vmlinux and modules
              4a) link vmlinux
              4b) link modules (*.ko)
      
      In the new build flow, modpost is invoked just once.
      
      vmlinux and modules are built in parallel. One exception is
      CONFIG_DEBUG_INFO_BTF_MODULES=y, where modules depend on vmlinux.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Tested-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Reviewed-by: default avatarNicolas Schier <nicolas@fjasle.eu>
      f73edc89
    • Masahiro Yamada's avatar
      kbuild: move vmlinux.o rule to the top Makefile · 9c5a0ac3
      Masahiro Yamada authored
      
      Move the build rules of vmlinux.o out of scripts/link-vmlinux.sh to
      clearly separate 1) pre-modpost, 2) modpost, 3) post-modpost stages.
      This will make further refactoring possible.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Tested-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Reviewed-by: default avatarNicolas Schier <nicolas@fjasle.eu>
      9c5a0ac3
    • Masahiro Yamada's avatar
      kbuild: move .vmlinux.objs rule to Makefile.modpost · 26ef40de
      Masahiro Yamada authored
      
      .vmlinux.objs is used by modpost, so scripts/Makefile.modpost is
      a better place to generate it.
      
      It is used only when CONFIG_MODVERSIONS=y. It should be guarded
      by "ifdef CONFIG_MODVERSIONS".
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Tested-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Reviewed-by: default avatarNicolas Schier <nicolas@fjasle.eu>
      26ef40de
    • Masahiro Yamada's avatar
      kbuild: build init/built-in.a just once · 2df8220c
      Masahiro Yamada authored
      
      Kbuild builds init/built-in.a twice; first during the ordinary
      directory descending, second from scripts/link-vmlinux.sh.
      
      We do this because UTS_VERSION contains the build version and the
      timestamp. We cannot update it during the normal directory traversal
      since we do not yet know if we need to update vmlinux. UTS_VERSION is
      temporarily calculated, but omitted from the update check. Otherwise,
      vmlinux would be rebuilt every time.
      
      When Kbuild results in running link-vmlinux.sh, it increments the
      version number in the .version file and takes the timestamp at that
      time to really fix UTS_VERSION.
      
      However, updating the same file twice is a footgun. To avoid nasty
      timestamp issues, all build artifacts that depend on init/built-in.a
      are atomically generated in link-vmlinux.sh, where some of them do not
      need rebuilding.
      
      To fix this issue, this commit changes as follows:
      
      [1] Split UTS_VERSION out to include/generated/utsversion.h from
          include/generated/compile.h
      
          include/generated/utsversion.h is generated just before the
          vmlinux link. It is generated under include/generated/ because
          some decompressors (s390, x86) use UTS_VERSION.
      
      [2] Split init_uts_ns and linux_banner out to init/version-timestamp.c
          from init/version.c
      
          init_uts_ns and linux_banner contain UTS_VERSION. During the ordinary
          directory descending, they are compiled with __weak and used to
          determine if vmlinux needs relinking. Just before the vmlinux link,
          they are compiled without __weak to embed the real version and
          timestamp.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      2df8220c
  6. Jun 04, 2022
    • Masahiro Yamada's avatar
      kbuild: factor out the common objtool arguments · b42d2306
      Masahiro Yamada authored
      
      scripts/Makefile.build and scripts/link-vmlinux.sh have similar setups
      for the objtool arguments.
      
      It was difficult to factor out them because all the vmlinux build rules
      were written in a shell script. It is somewhat tedious to touch the two
      files every time a new objtool option is supported.
      
      To reduce the code duplication, move the objtool for vmlinux.o into
      scripts/Makefile.vmlinux_o. Then, move the common macros to Makefile.lib
      so they are shared between Makefile.build and Makefile.vmlinux_o.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
      b42d2306
    • Masahiro Yamada's avatar
      kbuild: move vmlinux.o link to scripts/Makefile.vmlinux_o · 5d45950d
      Masahiro Yamada authored
      
      This is a preparation for moving the objtool rule in the next commit.
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
      5d45950d
    • Masahiro Yamada's avatar
      kbuild: clean .tmp_* pattern by make clean · b0d6207b
      Masahiro Yamada authored
      
      Change the "make clean" rule to remove all the .tmp_* files.
      
      .tmp_objdiff is the only exception, which should be removed by
      "make mrproper".
      
      Rename the record directory of objdiff, .tmp_objdiff to .objdiff to
      avoid the removal by "make clean".
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)
      b0d6207b
  7. Jun 01, 2022
  8. May 29, 2022
  9. May 27, 2022
  10. May 24, 2022
    • Masahiro Yamada's avatar
      kbuild: stop merging *.symversions · 7375cbcf
      Masahiro Yamada authored
      
      Now modpost reads symbol versions from .*.cmd files.
      
      The merged *.symversions are no longer needed.
      
      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)
      7375cbcf
    • 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
  11. May 11, 2022
  12. Apr 22, 2022
  13. Apr 19, 2022
  14. Apr 04, 2022
  15. Apr 01, 2022
  16. Mar 15, 2022
  17. Jan 13, 2022
  18. Jan 08, 2022
    • Masahiro Yamada's avatar
      kbuild: do not include include/config/auto.conf from shell scripts · 7d153696
      Masahiro Yamada authored
      Richard Weinberger pointed out the risk of sourcing the kernel config
      from shell scripts [1], and proposed some patches [2], [3]. It is a good
      point, but it took a long time because I was wondering how to fix this.
      
      This commit goes with simple grep approach because there are only a few
      scripts including the kernel configuration.
      
      scripts/link_vmlinux.sh has references to a bunch of CONFIG options,
      all of which are boolean. I added is_enabled() helper as
      scripts/package/{mkdebian,builddeb} do.
      
      scripts/gen_autoksyms.sh uses 'eval', stating "to expand the whitelist
      path". I removed it since it is the issue we are trying to fix.
      
      I was a bit worried about the cost of invoking the grep command over
      again. I extracted the grep parts from it, and measured the cost. It
      was approximately 0.03 sec, which I hope is acceptable.
      
      [test code]
      
        $ cat test-grep.sh
        #!/bin/sh
      
        is_enabled() {
                grep -q "^$1=y" include/config/auto.conf
        }
      
        is_enabled CONFIG_LTO_CLANG
        is_enabled CONFIG_LTO_CLANG
        is_enabled CONFIG_STACK_VALIDATION
        is_enabled CONFIG_UNWINDER_ORC
        is_enabled CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
        is_enabled CONFIG_VMLINUX_VALIDATION
        is_enabled CONFIG_FRAME_POINTER
        is_enabled CONFIG_GCOV_KERNEL
        is_enabled CONFIG_LTO_CLANG
        is_enabled CONFIG_RETPOLINE
        is_enabled CONFIG_X86_SMAP
        is_enabled CONFIG_LTO_CLANG
        is_enabled CONFIG_VMLINUX_MAP
        is_enabled CONFIG_KALLSYMS_ALL
        is_enabled CONFIG_KALLSYMS_ABSOLUTE_PERCPU
        is_enabled CONFIG_KALLSYMS_BASE_RELATIVE
        is_enabled CONFIG_DEBUG_INFO_BTF
        is_enabled CONFIG_KALLSYMS
        is_enabled CONFIG_DEBUG_INFO_BTF
        is_enabled CONFIG_BPF
        is_enabled CONFIG_BUILDTIME_TABLE_SORT
        is_enabled CONFIG_KALLSYMS
      
        $ time ./test-grep.sh
        real    0m0.036s
        user    0m0.027s
        sys     m0.009s
      
      [1]: https://lore.kernel.org/all/1919455.eZKeABUfgV@blindfold/
      [2]: https://lore.kernel.org/all/20180219092245.26404-1-richard@nod.at/
      [3]: https://lore.kernel.org/all/20210920213957.1064-2-richard@nod.at/
      
      
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Reviewed-by: default avatarNicolas Schier <n.schier@avm.de>
      7d153696
  19. Dec 09, 2021
  20. Nov 02, 2021
Loading