Clean up the variables in scripts/link-vmlinux.sh - Specify the extra objects directly in vmlinux_link() - Move the AS rule to kallsyms() - Set kallsymso and btf_vmlinux_bin_o where they are generated - Remove unneeded variable, kallsymso_prev - Introduce the btf_data variable - Introduce the strip_debug flag instead of checking the output name No functional change intended.
Unified · Split
| @@ -45,7 +45,6 @@ info() · 44 unmodified lines | ||
| 45 | 45 | |
| 46 | 46 | # Link of vmlinux |
| 47 | 47 | # ${1} - output file |
| 48 | −# ${2}, ${3}, ... - optional extra .o files | |
| 49 | 48 | vmlinux_link() |
| 50 | 49 | { |
| 51 | 50 | local output=${1} |
| @@ -90,7 +89,7 @@ vmlinux_link() · 38 unmodified lines | ||
| 90 | 89 | ldflags="${ldflags} ${wl}--script=${objtree}/${KBUILD_LDS}" |
| 91 | 90 | |
| 92 | 91 | # The kallsyms linking does not need debug symbols included. |
| 93 | − if [ "$output" != "${output#.tmp_vmlinux.kallsyms}" ] ; then | |
| 92 | + if [ -n "${strip_debug}" ] ; then | |
| 94 | 93 | ldflags="${ldflags} ${wl}--strip-debug" |
| 95 | 94 | fi |
| 96 | 95 | |
| @@ -101,7 +100,7 @@ vmlinux_link() · 4 unmodified lines | ||
| 101 | 100 | ${ld} ${ldflags} -o ${output} \ |
| 102 | 101 | ${wl}--whole-archive ${objs} ${wl}--no-whole-archive \ |
| 103 | 102 | ${wl}--start-group ${libs} ${wl}--end-group \ |
| 104 | − $@ ${ldlibs} | |
| 103 | + ${kallsymso} ${btf_vmlinux_bin_o} ${ldlibs} | |
| 105 | 104 | } |
| 106 | 105 | |
| 107 | 106 | # generate .BTF typeinfo from DWARF debuginfo |
| @@ -110,6 +109,7 @@ vmlinux_link() · 2 unmodified lines | ||
| 110 | 109 | gen_btf() |
| 111 | 110 | { |
| 112 | 111 | local pahole_ver |
| 112 | + local btf_data=${2} | |
| 113 | 113 | |
| 114 | 114 | if ! [ -x "$(command -v ${PAHOLE})" ]; then |
| 115 | 115 | echo >&2 "BTF: ${1}: pahole (${PAHOLE}) is not available" |
| @@ -124,16 +124,16 @@ gen_btf() · 8 unmodified lines | ||
| 124 | 124 | |
| 125 | 125 | vmlinux_link ${1} |
| 126 | 126 | |
| 127 | − info "BTF" ${2} | |
| 127 | + info BTF "${btf_data}" | |
| 128 | 128 | LLVM_OBJCOPY="${OBJCOPY}" ${PAHOLE} -J ${PAHOLE_FLAGS} ${1} |
| 129 | 129 | |
| 130 | − # Create ${2} which contains just .BTF section but no symbols. Add | |
| 130 | + # Create ${btf_data} which contains just .BTF section but no symbols. Add | |
| 131 | 131 | # SHF_ALLOC because .BTF will be part of the vmlinux image. --strip-all |
| 132 | 132 | # deletes all symbols including __start_BTF and __stop_BTF, which will |
| 133 | 133 | # be redefined in the linker script. Add 2>/dev/null to suppress GNU |
| 134 | 134 | # objcopy warnings: "empty loadable segment detected at ..." |
| 135 | 135 | ${OBJCOPY} --only-section=.BTF --set-section-flags .BTF=alloc,readonly \ |
| 136 | − --strip-all ${1} ${2} 2>/dev/null | |
| 136 | + --strip-all ${1} "${btf_data}" 2>/dev/null | |
| 137 | 137 | # Change e_type to ET_REL so that it can be used to link final vmlinux. |
| 138 | 138 | # GNU ld 2.35+ and lld do not allow an ET_EXEC input. |
| 139 | 139 | if is_enabled CONFIG_CPU_BIG_ENDIAN; then |
| @@ -141,10 +141,12 @@ gen_btf() · 1 unmodified line | ||
| 141 | 141 | else |
| 142 | 142 | et_rel='\1\0' |
| 143 | 143 | fi |
| 144 | − printf "${et_rel}" | dd of=${2} conv=notrunc bs=1 seek=16 status=none | |
| 144 | + printf "${et_rel}" | dd of="${btf_data}" conv=notrunc bs=1 seek=16 status=none | |
| 145 | + | |
| 146 | + btf_vmlinux_bin_o=${btf_data} | |
| 145 | 147 | } |
| 146 | 148 | |
| 147 | −# Create ${2} .S file with all symbols from the ${1} object file | |
| 149 | +# Create ${2}.o file with all symbols from the ${1} object file | |
| 148 | 150 | kallsyms() |
| 149 | 151 | { |
| 150 | 152 | local kallsymopt; |
| @@ -165,27 +167,25 @@ kallsyms() · 14 unmodified lines | ||
| 165 | 167 | kallsymopt="${kallsymopt} --lto-clang" |
| 166 | 168 | fi |
| 167 | 169 | |
| 168 | − info KSYMS ${2} | |
| 169 | − scripts/kallsyms ${kallsymopt} ${1} > ${2} | |
| 170 | + info KSYMS "${2}.S" | |
| 171 | + scripts/kallsyms ${kallsymopt} "${1}" > "${2}.S" | |
| 172 | + | |
| 173 | + info AS "${2}.o" | |
| 174 | + ${CC} ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS} \ | |
| 175 | + ${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} -c -o "${2}.o" "${2}.S" | |
| 176 | + | |
| 177 | + kallsymso=${2}.o | |
| 170 | 178 | } |
| 171 | 179 | |
| 172 | 180 | # Perform one step in kallsyms generation, including temporary linking of |
| 173 | 181 | # vmlinux. |
| 174 | 182 | kallsyms_step() |
| 175 | 183 | { |
| 176 | − kallsymso_prev=${kallsymso} | |
| 177 | 184 | kallsyms_vmlinux=.tmp_vmlinux.kallsyms${1} |
| 178 | − kallsymso=${kallsyms_vmlinux}.o | |
| 179 | − kallsyms_S=${kallsyms_vmlinux}.S | |
| 180 | − | |
| 181 | − vmlinux_link ${kallsyms_vmlinux} "${kallsymso_prev}" ${btf_vmlinux_bin_o} | |
| 182 | − mksysmap ${kallsyms_vmlinux} ${kallsyms_vmlinux}.syms | |
| 183 | − kallsyms ${kallsyms_vmlinux}.syms ${kallsyms_S} | |
| 184 | 185 | |
| 185 | − info AS ${kallsymso} | |
| 186 | − ${CC} ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS} \ | |
| 187 | − ${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \ | |
| 188 | − -c -o ${kallsymso} ${kallsyms_S} | |
| 186 | + vmlinux_link "${kallsyms_vmlinux}" | |
| 187 | + mksysmap "${kallsyms_vmlinux}" "${kallsyms_vmlinux}.syms" | |
| 188 | + kallsyms "${kallsyms_vmlinux}.syms" "${kallsyms_vmlinux}" | |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | # Create map file with all symbols from ${1} |
| @@ -223,19 +223,18 @@ fi · 31 unmodified lines | ||
| 223 | 223 | |
| 224 | 224 | ${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init init/version-timestamp.o |
| 225 | 225 | |
| 226 | −btf_vmlinux_bin_o="" | |
| 226 | +btf_vmlinux_bin_o= | |
| 227 | +kallsymso= | |
| 228 | +strip_debug= | |
| 229 | + | |
| 227 | 230 | if is_enabled CONFIG_DEBUG_INFO_BTF; then |
| 228 | − btf_vmlinux_bin_o=.btf.vmlinux.bin.o | |
| 229 | − if ! gen_btf .tmp_vmlinux.btf $btf_vmlinux_bin_o ; then | |
| 231 | + if ! gen_btf .tmp_vmlinux.btf .btf.vmlinux.bin.o ; then | |
| 230 | 232 | echo >&2 "Failed to generate BTF for vmlinux" |
| 231 | 233 | echo >&2 "Try to disable CONFIG_DEBUG_INFO_BTF" |
| 232 | 234 | exit 1 |
| 233 | 235 | fi |
| 234 | 236 | fi |
| 235 | 237 | |
| 236 | −kallsymso="" | |
| 237 | −kallsymso_prev="" | |
| 238 | −kallsyms_vmlinux="" | |
| 239 | 238 | if is_enabled CONFIG_KALLSYMS; then |
| 240 | 239 | |
| 241 | 240 | # kallsyms support |
| @@ -261,11 +260,13 @@ if is_enabled CONFIG_KALLSYMS; then · 19 unmodified lines | ||
| 261 | 260 | # a) Verify that the System.map from vmlinux matches the map from |
| 262 | 261 | # ${kallsymso}. |
| 263 | 262 | |
| 263 | + # The kallsyms linking does not need debug symbols included. | |
| 264 | + strip_debug=1 | |
| 265 | + | |
| 264 | 266 | kallsyms_step 1 |
| 265 | − kallsyms_step 2 | |
| 267 | + size1=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" ${kallsymso}) | |
| 266 | 268 | |
| 267 | − # step 3 | |
| 268 | − size1=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" ${kallsymso_prev}) | |
| 269 | + kallsyms_step 2 | |
| 269 | 270 | size2=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" ${kallsymso}) |
| 270 | 271 | |
| 271 | 272 | if [ $size1 -ne $size2 ] || [ -n "${KALLSYMS_EXTRA_PASS}" ]; then |
| @@ -273,7 +274,9 @@ if is_enabled CONFIG_KALLSYMS; then · 1 unmodified line | ||
| 273 | 274 | fi |
| 274 | 275 | fi |
| 275 | 276 | |
| 276 | −vmlinux_link vmlinux "${kallsymso}" ${btf_vmlinux_bin_o} | |
| 277 | +strip_debug= | |
| 278 | + | |
| 279 | +vmlinux_link vmlinux | |
| 277 | 280 | |
| 278 | 281 | # fill in BTF IDs |
| 279 | 282 | if is_enabled CONFIG_DEBUG_INFO_BTF && is_enabled CONFIG_BPF; then |