link-vmlinux.sh (272172bd418cc32aa466588150c8001bc229c712) | link-vmlinux.sh (341dfcf8d78eaa3a2dc96dea06f0392eb2978364) |
---|---|
1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0 3# 4# link vmlinux 5# 6# vmlinux is linked from the objects selected by $(KBUILD_VMLINUX_OBJS) and 7# $(KBUILD_VMLINUX_LIBS). Most are built-in.a files from top-level directories 8# in the kernel tree, others are specified in arch/$(ARCH)/Makefile. --- 42 unchanged lines hidden (view full) --- 51 --start-group \ 52 ${KBUILD_VMLINUX_LIBS} \ 53 --end-group" 54 55 ${LD} ${KBUILD_LDFLAGS} -r -o ${1} ${objects} 56} 57 58# Link of vmlinux | 1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0 3# 4# link vmlinux 5# 6# vmlinux is linked from the objects selected by $(KBUILD_VMLINUX_OBJS) and 7# $(KBUILD_VMLINUX_LIBS). Most are built-in.a files from top-level directories 8# in the kernel tree, others are specified in arch/$(ARCH)/Makefile. --- 42 unchanged lines hidden (view full) --- 51 --start-group \ 52 ${KBUILD_VMLINUX_LIBS} \ 53 --end-group" 54 55 ${LD} ${KBUILD_LDFLAGS} -r -o ${1} ${objects} 56} 57 58# Link of vmlinux |
59# ${1} - optional extra .o files 60# ${2} - output file | 59# ${1} - output file 60# ${@:2} - optional extra .o files |
61vmlinux_link() 62{ 63 local lds="${objtree}/${KBUILD_LDS}" 64 local objects 65 66 if [ "${SRCARCH}" != "um" ]; then 67 objects="--whole-archive \ 68 ${KBUILD_VMLINUX_OBJS} \ 69 --no-whole-archive \ 70 --start-group \ 71 ${KBUILD_VMLINUX_LIBS} \ 72 --end-group \ | 61vmlinux_link() 62{ 63 local lds="${objtree}/${KBUILD_LDS}" 64 local objects 65 66 if [ "${SRCARCH}" != "um" ]; then 67 objects="--whole-archive \ 68 ${KBUILD_VMLINUX_OBJS} \ 69 --no-whole-archive \ 70 --start-group \ 71 ${KBUILD_VMLINUX_LIBS} \ 72 --end-group \ |
73 ${1}" | 73 ${@:2}" |
74 | 74 |
75 ${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} -o ${2} \ | 75 ${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} -o ${1} \ |
76 -T ${lds} ${objects} 77 else 78 objects="-Wl,--whole-archive \ 79 ${KBUILD_VMLINUX_OBJS} \ 80 -Wl,--no-whole-archive \ 81 -Wl,--start-group \ 82 ${KBUILD_VMLINUX_LIBS} \ 83 -Wl,--end-group \ | 76 -T ${lds} ${objects} 77 else 78 objects="-Wl,--whole-archive \ 79 ${KBUILD_VMLINUX_OBJS} \ 80 -Wl,--no-whole-archive \ 81 -Wl,--start-group \ 82 ${KBUILD_VMLINUX_LIBS} \ 83 -Wl,--end-group \ |
84 ${1}" | 84 ${@:2}" |
85 | 85 |
86 ${CC} ${CFLAGS_vmlinux} -o ${2} \ | 86 ${CC} ${CFLAGS_vmlinux} -o ${1} \ |
87 -Wl,-T,${lds} \ 88 ${objects} \ 89 -lutil -lrt -lpthread 90 rm -f linux 91 fi 92} 93 94# generate .BTF typeinfo from DWARF debuginfo | 87 -Wl,-T,${lds} \ 88 ${objects} \ 89 -lutil -lrt -lpthread 90 rm -f linux 91 fi 92} 93 94# generate .BTF typeinfo from DWARF debuginfo |
95# ${1} - vmlinux image 96# ${2} - file to dump raw BTF data into |
|
95gen_btf() 96{ | 97gen_btf() 98{ |
97 local pahole_ver; | 99 local pahole_ver 100 local bin_arch |
98 99 if ! [ -x "$(command -v ${PAHOLE})" ]; then 100 info "BTF" "${1}: pahole (${PAHOLE}) is not available" | 101 102 if ! [ -x "$(command -v ${PAHOLE})" ]; then 103 info "BTF" "${1}: pahole (${PAHOLE}) is not available" |
101 return 0 | 104 return 1 |
102 fi 103 104 pahole_ver=$(${PAHOLE} --version | sed -E 's/v([0-9]+)\.([0-9]+)/\1\2/') 105 if [ "${pahole_ver}" -lt "113" ]; then 106 info "BTF" "${1}: pahole version $(${PAHOLE} --version) is too old, need at least v1.13" | 105 fi 106 107 pahole_ver=$(${PAHOLE} --version | sed -E 's/v([0-9]+)\.([0-9]+)/\1\2/') 108 if [ "${pahole_ver}" -lt "113" ]; then 109 info "BTF" "${1}: pahole version $(${PAHOLE} --version) is too old, need at least v1.13" |
107 return 0 | 110 return 1 |
108 fi 109 | 111 fi 112 |
110 info "BTF" ${1} | 113 info "BTF" ${2} 114 vmlinux_link ${1} |
111 LLVM_OBJCOPY=${OBJCOPY} ${PAHOLE} -J ${1} | 115 LLVM_OBJCOPY=${OBJCOPY} ${PAHOLE} -J ${1} |
116 117 # dump .BTF section into raw binary file to link with final vmlinux 118 bin_arch=$(${OBJDUMP} -f ${1} | grep architecture | \ 119 cut -d, -f1 | cut -d' ' -f2) 120 ${OBJCOPY} --dump-section .BTF=.btf.kernel.bin ${1} 2>/dev/null 121 ${OBJCOPY} -I binary -O ${CONFIG_OUTPUT_FORMAT} -B ${bin_arch} \ 122 --rename-section .data=.BTF .btf.kernel.bin ${2} |
|
112} 113 114# Create ${2} .o file with all symbols from the ${1} object file 115kallsyms() 116{ 117 info KSYM ${2} 118 local kallsymopt; 119 --- 28 unchanged lines hidden (view full) --- 148sortextable() 149{ 150 ${objtree}/scripts/sortextable ${1} 151} 152 153# Delete output files in case of error 154cleanup() 155{ | 123} 124 125# Create ${2} .o file with all symbols from the ${1} object file 126kallsyms() 127{ 128 info KSYM ${2} 129 local kallsymopt; 130 --- 28 unchanged lines hidden (view full) --- 159sortextable() 160{ 161 ${objtree}/scripts/sortextable ${1} 162} 163 164# Delete output files in case of error 165cleanup() 166{ |
167 rm -f .btf.* |
|
156 rm -f .tmp_System.map 157 rm -f .tmp_kallsyms* 158 rm -f .tmp_vmlinux* 159 rm -f System.map 160 rm -f vmlinux 161 rm -f vmlinux.o 162} 163 --- 41 unchanged lines hidden (view full) --- 205# final build of init/ 206${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init 207 208#link vmlinux.o 209info LD vmlinux.o 210modpost_link vmlinux.o 211 212# modpost vmlinux.o to check for section mismatches | 168 rm -f .tmp_System.map 169 rm -f .tmp_kallsyms* 170 rm -f .tmp_vmlinux* 171 rm -f System.map 172 rm -f vmlinux 173 rm -f vmlinux.o 174} 175 --- 41 unchanged lines hidden (view full) --- 217# final build of init/ 218${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init 219 220#link vmlinux.o 221info LD vmlinux.o 222modpost_link vmlinux.o 223 224# modpost vmlinux.o to check for section mismatches |
213${MAKE} -f "${srctree}/scripts/Makefile.modpost" MODPOST_VMLINUX=1 | 225${MAKE} -f "${srctree}/scripts/Makefile.modpost" vmlinux.o |
214 215info MODINFO modules.builtin.modinfo 216${OBJCOPY} -j .modinfo -O binary vmlinux.o modules.builtin.modinfo 217 | 226 227info MODINFO modules.builtin.modinfo 228${OBJCOPY} -j .modinfo -O binary vmlinux.o modules.builtin.modinfo 229 |
230btf_kernel_bin_o="" 231if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then 232 if gen_btf .tmp_vmlinux.btf .btf.kernel.bin.o ; then 233 btf_kernel_bin_o=.btf.kernel.bin.o 234 fi 235fi 236 |
|
218kallsymso="" 219kallsyms_vmlinux="" 220if [ -n "${CONFIG_KALLSYMS}" ]; then 221 222 # kallsyms support 223 # Generate section listing all symbols and add it into vmlinux 224 # It's a three step process: 225 # 1) Link .tmp_vmlinux1 so it has all symbols and sections, --- 15 unchanged lines hidden (view full) --- 241 # 242 # a) Verify that the System.map from vmlinux matches the map from 243 # ${kallsymso}. 244 245 kallsymso=.tmp_kallsyms2.o 246 kallsyms_vmlinux=.tmp_vmlinux2 247 248 # step 1 | 237kallsymso="" 238kallsyms_vmlinux="" 239if [ -n "${CONFIG_KALLSYMS}" ]; then 240 241 # kallsyms support 242 # Generate section listing all symbols and add it into vmlinux 243 # It's a three step process: 244 # 1) Link .tmp_vmlinux1 so it has all symbols and sections, --- 15 unchanged lines hidden (view full) --- 260 # 261 # a) Verify that the System.map from vmlinux matches the map from 262 # ${kallsymso}. 263 264 kallsymso=.tmp_kallsyms2.o 265 kallsyms_vmlinux=.tmp_vmlinux2 266 267 # step 1 |
249 vmlinux_link "" .tmp_vmlinux1 | 268 vmlinux_link .tmp_vmlinux1 ${btf_kernel_bin_o} |
250 kallsyms .tmp_vmlinux1 .tmp_kallsyms1.o 251 252 # step 2 | 269 kallsyms .tmp_vmlinux1 .tmp_kallsyms1.o 270 271 # step 2 |
253 vmlinux_link .tmp_kallsyms1.o .tmp_vmlinux2 | 272 vmlinux_link .tmp_vmlinux2 .tmp_kallsyms1.o ${btf_kernel_bin_o} |
254 kallsyms .tmp_vmlinux2 .tmp_kallsyms2.o 255 256 # step 3 257 size1=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" .tmp_kallsyms1.o) 258 size2=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" .tmp_kallsyms2.o) 259 260 if [ $size1 -ne $size2 ] || [ -n "${KALLSYMS_EXTRA_PASS}" ]; then 261 kallsymso=.tmp_kallsyms3.o 262 kallsyms_vmlinux=.tmp_vmlinux3 263 | 273 kallsyms .tmp_vmlinux2 .tmp_kallsyms2.o 274 275 # step 3 276 size1=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" .tmp_kallsyms1.o) 277 size2=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" .tmp_kallsyms2.o) 278 279 if [ $size1 -ne $size2 ] || [ -n "${KALLSYMS_EXTRA_PASS}" ]; then 280 kallsymso=.tmp_kallsyms3.o 281 kallsyms_vmlinux=.tmp_vmlinux3 282 |
264 vmlinux_link .tmp_kallsyms2.o .tmp_vmlinux3 265 | 283 vmlinux_link .tmp_vmlinux3 .tmp_kallsyms2.o ${btf_kernel_bin_o} |
266 kallsyms .tmp_vmlinux3 .tmp_kallsyms3.o 267 fi 268fi 269 270info LD vmlinux | 284 kallsyms .tmp_vmlinux3 .tmp_kallsyms3.o 285 fi 286fi 287 288info LD vmlinux |
271vmlinux_link "${kallsymso}" vmlinux | 289vmlinux_link vmlinux "${kallsymso}" "${btf_kernel_bin_o}" |
272 | 290 |
273if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then 274 gen_btf vmlinux 275fi 276 | |
277if [ -n "${CONFIG_BUILDTIME_EXTABLE_SORT}" ]; then 278 info SORTEX vmlinux 279 sortextable vmlinux 280fi 281 282info SYSMAP System.map 283mksysmap vmlinux System.map 284 285# step a (see comment above) 286if [ -n "${CONFIG_KALLSYMS}" ]; then 287 mksysmap ${kallsyms_vmlinux} .tmp_System.map 288 289 if ! cmp -s System.map .tmp_System.map; then 290 echo >&2 Inconsistent kallsyms data 291 echo >&2 Try "make KALLSYMS_EXTRA_PASS=1" as a workaround 292 exit 1 293 fi 294fi | 291if [ -n "${CONFIG_BUILDTIME_EXTABLE_SORT}" ]; then 292 info SORTEX vmlinux 293 sortextable vmlinux 294fi 295 296info SYSMAP System.map 297mksysmap vmlinux System.map 298 299# step a (see comment above) 300if [ -n "${CONFIG_KALLSYMS}" ]; then 301 mksysmap ${kallsyms_vmlinux} .tmp_System.map 302 303 if ! cmp -s System.map .tmp_System.map; then 304 echo >&2 Inconsistent kallsyms data 305 echo >&2 Try "make KALLSYMS_EXTRA_PASS=1" as a workaround 306 exit 1 307 fi 308fi |