Skip to content

Commit

Permalink
bpf: Support llvm-objcopy for vmlinux BTF
Browse files Browse the repository at this point in the history
Commit da5fb18 ("bpf: Support pre-2.25-binutils objcopy for vmlinux
BTF") switched from --dump-section to
--only-section/--change-section-address for BTF export assuming
those ("legacy") options should cover all objcopy versions.

Turns out llvm-objcopy doesn't implement --change-section-address [1],
but it does support --dump-section. Let's partially roll back and
try to use --dump-section first and fall back to
--only-section/--change-section-address for the older binutils.

1. https://bugs.llvm.org/show_bug.cgi?id=45217

Fixes: df786c9 ("bpf: Force .BTF section start to zero when dumping from vmlinux")
Tested-by: Nick Desaulniers <[email protected]>
Reported-by: Nathan Chancellor <[email protected]>
Link: ClangBuiltLinux#871
Signed-off-by: Stanislav Fomichev <[email protected]>
  • Loading branch information
fomichev authored and intel-lab-lkp committed Mar 17, 2020
1 parent 90db6d7 commit d2770fa
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions scripts/link-vmlinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ gen_btf()
cut -d, -f1 | cut -d' ' -f2)
bin_format=$(LANG=C ${OBJDUMP} -f ${1} | grep 'file format' | \
awk '{print $4}')

# Compatibility issues:
# - pre-2.25 binutils objcopy doesn't support --dump-section
# - llvm-objcopy doesn't support --change-section-address, but
# does support --dump-section
#
# Try to use --dump-section which should cover both recent
# binutils and llvm-objcopy and fall back to --only-section
# for pre-2.25 binutils.
${OBJCOPY} --dump-section .BTF=$bin_file ${1} 2>/dev/null || \
${OBJCOPY} --change-section-address .BTF=0 \
--set-section-flags .BTF=alloc -O binary \
--only-section=.BTF ${1} .btf.vmlinux.bin
Expand Down

0 comments on commit d2770fa

Please sign in to comment.