From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 9E7F5385841A; Sat, 2 Mar 2024 00:38:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E7F5385841A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709339922; bh=qu66pR2Kp1hhGGErJyeAEmtgM5mvXSDTGJy490P2kDA=; h=From:To:Subject:Date:From; b=Jb6ZhkocKpmmwNiHuZQ/fv8Gnh0Q57o1E8skmhE7WJbFYd2Ov/ctK2iqSnkieH/su 4JdZlOpzcwdWKrupdXTpyUz+uZ0t6215TJPCU5UgfjDOfO50kohbUZEJ1X1CAfVvsz +Qa658q+uprQolbu/V3uPo9ZkjPhDwGHniYpkgyo= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-8388] ggc-common: Fix save PCH assertion X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: 21d7bffdbe2046cc787fa31a5df5c71dc645b304 X-Git-Newrev: f03c78b5b441485b3026990e213a40d0a7dfe582 Message-Id: <20240302003842.9E7F5385841A@sourceware.org> Date: Sat, 2 Mar 2024 00:38:42 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f03c78b5b441485b3026990e213a40d0a7dfe582 commit r13-8388-gf03c78b5b441485b3026990e213a40d0a7dfe582 Author: Jakub Jelinek Date: Sat Feb 3 14:37:19 2024 +0100 ggc-common: Fix save PCH assertion We are getting a gnuradio PCH ICE /usr/include/pybind11/stl.h:447:1: internal compiler error: in gt_pch_save, at ggc-common.cc:693 0x1304e7d gt_pch_save(_IO_FILE*) ../../gcc/ggc-common.cc:693 0x12a45fb c_common_write_pch() ../../gcc/c-family/c-pch.cc:175 0x18ad711 c_parse_final_cleanups() ../../gcc/cp/decl2.cc:5062 0x213988b c_common_parse_file() ../../gcc/c-family/c-opts.cc:1319 (unfortunately it isn't reproduceable always, but often needs up to 100 attempts, isn't reproduceable in a cross etc.). The bug is in the assertion I've added in gt_pch_save when adding relocation support for the PCH files in case they happen not to be mmapped at the selected address. addr is a relocated address which points to a location in the PCH blob (starting at mmi.preferred_base, with mmi.size bytes) which contains a pointer that needs to be relocated. So the assertion is meant to verify the address is within the PCH blob, obviously it needs to be equal or above mmi.preferred_base, but I got the other comparison wrong and when one is very unlucky and the last sizeof (void *) bytes of the blob happen to be a pointer which needs to be relocated, such as on the s390x host addr 0x8008a04ff8, mmi.preferred_base 0x8000000000 and mmi.size 0x8a05000, addr + sizeof (void *) is equal to mmi.preferred_base + mmi.size and that is still fine, both addresses are end of something. 2024-02-03 Jakub Jelinek * ggc-common.cc (gt_pch_save): Allow addr to be equal to mmi.preferred_base + mmi.size - sizeof (void *). (cherry picked from commit a4e240643cfa387579d4fa2bf9210a7d20433847) Diff: --- gcc/ggc-common.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/ggc-common.cc b/gcc/ggc-common.cc index db317f49993..3d7142de9db 100644 --- a/gcc/ggc-common.cc +++ b/gcc/ggc-common.cc @@ -673,7 +673,7 @@ gt_pch_save (FILE *f) { gcc_assert ((uintptr_t) addr >= (uintptr_t) mmi.preferred_base && ((uintptr_t) addr + sizeof (void *) - < (uintptr_t) mmi.preferred_base + mmi.size)); + <= (uintptr_t) mmi.preferred_base + mmi.size)); if (addr == last_addr) continue; if (last_addr == NULL)