2012-05-05 10:18:41 +02:00
|
|
|
#!/bin/sh
|
2017-11-01 15:07:57 +01:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2012-05-05 10:18:41 +02:00
|
|
|
#
|
|
|
|
|
# link vmlinux
|
|
|
|
|
#
|
2022-09-25 03:19:14 +09:00
|
|
|
# vmlinux is linked from the objects in vmlinux.a and $(KBUILD_VMLINUX_LIBS).
|
|
|
|
|
# vmlinux.a contains objects that are linked unconditionally.
|
2019-01-17 09:10:04 +09:00
|
|
|
# $(KBUILD_VMLINUX_LIBS) are archives which are linked conditionally
|
|
|
|
|
# (not within --whole-archive), and do not require symbol indexes added.
|
2012-05-05 10:18:41 +02:00
|
|
|
#
|
|
|
|
|
# vmlinux
|
|
|
|
|
# ^
|
|
|
|
|
# |
|
2022-09-25 03:19:14 +09:00
|
|
|
# +--< vmlinux.a
|
2012-05-05 10:18:41 +02:00
|
|
|
# |
|
2017-06-20 01:52:05 +10:00
|
|
|
# +--< $(KBUILD_VMLINUX_LIBS)
|
|
|
|
|
# | +--< lib/lib.a + more
|
|
|
|
|
# |
|
2012-05-05 10:18:41 +02:00
|
|
|
# +-< ${kallsymso} (see description in KALLSYMS section)
|
|
|
|
|
#
|
|
|
|
|
# vmlinux version (uname -v) cannot be updated during normal
|
|
|
|
|
# descending-into-subdirs phase since we do not yet know if we need to
|
|
|
|
|
# update vmlinux.
|
|
|
|
|
# Therefore this step is delayed until just before final link of vmlinux.
|
|
|
|
|
#
|
|
|
|
|
# System.map is generated to document addresses of all kernel symbols
|
|
|
|
|
|
|
|
|
|
# Error out on error
|
|
|
|
|
set -e
|
|
|
|
|
|
2020-07-02 04:29:36 +09:00
|
|
|
LD="$1"
|
|
|
|
|
KBUILD_LDFLAGS="$2"
|
|
|
|
|
LDFLAGS_vmlinux="$3"
|
2025-03-11 12:06:18 +01:00
|
|
|
VMLINUX="$4"
|
2020-07-02 04:29:36 +09:00
|
|
|
|
2021-12-14 11:53:52 +09:00
|
|
|
is_enabled() {
|
|
|
|
|
grep -q "^$1=y" include/config/auto.conf
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 10:18:41 +02:00
|
|
|
# Nice output in kbuild format
|
|
|
|
|
# Will be supressed by "make -s"
|
|
|
|
|
info()
|
|
|
|
|
{
|
2021-05-17 16:03:14 +09:00
|
|
|
printf " %-7s %s\n" "${1}" "${2}"
|
2012-05-05 10:18:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Link of vmlinux
|
2019-08-12 11:39:47 -07:00
|
|
|
# ${1} - output file
|
2012-05-05 10:18:41 +02:00
|
|
|
vmlinux_link()
|
|
|
|
|
{
|
2019-09-05 10:59:38 -07:00
|
|
|
local output=${1}
|
2021-08-19 09:57:37 +09:00
|
|
|
local objs
|
|
|
|
|
local libs
|
2021-08-19 09:57:39 +09:00
|
|
|
local ld
|
|
|
|
|
local ldflags
|
|
|
|
|
local ldlibs
|
2012-05-05 10:18:41 +02:00
|
|
|
|
2019-09-20 08:36:47 -07:00
|
|
|
info LD ${output}
|
|
|
|
|
|
2019-09-05 10:59:38 -07:00
|
|
|
# skip output file argument
|
|
|
|
|
shift
|
|
|
|
|
|
2025-09-17 09:04:05 -07:00
|
|
|
if is_enabled CONFIG_LTO_CLANG || is_enabled CONFIG_X86_KERNEL_IBT ||
|
|
|
|
|
is_enabled CONFIG_KLP_BUILD; then
|
2021-08-19 09:57:37 +09:00
|
|
|
# Use vmlinux.o instead of performing the slow LTO link again.
|
|
|
|
|
objs=vmlinux.o
|
|
|
|
|
libs=
|
|
|
|
|
else
|
2022-09-25 03:19:14 +09:00
|
|
|
objs=vmlinux.a
|
2021-08-19 09:57:37 +09:00
|
|
|
libs="${KBUILD_VMLINUX_LIBS}"
|
|
|
|
|
fi
|
|
|
|
|
|
2024-09-23 16:56:03 +09:00
|
|
|
if is_enabled CONFIG_GENERIC_BUILTIN_DTB; then
|
|
|
|
|
objs="${objs} .builtin-dtbs.o"
|
|
|
|
|
fi
|
|
|
|
|
|
2025-09-18 10:05:52 +02:00
|
|
|
objs="${objs} .vmlinux.export.o"
|
2022-08-28 11:39:53 +09:00
|
|
|
objs="${objs} init/version-timestamp.o"
|
|
|
|
|
|
2021-08-19 09:57:39 +09:00
|
|
|
if [ "${SRCARCH}" = "um" ]; then
|
|
|
|
|
wl=-Wl,
|
|
|
|
|
ld="${CC}"
|
|
|
|
|
ldflags="${CFLAGS_vmlinux}"
|
|
|
|
|
ldlibs="-lutil -lrt -lpthread"
|
|
|
|
|
else
|
|
|
|
|
wl=
|
|
|
|
|
ld="${LD}"
|
|
|
|
|
ldflags="${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux}"
|
|
|
|
|
ldlibs=
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
ldflags="${ldflags} ${wl}--script=${objtree}/${KBUILD_LDS}"
|
|
|
|
|
|
2020-03-03 18:18:34 -08:00
|
|
|
# The kallsyms linking does not need debug symbols included.
|
2024-06-10 20:25:16 +09:00
|
|
|
if [ -n "${strip_debug}" ] ; then
|
2021-08-19 09:57:39 +09:00
|
|
|
ldflags="${ldflags} ${wl}--strip-debug"
|
2020-03-03 18:18:34 -08:00
|
|
|
fi
|
|
|
|
|
|
2025-03-13 19:26:03 +09:00
|
|
|
if [ -n "${generate_map}" ]; then
|
|
|
|
|
ldflags="${ldflags} ${wl}-Map=vmlinux.map"
|
2021-03-05 10:27:07 +01:00
|
|
|
fi
|
|
|
|
|
|
2021-08-19 09:57:39 +09:00
|
|
|
${ld} ${ldflags} -o ${output} \
|
|
|
|
|
${wl}--whole-archive ${objs} ${wl}--no-whole-archive \
|
|
|
|
|
${wl}--start-group ${libs} ${wl}--end-group \
|
2024-10-30 12:38:44 +05:30
|
|
|
${kallsymso} ${btf_vmlinux_bin_o} ${arch_vmlinux_o} ${ldlibs}
|
2012-05-05 10:18:41 +02:00
|
|
|
}
|
|
|
|
|
|
2024-06-10 20:25:16 +09:00
|
|
|
# Create ${2}.o file with all symbols from the ${1} object file
|
2012-05-05 10:18:41 +02:00
|
|
|
kallsyms()
|
|
|
|
|
{
|
|
|
|
|
local kallsymopt;
|
|
|
|
|
|
2021-12-14 11:53:52 +09:00
|
|
|
if is_enabled CONFIG_KALLSYMS_ALL; then
|
2012-09-06 22:11:25 +01:00
|
|
|
kallsymopt="${kallsymopt} --all-symbols"
|
2012-05-05 10:18:41 +02:00
|
|
|
fi
|
|
|
|
|
|
2026-01-16 10:34:02 +01:00
|
|
|
if is_enabled CONFIG_64BIT || is_enabled CONFIG_RELOCATABLE; then
|
|
|
|
|
kallsymopt="${kallsymopt} --pc-relative"
|
|
|
|
|
fi
|
|
|
|
|
|
2024-06-10 20:25:16 +09:00
|
|
|
info KSYMS "${2}.S"
|
|
|
|
|
scripts/kallsyms ${kallsymopt} "${1}" > "${2}.S"
|
|
|
|
|
|
|
|
|
|
info AS "${2}.o"
|
|
|
|
|
${CC} ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS} \
|
|
|
|
|
${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} -c -o "${2}.o" "${2}.S"
|
|
|
|
|
|
|
|
|
|
kallsymso=${2}.o
|
2012-05-05 10:18:41 +02:00
|
|
|
}
|
|
|
|
|
|
2024-06-10 20:25:18 +09:00
|
|
|
# Perform kallsyms for the given temporary vmlinux.
|
|
|
|
|
sysmap_and_kallsyms()
|
2019-08-13 08:15:32 -07:00
|
|
|
{
|
2024-06-10 20:25:18 +09:00
|
|
|
mksysmap "${1}" "${1}.syms"
|
|
|
|
|
kallsyms "${1}.syms" "${1}.kallsyms"
|
2019-08-13 08:15:32 -07:00
|
|
|
|
2024-06-10 20:25:18 +09:00
|
|
|
kallsyms_sysmap=${1}.syms
|
2019-08-13 08:15:32 -07:00
|
|
|
}
|
|
|
|
|
|
2012-05-05 10:18:41 +02:00
|
|
|
# Create map file with all symbols from ${1}
|
|
|
|
|
# See mksymap for additional details
|
|
|
|
|
mksysmap()
|
|
|
|
|
{
|
2022-09-26 18:02:26 +09:00
|
|
|
info NM ${2}
|
2024-06-05 13:58:09 -04:00
|
|
|
${NM} -n "${1}" | sed -f "${srctree}/scripts/mksysmap" > "${2}"
|
2012-05-05 10:18:41 +02:00
|
|
|
}
|
|
|
|
|
|
2019-12-04 08:46:31 +08:00
|
|
|
sorttable()
|
2012-05-28 10:32:28 -07:00
|
|
|
{
|
2025-02-18 14:59:22 -05:00
|
|
|
${NM} -S ${1} > .tmp_vmlinux.nm-sort
|
|
|
|
|
${objtree}/scripts/sorttable -s .tmp_vmlinux.nm-sort ${1}
|
2012-05-28 10:32:28 -07:00
|
|
|
}
|
|
|
|
|
|
2012-05-05 10:18:41 +02:00
|
|
|
cleanup()
|
|
|
|
|
{
|
2019-08-12 11:39:47 -07:00
|
|
|
rm -f .btf.*
|
2025-02-18 14:59:22 -05:00
|
|
|
rm -f .tmp_vmlinux.nm-sort
|
2012-05-05 10:18:41 +02:00
|
|
|
rm -f System.map
|
|
|
|
|
rm -f vmlinux
|
2021-03-05 10:27:07 +01:00
|
|
|
rm -f vmlinux.map
|
2012-05-05 10:18:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Use "make V=1" to debug this script
|
|
|
|
|
case "${KBUILD_VERBOSE}" in
|
|
|
|
|
*1*)
|
|
|
|
|
set -x
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
if [ "$1" = "clean" ]; then
|
|
|
|
|
cleanup
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2022-08-28 11:39:53 +09:00
|
|
|
${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init init/version-timestamp.o
|
|
|
|
|
|
2024-10-30 12:38:44 +05:30
|
|
|
arch_vmlinux_o=
|
|
|
|
|
if is_enabled CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX; then
|
|
|
|
|
arch_vmlinux_o=arch/${SRCARCH}/tools/vmlinux.arch.o
|
|
|
|
|
fi
|
|
|
|
|
|
2024-06-10 20:25:16 +09:00
|
|
|
btf_vmlinux_bin_o=
|
2025-12-19 10:18:25 -08:00
|
|
|
btfids_vmlinux=
|
2024-06-10 20:25:16 +09:00
|
|
|
kallsymso=
|
|
|
|
|
strip_debug=
|
2025-03-13 19:26:03 +09:00
|
|
|
generate_map=
|
2024-06-10 20:25:16 +09:00
|
|
|
|
2025-10-21 20:43:40 -04:00
|
|
|
# Use "make UT=1" to trigger warnings on unused tracepoints
|
|
|
|
|
case "${WARN_ON_UNUSED_TRACEPOINTS}" in
|
|
|
|
|
*1*)
|
|
|
|
|
${objtree}/scripts/tracepoint-update vmlinux.o
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2024-06-10 20:25:17 +09:00
|
|
|
if is_enabled CONFIG_KALLSYMS; then
|
2024-11-26 16:58:01 +01:00
|
|
|
true > .tmp_vmlinux0.syms
|
|
|
|
|
kallsyms .tmp_vmlinux0.syms .tmp_vmlinux0.kallsyms
|
2024-06-10 20:25:18 +09:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if is_enabled CONFIG_KALLSYMS || is_enabled CONFIG_DEBUG_INFO_BTF; then
|
|
|
|
|
|
|
|
|
|
# The kallsyms linking does not need debug symbols, but the BTF does.
|
|
|
|
|
if ! is_enabled CONFIG_DEBUG_INFO_BTF; then
|
|
|
|
|
strip_debug=1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
vmlinux_link .tmp_vmlinux1
|
2024-06-10 20:25:17 +09:00
|
|
|
fi
|
|
|
|
|
|
2021-12-14 11:53:52 +09:00
|
|
|
if is_enabled CONFIG_DEBUG_INFO_BTF; then
|
2025-12-31 10:39:29 -08:00
|
|
|
info BTF .tmp_vmlinux1
|
2026-01-21 10:16:17 -08:00
|
|
|
if ! ${CONFIG_SHELL} ${srctree}/scripts/gen-btf.sh .tmp_vmlinux1; then
|
2019-11-27 08:14:10 -08:00
|
|
|
echo >&2 "Failed to generate BTF for vmlinux"
|
|
|
|
|
echo >&2 "Try to disable CONFIG_DEBUG_INFO_BTF"
|
|
|
|
|
exit 1
|
2019-08-12 11:39:47 -07:00
|
|
|
fi
|
2025-12-19 10:18:25 -08:00
|
|
|
btf_vmlinux_bin_o=.tmp_vmlinux1.btf.o
|
|
|
|
|
btfids_vmlinux=.tmp_vmlinux1.BTF_ids
|
2019-08-12 11:39:47 -07:00
|
|
|
fi
|
|
|
|
|
|
2021-12-14 11:53:52 +09:00
|
|
|
if is_enabled CONFIG_KALLSYMS; then
|
2012-05-05 10:18:41 +02:00
|
|
|
|
|
|
|
|
# kallsyms support
|
|
|
|
|
# Generate section listing all symbols and add it into vmlinux
|
2024-06-10 20:25:17 +09:00
|
|
|
# It's a four step process:
|
|
|
|
|
# 0) Generate a dummy __kallsyms with empty symbol list.
|
2024-11-26 16:58:01 +01:00
|
|
|
# 1) Link .tmp_vmlinux1.kallsyms so it has all symbols and sections,
|
2024-06-10 20:25:17 +09:00
|
|
|
# with a dummy __kallsyms.
|
2024-11-26 16:58:01 +01:00
|
|
|
# Running kallsyms on that gives us .tmp_vmlinux1.kallsyms.o with
|
2012-05-05 10:18:41 +02:00
|
|
|
# the right size
|
2024-11-26 16:58:01 +01:00
|
|
|
# 2) Link .tmp_vmlinux2.kallsyms so it now has a __kallsyms section of
|
2012-05-05 10:18:41 +02:00
|
|
|
# the right size, but due to the added section, some
|
|
|
|
|
# addresses have shifted.
|
2024-11-26 16:58:01 +01:00
|
|
|
# From here, we generate a correct .tmp_vmlinux2.kallsyms.o
|
2016-11-24 03:41:37 +11:00
|
|
|
# 3) That link may have expanded the kernel image enough that
|
|
|
|
|
# more linker branch stubs / trampolines had to be added, which
|
|
|
|
|
# introduces new names, which further expands kallsyms. Do another
|
|
|
|
|
# pass if that is the case. In theory it's possible this results
|
|
|
|
|
# in even more stubs, but unlikely.
|
|
|
|
|
# KALLSYMS_EXTRA_PASS=1 may also used to debug or work around
|
|
|
|
|
# other bugs.
|
|
|
|
|
# 4) The correct ${kallsymso} is linked into the final vmlinux.
|
2012-05-05 10:18:41 +02:00
|
|
|
#
|
|
|
|
|
# a) Verify that the System.map from vmlinux matches the map from
|
|
|
|
|
# ${kallsymso}.
|
|
|
|
|
|
2024-06-10 20:25:16 +09:00
|
|
|
# The kallsyms linking does not need debug symbols included.
|
|
|
|
|
strip_debug=1
|
2012-05-05 10:18:41 +02:00
|
|
|
|
2024-06-10 20:25:18 +09:00
|
|
|
sysmap_and_kallsyms .tmp_vmlinux1
|
2024-06-10 20:25:16 +09:00
|
|
|
size1=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" ${kallsymso})
|
|
|
|
|
|
2024-06-10 20:25:18 +09:00
|
|
|
vmlinux_link .tmp_vmlinux2
|
|
|
|
|
sysmap_and_kallsyms .tmp_vmlinux2
|
2019-08-13 08:15:32 -07:00
|
|
|
size2=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" ${kallsymso})
|
2016-11-24 03:41:37 +11:00
|
|
|
|
|
|
|
|
if [ $size1 -ne $size2 ] || [ -n "${KALLSYMS_EXTRA_PASS}" ]; then
|
2024-06-10 20:25:18 +09:00
|
|
|
vmlinux_link .tmp_vmlinux3
|
|
|
|
|
sysmap_and_kallsyms .tmp_vmlinux3
|
2012-05-05 10:18:41 +02:00
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2024-06-10 20:25:16 +09:00
|
|
|
strip_debug=
|
|
|
|
|
|
2025-03-13 19:26:03 +09:00
|
|
|
if is_enabled CONFIG_VMLINUX_MAP; then
|
|
|
|
|
generate_map=1
|
|
|
|
|
fi
|
|
|
|
|
|
2025-03-11 12:06:18 +01:00
|
|
|
vmlinux_link "${VMLINUX}"
|
2019-04-02 09:49:50 -07:00
|
|
|
|
2024-09-14 02:37:52 +09:00
|
|
|
if is_enabled CONFIG_DEBUG_INFO_BTF; then
|
2025-12-31 10:39:29 -08:00
|
|
|
info BTFIDS ${VMLINUX}
|
2025-12-30 17:25:57 -08:00
|
|
|
${RESOLVE_BTFIDS} --patch_btfids ${btfids_vmlinux} ${VMLINUX}
|
2020-07-11 23:53:24 +02:00
|
|
|
fi
|
|
|
|
|
|
2025-03-11 12:06:18 +01:00
|
|
|
mksysmap "${VMLINUX}" System.map
|
2021-12-12 19:33:58 +08:00
|
|
|
|
2021-12-14 11:53:52 +09:00
|
|
|
if is_enabled CONFIG_BUILDTIME_TABLE_SORT; then
|
2025-03-11 12:06:18 +01:00
|
|
|
info SORTTAB "${VMLINUX}"
|
|
|
|
|
if ! sorttable "${VMLINUX}"; then
|
2019-12-04 08:46:33 +08:00
|
|
|
echo >&2 Failed to sort kernel tables
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2012-05-28 10:32:28 -07:00
|
|
|
fi
|
|
|
|
|
|
2012-05-05 10:18:41 +02:00
|
|
|
# step a (see comment above)
|
2021-12-14 11:53:52 +09:00
|
|
|
if is_enabled CONFIG_KALLSYMS; then
|
2024-06-10 20:25:18 +09:00
|
|
|
if ! cmp -s System.map "${kallsyms_sysmap}"; then
|
2012-07-07 23:04:40 +02:00
|
|
|
echo >&2 Inconsistent kallsyms data
|
2023-03-06 13:32:53 -08:00
|
|
|
echo >&2 'Try "make KALLSYMS_EXTRA_PASS=1" as a workaround'
|
2012-05-05 10:18:41 +02:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2021-03-05 11:02:12 +01:00
|
|
|
|
|
|
|
|
# For fixdep
|
2025-03-11 12:06:18 +01:00
|
|
|
echo "${VMLINUX}: $0" > ".${VMLINUX}.d"
|