An error occurred fetching the project authors.
  1. 29 May, 2024 4 commits
    • Masahiro Yamada's avatar
      kbuild: remove a stale comment about cleaning in link-vmlinux.sh · 3c562a70
      Masahiro Yamada authored
      Remove the left-over of commit 51eb95e2 ("kbuild: Don't remove
      link-vmlinux temporary files on exit/signal").
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      3c562a70
    • Masahiro Yamada's avatar
      kbuild: fix short log for AS in link-vmlinux.sh · 3430f65d
      Masahiro Yamada authored
      In convention, short logs print the output file, not the input file.
      
      Let's change the suffix for 'AS' since it assembles *.S into *.o.
      
      [Before]
      
        LD      .tmp_vmlinux.kallsyms1
        NM      .tmp_vmlinux.kallsyms1.syms
        KSYMS   .tmp_vmlinux.kallsyms1.S
        AS      .tmp_vmlinux.kallsyms1.S
        LD      .tmp_vmlinux.kallsyms2
        NM      .tmp_vmlinux.kallsyms2.syms
        KSYMS   .tmp_vmlinux.kallsyms2.S
        AS      .tmp_vmlinux.kallsyms2.S
        LD      vmlinux
      
      [After]
      
        LD      .tmp_vmlinux.kallsyms1
        NM      .tmp_vmlinux.kallsyms1.syms
        KSYMS   .tmp_vmlinux.kallsyms1.S
        AS      .tmp_vmlinux.kallsyms1.o
        LD      .tmp_vmlinux.kallsyms2
        NM      .tmp_vmlinux.kallsyms2.syms
        KSYMS   .tmp_vmlinux.kallsyms2.S
        AS      .tmp_vmlinux.kallsyms2.o
        LD      vmlinux
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      3430f65d
    • Masahiro Yamada's avatar
      kbuild: change scripts/mksysmap into sed script · b18b0470
      Masahiro Yamada authored
      The previous commit removed the subshell execution from scripts/mksysmap,
      which is now simple enough to become a sed script.
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      b18b0470
    • Masahiro Yamada's avatar
      kbuild: avoid unneeded kallsyms step 3 · 04b8cb09
      Masahiro Yamada authored
      Since commit 951bcae6 ("kallsyms: Avoid weak references for kallsyms
      symbols"), the kallsyms step 3 always occurs.
      
      You can compare the build logs.
      
      [Before 951bcae6]
      
        $ git checkout 951bcae6^
        $ make defconfig all
             [ snip ]
          LD      .tmp_vmlinux.kallsyms1
          NM      .tmp_vmlinux.kallsyms1.syms
          KSYMS   .tmp_vmlinux.kallsyms1.S
          AS      .tmp_vmlinux.kallsyms1.S
          LD      .tmp_vmlinux.kallsyms2
          NM      .tmp_vmlinux.kallsyms2.syms
          KSYMS   .tmp_vmlinux.kallsyms2.S
          AS      .tmp_vmlinux.kallsyms2.S
          LD      vmlinux
      
      [After 951bcae6]
      
        $ git checkout 951bcae6
        $ make defconfig all
             [ snip ]
          LD      .tmp_vmlinux.kallsyms1
          NM      .tmp_vmlinux.kallsyms1.syms
          KSYMS   .tmp_vmlinux.kallsyms1.S
          AS      .tmp_vmlinux.kallsyms1.S
          LD      .tmp_vmlinux.kallsyms2
          NM      .tmp_vmlinux.kallsyms2.syms
          KSYMS   .tmp_vmlinux.kallsyms2.S
          AS      .tmp_vmlinux.kallsyms2.S
          LD      .tmp_vmlinux.kallsyms3             # should not happen
          NM      .tmp_vmlinux.kallsyms3.syms        # should not happen
          KSYMS   .tmp_vmlinux.kallsyms3.S           # should not happen
          AS      .tmp_vmlinux.kallsyms3.S           # should not happen
          LD      vmlinux
      
      The resulting vmlinux is correct, but it always requires an additional
      linking step.
      
      The symbols produced by kallsyms are excluded from kallsyms itself
      because they were previously missing in step 1. With those symbols
      excluded, the symbol lists matched between step 1 and step 2,
      eliminating the need for step 3. Now, this has a negative effect.
      
      Since 951bcae6, the PROVIDE() directives provide the fallback
      definitions, which are not trimmed from the sysbol list in step 1
      because ${kallsymso_prev} is empty at this point.
      
      In step 2, ${kallsymso_prev} is set, and the kallsyms_* symbols are
      trimmed from the symbol list.
      
      Due to the table size difference between step 1 and step 2 (the former
      is larger due to the presence of kallsyms_*), step 3 is triggered.
      
      Now that the kallsyms_* symbols are always linked, let's stop omitting
      them from kallsyms. This avoids unnecessary step 3.
      
      Fixes: 951bcae6 ("kallsyms: Avoid weak references for kallsyms symbols")
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      04b8cb09
  2. 14 Feb, 2024 1 commit
    • Nathan Chancellor's avatar
      kbuild: Fix changing ELF file type for output of gen_btf for big endian · e3a9ee96
      Nathan Chancellor authored
      Commit 90ceddcb ("bpf: Support llvm-objcopy for vmlinux BTF")
      changed the ELF type of .btf.vmlinux.bin.o to ET_REL via dd, which works
      fine for little endian platforms:
      
         00000000  7f 45 4c 46 02 01 01 00  00 00 00 00 00 00 00 00  |.ELF............|
        -00000010  03 00 b7 00 01 00 00 00  00 00 00 80 00 80 ff ff  |................|
        +00000010  01 00 b7 00 01 00 00 00  00 00 00 80 00 80 ff ff  |................|
      
      However, for big endian platforms, it changes the wrong byte, resulting
      in an invalid ELF file type, which ld.lld rejects:
      
         00000000  7f 45 4c 46 02 02 01 00  00 00 00 00 00 00 00 00  |.ELF............|
        -00000010  00 03 00 16 00 00 00 01  00 00 00 00 00 10 00 00  |................|
        +00000010  01 03 00 16 00 00 00 01  00 00 00 00 00 10 00 00  |................|
      
        Type:                              <unknown>: 103
      
        ld.lld: error: .btf.vmlinux.bin.o: unknown file type
      
      Fix this by updating the entire 16-bit e_type field rather than just a
      single byte, so that everything works correctly for all platforms and
      linkers.
      
         00000000  7f 45 4c 46 02 02 01 00  00 00 00 00 00 00 00 00  |.ELF............|
        -00000010  00 03 00 16 00 00 00 01  00 00 00 00 00 10 00 00  |................|
        +00000010  00 01 00 16 00 00 00 01  00 00 00 00 00 10 00 00  |................|
      
        Type:                              REL (Relocatable file)
      
      While in the area, update the comment to mention that binutils 2.35+
      matches LLD's behavior of rejecting an ET_EXEC input, which occurred
      after the comment was added.
      
      Cc: stable@vger.kernel.org
      Fixes: 90ceddcb ("bpf: Support llvm-objcopy for vmlinux BTF")
      Link: https://github.com/llvm/llvm-project/pull/75643Suggested-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
      Reviewed-by: default avatarFangrui Song <maskray@google.com>
      Reviewed-by: default avatarNicolas Schier <nicolas@fjasle.eu>
      Reviewed-by: default avatarKees Cook <keescook@chromium.org>
      Reviewed-by: default avatarJustin Stitt <justinstitt@google.com>
      Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
      e3a9ee96
  3. 17 Apr, 2023 1 commit
  4. 08 Apr, 2023 1 commit
  5. 13 Nov, 2022 1 commit
    • 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
  6. 02 Oct, 2022 5 commits
  7. 28 Sep, 2022 4 commits
    • 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
  8. 04 Jun, 2022 3 commits
    • 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
  9. 01 Jun, 2022 1 commit
  10. 29 May, 2022 1 commit
  11. 27 May, 2022 1 commit
  12. 24 May, 2022 2 commits
    • 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
  13. 11 May, 2022 1 commit
  14. 22 Apr, 2022 10 commits
  15. 19 Apr, 2022 1 commit
  16. 04 Apr, 2022 1 commit
  17. 01 Apr, 2022 1 commit
  18. 15 Mar, 2022 1 commit