local lds="${objtree}/${KBUILD_LDS}"
        local output=${1}
        local objects
+       local strip_debug
 
        info LD ${output}
 
        # skip output file argument
        shift
 
+       # The kallsyms linking does not need debug symbols included.
+       if [ "$output" != "${output#.tmp_vmlinux.kallsyms}" ] ; then
+               strip_debug=-Wl,--strip-debug
+       fi
+
        if [ "${SRCARCH}" != "um" ]; then
                objects="--whole-archive                        \
                        ${KBUILD_VMLINUX_OBJS}                  \
                        ${@}"
 
                ${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux}      \
+                       ${strip_debug#-Wl,}                     \
                        -o ${output}                            \
                        -T ${lds} ${objects}
        else
                        ${@}"
 
                ${CC} ${CFLAGS_vmlinux}                         \
+                       ${strip_debug}                          \
                        -o ${output}                            \
                        -Wl,-T,${lds}                           \
                        ${objects}                              \
 {
        local pahole_ver
        local bin_arch
+       local bin_format
+       local bin_file
 
        if ! [ -x "$(command -v ${PAHOLE})" ]; then
                echo >&2 "BTF: ${1}: pahole (${PAHOLE}) is not available"
                return 1
        fi
 
-       info "BTF" ${2}
        vmlinux_link ${1}
+
+       info "BTF" ${2}
        LLVM_OBJCOPY=${OBJCOPY} ${PAHOLE} -J ${1}
 
        # dump .BTF section into raw binary file to link with final vmlinux
                cut -d, -f1 | cut -d' ' -f2)
        bin_format=$(LANG=C ${OBJDUMP} -f ${1} | grep 'file format' | \
                awk '{print $4}')
+       bin_file=.btf.vmlinux.bin
        ${OBJCOPY} --change-section-address .BTF=0 \
                --set-section-flags .BTF=alloc -O binary \
-               --only-section=.BTF ${1} .btf.vmlinux.bin
+               --only-section=.BTF ${1} $bin_file
        ${OBJCOPY} -I binary -O ${bin_format} -B ${bin_arch} \
-               --rename-section .data=.BTF .btf.vmlinux.bin ${2}
+               --rename-section .data=.BTF $bin_file ${2}
 }
 
 # Create ${2} .o file with all symbols from the ${1} object file
 kallsyms_step()
 {
        kallsymso_prev=${kallsymso}
-       kallsymso=.tmp_kallsyms${1}.o
-       kallsyms_vmlinux=.tmp_vmlinux${1}
+       kallsyms_vmlinux=.tmp_vmlinux.kallsyms${1}
+       kallsymso=${kallsyms_vmlinux}.o
 
        vmlinux_link ${kallsyms_vmlinux} "${kallsymso_prev}" ${btf_vmlinux_bin_o}
        kallsyms ${kallsyms_vmlinux} ${kallsymso}
 {
        rm -f .btf.*
        rm -f .tmp_System.map
-       rm -f .tmp_kallsyms*
        rm -f .tmp_vmlinux*
        rm -f System.map
        rm -f vmlinux
 
 btf_vmlinux_bin_o=""
 if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then
-       if gen_btf .tmp_vmlinux.btf .btf.vmlinux.bin.o ; then
-               btf_vmlinux_bin_o=.btf.vmlinux.bin.o
-       else
+       btf_vmlinux_bin_o=.btf.vmlinux.bin.o
+       if ! gen_btf .tmp_vmlinux.btf $btf_vmlinux_bin_o ; then
                echo >&2 "Failed to generate BTF for vmlinux"
                echo >&2 "Try to disable CONFIG_DEBUG_INFO_BTF"
                exit 1