mbox series

[dwarves,0/4] BTF ELF writing changes

Message ID 20210125130625.2030186-1-gprocida@google.com (mailing list archive)
Headers show
Series BTF ELF writing changes | expand

Message

Giuliano Procida Jan. 25, 2021, 1:06 p.m. UTC
Hi.

This follows on from my change to improve the error handling around
llvm-objcopy in libbtf.c.

Note on recipients: Please let me know if I should adjust To or CC.

Note on style: I've generally placed declarations as allowed by C99,
closest to point of use. Let me know if you'd prefer otherwise.

1. Improve ELF error reporting

2. Add .BTF section using libelf

This shows the minimal amount of code needed to drive libelf. However,
it leaves layout up to libelf, which is almost certainly not wanted.

As an unexpcted side-effect, vmlinux is larger than before. It seems
llvm-objcopy likes to trim down .strtab.

3. Manually lay out updated ELF sections

This does full layout of new and updated ELF sections. If the update
ELF sections were not the last ones in the file by offset, then it can
leave gaps between sections.

4. Align .BTF section to 8 bytes

This was my original aim.

Regards.

Giuliano Procida (4):
  btf_encoder: Improve ELF error reporting
  btf_encoder: Add .BTF section using libelf
  btf_encoder: Manually lay out updated ELF sections
  btf_encoder: Align .BTF section to 8 bytes

 libbtf.c | 222 +++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 175 insertions(+), 47 deletions(-)

Comments

Jiri Olsa Jan. 26, 2021, 7:55 p.m. UTC | #1
On Mon, Jan 25, 2021 at 01:06:21PM +0000, Giuliano Procida wrote:
> Hi.
> 
> This follows on from my change to improve the error handling around
> llvm-objcopy in libbtf.c.
> 
> Note on recipients: Please let me know if I should adjust To or CC.
> 
> Note on style: I've generally placed declarations as allowed by C99,
> closest to point of use. Let me know if you'd prefer otherwise.
> 
> 1. Improve ELF error reporting
> 
> 2. Add .BTF section using libelf
> 
> This shows the minimal amount of code needed to drive libelf. However,
> it leaves layout up to libelf, which is almost certainly not wanted.
> 
> As an unexpcted side-effect, vmlinux is larger than before. It seems
> llvm-objcopy likes to trim down .strtab.
> 
> 3. Manually lay out updated ELF sections
> 
> This does full layout of new and updated ELF sections. If the update
> ELF sections were not the last ones in the file by offset, then it can
> leave gaps between sections.
> 
> 4. Align .BTF section to 8 bytes
> 
> This was my original aim.
> 
> Regards.
> 
> Giuliano Procida (4):
>   btf_encoder: Improve ELF error reporting
>   btf_encoder: Add .BTF section using libelf
>   btf_encoder: Manually lay out updated ELF sections
>   btf_encoder: Align .BTF section to 8 bytes

hi,
I can't apply this on dwarves git master, which commit is it based on?

thanks,
jirka

> 
>  libbtf.c | 222 +++++++++++++++++++++++++++++++++++++++++++------------
>  1 file changed, 175 insertions(+), 47 deletions(-)
> 
> -- 
> 2.30.0.280.ga3ce27912f-goog
>
Giuliano Procida Jan. 27, 2021, 1:10 a.m. UTC | #2
Hi.

On Tue, 26 Jan 2021 at 19:56, Jiri Olsa <jolsa@redhat.com> wrote:
>
> On Mon, Jan 25, 2021 at 01:06:21PM +0000, Giuliano Procida wrote:
> > Hi.
> >
> > This follows on from my change to improve the error handling around
> > llvm-objcopy in libbtf.c.
> >
> > Note on recipients: Please let me know if I should adjust To or CC.
> >
> > Note on style: I've generally placed declarations as allowed by C99,
> > closest to point of use. Let me know if you'd prefer otherwise.
> >
> > 1. Improve ELF error reporting
> >
> > 2. Add .BTF section using libelf
> >
> > This shows the minimal amount of code needed to drive libelf. However,
> > it leaves layout up to libelf, which is almost certainly not wanted.
> >
> > As an unexpcted side-effect, vmlinux is larger than before. It seems
> > llvm-objcopy likes to trim down .strtab.
> >
> > 3. Manually lay out updated ELF sections
> >
> > This does full layout of new and updated ELF sections. If the update
> > ELF sections were not the last ones in the file by offset, then it can
> > leave gaps between sections.
> >
> > 4. Align .BTF section to 8 bytes
> >
> > This was my original aim.
> >
> > Regards.
> >
> > Giuliano Procida (4):
> >   btf_encoder: Improve ELF error reporting
> >   btf_encoder: Add .BTF section using libelf
> >   btf_encoder: Manually lay out updated ELF sections
> >   btf_encoder: Align .BTF section to 8 bytes
>
> hi,
> I can't apply this on dwarves git master, which commit is it based on?
>

It's based on:
https://www.spinics.net/lists/dwarves/msg00775.html (0/3)
https://www.spinics.net/lists/dwarves/msg00774.html (1/3, unrelated fix)
https://www.spinics.net/lists/dwarves/msg00773.html (2/3, this is the
one you'll need for a clean git am; obsoleted by this new series)
(3/3 was abandoned)

Arnaldo did say the two commits were applied... but perhaps they
haven't been pushed to public master yet.

> thanks,
> jirka
>

You're welcome.
Giuliano.

> >
> >  libbtf.c | 222 +++++++++++++++++++++++++++++++++++++++++++------------
> >  1 file changed, 175 insertions(+), 47 deletions(-)
> >
> > --
> > 2.30.0.280.ga3ce27912f-goog
> >
>
Arnaldo Carvalho de Melo Jan. 27, 2021, 1:42 a.m. UTC | #3
Em Wed, Jan 27, 2021 at 01:10:40AM +0000, Giuliano Procida escreveu:
> Hi.
> 
> On Tue, 26 Jan 2021 at 19:56, Jiri Olsa <jolsa@redhat.com> wrote:
> >
> > On Mon, Jan 25, 2021 at 01:06:21PM +0000, Giuliano Procida wrote:
> > > Hi.
> > >
> > > This follows on from my change to improve the error handling around
> > > llvm-objcopy in libbtf.c.
> > >
> > > Note on recipients: Please let me know if I should adjust To or CC.
> > >
> > > Note on style: I've generally placed declarations as allowed by C99,
> > > closest to point of use. Let me know if you'd prefer otherwise.
> > >
> > > 1. Improve ELF error reporting
> > >
> > > 2. Add .BTF section using libelf
> > >
> > > This shows the minimal amount of code needed to drive libelf. However,
> > > it leaves layout up to libelf, which is almost certainly not wanted.
> > >
> > > As an unexpcted side-effect, vmlinux is larger than before. It seems
> > > llvm-objcopy likes to trim down .strtab.
> > >
> > > 3. Manually lay out updated ELF sections
> > >
> > > This does full layout of new and updated ELF sections. If the update
> > > ELF sections were not the last ones in the file by offset, then it can
> > > leave gaps between sections.
> > >
> > > 4. Align .BTF section to 8 bytes
> > >
> > > This was my original aim.
> > >
> > > Regards.
> > >
> > > Giuliano Procida (4):
> > >   btf_encoder: Improve ELF error reporting
> > >   btf_encoder: Add .BTF section using libelf
> > >   btf_encoder: Manually lay out updated ELF sections
> > >   btf_encoder: Align .BTF section to 8 bytes
> >
> > hi,
> > I can't apply this on dwarves git master, which commit is it based on?
> >
> 
> It's based on:
> https://www.spinics.net/lists/dwarves/msg00775.html (0/3)
> https://www.spinics.net/lists/dwarves/msg00774.html (1/3, unrelated fix)
> https://www.spinics.net/lists/dwarves/msg00773.html (2/3, this is the
> one you'll need for a clean git am; obsoleted by this new series)
> (3/3 was abandoned)
> 
> Arnaldo did say the two commits were applied... but perhaps they
> haven't been pushed to public master yet.

I pushed what I have now, please check if anything is missing.

I'm now working on DWARF4's DW_AT_data_bit_offset, that gcc uses when
dwarf-5 is asked for, I should have something usable tomorrow and
hopefully this will be the last stuff to get into 1.20.

dd

thanks,

- Arnaldo
 
> > thanks,
> > jirka
> >
> 
> You're welcome.
> Giuliano.
> 
> > >
> > >  libbtf.c | 222 +++++++++++++++++++++++++++++++++++++++++++------------
> > >  1 file changed, 175 insertions(+), 47 deletions(-)
> > >
> > > --
> > > 2.30.0.280.ga3ce27912f-goog
> > >
> >
Arnaldo Carvalho de Melo Jan. 27, 2021, 2:06 p.m. UTC | #4
Em Mon, Jan 25, 2021 at 01:06:21PM +0000, Giuliano Procida escreveu:
> Hi.
> 
> This follows on from my change to improve the error handling around
> llvm-objcopy in libbtf.c.
> 
> Note on recipients: Please let me know if I should adjust To or CC.
> 
> Note on style: I've generally placed declarations as allowed by C99,
> closest to point of use. Let me know if you'd prefer otherwise.
> 
> 1. Improve ELF error reporting

applied
 
> 2. Add .BTF section using libelf
> 
> This shows the minimal amount of code needed to drive libelf. However,
> it leaves layout up to libelf, which is almost certainly not wanted.
> 
> As an unexpcted side-effect, vmlinux is larger than before. It seems
> llvm-objcopy likes to trim down .strtab.

We have to test this thoroughly, I'm adding support to gcc's -gdwarf-5
DW_AT_data_bit_offset, I think I should get that done and release 1.20,
if some bug is still left on that new code, we can just fallback to
-gdwarf-4.

Then get back to the last 2 patches in your series, ok?

- Arnaldo
 
> 3. Manually lay out updated ELF sections
> 
> This does full layout of new and updated ELF sections. If the update
> ELF sections were not the last ones in the file by offset, then it can
> leave gaps between sections.
> 
> 4. Align .BTF section to 8 bytes
> 
> This was my original aim.
> 
> Regards.
> 
> Giuliano Procida (4):
>   btf_encoder: Improve ELF error reporting
>   btf_encoder: Add .BTF section using libelf
>   btf_encoder: Manually lay out updated ELF sections
>   btf_encoder: Align .BTF section to 8 bytes
> 
>  libbtf.c | 222 +++++++++++++++++++++++++++++++++++++++++++------------
>  1 file changed, 175 insertions(+), 47 deletions(-)
> 
> -- 
> 2.30.0.280.ga3ce27912f-goog
>
Giuliano Procida Jan. 27, 2021, 2:36 p.m. UTC | #5
Hi.

On Wed, 27 Jan 2021 at 14:06, Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
>
> Em Mon, Jan 25, 2021 at 01:06:21PM +0000, Giuliano Procida escreveu:
> > Hi.
> >
> > This follows on from my change to improve the error handling around
> > llvm-objcopy in libbtf.c.
> >
> > Note on recipients: Please let me know if I should adjust To or CC.
> >
> > Note on style: I've generally placed declarations as allowed by C99,
> > closest to point of use. Let me know if you'd prefer otherwise.
> >
> > 1. Improve ELF error reporting
>
> applied
>
> > 2. Add .BTF section using libelf
> >
> > This shows the minimal amount of code needed to drive libelf. However,
> > it leaves layout up to libelf, which is almost certainly not wanted.
> >
> > As an unexpcted side-effect, vmlinux is larger than before. It seems
> > llvm-objcopy likes to trim down .strtab.
>
> We have to test this thoroughly, I'm adding support to gcc's -gdwarf-5
> DW_AT_data_bit_offset, I think I should get that done and release 1.20,
> if some bug is still left on that new code, we can just fallback to
> -gdwarf-4.
>
> Then get back to the last 2 patches in your series, ok?
>

That's fine.

I've spent a little time digging into what llvm-objcopy (11.0.0) is
doing. It turns out it will rewrite an ELF file even if you just do
llvm-objcopy --dump-section .strtab=/dev/null elf_file, and even if
the file is not writable.

Our AOSP kernels have a lot symbols filtered out of the symbol table
and perhaps this is what makes such a difference to the size of
.strtab after llvm-objcopy has done its thing. I will try on a vanilla
kernel.

Giuliano.

> - Arnaldo
>
> > 3. Manually lay out updated ELF sections
> >
> > This does full layout of new and updated ELF sections. If the update
> > ELF sections were not the last ones in the file by offset, then it can
> > leave gaps between sections.
> >
> > 4. Align .BTF section to 8 bytes
> >
> > This was my original aim.
> >
> > Regards.
> >
> > Giuliano Procida (4):
> >   btf_encoder: Improve ELF error reporting
> >   btf_encoder: Add .BTF section using libelf
> >   btf_encoder: Manually lay out updated ELF sections
> >   btf_encoder: Align .BTF section to 8 bytes
> >
> >  libbtf.c | 222 +++++++++++++++++++++++++++++++++++++++++++------------
> >  1 file changed, 175 insertions(+), 47 deletions(-)
> >
> > --
> > 2.30.0.280.ga3ce27912f-goog
> >
>
> --
>
> - Arnaldo