linux-yocto/scripts/mksysmap
Masahiro Yamada 04b8cb0945 kbuild: avoid unneeded kallsyms step 3
Since commit 951bcae6c5 ("kallsyms: Avoid weak references for kallsyms
symbols"), the kallsyms step 3 always occurs.

You can compare the build logs.

[Before 951bcae6c5]

  $ git checkout 951bcae6c5a0^
  $ 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 951bcae6c5]

  $ git checkout 951bcae6c5
  $ 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 951bcae6c5, 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: 951bcae6c5 ("kallsyms: Avoid weak references for kallsyms symbols")
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2024-05-29 16:40:03 +09:00

2.1 KiB
Executable File

#!/bin/sh -x

Based on the vmlinux file create the System.map file

System.map is used by module-init tools and some debugging

tools to retrieve the actual addresses of symbols in the kernel.

Usage

mksysmap vmlinux System.map

Generate System.map (actual filename passed as second argument)

The following refers to the symbol type as per nm(1).

readprofile starts reading symbols when _stext is found, and

continue until it finds a symbol which is not either of 'T', 't',

'W' or 'w'.

${NM} -n ${1} | sed >${2} -e "

---------------------------------------------------------------------------

Ignored symbol types

a: local absolute symbols

N: debugging symbols

U: undefined global symbols

w: local weak symbols

/ [aNUw] /d

---------------------------------------------------------------------------

Ignored prefixes

(do not forget a space before each pattern)

local symbols for ARM, MIPS, etc.

/ \$/d

local labels, .LBB, .Ltmpxxx, .L__unnamed_xx, .LASANPC, etc.

/ .L/d

arm64 EFI stub namespace

/ _efistub/d

arm64 local symbols in PIE namespace

/ _pi\$/d / _pi.L/d

arm64 local symbols in non-VHE KVM namespace

/ _kvm_nvhe\$/d / _kvm_nvhe.L/d

lld arm/aarch64/mips thunks

/ _:alnum:*Thunk/d

CFI type identifiers

/ _kcfi_typeid/d / _kvm_nvhe___kcfi_typeid/d / _pi___kcfi_typeid/d

CRC from modversions

/ _crc/d

EXPORT_SYMBOL (symbol name)

/ _kstrtab/d

EXPORT_SYMBOL (namespace)

/ _kstrtabns/d

---------------------------------------------------------------------------

Ignored suffixes

(do not forget '$' after each pattern)

arm

/_from_arm$/d /_from_thumb$/d /_veneer$/d

---------------------------------------------------------------------------

Ignored symbols (exact match)

(do not forget a space before and '$' after each pattern)

for LoongArch?

/ L0$/d

ppc

/ SDA_BASE$/d / SDA2_BASE$/d

---------------------------------------------------------------------------

Ignored patterns

(symbols that contain the pattern are ignored)

ppc stub

/.long_branch./d /.plt_branch./d "