VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   33 Branches   55 Tags
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200   1) #!/bin/sh
b24413180f560 (Greg Kroah-Hartman       2017-11-01 15:07:57 +0100   2) # SPDX-License-Identifier: GPL-2.0
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200   3) #
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200   4) # link vmlinux
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200   5) #
d151e9719f184 (Masahiro Yamada          2019-01-17 09:10:04 +0900   6) # vmlinux is linked from the objects selected by $(KBUILD_VMLINUX_OBJS) and
d151e9719f184 (Masahiro Yamada          2019-01-17 09:10:04 +0900   7) # $(KBUILD_VMLINUX_LIBS). Most are built-in.a files from top-level directories
d151e9719f184 (Masahiro Yamada          2019-01-17 09:10:04 +0900   8) # in the kernel tree, others are specified in arch/$(ARCH)/Makefile.
d151e9719f184 (Masahiro Yamada          2019-01-17 09:10:04 +0900   9) # $(KBUILD_VMLINUX_LIBS) are archives which are linked conditionally
d151e9719f184 (Masahiro Yamada          2019-01-17 09:10:04 +0900  10) # (not within --whole-archive), and do not require symbol indexes added.
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  11) #
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  12) # vmlinux
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  13) #   ^
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  14) #   |
d151e9719f184 (Masahiro Yamada          2019-01-17 09:10:04 +0900  15) #   +--< $(KBUILD_VMLINUX_OBJS)
d151e9719f184 (Masahiro Yamada          2019-01-17 09:10:04 +0900  16) #   |    +--< init/built-in.a drivers/built-in.a mm/built-in.a + more
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  17) #   |
3a166fc2d4ef7 (Nicholas Piggin          2017-06-20 01:52:05 +1000  18) #   +--< $(KBUILD_VMLINUX_LIBS)
3a166fc2d4ef7 (Nicholas Piggin          2017-06-20 01:52:05 +1000  19) #   |    +--< lib/lib.a + more
3a166fc2d4ef7 (Nicholas Piggin          2017-06-20 01:52:05 +1000  20) #   |
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  21) #   +-< ${kallsymso} (see description in KALLSYMS section)
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  22) #
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  23) # vmlinux version (uname -v) cannot be updated during normal
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  24) # descending-into-subdirs phase since we do not yet know if we need to
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  25) # update vmlinux.
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  26) # Therefore this step is delayed until just before final link of vmlinux.
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  27) #
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  28) # System.map is generated to document addresses of all kernel symbols
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  29) 
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  30) # Error out on error
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  31) set -e
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  32) 
3ec8a5b33deac (Masahiro Yamada          2020-07-02 04:29:36 +0900  33) LD="$1"
3ec8a5b33deac (Masahiro Yamada          2020-07-02 04:29:36 +0900  34) KBUILD_LDFLAGS="$2"
3ec8a5b33deac (Masahiro Yamada          2020-07-02 04:29:36 +0900  35) LDFLAGS_vmlinux="$3"
3ec8a5b33deac (Masahiro Yamada          2020-07-02 04:29:36 +0900  36) 
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  37) # Nice output in kbuild format
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  38) # Will be supressed by "make -s"
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  39) info()
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  40) {
c39013ee64b50 (Masahiro Yamada          2021-05-17 16:03:14 +0900  41) 	printf "  %-7s %s\n" "${1}" "${2}"
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  42) }
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  43) 
a8cccdd954732 (Sami Tolvanen            2020-12-11 10:46:24 -0800  44) # Generate a linker script to ensure correct ordering of initcalls.
a8cccdd954732 (Sami Tolvanen            2020-12-11 10:46:24 -0800  45) gen_initcalls()
a8cccdd954732 (Sami Tolvanen            2020-12-11 10:46:24 -0800  46) {
a8cccdd954732 (Sami Tolvanen            2020-12-11 10:46:24 -0800  47) 	info GEN .tmp_initcalls.lds
a8cccdd954732 (Sami Tolvanen            2020-12-11 10:46:24 -0800  48) 
a8cccdd954732 (Sami Tolvanen            2020-12-11 10:46:24 -0800  49) 	${PYTHON} ${srctree}/scripts/jobserver-exec		\
a8cccdd954732 (Sami Tolvanen            2020-12-11 10:46:24 -0800  50) 	${PERL} ${srctree}/scripts/generate_initcall_order.pl	\
a8cccdd954732 (Sami Tolvanen            2020-12-11 10:46:24 -0800  51) 		${KBUILD_VMLINUX_OBJS} ${KBUILD_VMLINUX_LIBS}	\
a8cccdd954732 (Sami Tolvanen            2020-12-11 10:46:24 -0800  52) 		> .tmp_initcalls.lds
a8cccdd954732 (Sami Tolvanen            2020-12-11 10:46:24 -0800  53) }
a8cccdd954732 (Sami Tolvanen            2020-12-11 10:46:24 -0800  54) 
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  55) # If CONFIG_LTO_CLANG is selected, collect generated symbol versions into
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  56) # .tmp_symversions.lds
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  57) gen_symversions()
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  58) {
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  59) 	info GEN .tmp_symversions.lds
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  60) 	rm -f .tmp_symversions.lds
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  61) 
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  62) 	for o in ${KBUILD_VMLINUX_OBJS} ${KBUILD_VMLINUX_LIBS}; do
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  63) 		if [ -f ${o}.symversions ]; then
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  64) 			cat ${o}.symversions >> .tmp_symversions.lds
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  65) 		fi
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  66) 	done
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  67) }
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  68) 
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  69) # Link of vmlinux.o used for section mismatch analysis
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  70) # ${1} output file
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  71) modpost_link()
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200  72) {
a5967db9af51a (Stephen Rothwell         2016-08-24 22:29:19 +1000  73) 	local objects
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  74) 	local lds=""
a5967db9af51a (Stephen Rothwell         2016-08-24 22:29:19 +1000  75) 
6358d6e8b9846 (Nicholas Piggin          2018-02-11 00:25:03 +1000  76) 	objects="--whole-archive				\
d151e9719f184 (Masahiro Yamada          2019-01-17 09:10:04 +0900  77) 		${KBUILD_VMLINUX_OBJS}				\
6358d6e8b9846 (Nicholas Piggin          2018-02-11 00:25:03 +1000  78) 		--no-whole-archive				\
6358d6e8b9846 (Nicholas Piggin          2018-02-11 00:25:03 +1000  79) 		--start-group					\
6358d6e8b9846 (Nicholas Piggin          2018-02-11 00:25:03 +1000  80) 		${KBUILD_VMLINUX_LIBS}				\
6358d6e8b9846 (Nicholas Piggin          2018-02-11 00:25:03 +1000  81) 		--end-group"
6358d6e8b9846 (Nicholas Piggin          2018-02-11 00:25:03 +1000  82) 
dc5723b02e523 (Sami Tolvanen            2020-12-11 10:46:19 -0800  83) 	if [ -n "${CONFIG_LTO_CLANG}" ]; then
a8cccdd954732 (Sami Tolvanen            2020-12-11 10:46:24 -0800  84) 		gen_initcalls
a8cccdd954732 (Sami Tolvanen            2020-12-11 10:46:24 -0800  85) 		lds="-T .tmp_initcalls.lds"
a8cccdd954732 (Sami Tolvanen            2020-12-11 10:46:24 -0800  86) 
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  87) 		if [ -n "${CONFIG_MODVERSIONS}" ]; then
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  88) 			gen_symversions
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  89) 			lds="${lds} -T .tmp_symversions.lds"
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  90) 		fi
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  91) 
dc5723b02e523 (Sami Tolvanen            2020-12-11 10:46:19 -0800  92) 		# This might take a while, so indicate that we're doing
dc5723b02e523 (Sami Tolvanen            2020-12-11 10:46:19 -0800  93) 		# an LTO link
dc5723b02e523 (Sami Tolvanen            2020-12-11 10:46:19 -0800  94) 		info LTO ${1}
dc5723b02e523 (Sami Tolvanen            2020-12-11 10:46:19 -0800  95) 	else
dc5723b02e523 (Sami Tolvanen            2020-12-11 10:46:19 -0800  96) 		info LD ${1}
dc5723b02e523 (Sami Tolvanen            2020-12-11 10:46:19 -0800  97) 	fi
dc5723b02e523 (Sami Tolvanen            2020-12-11 10:46:19 -0800  98) 
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800  99) 	${LD} ${KBUILD_LDFLAGS} -r -o ${1} ${lds} ${objects}
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 100) }
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 101) 
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 102) objtool_link()
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 103) {
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 104) 	local objtoolcmd;
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 105) 	local objtoolopt;
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 106) 
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 107) 	if [ "${CONFIG_LTO_CLANG} ${CONFIG_STACK_VALIDATION}" = "y y" ]; then
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 108) 		# Don't perform vmlinux validation unless explicitly requested,
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 109) 		# but run objtool on vmlinux.o now that we have an object file.
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 110) 		if [ -n "${CONFIG_UNWINDER_ORC}" ]; then
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 111) 			objtoolcmd="orc generate"
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 112) 		fi
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 113) 
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 114) 		objtoolopt="${objtoolopt} --duplicate"
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 115) 
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 116) 		if [ -n "${CONFIG_FTRACE_MCOUNT_USE_OBJTOOL}" ]; then
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 117) 			objtoolopt="${objtoolopt} --mcount"
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 118) 		fi
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 119) 	fi
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 120) 
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 121) 	if [ -n "${CONFIG_VMLINUX_VALIDATION}" ]; then
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 122) 		objtoolopt="${objtoolopt} --noinstr"
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 123) 	fi
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 124) 
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 125) 	if [ -n "${objtoolopt}" ]; then
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 126) 		if [ -z "${objtoolcmd}" ]; then
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 127) 			objtoolcmd="check"
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 128) 		fi
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 129) 		objtoolopt="${objtoolopt} --vmlinux"
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 130) 		if [ -z "${CONFIG_FRAME_POINTER}" ]; then
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 131) 			objtoolopt="${objtoolopt} --no-fp"
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 132) 		fi
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 133) 		if [ -n "${CONFIG_GCOV_KERNEL}" ] || [ -n "${CONFIG_LTO_CLANG}" ]; then
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 134) 			objtoolopt="${objtoolopt} --no-unreachable"
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 135) 		fi
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 136) 		if [ -n "${CONFIG_RETPOLINE}" ]; then
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 137) 			objtoolopt="${objtoolopt} --retpoline"
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 138) 		fi
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 139) 		if [ -n "${CONFIG_X86_SMAP}" ]; then
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 140) 			objtoolopt="${objtoolopt} --uaccess"
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 141) 		fi
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 142) 		info OBJTOOL ${1}
b1a1a1a09b460 (Sami Tolvanen            2020-04-13 16:10:13 -0700 143) 		tools/objtool/objtool ${objtoolcmd} ${objtoolopt} ${1}
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 144) 	fi
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 145) }
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 146) 
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 147) # Link of vmlinux
341dfcf8d78ea (Andrii Nakryiko          2019-08-12 11:39:47 -0700 148) # ${1} - output file
618916a4bf169 (Andrii Nakryiko          2019-09-05 10:59:38 -0700 149) # ${2}, ${3}, ... - optional extra .o files
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 150) vmlinux_link()
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 151) {
618916a4bf169 (Andrii Nakryiko          2019-09-05 10:59:38 -0700 152) 	local output=${1}
8f1305124ea48 (Masahiro Yamada          2021-08-19 09:57:37 +0900 153) 	local objs
8f1305124ea48 (Masahiro Yamada          2021-08-19 09:57:37 +0900 154) 	local libs
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 155) 	local ld
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 156) 	local ldflags
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 157) 	local ldlibs
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 158) 
d7b0827f28ab3 (Linus Torvalds           2019-09-20 08:36:47 -0700 159) 	info LD ${output}
d7b0827f28ab3 (Linus Torvalds           2019-09-20 08:36:47 -0700 160) 
618916a4bf169 (Andrii Nakryiko          2019-09-05 10:59:38 -0700 161) 	# skip output file argument
618916a4bf169 (Andrii Nakryiko          2019-09-05 10:59:38 -0700 162) 	shift
618916a4bf169 (Andrii Nakryiko          2019-09-05 10:59:38 -0700 163) 
8f1305124ea48 (Masahiro Yamada          2021-08-19 09:57:37 +0900 164) 	if [ -n "${CONFIG_LTO_CLANG}" ]; then
8f1305124ea48 (Masahiro Yamada          2021-08-19 09:57:37 +0900 165) 		# Use vmlinux.o instead of performing the slow LTO link again.
8f1305124ea48 (Masahiro Yamada          2021-08-19 09:57:37 +0900 166) 		objs=vmlinux.o
8f1305124ea48 (Masahiro Yamada          2021-08-19 09:57:37 +0900 167) 		libs=
8f1305124ea48 (Masahiro Yamada          2021-08-19 09:57:37 +0900 168) 	else
8f1305124ea48 (Masahiro Yamada          2021-08-19 09:57:37 +0900 169) 		objs="${KBUILD_VMLINUX_OBJS}"
8f1305124ea48 (Masahiro Yamada          2021-08-19 09:57:37 +0900 170) 		libs="${KBUILD_VMLINUX_LIBS}"
8f1305124ea48 (Masahiro Yamada          2021-08-19 09:57:37 +0900 171) 	fi
8f1305124ea48 (Masahiro Yamada          2021-08-19 09:57:37 +0900 172) 
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 173) 	if [ "${SRCARCH}" = "um" ]; then
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 174) 		wl=-Wl,
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 175) 		ld="${CC}"
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 176) 		ldflags="${CFLAGS_vmlinux}"
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 177) 		ldlibs="-lutil -lrt -lpthread"
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 178) 	else
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 179) 		wl=
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 180) 		ld="${LD}"
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 181) 		ldflags="${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux}"
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 182) 		ldlibs=
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 183) 	fi
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 184) 
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 185) 	ldflags="${ldflags} ${wl}--script=${objtree}/${KBUILD_LDS}"
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 186) 
af73d78bd384a (Kees Cook                2020-03-03 18:18:34 -0800 187) 	# The kallsyms linking does not need debug symbols included.
af73d78bd384a (Kees Cook                2020-03-03 18:18:34 -0800 188) 	if [ "$output" != "${output#.tmp_vmlinux.kallsyms}" ] ; then
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 189) 		ldflags="${ldflags} ${wl}--strip-debug"
af73d78bd384a (Kees Cook                2020-03-03 18:18:34 -0800 190) 	fi
af73d78bd384a (Kees Cook                2020-03-03 18:18:34 -0800 191) 
5cc1247204616 (Rasmus Villemoes         2021-03-05 10:27:07 +0100 192) 	if [ -n "${CONFIG_VMLINUX_MAP}" ]; then
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 193) 		ldflags="${ldflags} ${wl}-Map=${output}.map"
5cc1247204616 (Rasmus Villemoes         2021-03-05 10:27:07 +0100 194) 	fi
5cc1247204616 (Rasmus Villemoes         2021-03-05 10:27:07 +0100 195) 
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 196) 	${ld} ${ldflags} -o ${output}					\
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 197) 		${wl}--whole-archive ${objs} ${wl}--no-whole-archive	\
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 198) 		${wl}--start-group ${libs} ${wl}--end-group		\
5df77ad61fd71 (Masahiro Yamada          2021-08-19 09:57:39 +0900 199) 		$@ ${ldlibs}
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 200) }
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 201) 
e83b9f55448af (Andrii Nakryiko          2019-04-02 09:49:50 -0700 202) # generate .BTF typeinfo from DWARF debuginfo
341dfcf8d78ea (Andrii Nakryiko          2019-08-12 11:39:47 -0700 203) # ${1} - vmlinux image
341dfcf8d78ea (Andrii Nakryiko          2019-08-12 11:39:47 -0700 204) # ${2} - file to dump raw BTF data into
e83b9f55448af (Andrii Nakryiko          2019-04-02 09:49:50 -0700 205) gen_btf()
e83b9f55448af (Andrii Nakryiko          2019-04-02 09:49:50 -0700 206) {
341dfcf8d78ea (Andrii Nakryiko          2019-08-12 11:39:47 -0700 207) 	local pahole_ver
db16c1fe92d7b (Ilya Leoshkevich         2021-04-13 21:00:43 +0200 208) 	local extra_paholeopt=
e83b9f55448af (Andrii Nakryiko          2019-04-02 09:49:50 -0700 209) 
581b31c36cfc5 (Andrii Nakryiko          2019-05-05 17:10:33 -0700 210) 	if ! [ -x "$(command -v ${PAHOLE})" ]; then
2a67a6ccb01f2 (Chris Down               2020-01-22 00:01:10 +0000 211) 		echo >&2 "BTF: ${1}: pahole (${PAHOLE}) is not available"
341dfcf8d78ea (Andrii Nakryiko          2019-08-12 11:39:47 -0700 212) 		return 1
581b31c36cfc5 (Andrii Nakryiko          2019-05-05 17:10:33 -0700 213) 	fi
581b31c36cfc5 (Andrii Nakryiko          2019-05-05 17:10:33 -0700 214) 
e83b9f55448af (Andrii Nakryiko          2019-04-02 09:49:50 -0700 215) 	pahole_ver=$(${PAHOLE} --version | sed -E 's/v([0-9]+)\.([0-9]+)/\1\2/')
21a85bd601ee5 (Lorenz Bauer             2020-06-08 10:42:57 +0100 216) 	if [ "${pahole_ver}" -lt "116" ]; then
21a85bd601ee5 (Lorenz Bauer             2020-06-08 10:42:57 +0100 217) 		echo >&2 "BTF: ${1}: pahole version $(${PAHOLE} --version) is too old, need at least v1.16"
341dfcf8d78ea (Andrii Nakryiko          2019-08-12 11:39:47 -0700 218) 		return 1
e83b9f55448af (Andrii Nakryiko          2019-04-02 09:49:50 -0700 219) 	fi
e83b9f55448af (Andrii Nakryiko          2019-04-02 09:49:50 -0700 220) 
341dfcf8d78ea (Andrii Nakryiko          2019-08-12 11:39:47 -0700 221) 	vmlinux_link ${1}
af73d78bd384a (Kees Cook                2020-03-03 18:18:34 -0800 222) 
a0b8200d06ad6 (Andrii Nakryiko          2021-06-28 19:41:34 -0700 223) 	if [ "${pahole_ver}" -ge "118" ] && [ "${pahole_ver}" -le "121" ]; then
a0b8200d06ad6 (Andrii Nakryiko          2021-06-28 19:41:34 -0700 224) 		# pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars
a0b8200d06ad6 (Andrii Nakryiko          2021-06-28 19:41:34 -0700 225) 		extra_paholeopt="${extra_paholeopt} --skip_encoding_btf_vars"
a0b8200d06ad6 (Andrii Nakryiko          2021-06-28 19:41:34 -0700 226) 	fi
db16c1fe92d7b (Ilya Leoshkevich         2021-04-13 21:00:43 +0200 227) 	if [ "${pahole_ver}" -ge "121" ]; then
db16c1fe92d7b (Ilya Leoshkevich         2021-04-13 21:00:43 +0200 228) 		extra_paholeopt="${extra_paholeopt} --btf_gen_floats"
db16c1fe92d7b (Ilya Leoshkevich         2021-04-13 21:00:43 +0200 229) 	fi
db16c1fe92d7b (Ilya Leoshkevich         2021-04-13 21:00:43 +0200 230) 
af73d78bd384a (Kees Cook                2020-03-03 18:18:34 -0800 231) 	info "BTF" ${2}
ff2e6efda0d5c (Javier Martinez Canillas 2021-05-26 23:52:28 +0200 232) 	LLVM_OBJCOPY="${OBJCOPY}" ${PAHOLE} -J ${extra_paholeopt} ${1}
341dfcf8d78ea (Andrii Nakryiko          2019-08-12 11:39:47 -0700 233) 
90ceddcb49500 (Fangrui Song             2020-03-18 15:27:46 -0700 234) 	# Create ${2} which contains just .BTF section but no symbols. Add
90ceddcb49500 (Fangrui Song             2020-03-18 15:27:46 -0700 235) 	# SHF_ALLOC because .BTF will be part of the vmlinux image. --strip-all
90ceddcb49500 (Fangrui Song             2020-03-18 15:27:46 -0700 236) 	# deletes all symbols including __start_BTF and __stop_BTF, which will
90ceddcb49500 (Fangrui Song             2020-03-18 15:27:46 -0700 237) 	# be redefined in the linker script. Add 2>/dev/null to suppress GNU
90ceddcb49500 (Fangrui Song             2020-03-18 15:27:46 -0700 238) 	# objcopy warnings: "empty loadable segment detected at ..."
90ceddcb49500 (Fangrui Song             2020-03-18 15:27:46 -0700 239) 	${OBJCOPY} --only-section=.BTF --set-section-flags .BTF=alloc,readonly \
90ceddcb49500 (Fangrui Song             2020-03-18 15:27:46 -0700 240) 		--strip-all ${1} ${2} 2>/dev/null
90ceddcb49500 (Fangrui Song             2020-03-18 15:27:46 -0700 241) 	# Change e_type to ET_REL so that it can be used to link final vmlinux.
90ceddcb49500 (Fangrui Song             2020-03-18 15:27:46 -0700 242) 	# Unlike GNU ld, lld does not allow an ET_EXEC input.
90ceddcb49500 (Fangrui Song             2020-03-18 15:27:46 -0700 243) 	printf '\1' | dd of=${2} conv=notrunc bs=1 seek=16 status=none
e83b9f55448af (Andrii Nakryiko          2019-04-02 09:49:50 -0700 244) }
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 245) 
08beb669cb3f1 (Masahiro Yamada          2020-09-25 00:45:46 +0900 246) # Create ${2} .S file with all symbols from the ${1} object file
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 247) kallsyms()
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 248) {
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 249) 	local kallsymopt;
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 250) 
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 251) 	if [ -n "${CONFIG_KALLSYMS_ALL}" ]; then
6895f97e15895 (James Hogan              2012-09-06 22:11:25 +0100 252) 		kallsymopt="${kallsymopt} --all-symbols"
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 253) 	fi
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 254) 
4d5d5664c9008 (Ard Biesheuvel           2016-03-15 14:58:12 -0700 255) 	if [ -n "${CONFIG_KALLSYMS_ABSOLUTE_PERCPU}" ]; then
c6bda7c988a57 (Rusty Russell            2014-03-17 14:05:46 +1030 256) 		kallsymopt="${kallsymopt} --absolute-percpu"
c6bda7c988a57 (Rusty Russell            2014-03-17 14:05:46 +1030 257) 	fi
c6bda7c988a57 (Rusty Russell            2014-03-17 14:05:46 +1030 258) 
2213e9a66bb87 (Ard Biesheuvel           2016-03-15 14:58:19 -0700 259) 	if [ -n "${CONFIG_KALLSYMS_BASE_RELATIVE}" ]; then
2213e9a66bb87 (Ard Biesheuvel           2016-03-15 14:58:19 -0700 260) 		kallsymopt="${kallsymopt} --base-relative"
2213e9a66bb87 (Ard Biesheuvel           2016-03-15 14:58:19 -0700 261) 	fi
2213e9a66bb87 (Ard Biesheuvel           2016-03-15 14:58:19 -0700 262) 
08beb669cb3f1 (Masahiro Yamada          2020-09-25 00:45:46 +0900 263) 	info KSYMS ${2}
08beb669cb3f1 (Masahiro Yamada          2020-09-25 00:45:46 +0900 264) 	${NM} -n ${1} | scripts/kallsyms ${kallsymopt} > ${2}
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 265) }
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 266) 
8959e39272d6e (Kees Cook                2019-08-13 08:15:32 -0700 267) # Perform one step in kallsyms generation, including temporary linking of
8959e39272d6e (Kees Cook                2019-08-13 08:15:32 -0700 268) # vmlinux.
8959e39272d6e (Kees Cook                2019-08-13 08:15:32 -0700 269) kallsyms_step()
8959e39272d6e (Kees Cook                2019-08-13 08:15:32 -0700 270) {
8959e39272d6e (Kees Cook                2019-08-13 08:15:32 -0700 271) 	kallsymso_prev=${kallsymso}
af73d78bd384a (Kees Cook                2020-03-03 18:18:34 -0800 272) 	kallsyms_vmlinux=.tmp_vmlinux.kallsyms${1}
af73d78bd384a (Kees Cook                2020-03-03 18:18:34 -0800 273) 	kallsymso=${kallsyms_vmlinux}.o
08beb669cb3f1 (Masahiro Yamada          2020-09-25 00:45:46 +0900 274) 	kallsyms_S=${kallsyms_vmlinux}.S
8959e39272d6e (Kees Cook                2019-08-13 08:15:32 -0700 275) 
d7b0827f28ab3 (Linus Torvalds           2019-09-20 08:36:47 -0700 276) 	vmlinux_link ${kallsyms_vmlinux} "${kallsymso_prev}" ${btf_vmlinux_bin_o}
08beb669cb3f1 (Masahiro Yamada          2020-09-25 00:45:46 +0900 277) 	kallsyms ${kallsyms_vmlinux} ${kallsyms_S}
08beb669cb3f1 (Masahiro Yamada          2020-09-25 00:45:46 +0900 278) 
08beb669cb3f1 (Masahiro Yamada          2020-09-25 00:45:46 +0900 279) 	info AS ${kallsyms_S}
08beb669cb3f1 (Masahiro Yamada          2020-09-25 00:45:46 +0900 280) 	${CC} ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS} \
08beb669cb3f1 (Masahiro Yamada          2020-09-25 00:45:46 +0900 281) 	      ${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \
08beb669cb3f1 (Masahiro Yamada          2020-09-25 00:45:46 +0900 282) 	      -c -o ${kallsymso} ${kallsyms_S}
8959e39272d6e (Kees Cook                2019-08-13 08:15:32 -0700 283) }
8959e39272d6e (Kees Cook                2019-08-13 08:15:32 -0700 284) 
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 285) # Create map file with all symbols from ${1}
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 286) # See mksymap for additional details
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 287) mksysmap()
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 288) {
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 289) 	${CONFIG_SHELL} "${srctree}/scripts/mksysmap" ${1} ${2}
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 290) }
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 291) 
1091670637be8 (Shile Zhang              2019-12-04 08:46:31 +0800 292) sorttable()
1347a2cebcb4c (Linus Torvalds           2012-05-28 10:32:28 -0700 293) {
1091670637be8 (Shile Zhang              2019-12-04 08:46:31 +0800 294) 	${objtree}/scripts/sorttable ${1}
1347a2cebcb4c (Linus Torvalds           2012-05-28 10:32:28 -0700 295) }
1347a2cebcb4c (Linus Torvalds           2012-05-28 10:32:28 -0700 296) 
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 297) # Delete output files in case of error
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 298) cleanup()
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 299) {
341dfcf8d78ea (Andrii Nakryiko          2019-08-12 11:39:47 -0700 300) 	rm -f .btf.*
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 301) 	rm -f .tmp_System.map
a8cccdd954732 (Sami Tolvanen            2020-12-11 10:46:24 -0800 302) 	rm -f .tmp_initcalls.lds
38e8918490038 (Sami Tolvanen            2020-12-11 10:46:20 -0800 303) 	rm -f .tmp_symversions.lds
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 304) 	rm -f .tmp_vmlinux*
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 305) 	rm -f System.map
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 306) 	rm -f vmlinux
5cc1247204616 (Rasmus Villemoes         2021-03-05 10:27:07 +0100 307) 	rm -f vmlinux.map
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 308) 	rm -f vmlinux.o
0b956e204132c (Rasmus Villemoes         2021-03-05 11:02:12 +0100 309) 	rm -f .vmlinux.d
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 310) }
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 311) 
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 312) # Use "make V=1" to debug this script
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 313) case "${KBUILD_VERBOSE}" in
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 314) *1*)
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 315) 	set -x
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 316) 	;;
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 317) esac
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 318) 
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 319) if [ "$1" = "clean" ]; then
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 320) 	cleanup
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 321) 	exit 0
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 322) fi
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 323) 
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 324) # We need access to CONFIG_ symbols
94cf8acc38e57 (Masahiro Yamada          2019-03-08 14:49:10 +0900 325) . include/config/auto.conf
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 326) 
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 327) # Update version
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 328) info GEN .version
278ae6040397f (Masahiro Yamada          2017-09-22 14:31:13 +0900 329) if [ -r .version ]; then
278ae6040397f (Masahiro Yamada          2017-09-22 14:31:13 +0900 330) 	VERSION=$(expr 0$(cat .version) + 1)
278ae6040397f (Masahiro Yamada          2017-09-22 14:31:13 +0900 331) 	echo $VERSION > .version
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 332) else
278ae6040397f (Masahiro Yamada          2017-09-22 14:31:13 +0900 333) 	rm -f .version
278ae6040397f (Masahiro Yamada          2017-09-22 14:31:13 +0900 334) 	echo 1 > .version
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 335) fi;
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 336) 
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 337) # final build of init/
083bc0e1ce91e (Masahiro Yamada          2020-02-11 05:06:34 +0900 338) ${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init need-builtin=1
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 339) 
abac4c89731c0 (Nicholas Piggin          2016-11-24 03:41:43 +1100 340) #link vmlinux.o
abac4c89731c0 (Nicholas Piggin          2016-11-24 03:41:43 +1100 341) modpost_link vmlinux.o
6804c1afd794c (Peter Zijlstra           2020-03-18 13:33:54 +0100 342) objtool_link vmlinux.o
abac4c89731c0 (Nicholas Piggin          2016-11-24 03:41:43 +1100 343) 
abac4c89731c0 (Nicholas Piggin          2016-11-24 03:41:43 +1100 344) # modpost vmlinux.o to check for section mismatches
a721588d9475c (Masahiro Yamada          2019-07-31 00:59:02 +0900 345) ${MAKE} -f "${srctree}/scripts/Makefile.modpost" MODPOST_VMLINUX=1
abac4c89731c0 (Nicholas Piggin          2016-11-24 03:41:43 +1100 346) 
898490c010b5d (Alexey Gladkov           2019-04-29 18:11:14 +0200 347) info MODINFO modules.builtin.modinfo
898490c010b5d (Alexey Gladkov           2019-04-29 18:11:14 +0200 348) ${OBJCOPY} -j .modinfo -O binary vmlinux.o modules.builtin.modinfo
8b41fc4454e36 (Masahiro Yamada          2019-12-19 17:33:29 +0900 349) info GEN modules.builtin
8b41fc4454e36 (Masahiro Yamada          2019-12-19 17:33:29 +0900 350) # The second line aids cases where multiple modules share the same object.
8b41fc4454e36 (Masahiro Yamada          2019-12-19 17:33:29 +0900 351) tr '\0' '\n' < modules.builtin.modinfo | sed -n 's/^[[:alnum:]:_]*\.file=//p' |
8b41fc4454e36 (Masahiro Yamada          2019-12-19 17:33:29 +0900 352) 	tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$/.ko/' > modules.builtin
898490c010b5d (Alexey Gladkov           2019-04-29 18:11:14 +0200 353) 
7fd785685e224 (Andrii Nakryiko          2019-08-13 11:54:42 -0700 354) btf_vmlinux_bin_o=""
341dfcf8d78ea (Andrii Nakryiko          2019-08-12 11:39:47 -0700 355) if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then
af73d78bd384a (Kees Cook                2020-03-03 18:18:34 -0800 356) 	btf_vmlinux_bin_o=.btf.vmlinux.bin.o
af73d78bd384a (Kees Cook                2020-03-03 18:18:34 -0800 357) 	if ! gen_btf .tmp_vmlinux.btf $btf_vmlinux_bin_o ; then
da5fb18225b49 (Stanislav Fomichev       2019-11-27 08:14:10 -0800 358) 		echo >&2 "Failed to generate BTF for vmlinux"
da5fb18225b49 (Stanislav Fomichev       2019-11-27 08:14:10 -0800 359) 		echo >&2 "Try to disable CONFIG_DEBUG_INFO_BTF"
da5fb18225b49 (Stanislav Fomichev       2019-11-27 08:14:10 -0800 360) 		exit 1
341dfcf8d78ea (Andrii Nakryiko          2019-08-12 11:39:47 -0700 361) 	fi
341dfcf8d78ea (Andrii Nakryiko          2019-08-12 11:39:47 -0700 362) fi
341dfcf8d78ea (Andrii Nakryiko          2019-08-12 11:39:47 -0700 363) 
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 364) kallsymso=""
8959e39272d6e (Kees Cook                2019-08-13 08:15:32 -0700 365) kallsymso_prev=""
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 366) kallsyms_vmlinux=""
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 367) if [ -n "${CONFIG_KALLSYMS}" ]; then
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 368) 
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 369) 	# kallsyms support
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 370) 	# Generate section listing all symbols and add it into vmlinux
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 371) 	# It's a three step process:
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 372) 	# 1)  Link .tmp_vmlinux1 so it has all symbols and sections,
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 373) 	#     but __kallsyms is empty.
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 374) 	#     Running kallsyms on that gives us .tmp_kallsyms1.o with
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 375) 	#     the right size
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 376) 	# 2)  Link .tmp_vmlinux2 so it now has a __kallsyms section of
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 377) 	#     the right size, but due to the added section, some
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 378) 	#     addresses have shifted.
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 379) 	#     From here, we generate a correct .tmp_kallsyms2.o
7e2b37c971a2a (Nicholas Piggin          2016-11-24 03:41:37 +1100 380) 	# 3)  That link may have expanded the kernel image enough that
7e2b37c971a2a (Nicholas Piggin          2016-11-24 03:41:37 +1100 381) 	#     more linker branch stubs / trampolines had to be added, which
7e2b37c971a2a (Nicholas Piggin          2016-11-24 03:41:37 +1100 382) 	#     introduces new names, which further expands kallsyms. Do another
7e2b37c971a2a (Nicholas Piggin          2016-11-24 03:41:37 +1100 383) 	#     pass if that is the case. In theory it's possible this results
7e2b37c971a2a (Nicholas Piggin          2016-11-24 03:41:37 +1100 384) 	#     in even more stubs, but unlikely.
7e2b37c971a2a (Nicholas Piggin          2016-11-24 03:41:37 +1100 385) 	#     KALLSYMS_EXTRA_PASS=1 may also used to debug or work around
7e2b37c971a2a (Nicholas Piggin          2016-11-24 03:41:37 +1100 386) 	#     other bugs.
7e2b37c971a2a (Nicholas Piggin          2016-11-24 03:41:37 +1100 387) 	# 4)  The correct ${kallsymso} is linked into the final vmlinux.
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 388) 	#
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 389) 	# a)  Verify that the System.map from vmlinux matches the map from
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 390) 	#     ${kallsymso}.
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 391) 
8959e39272d6e (Kees Cook                2019-08-13 08:15:32 -0700 392) 	kallsyms_step 1
8959e39272d6e (Kees Cook                2019-08-13 08:15:32 -0700 393) 	kallsyms_step 2
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 394) 
7e2b37c971a2a (Nicholas Piggin          2016-11-24 03:41:37 +1100 395) 	# step 3
8959e39272d6e (Kees Cook                2019-08-13 08:15:32 -0700 396) 	size1=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" ${kallsymso_prev})
8959e39272d6e (Kees Cook                2019-08-13 08:15:32 -0700 397) 	size2=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" ${kallsymso})
7e2b37c971a2a (Nicholas Piggin          2016-11-24 03:41:37 +1100 398) 
7e2b37c971a2a (Nicholas Piggin          2016-11-24 03:41:37 +1100 399) 	if [ $size1 -ne $size2 ] || [ -n "${KALLSYMS_EXTRA_PASS}" ]; then
8959e39272d6e (Kees Cook                2019-08-13 08:15:32 -0700 400) 		kallsyms_step 3
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 401) 	fi
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 402) fi
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 403) 
d7b0827f28ab3 (Linus Torvalds           2019-09-20 08:36:47 -0700 404) vmlinux_link vmlinux "${kallsymso}" ${btf_vmlinux_bin_o}
e83b9f55448af (Andrii Nakryiko          2019-04-02 09:49:50 -0700 405) 
c9a0f3b85e09d (Jiri Olsa                2020-07-11 23:53:24 +0200 406) # fill in BTF IDs
017dab341ee75 (Jiri Olsa                2020-09-23 20:57:34 +0200 407) if [ -n "${CONFIG_DEBUG_INFO_BTF}" -a -n "${CONFIG_BPF}" ]; then
017dab341ee75 (Jiri Olsa                2020-09-23 20:57:34 +0200 408) 	info BTFIDS vmlinux
017dab341ee75 (Jiri Olsa                2020-09-23 20:57:34 +0200 409) 	${RESOLVE_BTFIDS} vmlinux
c9a0f3b85e09d (Jiri Olsa                2020-07-11 23:53:24 +0200 410) fi
c9a0f3b85e09d (Jiri Olsa                2020-07-11 23:53:24 +0200 411) 
1091670637be8 (Shile Zhang              2019-12-04 08:46:31 +0800 412) if [ -n "${CONFIG_BUILDTIME_TABLE_SORT}" ]; then
1091670637be8 (Shile Zhang              2019-12-04 08:46:31 +0800 413) 	info SORTTAB vmlinux
f14bf6a350dfd (Shile Zhang              2019-12-04 08:46:33 +0800 414) 	if ! sorttable vmlinux; then
f14bf6a350dfd (Shile Zhang              2019-12-04 08:46:33 +0800 415) 		echo >&2 Failed to sort kernel tables
f14bf6a350dfd (Shile Zhang              2019-12-04 08:46:33 +0800 416) 		exit 1
f14bf6a350dfd (Shile Zhang              2019-12-04 08:46:33 +0800 417) 	fi
1347a2cebcb4c (Linus Torvalds           2012-05-28 10:32:28 -0700 418) fi
1347a2cebcb4c (Linus Torvalds           2012-05-28 10:32:28 -0700 419) 
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 420) info SYSMAP System.map
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 421) mksysmap vmlinux System.map
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 422) 
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 423) # step a (see comment above)
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 424) if [ -n "${CONFIG_KALLSYMS}" ]; then
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 425) 	mksysmap ${kallsyms_vmlinux} .tmp_System.map
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 426) 
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 427) 	if ! cmp -s System.map .tmp_System.map; then
5369f55021feb (Michal Marek             2012-07-07 23:04:40 +0200 428) 		echo >&2 Inconsistent kallsyms data
367e43c50d7f7 (Michal Marek             2012-08-10 11:55:11 +0200 429) 		echo >&2 Try "make KALLSYMS_EXTRA_PASS=1" as a workaround
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 430) 		exit 1
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 431) 	fi
1f2bfbd00e466 (Sam Ravnborg             2012-05-05 10:18:41 +0200 432) fi
0b956e204132c (Rasmus Villemoes         2021-03-05 11:02:12 +0100 433) 
0b956e204132c (Rasmus Villemoes         2021-03-05 11:02:12 +0100 434) # For fixdep
0b956e204132c (Rasmus Villemoes         2021-03-05 11:02:12 +0100 435) echo "vmlinux: $0" > .vmlinux.d