public inbox for dwarves@vger.kernel.org
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Giuliano Procida <gprocida@google.com>, dwarves@vger.kernel.org
Cc: Aleksei Vetrov <vvvvvv@google.com>
Subject: Re: pahole -J mishandles types in function scope
Date: Tue, 14 Jan 2025 10:38:19 -0800	[thread overview]
Message-ID: <e020162afdf6f8a4d319a54bb8236cac2d6c3e19.camel@gmail.com> (raw)
In-Reply-To: <CAGvU0Hkx7gzjZkAVGXQyp+_6Mp7gBOD3uOtbEQuyhPApQy_iFQ@mail.gmail.com>

On Tue, 2025-01-14 at 13:14 +0000, Giuliano Procida wrote:
> Tested with pahole v1.24.
> 
> The following code, when compiled with either GCC 14 or Clang 16 or
> several other versions, and post processed with pahole -J, results in
> the private definition of foo in bar being exposed as part of the type
> of baz in BTF - which is definitely wrong.
> 
> struct foo;
> 
> int bar() {
>   struct foo {
>     int x;
>   };
>   struct foo j = { 0 };
>   struct foo k = j;
>   return j.x == k.x;
> }
> 
> int baz(struct foo* j) {
>   return j != 0;
> }
> 
> Note that we had exactly the same bug in STG and I resolved it by
> pushing an anonymous scope before processing the function child DIEs
> (we deal with C++ scopes). You could perhaps push / pop a flag which
> inhibits type definition processing.
> 
> It's not possible to just ignore type DIEs inside functions because
> (at least) Clang sometimes emits references outside the function to
> such DIEs.
> 
> Regards,
> Giuliano.
> 

Hi Giuliano,

Thank you for the report, indeed, the BTF generated for your example is:

    [1] STRUCT 'foo' size=4 vlen=1
            'x' type_id=2 bits_offset=0
    [2] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
    [3] PTR '(anon)' type_id=1
    [4] FUNC_PROTO '(anon)' ret_type_id=2 vlen=0
    [5] FUNC 'bar' type_id=4 linkage=static
    [6] FUNC_PROTO '(anon)' ret_type_id=2 vlen=1
            'j' type_id=3        // <-------------- this is wrong
    [7] FUNC 'baz' type_id=6 linkage=static

Thanks,
Eduard


      reply	other threads:[~2025-01-14 18:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-14 13:14 pahole -J mishandles types in function scope Giuliano Procida
2025-01-14 18:38 ` Eduard Zingerman [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=e020162afdf6f8a4d319a54bb8236cac2d6c3e19.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=dwarves@vger.kernel.org \
    --cc=gprocida@google.com \
    --cc=vvvvvv@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