162306a36Sopenharmony_ci#!/bin/sh -x
262306a36Sopenharmony_ci# Based on the vmlinux file create the System.map file
362306a36Sopenharmony_ci# System.map is used by module-init tools and some debugging
462306a36Sopenharmony_ci# tools to retrieve the actual addresses of symbols in the kernel.
562306a36Sopenharmony_ci#
662306a36Sopenharmony_ci# Usage
762306a36Sopenharmony_ci# mksysmap vmlinux System.map [exclude]
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#####
1162306a36Sopenharmony_ci# Generate System.map (actual filename passed as second argument)
1262306a36Sopenharmony_ci# The following refers to the symbol type as per nm(1).
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci# readprofile starts reading symbols when _stext is found, and
1562306a36Sopenharmony_ci# continue until it finds a symbol which is not either of 'T', 't',
1662306a36Sopenharmony_ci# 'W' or 'w'.
1762306a36Sopenharmony_ci#
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci${NM} -n ${1} | sed >${2} -e "
2062306a36Sopenharmony_ci# ---------------------------------------------------------------------------
2162306a36Sopenharmony_ci# Ignored symbol types
2262306a36Sopenharmony_ci#
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci# a: local absolute symbols
2562306a36Sopenharmony_ci# N: debugging symbols
2662306a36Sopenharmony_ci# U: undefined global symbols
2762306a36Sopenharmony_ci# w: local weak symbols
2862306a36Sopenharmony_ci/ [aNUw] /d
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci# ---------------------------------------------------------------------------
3162306a36Sopenharmony_ci# Ignored prefixes
3262306a36Sopenharmony_ci#  (do not forget a space before each pattern)
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci# local symbols for ARM, MIPS, etc.
3562306a36Sopenharmony_ci/ \\$/d
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci# local labels, .LBB, .Ltmpxxx, .L__unnamed_xx, .LASANPC, etc.
3862306a36Sopenharmony_ci/ \.L/d
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci# arm64 EFI stub namespace
4162306a36Sopenharmony_ci/ __efistub_/d
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci# arm64 local symbols in PIE namespace
4462306a36Sopenharmony_ci/ __pi_\\$/d
4562306a36Sopenharmony_ci/ __pi_\.L/d
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci# arm64 local symbols in non-VHE KVM namespace
4862306a36Sopenharmony_ci/ __kvm_nvhe_\\$/d
4962306a36Sopenharmony_ci/ __kvm_nvhe_\.L/d
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci# lld arm/aarch64/mips thunks
5262306a36Sopenharmony_ci/ __[[:alnum:]]*Thunk_/d
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci# CFI type identifiers
5562306a36Sopenharmony_ci/ __kcfi_typeid_/d
5662306a36Sopenharmony_ci/ __kvm_nvhe___kcfi_typeid_/d
5762306a36Sopenharmony_ci/ __pi___kcfi_typeid_/d
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci# CRC from modversions
6062306a36Sopenharmony_ci/ __crc_/d
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci# EXPORT_SYMBOL (symbol name)
6362306a36Sopenharmony_ci/ __kstrtab_/d
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci# EXPORT_SYMBOL (namespace)
6662306a36Sopenharmony_ci/ __kstrtabns_/d
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci# ---------------------------------------------------------------------------
6962306a36Sopenharmony_ci# Ignored suffixes
7062306a36Sopenharmony_ci#  (do not forget '$' after each pattern)
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci# arm
7362306a36Sopenharmony_ci/_from_arm$/d
7462306a36Sopenharmony_ci/_from_thumb$/d
7562306a36Sopenharmony_ci/_veneer$/d
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci# ---------------------------------------------------------------------------
7862306a36Sopenharmony_ci# Ignored symbols (exact match)
7962306a36Sopenharmony_ci#  (do not forget a space before and '$' after each pattern)
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci# for LoongArch?
8262306a36Sopenharmony_ci/ L0$/d
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci# ppc
8562306a36Sopenharmony_ci/ _SDA_BASE_$/d
8662306a36Sopenharmony_ci/ _SDA2_BASE_$/d
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci# ---------------------------------------------------------------------------
8962306a36Sopenharmony_ci# Ignored patterns
9062306a36Sopenharmony_ci#  (symbols that contain the pattern are ignored)
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci# ppc stub
9362306a36Sopenharmony_ci/\.long_branch\./d
9462306a36Sopenharmony_ci/\.plt_branch\./d
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci# ---------------------------------------------------------------------------
9762306a36Sopenharmony_ci# Ignored kallsyms symbols
9862306a36Sopenharmony_ci#
9962306a36Sopenharmony_ci# If the 3rd parameter exists, symbols from it will be omitted from the output.
10062306a36Sopenharmony_ci# This makes kallsyms have the identical symbol lists in the step 1 and 2.
10162306a36Sopenharmony_ci# Without this, the step2 would get new symbols generated by scripts/kallsyms.c
10262306a36Sopenharmony_ci# when CONFIG_KALLSYMS_ALL is enabled. That might require one more pass.
10362306a36Sopenharmony_ci$(if [ $# -ge 3 ]; then ${NM} ${3} | sed -n '/ U /!s:.* \([^ ]*\)$:/ \1$/d:p'; fi)
10462306a36Sopenharmony_ci"
105