History

bpf: Force .BTF section start to zero when dumping from vmlinux

While trying to figure out why fentry_fexit selftest doesn't pass for me (old pahole, broken BTF), I found out that my latest patch can break vmlinux .BTF generation. objcopy preserves section start when doing --only-section, so there is a chance (depending on where pahole inserts .BTF section) to have leading empty zeroes. Let's explicitly force section offset to zero. Before: $ objcopy --set-section-flags .BTF=alloc -O binary \ --only-section=.BTF vmlinux .btf.vmlinux.bin $ xxd .btf.vmlinux.bin | head -n1 00000000: 0000 0000 0000 0000 0000 0000 0000 0000 ................ After: $ objcopy --change-section-address .BTF=0 \ --set-section-flags .BTF=alloc -O binary \ --only-section=.BTF vmlinux .btf.vmlinux.bin $ xxd .btf.vmlinux.bin | head -n1 00000000: 9feb 0100 1800 0000 0000 0000 80e1 1c00 ................ ^BTF magic As part of this change, I'm also dropping '2>/dev/null' from objcopy invocation to be able to catch possible other issues (objcopy doesn't produce any warnings for me anymore, it did before with --dump-section).

Stanislav Fomichev committed 6 years ago

Commit df786c91 parent ce277091 file · +3 −2Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/link-vmlinux.sh+3−2
@@ -127,8 +127,9 @@ gen_btf() · 126 unmodified lines
127 cut -d, -f1 | cut -d' ' -f2)127 cut -d, -f1 | cut -d' ' -f2)
128 bin_format=$(LANG=C ${OBJDUMP} -f ${1} | grep 'file format' | \128 bin_format=$(LANG=C ${OBJDUMP} -f ${1} | grep 'file format' | \
129 awk '{print $4}')129 awk '{print $4}')
130 ${OBJCOPY} --set-section-flags .BTF=alloc -O binary \130 ${OBJCOPY} --change-section-address .BTF=0 \
131 --only-section=.BTF ${1} .btf.vmlinux.bin 2>/dev/null131 --set-section-flags .BTF=alloc -O binary \
132 --only-section=.BTF ${1} .btf.vmlinux.bin
132 ${OBJCOPY} -I binary -O ${bin_format} -B ${bin_arch} \133 ${OBJCOPY} -I binary -O ${bin_format} -B ${bin_arch} \
133 --rename-section .data=.BTF .btf.vmlinux.bin ${2}134 --rename-section .data=.BTF .btf.vmlinux.bin ${2}
134}135}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t