public inbox for dwarves@vger.kernel.org
 help / color / mirror / Atom feed
From: "Alexis Lothoré" <alexis.lothore@bootlin.com>
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
Cc: "dwarves" <dwarves@vger.kernel.org>, "bpf" <bpf@vger.kernel.org>,
	"Alan Maguire" <alan.maguire@oracle.com>,
	"Arnaldo Carvalho de Melo" <acme@kernel.org>,
	"Alexei Starovoitov" <ast@fb.com>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	"Bastien Curutchet" <bastien.curutchet@bootlin.com>
Subject: Re: [PATCH RFC] btf_encoder: skip functions consuming structs passed by value on stack
Date: Thu, 19 Jun 2025 15:12:54 +0200	[thread overview]
Message-ID: <DAQJB898I4M9.2EE33TP8JV9X9@bootlin.com> (raw)
In-Reply-To: <CAADnVQJOiqCic664bPaBdwBwf1NGqfH-T6ZkQJOF7X4h7HuxBA@mail.gmail.com>

On Wed Jun 18, 2025 at 6:28 PM CEST, Alexei Starovoitov wrote:
> On Wed, Jun 18, 2025 at 8:02 AM Alexis Lothoré
> <alexis.lothore@bootlin.com> wrote:
>>
>> - those attributes are not reliably encoded by compilers in DWARF info
>
> What would be an example of unreliability?
> Maybe they're reliable enough for cases we're concerned about ?

The example I had in mind is around the fact that there is no explicit
dwarf attribute stating that a struct is packed. It may be deduced in some
cases by taking a look at the DW_TAG_byte_size and checking if it matches
the expected size of locations of all its members, but there are cases in
which the packed attribute does not change the struct size, while still
altering its alignment (but more below)
>
>> +
>> +               if (param_idx >= cu->nr_register_params) {
>> +                       if(dwarf_attr(die, DW_AT_type, &attr)){
>> +                               Dwarf_Die type_die;
>> +                               if (dwarf_formref_die(&attr, &type_die) &&
>> +                                               dwarf_tag(&type_die) == DW_TAG_structure_type) {
>> +                                       parm->uncertain_loc = 1;
>> +                               }
>> +                       }
>> +                       return parm;
>
> This is too pessimistic.
> In
> bpf_testmod_test_struct_arg_9(u64 a, void *b, short c, int d, void *e, char f,
>                               short g, struct bpf_testmod_struct_arg_5
> h, long i)
>
> struct bpf_testmod_struct_arg_5 {
>         char a;
>         short b;
>         int c;
>         long d;
> };
>
> though it's passed on the stack it fits into normal calling convention.
> It doesn't have align or packed attributes, so no need to exclude it ?

I went for the simplest solution, assuming that there were cases involving
packing/alignent customization that we would not be able to detect (eg: the
packed attr that does not change size but reduce alignment). But thinking
more about it, those cases need really specific conditions thay may not
exist currently in the kernel (eg: having some __int128 embedded in a
struct).

I see that pahole already has some logic to check if a struct is
altered (eg class__infer_packed_attributes), I'll check if I can come with
something more selective.

Alexis

-- 
Alexis Lothoré, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


  reply	other threads:[~2025-06-19 13:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-18 15:02 [PATCH RFC] btf_encoder: skip functions consuming structs passed by value on stack Alexis Lothoré
2025-06-18 16:28 ` Alexei Starovoitov
2025-06-19 13:12   ` Alexis Lothoré [this message]
2025-06-19 15:41     ` Alan Maguire
2025-06-19 16:06       ` Alexis Lothoré
2025-06-19 16:49     ` Alexei Starovoitov

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=DAQJB898I4M9.2EE33TP8JV9X9@bootlin.com \
    --to=alexis.lothore@bootlin.com \
    --cc=acme@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ast@fb.com \
    --cc=bastien.curutchet@bootlin.com \
    --cc=bpf@vger.kernel.org \
    --cc=dwarves@vger.kernel.org \
    --cc=thomas.petazzoni@bootlin.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