dwarves.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bill Wendling <morbo@google.com>
To: dwarves@vger.kernel.org
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	Fangrui Song <maskray@google.com>
Subject: Re: [PATCH dwarves 0/1] LLD .BTF section patch
Date: Mon, 28 Nov 2022 12:20:37 -0800	[thread overview]
Message-ID: <CAGG=3QUxBQ_BcC4F8cZidgO=MCGcu8ciVbMq+=6=T8omjrVPRA@mail.gmail.com> (raw)
In-Reply-To: <20221122000011.241697-1-morbo@google.com>

On Mon, Nov 21, 2022 at 4:00 PM Bill Wendling <morbo@google.com> wrote:
>
> This patch is an attempted fix for the issue discussed in [1]. I believe it's
> actually caused by pahole generating a corrupted ELF file.
>
> LLD generates a zero-sized .BTF section, while BFD doesn't. When pahole goes to
> add the .BTF data to an LLD-generated file, the section exists, but is too
> small. The ELF calls don't appear to adjust following sections' addresses in
> this case.
>
> To avoid this, the patch does some magic with objcopy to generate a separate
> .BTF section and perform some renaming.
>
> NOTE: This patch resembles a hack. If it's possible to adjust a section's size
> with ELF calls we should do it that way.
>
For instance, this could be done in the kernel like the following. I
don't know which is the more acceptable alternative.

diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index b808ef0..e6bfe51 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -212,6 +212,24 @@

  info "BTF" ${2}
  vmlinux_link ${1}
+ if ${LD_vmlinux} --version | grep -q LLD ; then
+ # LLD will generate a zero-sized .BTF section (the BFD linker
+ # doesn't). In that case, pahole tries to use the zero-sized
+ # section to house the BTF information. However, pahole doesn't
+ # adjust the addresses of sections around the .BTF section,
+ # resulting in an ELF file that appears invalid to further
+ # linkers. Avoid this issue by renaming the .BTF to .BTF_old
+ # and letting pahole add a new .BTF section.
+ # TODO(b/182271653): If/when pahole is fixed, we should remove
+ # this code.
+ BTF_SECTION=$(${READELF} -SW ${1} | grep -v .BTF_ids | grep .BTF)
+ if [[ -n "${BTF_SECTION}" ]]; then
+ BTF_SIZE=$(echo ${BTF_SECTION} | awk '{print $6}')
+ if [[ "0x${BTF_SIZE}" -eq 0 ]]; then
+ ${OBJCOPY} --rename-section .BTF=.BTF.old ${1}
+ fi
+ fi
+ fi
  LLVM_OBJCOPY=${OBJCOPY} ${PAHOLE} -J ${1}

  # Create ${2} which contains just .BTF section but no symbols. Add

> [1]: https://lore.kernel.org/dwarves/20210317232657.mdnsuoqx6nbddjgt@google.com/
>
> Bill Wendling (1):
>   btf_encoder: Generate a new .BTF section even if one exists
>
>  btf_encoder.c | 88 +++++++++++++++++++++++++++++++--------------------
>  1 file changed, 54 insertions(+), 34 deletions(-)
>
> --
> 2.38.1.584.g0f3c55d4c2-goog
>

      parent reply	other threads:[~2022-11-28 20:20 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-22  0:00 [PATCH dwarves 0/1] LLD .BTF section patch Bill Wendling
2022-11-22  0:00 ` [PATCH 1/1] btf_encoder: Generate a new .BTF section even if one exists Bill Wendling
2022-11-30 22:59   ` Andrii Nakryiko
2022-12-01  0:21     ` Bill Wendling
2022-12-01 19:56       ` Andrii Nakryiko
2022-12-01 20:19         ` Bill Wendling
2022-12-06 18:38           ` Andrii Nakryiko
2022-12-06 18:43             ` Andrii Nakryiko
2022-12-06 20:15             ` Bill Wendling
2022-12-06 22:52               ` Andrii Nakryiko
2022-12-07 20:16                 ` Bill Wendling
2022-12-07 20:33                   ` Andrii Nakryiko
2022-12-15 23:00                     ` Bill Wendling
2022-12-16  0:09                       ` Bill Wendling
2022-12-20 22:00                         ` Andrii Nakryiko
2022-11-28 20:20 ` Bill Wendling [this message]

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='CAGG=3QUxBQ_BcC4F8cZidgO=MCGcu8ciVbMq+=6=T8omjrVPRA@mail.gmail.com' \
    --to=morbo@google.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=dwarves@vger.kernel.org \
    --cc=maskray@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;
as well as URLs for NNTP newsgroup(s).