From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 22D093858C39 for ; Sat, 3 Feb 2024 08:34:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 22D093858C39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 22D093858C39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706949264; cv=none; b=JvOAZpmVa1iDdch/rpqlmcN+fIOGt59iXc6CVH9LRfEDu2IzGjoJimmBEF1bcJAsq7m+c37cFIE3wG28c/cTerO2+Uum5NkprlJAM/98QaH++1TlwGt2+HthmamI9XmKY4mh6KgJtRHMkdz12SBvDvGtPJqI9jP9JucRM3BD194= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706949264; c=relaxed/simple; bh=h3dnJGxA2ZrzmLIC5ah7E9YNjbWqNPvJqm4FzF+gUys=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=q8iNOtN0JU0rGACKEfcyYiRWKcBWKF/G+1H1S/8apSgdsQV2AhpvfoJ+jfun1E50CtN6lX+b6XWf+VyWn7UWjs7xnlKvjxquXx2JOatztlpPXnUTpzqhP7Rup9Iar5Av5znkSLw3tNPrYHf8zPtwcueeN5dLDO/IJXszzjiYbSw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706949259; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=IITF+eqLfag8zyYwJdbb4emV+YZDNFcqt2o8hMy8vsU=; b=D7N3ge0fWqbpXdHjQf2Fac4f3aR6CduR5KcCNxMaVyQj+PG+wLKU+ay1k6AD2LBfQYJ5Bv y7Ehm1T5umZFCqqHsWkRccNYUjB7SaaY22U28D2rqSXqdMA/slqPptrKJ7gDY3an4kMbdq n0UbZSTOM/4S2suv28MSxhLhgcobn5Y= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-279-nQRs-jTxMcSprKMYJhfj1Q-1; Sat, 03 Feb 2024 03:34:18 -0500 X-MC-Unique: nQRs-jTxMcSprKMYJhfj1Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BE81683B86C; Sat, 3 Feb 2024 08:34:17 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7AFA02166B31; Sat, 3 Feb 2024 08:34:17 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 4138YEdA1643499 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 3 Feb 2024 09:34:15 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 4138YDNf1643498; Sat, 3 Feb 2024 09:34:13 +0100 Date: Sat, 3 Feb 2024 09:34:13 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] ggc-common: Fix save PCH assertion Message-ID: Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi! 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. Bootstrapped/regtested on x86_64-linux and i686-linux, plus tested on s390x on the testcase which was ICEing in 1-100 iterations and there it survived 7750 attempts without ICE (forgot to stop it earlier), ok for trunk? 2024-02-03 Jakub Jelinek * ggc-common.cc (gt_pch_save): Allow addr to be equal to mmi.preferred_base + mmi.size - sizeof (void *). --- gcc/ggc-common.cc.jj 2024-01-03 11:51:39.397622018 +0100 +++ gcc/ggc-common.cc 2024-02-02 17:33:13.106727473 +0100 @@ -692,7 +692,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) Jakub