18c2ecf20Sopenharmony_ci#!/bin/sh 28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 38c2ecf20Sopenharmony_ci# 48c2ecf20Sopenharmony_ci# link vmlinux 58c2ecf20Sopenharmony_ci# 68c2ecf20Sopenharmony_ci# vmlinux is linked from the objects selected by $(KBUILD_VMLINUX_OBJS) and 78c2ecf20Sopenharmony_ci# $(KBUILD_VMLINUX_LIBS). Most are built-in.a files from top-level directories 88c2ecf20Sopenharmony_ci# in the kernel tree, others are specified in arch/$(ARCH)/Makefile. 98c2ecf20Sopenharmony_ci# $(KBUILD_VMLINUX_LIBS) are archives which are linked conditionally 108c2ecf20Sopenharmony_ci# (not within --whole-archive), and do not require symbol indexes added. 118c2ecf20Sopenharmony_ci# 128c2ecf20Sopenharmony_ci# vmlinux 138c2ecf20Sopenharmony_ci# ^ 148c2ecf20Sopenharmony_ci# | 158c2ecf20Sopenharmony_ci# +--< $(KBUILD_VMLINUX_OBJS) 168c2ecf20Sopenharmony_ci# | +--< init/built-in.a drivers/built-in.a mm/built-in.a + more 178c2ecf20Sopenharmony_ci# | 188c2ecf20Sopenharmony_ci# +--< $(KBUILD_VMLINUX_LIBS) 198c2ecf20Sopenharmony_ci# | +--< lib/lib.a + more 208c2ecf20Sopenharmony_ci# | 218c2ecf20Sopenharmony_ci# +-< ${kallsymso} (see description in KALLSYMS section) 228c2ecf20Sopenharmony_ci# 238c2ecf20Sopenharmony_ci# vmlinux version (uname -v) cannot be updated during normal 248c2ecf20Sopenharmony_ci# descending-into-subdirs phase since we do not yet know if we need to 258c2ecf20Sopenharmony_ci# update vmlinux. 268c2ecf20Sopenharmony_ci# Therefore this step is delayed until just before final link of vmlinux. 278c2ecf20Sopenharmony_ci# 288c2ecf20Sopenharmony_ci# System.map is generated to document addresses of all kernel symbols 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci# Error out on error 318c2ecf20Sopenharmony_ciset -e 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ciLD="$1" 348c2ecf20Sopenharmony_ciKBUILD_LDFLAGS="$2" 358c2ecf20Sopenharmony_ciLDFLAGS_vmlinux="$3" 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci# Nice output in kbuild format 388c2ecf20Sopenharmony_ci# Will be supressed by "make -s" 398c2ecf20Sopenharmony_ciinfo() 408c2ecf20Sopenharmony_ci{ 418c2ecf20Sopenharmony_ci if [ "${quiet}" != "silent_" ]; then 428c2ecf20Sopenharmony_ci printf " %-7s %s\n" "${1}" "${2}" 438c2ecf20Sopenharmony_ci fi 448c2ecf20Sopenharmony_ci} 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci# Generate a linker script to ensure correct ordering of initcalls. 478c2ecf20Sopenharmony_cigen_initcalls() 488c2ecf20Sopenharmony_ci{ 498c2ecf20Sopenharmony_ci info GEN .tmp_initcalls.lds 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci ${PYTHON3} ${srctree}/scripts/jobserver-exec \ 528c2ecf20Sopenharmony_ci ${PERL} ${srctree}/scripts/generate_initcall_order.pl \ 538c2ecf20Sopenharmony_ci ${KBUILD_VMLINUX_OBJS} ${KBUILD_VMLINUX_LIBS} \ 548c2ecf20Sopenharmony_ci > .tmp_initcalls.lds 558c2ecf20Sopenharmony_ci} 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci# If CONFIG_LTO_CLANG is selected, collect generated symbol versions into 588c2ecf20Sopenharmony_ci# .tmp_symversions.lds 598c2ecf20Sopenharmony_cigen_symversions() 608c2ecf20Sopenharmony_ci{ 618c2ecf20Sopenharmony_ci info GEN .tmp_symversions.lds 628c2ecf20Sopenharmony_ci rm -f .tmp_symversions.lds 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci for o in ${KBUILD_VMLINUX_OBJS} ${KBUILD_VMLINUX_LIBS}; do 658c2ecf20Sopenharmony_ci if [ -f ${o}.symversions ]; then 668c2ecf20Sopenharmony_ci cat ${o}.symversions >> .tmp_symversions.lds 678c2ecf20Sopenharmony_ci fi 688c2ecf20Sopenharmony_ci done 698c2ecf20Sopenharmony_ci} 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci# Link of vmlinux.o used for section mismatch analysis 728c2ecf20Sopenharmony_ci# ${1} output file 738c2ecf20Sopenharmony_cimodpost_link() 748c2ecf20Sopenharmony_ci{ 758c2ecf20Sopenharmony_ci local objects 768c2ecf20Sopenharmony_ci local lds="" 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci objects="--whole-archive \ 798c2ecf20Sopenharmony_ci ${KBUILD_VMLINUX_OBJS} \ 808c2ecf20Sopenharmony_ci --no-whole-archive \ 818c2ecf20Sopenharmony_ci --start-group \ 828c2ecf20Sopenharmony_ci ${KBUILD_VMLINUX_LIBS} \ 838c2ecf20Sopenharmony_ci --end-group" 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci if [ -n "${CONFIG_LTO_CLANG}" ]; then 868c2ecf20Sopenharmony_ci gen_initcalls 878c2ecf20Sopenharmony_ci lds="-T .tmp_initcalls.lds" 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci if [ -n "${CONFIG_MODVERSIONS}" ]; then 908c2ecf20Sopenharmony_ci gen_symversions 918c2ecf20Sopenharmony_ci lds="${lds} -T .tmp_symversions.lds" 928c2ecf20Sopenharmony_ci fi 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci # This might take a while, so indicate that we're doing 958c2ecf20Sopenharmony_ci # an LTO link 968c2ecf20Sopenharmony_ci info LTO ${1} 978c2ecf20Sopenharmony_ci else 988c2ecf20Sopenharmony_ci info LD ${1} 998c2ecf20Sopenharmony_ci fi 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci ${LD} ${KBUILD_LDFLAGS} -r -o ${1} ${lds} ${objects} 1028c2ecf20Sopenharmony_ci} 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ciobjtool_link() 1058c2ecf20Sopenharmony_ci{ 1068c2ecf20Sopenharmony_ci local objtoolopt; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci if [ -n "${CONFIG_VMLINUX_VALIDATION}" ]; then 1098c2ecf20Sopenharmony_ci objtoolopt="check" 1108c2ecf20Sopenharmony_ci if [ -n "${CONFIG_CPU_UNRET_ENTRY}" ]; then 1118c2ecf20Sopenharmony_ci objtoolopt="${objtoolopt} --unret" 1128c2ecf20Sopenharmony_ci fi 1138c2ecf20Sopenharmony_ci if [ -z "${CONFIG_FRAME_POINTER}" ]; then 1148c2ecf20Sopenharmony_ci objtoolopt="${objtoolopt} --no-fp" 1158c2ecf20Sopenharmony_ci fi 1168c2ecf20Sopenharmony_ci if [ -n "${CONFIG_GCOV_KERNEL}" ]; then 1178c2ecf20Sopenharmony_ci objtoolopt="${objtoolopt} --no-unreachable" 1188c2ecf20Sopenharmony_ci fi 1198c2ecf20Sopenharmony_ci if [ -n "${CONFIG_RETPOLINE}" ]; then 1208c2ecf20Sopenharmony_ci objtoolopt="${objtoolopt} --retpoline" 1218c2ecf20Sopenharmony_ci fi 1228c2ecf20Sopenharmony_ci if [ -n "${CONFIG_X86_SMAP}" ]; then 1238c2ecf20Sopenharmony_ci objtoolopt="${objtoolopt} --uaccess" 1248c2ecf20Sopenharmony_ci fi 1258c2ecf20Sopenharmony_ci if [ -n "${CONFIG_SLS}" ]; then 1268c2ecf20Sopenharmony_ci objtoolopt="${objtoolopt} --sls" 1278c2ecf20Sopenharmony_ci fi 1288c2ecf20Sopenharmony_ci info OBJTOOL ${1} 1298c2ecf20Sopenharmony_ci tools/objtool/objtool ${objtoolopt} ${1} 1308c2ecf20Sopenharmony_ci fi 1318c2ecf20Sopenharmony_ci} 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci# Link of vmlinux 1348c2ecf20Sopenharmony_ci# ${1} - output file 1358c2ecf20Sopenharmony_ci# ${2}, ${3}, ... - optional extra .o files 1368c2ecf20Sopenharmony_civmlinux_link() 1378c2ecf20Sopenharmony_ci{ 1388c2ecf20Sopenharmony_ci local lds="${objtree}/${KBUILD_LDS}" 1398c2ecf20Sopenharmony_ci local output=${1} 1408c2ecf20Sopenharmony_ci local objects 1418c2ecf20Sopenharmony_ci local strip_debug 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci info LD ${output} 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci # skip output file argument 1468c2ecf20Sopenharmony_ci shift 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci # The kallsyms linking does not need debug symbols included. 1498c2ecf20Sopenharmony_ci if [ "$output" != "${output#.tmp_vmlinux.kallsyms}" ] ; then 1508c2ecf20Sopenharmony_ci strip_debug=-Wl,--strip-debug 1518c2ecf20Sopenharmony_ci fi 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci if [ "${SRCARCH}" != "um" ]; then 1548c2ecf20Sopenharmony_ci if [ -n "${CONFIG_LTO_CLANG}" ]; then 1558c2ecf20Sopenharmony_ci # Use vmlinux.o instead of performing the slow LTO 1568c2ecf20Sopenharmony_ci # link again. 1578c2ecf20Sopenharmony_ci objects="--whole-archive \ 1588c2ecf20Sopenharmony_ci vmlinux.o \ 1598c2ecf20Sopenharmony_ci --no-whole-archive \ 1608c2ecf20Sopenharmony_ci ${@}" 1618c2ecf20Sopenharmony_ci else 1628c2ecf20Sopenharmony_ci objects="--whole-archive \ 1638c2ecf20Sopenharmony_ci ${KBUILD_VMLINUX_OBJS} \ 1648c2ecf20Sopenharmony_ci --no-whole-archive \ 1658c2ecf20Sopenharmony_ci --start-group \ 1668c2ecf20Sopenharmony_ci ${KBUILD_VMLINUX_LIBS} \ 1678c2ecf20Sopenharmony_ci --end-group \ 1688c2ecf20Sopenharmony_ci ${@}" 1698c2ecf20Sopenharmony_ci fi 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci ${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} \ 1728c2ecf20Sopenharmony_ci ${strip_debug#-Wl,} \ 1738c2ecf20Sopenharmony_ci -o ${output} \ 1748c2ecf20Sopenharmony_ci -T ${lds} ${objects} 1758c2ecf20Sopenharmony_ci else 1768c2ecf20Sopenharmony_ci objects="-Wl,--whole-archive \ 1778c2ecf20Sopenharmony_ci ${KBUILD_VMLINUX_OBJS} \ 1788c2ecf20Sopenharmony_ci -Wl,--no-whole-archive \ 1798c2ecf20Sopenharmony_ci -Wl,--start-group \ 1808c2ecf20Sopenharmony_ci ${KBUILD_VMLINUX_LIBS} \ 1818c2ecf20Sopenharmony_ci -Wl,--end-group \ 1828c2ecf20Sopenharmony_ci ${@}" 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci ${CC} ${CFLAGS_vmlinux} \ 1858c2ecf20Sopenharmony_ci ${strip_debug} \ 1868c2ecf20Sopenharmony_ci -o ${output} \ 1878c2ecf20Sopenharmony_ci -Wl,-T,${lds} \ 1888c2ecf20Sopenharmony_ci ${objects} \ 1898c2ecf20Sopenharmony_ci -lutil -lrt -lpthread 1908c2ecf20Sopenharmony_ci rm -f linux 1918c2ecf20Sopenharmony_ci fi 1928c2ecf20Sopenharmony_ci} 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci# generate .BTF typeinfo from DWARF debuginfo 1958c2ecf20Sopenharmony_ci# ${1} - vmlinux image 1968c2ecf20Sopenharmony_ci# ${2} - file to dump raw BTF data into 1978c2ecf20Sopenharmony_cigen_btf() 1988c2ecf20Sopenharmony_ci{ 1998c2ecf20Sopenharmony_ci local pahole_ver 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci if ! [ -x "$(command -v ${PAHOLE})" ]; then 2028c2ecf20Sopenharmony_ci echo >&2 "BTF: ${1}: pahole (${PAHOLE}) is not available" 2038c2ecf20Sopenharmony_ci return 1 2048c2ecf20Sopenharmony_ci fi 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci pahole_ver=$(${PAHOLE} --version | sed -E 's/v([0-9]+)\.([0-9]+)/\1\2/') 2078c2ecf20Sopenharmony_ci if [ "${pahole_ver}" -lt "116" ]; then 2088c2ecf20Sopenharmony_ci echo >&2 "BTF: ${1}: pahole version $(${PAHOLE} --version) is too old, need at least v1.16" 2098c2ecf20Sopenharmony_ci return 1 2108c2ecf20Sopenharmony_ci fi 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci vmlinux_link ${1} 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci info "BTF" ${2} 2158c2ecf20Sopenharmony_ci LLVM_OBJCOPY="${OBJCOPY}" ${PAHOLE} -J ${PAHOLE_FLAGS} ${1} 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci # Create ${2} which contains just .BTF section but no symbols. Add 2188c2ecf20Sopenharmony_ci # SHF_ALLOC because .BTF will be part of the vmlinux image. --strip-all 2198c2ecf20Sopenharmony_ci # deletes all symbols including __start_BTF and __stop_BTF, which will 2208c2ecf20Sopenharmony_ci # be redefined in the linker script. Add 2>/dev/null to suppress GNU 2218c2ecf20Sopenharmony_ci # objcopy warnings: "empty loadable segment detected at ..." 2228c2ecf20Sopenharmony_ci ${OBJCOPY} --only-section=.BTF --set-section-flags .BTF=alloc,readonly \ 2238c2ecf20Sopenharmony_ci --strip-all ${1} ${2} 2>/dev/null 2248c2ecf20Sopenharmony_ci # Change e_type to ET_REL so that it can be used to link final vmlinux. 2258c2ecf20Sopenharmony_ci # GNU ld 2.35+ and lld do not allow an ET_EXEC input. 2268c2ecf20Sopenharmony_ci if [ -n "${CONFIG_CPU_BIG_ENDIAN}" ]; then 2278c2ecf20Sopenharmony_ci et_rel='\0\1' 2288c2ecf20Sopenharmony_ci else 2298c2ecf20Sopenharmony_ci et_rel='\1\0' 2308c2ecf20Sopenharmony_ci fi 2318c2ecf20Sopenharmony_ci printf "${et_rel}" | dd of=${2} conv=notrunc bs=1 seek=16 status=none 2328c2ecf20Sopenharmony_ci} 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci# Create ${2} .S file with all symbols from the ${1} object file 2358c2ecf20Sopenharmony_cikallsyms() 2368c2ecf20Sopenharmony_ci{ 2378c2ecf20Sopenharmony_ci local kallsymopt; 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci if [ -n "${CONFIG_KALLSYMS_ALL}" ]; then 2408c2ecf20Sopenharmony_ci kallsymopt="${kallsymopt} --all-symbols" 2418c2ecf20Sopenharmony_ci fi 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci if [ -n "${CONFIG_KALLSYMS_ABSOLUTE_PERCPU}" ]; then 2448c2ecf20Sopenharmony_ci kallsymopt="${kallsymopt} --absolute-percpu" 2458c2ecf20Sopenharmony_ci fi 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci if [ -n "${CONFIG_KALLSYMS_BASE_RELATIVE}" ]; then 2488c2ecf20Sopenharmony_ci kallsymopt="${kallsymopt} --base-relative" 2498c2ecf20Sopenharmony_ci fi 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci info KSYMS ${2} 2528c2ecf20Sopenharmony_ci ${NM} -n ${1} | scripts/kallsyms ${kallsymopt} > ${2} 2538c2ecf20Sopenharmony_ci} 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci# Perform one step in kallsyms generation, including temporary linking of 2568c2ecf20Sopenharmony_ci# vmlinux. 2578c2ecf20Sopenharmony_cikallsyms_step() 2588c2ecf20Sopenharmony_ci{ 2598c2ecf20Sopenharmony_ci kallsymso_prev=${kallsymso} 2608c2ecf20Sopenharmony_ci kallsyms_vmlinux=.tmp_vmlinux.kallsyms${1} 2618c2ecf20Sopenharmony_ci kallsymso=${kallsyms_vmlinux}.o 2628c2ecf20Sopenharmony_ci kallsyms_S=${kallsyms_vmlinux}.S 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci vmlinux_link ${kallsyms_vmlinux} "${kallsymso_prev}" ${btf_vmlinux_bin_o} 2658c2ecf20Sopenharmony_ci kallsyms ${kallsyms_vmlinux} ${kallsyms_S} 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci info AS ${kallsyms_S} 2688c2ecf20Sopenharmony_ci ${CC} ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS} \ 2698c2ecf20Sopenharmony_ci ${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \ 2708c2ecf20Sopenharmony_ci -c -o ${kallsymso} ${kallsyms_S} 2718c2ecf20Sopenharmony_ci} 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci# Create map file with all symbols from ${1} 2748c2ecf20Sopenharmony_ci# See mksymap for additional details 2758c2ecf20Sopenharmony_cimksysmap() 2768c2ecf20Sopenharmony_ci{ 2778c2ecf20Sopenharmony_ci ${CONFIG_SHELL} "${srctree}/scripts/mksysmap" ${1} ${2} 2788c2ecf20Sopenharmony_ci} 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_cisorttable() 2818c2ecf20Sopenharmony_ci{ 2828c2ecf20Sopenharmony_ci ${objtree}/scripts/sorttable ${1} 2838c2ecf20Sopenharmony_ci} 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci# Delete output files in case of error 2868c2ecf20Sopenharmony_cicleanup() 2878c2ecf20Sopenharmony_ci{ 2888c2ecf20Sopenharmony_ci rm -f .btf.* 2898c2ecf20Sopenharmony_ci rm -f .tmp_System.map 2908c2ecf20Sopenharmony_ci rm -f .tmp_initcalls.lds 2918c2ecf20Sopenharmony_ci rm -f .tmp_symversions.lds 2928c2ecf20Sopenharmony_ci rm -f .tmp_vmlinux* 2938c2ecf20Sopenharmony_ci rm -f System.map 2948c2ecf20Sopenharmony_ci rm -f vmlinux 2958c2ecf20Sopenharmony_ci rm -f vmlinux.o 2968c2ecf20Sopenharmony_ci} 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_cion_exit() 2998c2ecf20Sopenharmony_ci{ 3008c2ecf20Sopenharmony_ci if [ $? -ne 0 ]; then 3018c2ecf20Sopenharmony_ci cleanup 3028c2ecf20Sopenharmony_ci fi 3038c2ecf20Sopenharmony_ci} 3048c2ecf20Sopenharmony_citrap on_exit EXIT 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_cion_signals() 3078c2ecf20Sopenharmony_ci{ 3088c2ecf20Sopenharmony_ci exit 1 3098c2ecf20Sopenharmony_ci} 3108c2ecf20Sopenharmony_citrap on_signals HUP INT QUIT TERM 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci# Use "make V=1" to debug this script 3138c2ecf20Sopenharmony_cicase "${KBUILD_VERBOSE}" in 3148c2ecf20Sopenharmony_ci*1*) 3158c2ecf20Sopenharmony_ci set -x 3168c2ecf20Sopenharmony_ci ;; 3178c2ecf20Sopenharmony_ciesac 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ciif [ "$1" = "clean" ]; then 3208c2ecf20Sopenharmony_ci cleanup 3218c2ecf20Sopenharmony_ci exit 0 3228c2ecf20Sopenharmony_cifi 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_ci# We need access to CONFIG_ symbols 3258c2ecf20Sopenharmony_ci. include/config/auto.conf 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci# Update version 3288c2ecf20Sopenharmony_ciinfo GEN .version 3298c2ecf20Sopenharmony_ciif [ -r .version ]; then 3308c2ecf20Sopenharmony_ci VERSION=$(expr 0$(cat .version) + 1) 3318c2ecf20Sopenharmony_ci echo $VERSION > .version 3328c2ecf20Sopenharmony_cielse 3338c2ecf20Sopenharmony_ci rm -f .version 3348c2ecf20Sopenharmony_ci echo 1 > .version 3358c2ecf20Sopenharmony_cifi; 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci# final build of init/ 3388c2ecf20Sopenharmony_ci${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init need-builtin=1 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci#link vmlinux.o 3418c2ecf20Sopenharmony_cimodpost_link vmlinux.o 3428c2ecf20Sopenharmony_ciobjtool_link vmlinux.o 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci# modpost vmlinux.o to check for section mismatches 3458c2ecf20Sopenharmony_ci${MAKE} -f "${srctree}/scripts/Makefile.modpost" MODPOST_VMLINUX=1 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ciinfo MODINFO modules.builtin.modinfo 3488c2ecf20Sopenharmony_ci${OBJCOPY} -j .modinfo -O binary vmlinux.o modules.builtin.modinfo 3498c2ecf20Sopenharmony_ciinfo GEN modules.builtin 3508c2ecf20Sopenharmony_ci# The second line aids cases where multiple modules share the same object. 3518c2ecf20Sopenharmony_citr '\0' '\n' < modules.builtin.modinfo | sed -n 's/^[[:alnum:]:_]*\.file=//p' | 3528c2ecf20Sopenharmony_ci tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$/.ko/' > modules.builtin 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_cibtf_vmlinux_bin_o="" 3558c2ecf20Sopenharmony_ciif [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then 3568c2ecf20Sopenharmony_ci btf_vmlinux_bin_o=.btf.vmlinux.bin.o 3578c2ecf20Sopenharmony_ci if ! gen_btf .tmp_vmlinux.btf $btf_vmlinux_bin_o ; then 3588c2ecf20Sopenharmony_ci echo >&2 "Failed to generate BTF for vmlinux" 3598c2ecf20Sopenharmony_ci echo >&2 "Try to disable CONFIG_DEBUG_INFO_BTF" 3608c2ecf20Sopenharmony_ci exit 1 3618c2ecf20Sopenharmony_ci fi 3628c2ecf20Sopenharmony_cifi 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_cikallsymso="" 3658c2ecf20Sopenharmony_cikallsymso_prev="" 3668c2ecf20Sopenharmony_cikallsyms_vmlinux="" 3678c2ecf20Sopenharmony_ciif [ -n "${CONFIG_KALLSYMS}" ]; then 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci # kallsyms support 3708c2ecf20Sopenharmony_ci # Generate section listing all symbols and add it into vmlinux 3718c2ecf20Sopenharmony_ci # It's a three step process: 3728c2ecf20Sopenharmony_ci # 1) Link .tmp_vmlinux1 so it has all symbols and sections, 3738c2ecf20Sopenharmony_ci # but __kallsyms is empty. 3748c2ecf20Sopenharmony_ci # Running kallsyms on that gives us .tmp_kallsyms1.o with 3758c2ecf20Sopenharmony_ci # the right size 3768c2ecf20Sopenharmony_ci # 2) Link .tmp_vmlinux2 so it now has a __kallsyms section of 3778c2ecf20Sopenharmony_ci # the right size, but due to the added section, some 3788c2ecf20Sopenharmony_ci # addresses have shifted. 3798c2ecf20Sopenharmony_ci # From here, we generate a correct .tmp_kallsyms2.o 3808c2ecf20Sopenharmony_ci # 3) That link may have expanded the kernel image enough that 3818c2ecf20Sopenharmony_ci # more linker branch stubs / trampolines had to be added, which 3828c2ecf20Sopenharmony_ci # introduces new names, which further expands kallsyms. Do another 3838c2ecf20Sopenharmony_ci # pass if that is the case. In theory it's possible this results 3848c2ecf20Sopenharmony_ci # in even more stubs, but unlikely. 3858c2ecf20Sopenharmony_ci # KALLSYMS_EXTRA_PASS=1 may also used to debug or work around 3868c2ecf20Sopenharmony_ci # other bugs. 3878c2ecf20Sopenharmony_ci # 4) The correct ${kallsymso} is linked into the final vmlinux. 3888c2ecf20Sopenharmony_ci # 3898c2ecf20Sopenharmony_ci # a) Verify that the System.map from vmlinux matches the map from 3908c2ecf20Sopenharmony_ci # ${kallsymso}. 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci kallsyms_step 1 3938c2ecf20Sopenharmony_ci kallsyms_step 2 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci # step 3 3968c2ecf20Sopenharmony_ci size1=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" ${kallsymso_prev}) 3978c2ecf20Sopenharmony_ci size2=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" ${kallsymso}) 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci if [ $size1 -ne $size2 ] || [ -n "${KALLSYMS_EXTRA_PASS}" ]; then 4008c2ecf20Sopenharmony_ci kallsyms_step 3 4018c2ecf20Sopenharmony_ci fi 4028c2ecf20Sopenharmony_cifi 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_civmlinux_link vmlinux "${kallsymso}" ${btf_vmlinux_bin_o} 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci# fill in BTF IDs 4078c2ecf20Sopenharmony_ciif [ -n "${CONFIG_DEBUG_INFO_BTF}" -a -n "${CONFIG_BPF}" ]; then 4088c2ecf20Sopenharmony_ci info BTFIDS vmlinux 4098c2ecf20Sopenharmony_ci ${RESOLVE_BTFIDS} vmlinux 4108c2ecf20Sopenharmony_cifi 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ciif [ -n "${CONFIG_BUILDTIME_TABLE_SORT}" ]; then 4138c2ecf20Sopenharmony_ci info SORTTAB vmlinux 4148c2ecf20Sopenharmony_ci if ! sorttable vmlinux; then 4158c2ecf20Sopenharmony_ci echo >&2 Failed to sort kernel tables 4168c2ecf20Sopenharmony_ci exit 1 4178c2ecf20Sopenharmony_ci fi 4188c2ecf20Sopenharmony_cifi 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_ciinfo SYSMAP System.map 4218c2ecf20Sopenharmony_cimksysmap vmlinux System.map 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci# step a (see comment above) 4248c2ecf20Sopenharmony_ciif [ -n "${CONFIG_KALLSYMS}" ]; then 4258c2ecf20Sopenharmony_ci mksysmap ${kallsyms_vmlinux} .tmp_System.map 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ci if ! cmp -s System.map .tmp_System.map; then 4288c2ecf20Sopenharmony_ci echo >&2 Inconsistent kallsyms data 4298c2ecf20Sopenharmony_ci echo >&2 Try "make KALLSYMS_EXTRA_PASS=1" as a workaround 4308c2ecf20Sopenharmony_ci exit 1 4318c2ecf20Sopenharmony_ci fi 4328c2ecf20Sopenharmony_cifi 433