From: Stanislav Fomichev <sdf@fomichev.me>
To: Fangrui Song <maskray@google.com>
Cc: Stanislav Fomichev <sdf@google.com>,
netdev@vger.kernel.org, bpf@vger.kernel.org, davem@davemloft.net,
ast@kernel.org, daniel@iogearbox.net,
Nick Desaulniers <ndesaulniers@google.com>,
Nathan Chancellor <natechancellor@gmail.com>,
clang-built-linux@googlegroups.com
Subject: Re: [PATCH bpf] bpf: Support llvm-objcopy for vmlinux BTF
Date: Mon, 16 Mar 2020 16:56:29 -0700 [thread overview]
Message-ID: <20200316235629.GC2179110@mini-arch.hsd1.ca.comcast.net> (raw)
In-Reply-To: <20200316231516.kakoiumx4afph34t@google.com>
On 03/16, Fangrui Song wrote:
> On 2020-03-16, Stanislav Fomichev wrote:
> > Commit da5fb18225b4 ("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: df786c9b9476 ("bpf: Force .BTF section start to zero when dumping from vmlinux")
> > Tested-by: Nick Desaulniers <ndesaulniers@google.com>
> > Reported-by: Nathan Chancellor <natechancellor@gmail.com>
> > Link: https://github.com/ClangBuiltLinux/linux/issues/871
> > Signed-off-by: Stanislav Fomichev <sdf@google.com>
> > ---
> > scripts/link-vmlinux.sh | 10 ++++++++++
> > 1 file changed, 10 insertions(+)
> >
> > diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
> > index dd484e92752e..8ddf57cbc439 100755
> > --- a/scripts/link-vmlinux.sh
> > +++ b/scripts/link-vmlinux.sh
> > @@ -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
> > --
> > 2.25.1.481.gfbce0eb801-goog
>
> So let me take advantage of this email to ask some questions about
> commit da5fb18225b4 ("bpf: Support pre-2.25-binutils objcopy for vmlinux BTF").
>
> Does .BTF have the SHF_ALLOC flag?
No, that's why we manually do '--set-section-flags .BTF=alloc' to
make --only-section work.
> Is it a GNU objcopy<2.25 bug that objcopy --set-section-flags .BTF=alloc -O binary --only-section=.BTF does not skip the content?
> Non-SHF_ALLOC sections usually have 0 sh_addr. Why do they need --change-section-address .BTF=0 at all?
I think that '--set-section-flags .BTF=alloc' causes objcopy to put
some non-zero (valid) sh_addr, that's why we need to reset it to 0.
(it's not clear if it's a feature or a bug and man isn't helpful)
> Regarding
>
> > Turns out llvm-objcopy doesn't implement --change-section-address [1],
>
> This option will be difficult to implement in llvm-objcopy if we intend
> it to have a GNU objcopy compatible behavior.
> Without --only-section, it is not very clear how
> --change-section-{address,vma,lma} will affect program headers.
> There will be a debate even if we decide to implement them in llvm-objcopy.
>
> Some PT_LOAD rewriting examples:
>
> objcopy --change-section-address .plt=0 a b
> objcopy --change-section-address .text=0 a b
>
> There is another bug related to -B
> (https://github.com/ClangBuiltLinux/linux/issues/871#issuecomment-599790909):
>
> + objcopy --change-section-address .BTF=0 --set-section-flags .BTF=alloc
> -O binary --only-section=.BTF .tmp_vmlinux.btf .btf.vmlinux.bin
> + objcopy -I binary -O elf64-x86-64 -B x86_64 --rename-section .data=.BTF .btf.vmlinux.bin .btf.vmlinux.bin.o
> objcopy: architecture x86_64 unknown
> + echo 'Failed to generate BTF for vmlinux'
>
> It should be i386:x86_64.
Here is what I get:
+ bin_arch=i386:x86-64
+ bin_format=elf64-x86-64
+ objcopy --change-section-address .BTF=0 --set-section-flags .BTF=alloc -O binary --only-section=.BTF .tmp_vmlinux.btf .btf.vmlinux.bin
+ objcopy -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.BTF .btf.vmlinux.bin .btf.vmlinux.bin.
Can you try to see where your x86_64 is coming from?
next prev parent reply other threads:[~2020-03-16 23:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-16 22:25 [PATCH bpf] bpf: Support llvm-objcopy for vmlinux BTF Stanislav Fomichev
2020-03-16 23:15 ` Fangrui Song
2020-03-16 23:56 ` Stanislav Fomichev [this message]
2020-03-17 0:56 ` Fangrui Song
2020-03-17 3:14 ` Andrii Nakryiko
2020-03-16 23:57 ` Nathan Chancellor
2020-03-17 0:01 ` Stanislav Fomichev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200316235629.GC2179110@mini-arch.hsd1.ca.comcast.net \
--to=sdf@fomichev.me \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=clang-built-linux@googlegroups.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=maskray@google.com \
--cc=natechancellor@gmail.com \
--cc=ndesaulniers@google.com \
--cc=netdev@vger.kernel.org \
--cc=sdf@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox