* [PATCH] ggc: do not wipe out unrelated data via gt_ggc_rtab
@ 2023-09-28 19:55 Sergei Trofimovich
2023-09-29 8:32 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Sergei Trofimovich @ 2023-09-28 19:55 UTC (permalink / raw)
To: gcc-patches, Andrew Pinski, Richard Biener, David Malcolm, Martin Jambor
Cc: Sergei Trofimovich, Sergei Trofimovich
From: Sergei Trofimovich <siarheit@google.com>
There are 3 GC root tables:
gt_ggc_rtab
gt_ggc_deletable_rtab
gt_pch_scalar_rtab
`deletable` and `scalar` tables are both simple: each element always
contains a pointer to the beginning of the object and it's size is the
full object.
`rtab` is different: it's `base` is a pointer in the middle of the
struct and `stride` points to the next GC pointer in the array.
Before the change there were 2 problems:
1. We memset()ed not just pointers but data around them.
2. We wen out of bounds of the last object described by gt_ggc_rtab
and triggered bootstrap failures in profile and asan bootstraps.
After the change we handle only pointers themselves like the rest of
ggc-common.cc code.
gcc/
PR/111505
* ggc-common.cc (ggc_zero_out_root_pointers): New helper.
* ggc-common.cc (ggc_common_finalize): Use helper instead of
memset() to wipe out pointers.
---
gcc/ggc-common.cc | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/gcc/ggc-common.cc b/gcc/ggc-common.cc
index 95803fa95a1..39e2581affd 100644
--- a/gcc/ggc-common.cc
+++ b/gcc/ggc-common.cc
@@ -75,6 +75,18 @@ ggc_mark_root_tab (const_ggc_root_tab_t rt)
(*rt->cb) (*(void **) ((char *)rt->base + rt->stride * i));
}
+/* Zero out all the roots in the table RT. */
+
+static void
+ggc_zero_rtab_roots (const_ggc_root_tab_t rt)
+{
+ size_t i;
+
+ for ( ; rt->base != NULL; rt++)
+ for (i = 0; i < rt->nelt; i++)
+ (*(void **) ((char *)rt->base + rt->stride * i)) = (void*)0;
+}
+
/* Iterate through all registered roots and mark each element. */
void
@@ -1307,8 +1319,7 @@ ggc_common_finalize ()
memset (rti->base, 0, rti->stride * rti->nelt);
for (rt = gt_ggc_rtab; *rt; rt++)
- for (rti = *rt; rti->base != NULL; rti++)
- memset (rti->base, 0, rti->stride * rti->nelt);
+ ggc_zero_rtab_roots (*rt);
for (rt = gt_pch_scalar_rtab; *rt; rt++)
for (rti = *rt; rti->base != NULL; rti++)
--
2.42.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] ggc: do not wipe out unrelated data via gt_ggc_rtab
2023-09-28 19:55 [PATCH] ggc: do not wipe out unrelated data via gt_ggc_rtab Sergei Trofimovich
@ 2023-09-29 8:32 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-09-29 8:32 UTC (permalink / raw)
To: Sergei Trofimovich
Cc: gcc-patches, Andrew Pinski, David Malcolm, Martin Jambor,
Sergei Trofimovich
On Thu, 28 Sep 2023, Sergei Trofimovich wrote:
> From: Sergei Trofimovich <siarheit@google.com>
>
> There are 3 GC root tables:
>
> gt_ggc_rtab
> gt_ggc_deletable_rtab
> gt_pch_scalar_rtab
>
> `deletable` and `scalar` tables are both simple: each element always
> contains a pointer to the beginning of the object and it's size is the
> full object.
>
> `rtab` is different: it's `base` is a pointer in the middle of the
> struct and `stride` points to the next GC pointer in the array.
>
> Before the change there were 2 problems:
>
> 1. We memset()ed not just pointers but data around them.
> 2. We wen out of bounds of the last object described by gt_ggc_rtab
> and triggered bootstrap failures in profile and asan bootstraps.
>
> After the change we handle only pointers themselves like the rest of
> ggc-common.cc code.
OK/
Thanks,
Richard.
> gcc/
> PR/111505
> * ggc-common.cc (ggc_zero_out_root_pointers): New helper.
> * ggc-common.cc (ggc_common_finalize): Use helper instead of
> memset() to wipe out pointers.
> ---
> gcc/ggc-common.cc | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/ggc-common.cc b/gcc/ggc-common.cc
> index 95803fa95a1..39e2581affd 100644
> --- a/gcc/ggc-common.cc
> +++ b/gcc/ggc-common.cc
> @@ -75,6 +75,18 @@ ggc_mark_root_tab (const_ggc_root_tab_t rt)
> (*rt->cb) (*(void **) ((char *)rt->base + rt->stride * i));
> }
>
> +/* Zero out all the roots in the table RT. */
> +
> +static void
> +ggc_zero_rtab_roots (const_ggc_root_tab_t rt)
> +{
> + size_t i;
> +
> + for ( ; rt->base != NULL; rt++)
> + for (i = 0; i < rt->nelt; i++)
> + (*(void **) ((char *)rt->base + rt->stride * i)) = (void*)0;
> +}
> +
> /* Iterate through all registered roots and mark each element. */
>
> void
> @@ -1307,8 +1319,7 @@ ggc_common_finalize ()
> memset (rti->base, 0, rti->stride * rti->nelt);
>
> for (rt = gt_ggc_rtab; *rt; rt++)
> - for (rti = *rt; rti->base != NULL; rti++)
> - memset (rti->base, 0, rti->stride * rti->nelt);
> + ggc_zero_rtab_roots (*rt);
>
> for (rt = gt_pch_scalar_rtab; *rt; rt++)
> for (rti = *rt; rti->base != NULL; rti++)
>
--
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-09-29 8:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-28 19:55 [PATCH] ggc: do not wipe out unrelated data via gt_ggc_rtab Sergei Trofimovich
2023-09-29 8:32 ` Richard Biener
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).