From: David Faust <david.faust@oracle.com>
To: Cupertino Miranda <cupertino.miranda@oracle.com>
Cc: gcc-patches@gcc.gnu.org, jose.marchesi@oracle.com,
elena.zannoni@oracle.com
Subject: Re: [PATCH 3/3] bpf: Corrected index computation when present with unnamed struct fields
Date: Tue, 19 Mar 2024 10:07:06 -0700 [thread overview]
Message-ID: <d45ebd54-0d7b-43e2-ac88-843c94ae4d19@oracle.com> (raw)
In-Reply-To: <20240313142441.180242-3-cupertino.miranda@oracle.com>
On 3/13/24 07:24, Cupertino Miranda wrote:
> Any unnamed structure field if not a member of the BTF_KIND_STRUCT.
typo: if -> is
I'd suggest to clarify that "any unnamed structure field" is really
any unnamed non-struct-or-union field, since anonymous inner structs
and unions certainly are present in BTF (and you handle them here).
> For that reason, CO-RE access strings indexes should take that in
> consideration. This patch adds a condition to the incrementer that
> computes the index for the field access.
Otherwise, OK.
Thanks.
>
> gcc/ChangeLog:
> * config/bpf/core-builtins.cc (bpf_core_get_index): Check if
> field contains a DECL_NAME.
>
> gcc/testsuite/ChangeLog:
> * gcc.target/bpf/core-builtin-fieldinfo-offset-1.c: Add
> testcase for unnamed fields.
> ---
> gcc/config/bpf/core-builtins.cc | 6 +++++-
> .../gcc.target/bpf/core-builtin-fieldinfo-offset-1.c | 10 ++++++++--
> 2 files changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc
> index 70b14e48e6e5..8333ad81d0e0 100644
> --- a/gcc/config/bpf/core-builtins.cc
> +++ b/gcc/config/bpf/core-builtins.cc
> @@ -553,7 +553,11 @@ bpf_core_get_index (const tree node, bool *valid)
> {
> if (l == node)
> return i;
> - i++;
> + /* Skip unnamed padding, not represented by BTF. */
> + if (DECL_NAME(l) != NULL_TREE
> + || TREE_CODE (TREE_TYPE (l)) == UNION_TYPE
> + || TREE_CODE (TREE_TYPE (l)) == RECORD_TYPE)
> + i++;
> }
> }
> else if (code == ARRAY_REF || code == ARRAY_RANGE_REF || code == MEM_REF)
> diff --git a/gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-offset-1.c b/gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-offset-1.c
> index 27654205287d..8b1d8b012a2a 100644
> --- a/gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-offset-1.c
> +++ b/gcc/testsuite/gcc.target/bpf/core-builtin-fieldinfo-offset-1.c
> @@ -14,6 +14,9 @@ struct T {
> struct S s[2];
> char c;
> char d;
> + int a: 1;
> + int:31;
> + int f;
> };
>
> enum {
> @@ -38,7 +41,9 @@ unsigned int foo (struct T *t)
> unsigned e1 = __builtin_preserve_field_info (bar()->d, FIELD_BYTE_OFFSET);
> unsigned e2 = __builtin_preserve_field_info (bar()->s[1].a4, FIELD_BYTE_OFFSET);
>
> - return s0a1 + s0a4 + s0x + s1a1 + s1a4 + s1x + c + d + e1 + e2;
> + unsigned f1 = __builtin_preserve_field_info (t->f, FIELD_BYTE_OFFSET);
> +
> + return s0a1 + s0a4 + s0x + s1a1 + s1a4 + s1x + c + d + e1 + e2 + f1;
> }
>
> /* { dg-final { scan-assembler-times "\[\t \]mov\[\t \]%r\[0-9\],4" 2 } } */
> @@ -65,5 +70,6 @@ unsigned int foo (struct T *t)
> /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:1:1:4\"\\)" 1 } } */
> /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:2\"\\)" 1 } } */
> /* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:3\"\\)" 2 } } */
> +/* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:5\"\\)" 1 } } */
>
> -/* { dg-final { scan-assembler-times "0\[\t \]+\[^\n\]*bpfcr_kind" 10 } } */
> +/* { dg-final { scan-assembler-times "0\[\t \]+\[^\n\]*bpfcr_kind" 11 } } */
next prev parent reply other threads:[~2024-03-19 17:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-13 14:24 [PATCH 1/3] bpf: Fix CO-RE field expression builtins Cupertino Miranda
2024-03-13 14:24 ` [PATCH 2/3] bpf: Fix access string default for CO-RE type based relocations Cupertino Miranda
2024-03-19 16:57 ` David Faust
2024-03-20 20:31 ` Cupertino Miranda
2024-03-13 14:24 ` [PATCH 3/3] bpf: Corrected index computation when present with unnamed struct fields Cupertino Miranda
2024-03-19 17:07 ` David Faust [this message]
2024-03-20 20:32 ` Cupertino Miranda
2024-03-14 8:54 ` [PATCH 1/3] bpf: Fix CO-RE field expression builtins Jose E. Marchesi
2024-03-14 11:07 ` Cupertino Miranda
2024-03-14 13:23 ` Jose E. Marchesi
2024-03-14 13:44 ` Jose E. Marchesi
2024-03-20 20:31 ` Cupertino Miranda
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=d45ebd54-0d7b-43e2-ac88-843c94ae4d19@oracle.com \
--to=david.faust@oracle.com \
--cc=cupertino.miranda@oracle.com \
--cc=elena.zannoni@oracle.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jose.marchesi@oracle.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 read-only IMAP folder(s) and NNTP newsgroup(s).