link-vmlinux.sh (f81483aaeb59da530b286fe5d081e1705eb5c886) | link-vmlinux.sh (7d153696e5db1e37387c2f7ec06ffc8d4aac70a4) |
---|---|
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. --- 20 unchanged lines hidden (view full) --- 29 30# Error out on error 31set -e 32 33LD="$1" 34KBUILD_LDFLAGS="$2" 35LDFLAGS_vmlinux="$3" 36 | 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. --- 20 unchanged lines hidden (view full) --- 29 30# Error out on error 31set -e 32 33LD="$1" 34KBUILD_LDFLAGS="$2" 35LDFLAGS_vmlinux="$3" 36 |
37is_enabled() { 38 grep -q "^$1=y" include/config/auto.conf 39} 40 |
|
37# Nice output in kbuild format 38# Will be supressed by "make -s" 39info() 40{ 41 printf " %-7s %s\n" "${1}" "${2}" 42} 43 44# Generate a linker script to ensure correct ordering of initcalls. --- 30 unchanged lines hidden (view full) --- 75 76 objects="--whole-archive \ 77 ${KBUILD_VMLINUX_OBJS} \ 78 --no-whole-archive \ 79 --start-group \ 80 ${KBUILD_VMLINUX_LIBS} \ 81 --end-group" 82 | 41# Nice output in kbuild format 42# Will be supressed by "make -s" 43info() 44{ 45 printf " %-7s %s\n" "${1}" "${2}" 46} 47 48# Generate a linker script to ensure correct ordering of initcalls. --- 30 unchanged lines hidden (view full) --- 79 80 objects="--whole-archive \ 81 ${KBUILD_VMLINUX_OBJS} \ 82 --no-whole-archive \ 83 --start-group \ 84 ${KBUILD_VMLINUX_LIBS} \ 85 --end-group" 86 |
83 if [ -n "${CONFIG_LTO_CLANG}" ]; then | 87 if is_enabled CONFIG_LTO_CLANG; then |
84 gen_initcalls 85 lds="-T .tmp_initcalls.lds" 86 | 88 gen_initcalls 89 lds="-T .tmp_initcalls.lds" 90 |
87 if [ -n "${CONFIG_MODVERSIONS}" ]; then | 91 if is_enabled CONFIG_MODVERSIONS; then |
88 gen_symversions 89 lds="${lds} -T .tmp_symversions.lds" 90 fi 91 92 # This might take a while, so indicate that we're doing 93 # an LTO link 94 info LTO ${1} 95 else 96 info LD ${1} 97 fi 98 99 ${LD} ${KBUILD_LDFLAGS} -r -o ${1} ${lds} ${objects} 100} 101 102objtool_link() 103{ 104 local objtoolcmd; 105 local objtoolopt; 106 | 92 gen_symversions 93 lds="${lds} -T .tmp_symversions.lds" 94 fi 95 96 # This might take a while, so indicate that we're doing 97 # an LTO link 98 info LTO ${1} 99 else 100 info LD ${1} 101 fi 102 103 ${LD} ${KBUILD_LDFLAGS} -r -o ${1} ${lds} ${objects} 104} 105 106objtool_link() 107{ 108 local objtoolcmd; 109 local objtoolopt; 110 |
107 if [ "${CONFIG_LTO_CLANG} ${CONFIG_STACK_VALIDATION}" = "y y" ]; then | 111 if is_enabled CONFIG_LTO_CLANG && is_enabled CONFIG_STACK_VALIDATION; then |
108 # Don't perform vmlinux validation unless explicitly requested, 109 # but run objtool on vmlinux.o now that we have an object file. | 112 # Don't perform vmlinux validation unless explicitly requested, 113 # but run objtool on vmlinux.o now that we have an object file. |
110 if [ -n "${CONFIG_UNWINDER_ORC}" ]; then | 114 if is_enabled CONFIG_UNWINDER_ORC; then |
111 objtoolcmd="orc generate" 112 fi 113 114 objtoolopt="${objtoolopt} --duplicate" 115 | 115 objtoolcmd="orc generate" 116 fi 117 118 objtoolopt="${objtoolopt} --duplicate" 119 |
116 if [ -n "${CONFIG_FTRACE_MCOUNT_USE_OBJTOOL}" ]; then | 120 if is_enabled CONFIG_FTRACE_MCOUNT_USE_OBJTOOL; then |
117 objtoolopt="${objtoolopt} --mcount" 118 fi 119 fi 120 | 121 objtoolopt="${objtoolopt} --mcount" 122 fi 123 fi 124 |
121 if [ -n "${CONFIG_VMLINUX_VALIDATION}" ]; then | 125 if is_enabled CONFIG_VMLINUX_VALIDATION; then |
122 objtoolopt="${objtoolopt} --noinstr" 123 fi 124 125 if [ -n "${objtoolopt}" ]; then 126 if [ -z "${objtoolcmd}" ]; then 127 objtoolcmd="check" 128 fi 129 objtoolopt="${objtoolopt} --vmlinux" | 126 objtoolopt="${objtoolopt} --noinstr" 127 fi 128 129 if [ -n "${objtoolopt}" ]; then 130 if [ -z "${objtoolcmd}" ]; then 131 objtoolcmd="check" 132 fi 133 objtoolopt="${objtoolopt} --vmlinux" |
130 if [ -z "${CONFIG_FRAME_POINTER}" ]; then | 134 if ! is_enabled CONFIG_FRAME_POINTER; then |
131 objtoolopt="${objtoolopt} --no-fp" 132 fi | 135 objtoolopt="${objtoolopt} --no-fp" 136 fi |
133 if [ -n "${CONFIG_GCOV_KERNEL}" ] || [ -n "${CONFIG_LTO_CLANG}" ]; then | 137 if is_enabled CONFIG_GCOV_KERNEL || is_enabled CONFIG_LTO_CLANG; then |
134 objtoolopt="${objtoolopt} --no-unreachable" 135 fi | 138 objtoolopt="${objtoolopt} --no-unreachable" 139 fi |
136 if [ -n "${CONFIG_RETPOLINE}" ]; then | 140 if is_enabled CONFIG_RETPOLINE; then |
137 objtoolopt="${objtoolopt} --retpoline" 138 fi | 141 objtoolopt="${objtoolopt} --retpoline" 142 fi |
139 if [ -n "${CONFIG_X86_SMAP}" ]; then | 143 if is_enabled CONFIG_X86_SMAP; then |
140 objtoolopt="${objtoolopt} --uaccess" 141 fi 142 info OBJTOOL ${1} 143 tools/objtool/objtool ${objtoolcmd} ${objtoolopt} ${1} 144 fi 145} 146 147# Link of vmlinux --- 8 unchanged lines hidden (view full) --- 156 local ldflags 157 local ldlibs 158 159 info LD ${output} 160 161 # skip output file argument 162 shift 163 | 144 objtoolopt="${objtoolopt} --uaccess" 145 fi 146 info OBJTOOL ${1} 147 tools/objtool/objtool ${objtoolcmd} ${objtoolopt} ${1} 148 fi 149} 150 151# Link of vmlinux --- 8 unchanged lines hidden (view full) --- 160 local ldflags 161 local ldlibs 162 163 info LD ${output} 164 165 # skip output file argument 166 shift 167 |
164 if [ -n "${CONFIG_LTO_CLANG}" ]; then | 168 if is_enabled CONFIG_LTO_CLANG; then |
165 # Use vmlinux.o instead of performing the slow LTO link again. 166 objs=vmlinux.o 167 libs= 168 else 169 objs="${KBUILD_VMLINUX_OBJS}" 170 libs="${KBUILD_VMLINUX_LIBS}" 171 fi 172 --- 11 unchanged lines hidden (view full) --- 184 185 ldflags="${ldflags} ${wl}--script=${objtree}/${KBUILD_LDS}" 186 187 # The kallsyms linking does not need debug symbols included. 188 if [ "$output" != "${output#.tmp_vmlinux.kallsyms}" ] ; then 189 ldflags="${ldflags} ${wl}--strip-debug" 190 fi 191 | 169 # Use vmlinux.o instead of performing the slow LTO link again. 170 objs=vmlinux.o 171 libs= 172 else 173 objs="${KBUILD_VMLINUX_OBJS}" 174 libs="${KBUILD_VMLINUX_LIBS}" 175 fi 176 --- 11 unchanged lines hidden (view full) --- 188 189 ldflags="${ldflags} ${wl}--script=${objtree}/${KBUILD_LDS}" 190 191 # The kallsyms linking does not need debug symbols included. 192 if [ "$output" != "${output#.tmp_vmlinux.kallsyms}" ] ; then 193 ldflags="${ldflags} ${wl}--strip-debug" 194 fi 195 |
192 if [ -n "${CONFIG_VMLINUX_MAP}" ]; then | 196 if is_enabled CONFIG_VMLINUX_MAP; then |
193 ldflags="${ldflags} ${wl}-Map=${output}.map" 194 fi 195 196 ${ld} ${ldflags} -o ${output} \ 197 ${wl}--whole-archive ${objs} ${wl}--no-whole-archive \ 198 ${wl}--start-group ${libs} ${wl}--end-group \ 199 $@ ${ldlibs} 200} --- 33 unchanged lines hidden (view full) --- 234 printf '\1' | dd of=${2} conv=notrunc bs=1 seek=16 status=none 235} 236 237# Create ${2} .S file with all symbols from the ${1} object file 238kallsyms() 239{ 240 local kallsymopt; 241 | 197 ldflags="${ldflags} ${wl}-Map=${output}.map" 198 fi 199 200 ${ld} ${ldflags} -o ${output} \ 201 ${wl}--whole-archive ${objs} ${wl}--no-whole-archive \ 202 ${wl}--start-group ${libs} ${wl}--end-group \ 203 $@ ${ldlibs} 204} --- 33 unchanged lines hidden (view full) --- 238 printf '\1' | dd of=${2} conv=notrunc bs=1 seek=16 status=none 239} 240 241# Create ${2} .S file with all symbols from the ${1} object file 242kallsyms() 243{ 244 local kallsymopt; 245 |
242 if [ -n "${CONFIG_KALLSYMS_ALL}" ]; then | 246 if is_enabled CONFIG_KALLSYMS_ALL; then |
243 kallsymopt="${kallsymopt} --all-symbols" 244 fi 245 | 247 kallsymopt="${kallsymopt} --all-symbols" 248 fi 249 |
246 if [ -n "${CONFIG_KALLSYMS_ABSOLUTE_PERCPU}" ]; then | 250 if is_enabled CONFIG_KALLSYMS_ABSOLUTE_PERCPU; then |
247 kallsymopt="${kallsymopt} --absolute-percpu" 248 fi 249 | 251 kallsymopt="${kallsymopt} --absolute-percpu" 252 fi 253 |
250 if [ -n "${CONFIG_KALLSYMS_BASE_RELATIVE}" ]; then | 254 if is_enabled CONFIG_KALLSYMS_BASE_RELATIVE; then |
251 kallsymopt="${kallsymopt} --base-relative" 252 fi 253 254 info KSYMS ${2} 255 ${NM} -n ${1} | scripts/kallsyms ${kallsymopt} > ${2} 256} 257 258# Perform one step in kallsyms generation, including temporary linking of --- 48 unchanged lines hidden (view full) --- 307 ;; 308esac 309 310if [ "$1" = "clean" ]; then 311 cleanup 312 exit 0 313fi 314 | 255 kallsymopt="${kallsymopt} --base-relative" 256 fi 257 258 info KSYMS ${2} 259 ${NM} -n ${1} | scripts/kallsyms ${kallsymopt} > ${2} 260} 261 262# Perform one step in kallsyms generation, including temporary linking of --- 48 unchanged lines hidden (view full) --- 311 ;; 312esac 313 314if [ "$1" = "clean" ]; then 315 cleanup 316 exit 0 317fi 318 |
315# We need access to CONFIG_ symbols 316. include/config/auto.conf 317 | |
318# Update version 319info GEN .version 320if [ -r .version ]; then 321 VERSION=$(expr 0$(cat .version) + 1) 322 echo $VERSION > .version 323else 324 rm -f .version 325 echo 1 > .version --- 12 unchanged lines hidden (view full) --- 338info MODINFO modules.builtin.modinfo 339${OBJCOPY} -j .modinfo -O binary vmlinux.o modules.builtin.modinfo 340info GEN modules.builtin 341# The second line aids cases where multiple modules share the same object. 342tr '\0' '\n' < modules.builtin.modinfo | sed -n 's/^[[:alnum:]:_]*\.file=//p' | 343 tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$/.ko/' > modules.builtin 344 345btf_vmlinux_bin_o="" | 319# Update version 320info GEN .version 321if [ -r .version ]; then 322 VERSION=$(expr 0$(cat .version) + 1) 323 echo $VERSION > .version 324else 325 rm -f .version 326 echo 1 > .version --- 12 unchanged lines hidden (view full) --- 339info MODINFO modules.builtin.modinfo 340${OBJCOPY} -j .modinfo -O binary vmlinux.o modules.builtin.modinfo 341info GEN modules.builtin 342# The second line aids cases where multiple modules share the same object. 343tr '\0' '\n' < modules.builtin.modinfo | sed -n 's/^[[:alnum:]:_]*\.file=//p' | 344 tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$/.ko/' > modules.builtin 345 346btf_vmlinux_bin_o="" |
346if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then | 347if is_enabled CONFIG_DEBUG_INFO_BTF; then |
347 btf_vmlinux_bin_o=.btf.vmlinux.bin.o 348 if ! gen_btf .tmp_vmlinux.btf $btf_vmlinux_bin_o ; then 349 echo >&2 "Failed to generate BTF for vmlinux" 350 echo >&2 "Try to disable CONFIG_DEBUG_INFO_BTF" 351 exit 1 352 fi 353fi 354 355kallsymso="" 356kallsymso_prev="" 357kallsyms_vmlinux="" | 348 btf_vmlinux_bin_o=.btf.vmlinux.bin.o 349 if ! gen_btf .tmp_vmlinux.btf $btf_vmlinux_bin_o ; then 350 echo >&2 "Failed to generate BTF for vmlinux" 351 echo >&2 "Try to disable CONFIG_DEBUG_INFO_BTF" 352 exit 1 353 fi 354fi 355 356kallsymso="" 357kallsymso_prev="" 358kallsyms_vmlinux="" |
358if [ -n "${CONFIG_KALLSYMS}" ]; then | 359if is_enabled CONFIG_KALLSYMS; then |
359 360 # kallsyms support 361 # Generate section listing all symbols and add it into vmlinux 362 # It's a three step process: 363 # 1) Link .tmp_vmlinux.kallsyms1 so it has all symbols and sections, 364 # but __kallsyms is empty. 365 # Running kallsyms on that gives us .tmp_kallsyms1.o with 366 # the right size --- 23 unchanged lines hidden (view full) --- 390 if [ $size1 -ne $size2 ] || [ -n "${KALLSYMS_EXTRA_PASS}" ]; then 391 kallsyms_step 3 392 fi 393fi 394 395vmlinux_link vmlinux "${kallsymso}" ${btf_vmlinux_bin_o} 396 397# fill in BTF IDs | 360 361 # kallsyms support 362 # Generate section listing all symbols and add it into vmlinux 363 # It's a three step process: 364 # 1) Link .tmp_vmlinux.kallsyms1 so it has all symbols and sections, 365 # but __kallsyms is empty. 366 # Running kallsyms on that gives us .tmp_kallsyms1.o with 367 # the right size --- 23 unchanged lines hidden (view full) --- 391 if [ $size1 -ne $size2 ] || [ -n "${KALLSYMS_EXTRA_PASS}" ]; then 392 kallsyms_step 3 393 fi 394fi 395 396vmlinux_link vmlinux "${kallsymso}" ${btf_vmlinux_bin_o} 397 398# fill in BTF IDs |
398if [ -n "${CONFIG_DEBUG_INFO_BTF}" -a -n "${CONFIG_BPF}" ]; then | 399if is_enabled CONFIG_DEBUG_INFO_BTF && is_enabled CONFIG_BPF; then |
399 info BTFIDS vmlinux 400 ${RESOLVE_BTFIDS} vmlinux 401fi 402 | 400 info BTFIDS vmlinux 401 ${RESOLVE_BTFIDS} vmlinux 402fi 403 |
403if [ -n "${CONFIG_BUILDTIME_TABLE_SORT}" ]; then | 404if is_enabled CONFIG_BUILDTIME_TABLE_SORT; then |
404 info SORTTAB vmlinux 405 if ! sorttable vmlinux; then 406 echo >&2 Failed to sort kernel tables 407 exit 1 408 fi 409fi 410 411info SYSMAP System.map 412mksysmap vmlinux System.map 413 414# step a (see comment above) | 405 info SORTTAB vmlinux 406 if ! sorttable vmlinux; then 407 echo >&2 Failed to sort kernel tables 408 exit 1 409 fi 410fi 411 412info SYSMAP System.map 413mksysmap vmlinux System.map 414 415# step a (see comment above) |
415if [ -n "${CONFIG_KALLSYMS}" ]; then | 416if is_enabled CONFIG_KALLSYMS; then |
416 mksysmap ${kallsyms_vmlinux} .tmp_System.map 417 418 if ! cmp -s System.map .tmp_System.map; then 419 echo >&2 Inconsistent kallsyms data 420 echo >&2 Try "make KALLSYMS_EXTRA_PASS=1" as a workaround 421 exit 1 422 fi 423fi 424 425# For fixdep 426echo "vmlinux: $0" > .vmlinux.d | 417 mksysmap ${kallsyms_vmlinux} .tmp_System.map 418 419 if ! cmp -s System.map .tmp_System.map; then 420 echo >&2 Inconsistent kallsyms data 421 echo >&2 Try "make KALLSYMS_EXTRA_PASS=1" as a workaround 422 exit 1 423 fi 424fi 425 426# For fixdep 427echo "vmlinux: $0" > .vmlinux.d |