From patchwork Sat Feb 3 08:34:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 196207 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp913477dyc; Sat, 3 Feb 2024 00:36:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHhHy1q97fmUwb3mSU5geHt2KJLo9Q+ZSWpio2JSpnXYoEK0ZAVD4XkEeNOe5+e41lGG0mm X-Received: by 2002:a0c:c98a:0:b0:682:bfd0:d79e with SMTP id b10-20020a0cc98a000000b00682bfd0d79emr903315qvk.27.1706949411445; Sat, 03 Feb 2024 00:36:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706949411; cv=pass; d=google.com; s=arc-20160816; b=ze0/QeKh+2nc3MSn/zqwNJZNzQu1+VXBVQjnH3gNotjHdXcc0MwyHVL8EpV138n7SS ctDhflWgQjxNE6GWoV/BBHYg3Y3IIILMJYQSRfWKO77zWw4xqPpzJp87aHXGUFKbYjLp J4odKycQJUGZmymg2cyRoQPmllflOWPBxHV/mI5+sA7z1ORb5PasVDjxlvvrwUmUds4c An0yujSmEm3vaU3rhMmy8LWHIuWUvpnQfDrm2uG4UosDxZ/kXRLg0JoZ9cGhDLbsT4To rfb2Rpc7G14oSUx64tFOnx2E8jC58r8ZznXvbBlZC6ESK7TCnYqF/t7GbkslPRLZIvSo D82w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=IITF+eqLfag8zyYwJdbb4emV+YZDNFcqt2o8hMy8vsU=; fh=BorIAlFxQrlBHmxmA5SNezxdl4Bg1JoggzFdz0gI4Ok=; b=ZkdNvHlmK2EMxx7QciC7fGzEemlJvZ/MpR+YT2FCtFn34k7PmoQLYrh1R4UySbtwoh 4e8JbtGRTb07AkrlFeYvfV02W7zC9OyuKJrVDQIfZlWCbRHskofdWw4wU9CjY3Yh7q71 NRS6/tjU8RMREDkhG34iy0y8+VqkMObP3qxcUGNPxS4rI0EbvlHoKOyfTnQkm5waNjVf qs8aPyEK3ZN0TXjuTN166sxnwAIPXORiHbwKeF6cXq1YXGKeTcVrZuOYYaEwpEjMwQi3 T3JCjnsFzxQ1V73RmQ0S+yUjR2KPbdFNuALAAi80LGo8AQkCSDAiCyOu7DzKRamkbIGt 2JOA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=D7N3ge0f; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCWvAcUqZuIxl8a67F9wode5RLWsjoEEHPPXOZ0q18koeDzCJ1wu2GCBjIij9RDR7JFIsjbMHKvag3NqJMfrCao+s4YQAg== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id q1-20020a0ce9c1000000b006817d997962si3860150qvo.130.2024.02.03.00.36.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 00:36:51 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=D7N3ge0f; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D6DFA3858C39 for ; Sat, 3 Feb 2024 08:36:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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: 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-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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789866186408039262 X-GMAIL-MSGID: 1789866186408039262 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 *). Jakub --- 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)