Skip to content

Commit da5fb18

Browse files
fomichevAlexei Starovoitov
authored and
Alexei Starovoitov
committed
bpf: Support pre-2.25-binutils objcopy for vmlinux BTF
If vmlinux BTF generation fails, but CONFIG_DEBUG_INFO_BTF is set, .BTF section of vmlinux is empty and kernel will prohibit BPF loading and return "in-kernel BTF is malformed". --dump-section argument to binutils' objcopy was added in version 2.25. When using pre-2.25 binutils, BTF generation silently fails. Convert to --only-section which is present on pre-2.25 binutils. Documentation/process/changes.rst states that binutils 2.21+ is supported, not sure those standards apply to BPF subsystem. v2: * exit and print an error if gen_btf fails (John Fastabend) v3: * resend with Andrii's Acked-by/Tested-by tags Fixes: 341dfcf ("btf: expose BTF info through sysfs") Signed-off-by: Stanislav Fomichev <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Tested-by: Andrii Nakryiko <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Cc: John Fastabend <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent d0f0104 commit da5fb18

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

scripts/link-vmlinux.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ gen_btf()
127127
cut -d, -f1 | cut -d' ' -f2)
128128
bin_format=$(LANG=C ${OBJDUMP} -f ${1} | grep 'file format' | \
129129
awk '{print $4}')
130-
${OBJCOPY} --dump-section .BTF=.btf.vmlinux.bin ${1} 2>/dev/null
130+
${OBJCOPY} --set-section-flags .BTF=alloc -O binary \
131+
--only-section=.BTF ${1} .btf.vmlinux.bin 2>/dev/null
131132
${OBJCOPY} -I binary -O ${bin_format} -B ${bin_arch} \
132133
--rename-section .data=.BTF .btf.vmlinux.bin ${2}
133134
}
@@ -253,6 +254,10 @@ btf_vmlinux_bin_o=""
253254
if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then
254255
if gen_btf .tmp_vmlinux.btf .btf.vmlinux.bin.o ; then
255256
btf_vmlinux_bin_o=.btf.vmlinux.bin.o
257+
else
258+
echo >&2 "Failed to generate BTF for vmlinux"
259+
echo >&2 "Try to disable CONFIG_DEBUG_INFO_BTF"
260+
exit 1
256261
fi
257262
fi
258263

0 commit comments

Comments
 (0)