From patchwork Sat Mar 21 18:52:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1259525 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=qcZJejWu; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48l8sw4G5vz9sPF for ; Sun, 22 Mar 2020 05:53:06 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C85B3877030; Sat, 21 Mar 2020 18:53:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C85B3877030 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1584816781; bh=TJxX9Dai0w/ILYZkW0EjJLKtlHfbHT2LURITKzKrXOM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=qcZJejWuVpZedO+8oWzs8uyCF6DuouUmkJ+LeeMhNNNDJw/KZC79Ohn9AFR8LncY9 lrOKwIeVz0eX7udkpjaglPBuLNZ/klAvs8crQaiI9Ab9EfcunLV4UKXkHMvSjma813 o/K+H1obLDxNCEt+Tymg7f6iHeDwW72isvSgNQJ8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-u-204.mailbox.org (mout-u-204.mailbox.org [91.198.250.253]) by sourceware.org (Postfix) with ESMTPS id A42A6385E830 for ; Sat, 21 Mar 2020 18:52:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A42A6385E830 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 48l8sg754gzQkKl; Sat, 21 Mar 2020 19:52:55 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by gerste.heinlein-support.de (gerste.heinlein-support.de [91.198.250.173]) (amavisd-new, port 10030) with ESMTP id i279MyreSpH1; Sat, 21 Mar 2020 19:52:52 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH d] Committed fix for ICE in add_symbol_to_partition_1 at lto/lto-partition.c:215 (PR94920) Date: Sat, 21 Mar 2020 19:52:32 +0100 Message-Id: <20200321185232.13283-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Spam-Status: No, score=-32.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: Iain Buclaw Cc: jakub@redhat.com Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch addresses two problems with TypeInfo initializer generation. 1. D array fields pointing to compiler generated data are referencing public symbols with no unique prefix, which can lead to duplicate definition errors in some hard to reduce cases. To avoid name clashes, all symbols that are generated for TypeInfo initializers now use the assembler name of the TypeInfo decl as a prefix. 2. An ICE would occur during LTO pass because these same decls are considered to be part of the same comdat group as the TypeInfo decl that it's referred by, despite itself being neither marked public nor comdat. This resulted in decls being added to the LTRANS partition out of order, triggering an assert when add_symbol_to_partition_1 attempted to add them again. To remedy, TREE_PUBLIC and DECL_COMDAT are now set on all generated symbols. Jakub, I'll also want to backport this to the gcc-9 branch if there's no problem with that. Bootstrapped and tested on x86_64-linux-gnu, and committed to trunk. Regards, Iain. --- gcc/d/ChangeLog: 2020-03-21 Iain Buclaw PR d/94290 * typeinfo.cc (class TypeInfoVisitor): Replace type_ field with decl_. (TypeInfoVisitor::TypeInfoVisitor): Set decl_. (TypeInfoVisitor::result): Update. (TypeInfoVisitor::internal_reference): New function. (TypeInfoVisitor::layout_string): Use internal_reference. (TypeInfoVisitor::visit (TypeInfoTupleDeclaration *)): Likewise. (layout_typeinfo): Construct TypeInfoVisitor with typeinfo decl. (layout_classinfo): Likewise. --- gcc/d/typeinfo.cc | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc index d4f777159af..07011deaf6f 100644 --- a/gcc/d/typeinfo.cc +++ b/gcc/d/typeinfo.cc @@ -341,9 +341,29 @@ class TypeInfoVisitor : public Visitor { using Visitor::visit; - tree type_; + tree decl_; vec *init_; + /* Build an internal comdat symbol for the manifest constant VALUE, so that + its address can be taken. */ + + tree internal_reference (tree value) + { + /* Use the typeinfo decl name as a prefix for the internal symbol. */ + const char *prefix = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (this->decl_)); + tree decl = build_artificial_decl (TREE_TYPE (value), value, prefix); + + /* The internal pointer reference should be public, but not visible outside + the compilation unit. */ + DECL_EXTERNAL (decl) = 0; + TREE_PUBLIC (decl) = 1; + DECL_VISIBILITY (decl) = VISIBILITY_INTERNAL; + DECL_COMDAT (decl) = 1; + d_pushdecl (decl); + + return decl; + } + /* Add VALUE to the constructor values list. */ void layout_field (tree value) @@ -364,10 +384,8 @@ class TypeInfoVisitor : public Visitor TREE_STATIC (value) = 1; /* Taking the address, so assign the literal to a static var. */ - tree decl = build_artificial_decl (TREE_TYPE (value), value); + tree decl = this->internal_reference (value); TREE_READONLY (decl) = 1; - DECL_EXTERNAL (decl) = 0; - d_pushdecl (decl); value = d_array_value (build_ctype (Type::tchar->arrayOf ()), size_int (len), build_address (decl)); @@ -500,9 +518,9 @@ class TypeInfoVisitor : public Visitor public: - TypeInfoVisitor (tree type) + TypeInfoVisitor (tree decl) { - this->type_ = type; + this->decl_ = decl; this->init_ = NULL; } @@ -510,7 +528,7 @@ public: tree result (void) { - return build_struct_literal (this->type_, this->init_); + return build_struct_literal (TREE_TYPE (this->decl_), this->init_); } /* Layout of TypeInfo is: @@ -1125,19 +1143,12 @@ public: build_typeinfo (d->loc, arg->type)); } tree ctor = build_constructor (build_ctype (satype), elms); - tree decl = build_artificial_decl (TREE_TYPE (ctor), ctor); - - /* The internal pointer reference should be public, but not visible outside - the compilation unit, as it's referencing COMDAT decls. */ - TREE_PUBLIC (decl) = 1; - DECL_VISIBILITY (decl) = VISIBILITY_INTERNAL; - DECL_COMDAT (decl) = 1; + tree decl = this->internal_reference (ctor); tree length = size_int (ti->arguments->dim); tree ptr = build_address (decl); this->layout_field (d_array_value (array_type_node, length, ptr)); - d_pushdecl (decl); rest_of_decl_compilation (decl, 1, 0); } }; @@ -1152,8 +1163,7 @@ layout_typeinfo (TypeInfoDeclaration *d) if (!Type::dtypeinfo) create_frontend_tinfo_types (); - tree type = TREE_TYPE (get_typeinfo_decl (d)); - TypeInfoVisitor v = TypeInfoVisitor (type); + TypeInfoVisitor v = TypeInfoVisitor (get_typeinfo_decl (d)); d->accept (&v); return v.result (); } @@ -1168,8 +1178,7 @@ layout_classinfo (ClassDeclaration *cd) create_frontend_tinfo_types (); TypeInfoClassDeclaration *d = TypeInfoClassDeclaration::create (cd->type); - tree type = TREE_TYPE (get_classinfo_decl (cd)); - TypeInfoVisitor v = TypeInfoVisitor (type); + TypeInfoVisitor v = TypeInfoVisitor (get_classinfo_decl (cd)); d->accept (&v); return v.result (); }