From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7819) id 0E9D83858C2C; Fri, 29 Sep 2023 09:12:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E9D83858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695978727; bh=5vED1my8t+aCwCNKwofV1cwfBBW4DEZoR8zFr8qdxzI=; h=From:To:Subject:Date:From; b=aVRXyrltWC9QrrLVlyXIWPph/iA6yv3ib6dwh3R2Rm5TRXNmeEScuc1WPSlkssdmR bf20tHDu6Ws9alS1nnzYk4IIltT0QWpcLyfQhpWjrk7udhWoHj3TQFF+ETuSlJaSGz tTbWUfujXb+G372qgVQ1ZoTmPvaCsz7Nd5YdN2GE= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Sergei Trofimovich To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-4327] ggc: do not wipe out unrelated data via gt_ggc_rtab [PR111505] X-Act-Checkin: gcc X-Git-Author: Sergei Trofimovich X-Git-Refname: refs/heads/master X-Git-Oldrev: bcc97edf8c9e40232fa30e7f0070057b6516fd77 X-Git-Newrev: 7525707c5f3edb46958c4fdfbe30de5ddfa8923a Message-Id: <20230929091207.0E9D83858C2C@sourceware.org> Date: Fri, 29 Sep 2023 09:12:07 +0000 (GMT) List-Id: https://gcc.gnu.org/g:7525707c5f3edb46958c4fdfbe30de5ddfa8923a commit r14-4327-g7525707c5f3edb46958c4fdfbe30de5ddfa8923a Author: Sergei Trofimovich Date: Thu Sep 28 20:20:31 2023 +0100 ggc: do not wipe out unrelated data via gt_ggc_rtab [PR111505] 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 middle-end/111505 * ggc-common.cc (ggc_zero_out_root_pointers, ggc_common_finalize): Add new helper. Use helper instead of memset() to wipe out pointers. Diff: --- 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++)