From: Iain Buclaw Date: Tue, 7 Apr 2020 16:02:47 +0000 (+0200) Subject: d: Fix ICE in add_symbol_to_partition_1, at lto/lto-partition.c:215 X-Git-Tag: embedded-9-2020q2~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e926d076f28a91f3ea30bd0bcfa1f25958fdb59e;p=thirdparty%2Fgcc.git d: Fix ICE in add_symbol_to_partition_1, at lto/lto-partition.c:215 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. gcc/d/ChangeLog: PR d/94240 * 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. --- diff --git a/gcc/d/ChangeLog b/gcc/d/ChangeLog index f8268e87d4d3..9cc59c8ad1d5 100644 --- a/gcc/d/ChangeLog +++ b/gcc/d/ChangeLog @@ -1,3 +1,15 @@ +2020-04-07 Iain Buclaw + + PR d/94240 + * 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. + 2020-03-12 Release Manager * GCC 9.3.0 released. diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc index bbd3961181dd..0b19bcf7f345 100644 --- a/gcc/d/typeinfo.cc +++ b/gcc/d/typeinfo.cc @@ -324,9 +324,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; + d_comdat_linkage (decl); + d_pushdecl (decl); + + return decl; + } + /* Add VALUE to the constructor values list. */ void layout_field (tree value) @@ -347,10 +367,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)); @@ -483,9 +501,9 @@ class TypeInfoVisitor : public Visitor public: - TypeInfoVisitor (tree type) + TypeInfoVisitor (tree decl) { - this->type_ = type; + this->decl_ = decl; this->init_ = NULL; } @@ -493,7 +511,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: @@ -1108,19 +1126,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); } }; @@ -1132,8 +1143,7 @@ public: tree layout_typeinfo (TypeInfoDeclaration *d) { - 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 (); } @@ -1145,8 +1155,7 @@ tree layout_classinfo (ClassDeclaration *cd) { 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 (); }