Skip to content
This repository was archived by the owner on Jun 20, 2019. It is now read-only.

Commit 28b42cf

Browse files
committed
Prefer d_linkonce_linkage over d_comdat_linkage.
1 parent dea60d0 commit 28b42cf

File tree

3 files changed

+56
-48
lines changed

3 files changed

+56
-48
lines changed

gcc/d/ChangeLog

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@
2424
(build_closure): Don't set chain field for functions without context
2525
pointer.
2626

27+
2018-01-21 Iain Buclaw <[email protected]>
28+
29+
* decl.cc (DeclVisitor::visit(StructDeclaration)): Mark compiler
30+
generated symbols as DECL_ONE_ONLY instead of DECL_COMDAT.
31+
(DeclVisitor::visit(ClassDeclaration)): Likewise.
32+
(DeclVisitor::visit(InterfaceDeclaration)): Likewise.
33+
(DeclVisitor::visit(EnumDeclaration)): Likewise.
34+
(get_symbol_decl): Mark template instantiations as DECL_ONE_ONLY
35+
instead of DECL_COMDAT. Don't call mark_needed.
36+
(declare_extern_var): Don't call mark_needed.
37+
(d_finish_decl): Remove zero initializer for common symbols.
38+
(finish_thunk): Don't call d_comdat_linkage on generic thunk.
39+
(d_comdat_linkage): Don't set DECL_DECLARED_INLINE on functions.
40+
* typeinfo.cc (TypeInfoDeclVisitor::visit(TypeInfoDeclaration)): Mark
41+
built-in typeinfo symbols as DECL_ONE_ONLY instead of DECL_COMDAT.
42+
2743
2018-01-21 Iain Buclaw <[email protected]>
2844

2945
* d-lang.cc (d_init): Disable flag_weak if not supported.

gcc/d/decl.cc

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class DeclVisitor : public Visitor
314314
DECL_INITIAL (d->sinit) = layout_struct_initializer (d);
315315

316316
if (d->isInstantiated ())
317-
d_comdat_linkage (d->sinit);
317+
d_linkonce_linkage (d->sinit);
318318

319319
d_finish_decl (d->sinit);
320320

@@ -420,13 +420,13 @@ class DeclVisitor : public Visitor
420420

421421
/* Generate static initialiser. */
422422
DECL_INITIAL (d->sinit) = layout_class_initializer (d);
423-
d_comdat_linkage (d->sinit);
423+
d_linkonce_linkage (d->sinit);
424424
d_finish_decl (d->sinit);
425425

426426
/* Put out the TypeInfo. */
427427
create_typeinfo (d->type, NULL);
428428
DECL_INITIAL (d->csym) = layout_classinfo (d);
429-
d_comdat_linkage (d->csym);
429+
d_linkonce_linkage (d->csym);
430430
d_finish_decl (d->csym);
431431

432432
/* Put out the vtbl[]. */
@@ -487,7 +487,7 @@ class DeclVisitor : public Visitor
487487
d->type->vtinfo->accept (this);
488488

489489
DECL_INITIAL (d->csym) = layout_classinfo (d);
490-
d_comdat_linkage (d->csym);
490+
d_linkonce_linkage (d->csym);
491491
d_finish_decl (d->csym);
492492

493493
/* Add this decl to the current binding level. */
@@ -524,7 +524,7 @@ class DeclVisitor : public Visitor
524524
DECL_INITIAL (d->sinit) = build_expr (tc->sym->defaultval, true);
525525

526526
if (d->isInstantiated ())
527-
d_comdat_linkage (d->sinit);
527+
d_linkonce_linkage (d->sinit);
528528

529529
d_finish_decl (d->sinit);
530530

@@ -1152,6 +1152,7 @@ get_symbol_decl (Declaration *decl)
11521152
{
11531153
TREE_PUBLIC (decl->csym) = 1;
11541154
DECL_ARTIFICIAL (decl->csym) = 1;
1155+
DECL_DECLARED_INLINE_P (decl->csym) = 1;
11551156
d_comdat_linkage (decl->csym);
11561157
}
11571158

@@ -1229,13 +1230,7 @@ get_symbol_decl (Declaration *decl)
12291230
else
12301231
DECL_EXTERNAL (decl->csym) = 1;
12311232

1232-
d_comdat_linkage (decl->csym);
1233-
1234-
/* Normally the backend only emits COMDAT things when they are needed.
1235-
If this decl is meant to be externally visible, then make sure that
1236-
to mark it so that it is indeed needed. */
1237-
if (TREE_PUBLIC (decl->csym))
1238-
mark_needed (decl->csym);
1233+
d_linkonce_linkage (decl->csym);
12391234
}
12401235
else
12411236
{
@@ -1300,9 +1295,6 @@ declare_extern_var (tree ident, tree type)
13001295
TREE_STATIC (decl) = 1;
13011296
TREE_PUBLIC (decl) = 1;
13021297

1303-
/* Mark it needed so we don't forget to emit it. */
1304-
mark_needed (decl);
1305-
13061298
/* The decl has not been defined -- yet. */
13071299
DECL_EXTERNAL (decl) = 1;
13081300

@@ -1476,6 +1468,12 @@ d_finish_decl (tree decl)
14761468
}
14771469
}
14781470

1471+
/* Without weak symbols, symbol should be put in .common, but that can't
1472+
be done if there is a non-zero initializer. */
1473+
if (DECL_COMDAT (decl) && DECL_COMMON (decl)
1474+
&& initializer_zerop (DECL_INITIAL (decl)))
1475+
DECL_INITIAL (decl) = error_mark_node;
1476+
14791477
/* Add this decl to the current binding level. */
14801478
d_pushdecl (decl);
14811479

@@ -1615,8 +1613,6 @@ finish_thunk (tree thunk, tree function)
16151613

16161614
if (!stdarg_p (TREE_TYPE (thunk)))
16171615
{
1618-
/* Put generic thunk into COMDAT. */
1619-
d_comdat_linkage (thunk);
16201616
thunk_node->create_edge (funcn, NULL, thunk_node->count);
16211617
thunk_node->expand_thunk (false, true);
16221618
}
@@ -2159,14 +2155,6 @@ d_comdat_group (tree decl)
21592155
void
21602156
d_comdat_linkage (tree decl)
21612157
{
2162-
/* COMDAT definitions have to be public. */
2163-
if (!TREE_PUBLIC (decl))
2164-
return;
2165-
2166-
/* Necessary to allow DECL_ONE_ONLY or DECL_WEAK functions to be inlined. */
2167-
if (TREE_CODE (decl) == FUNCTION_DECL)
2168-
DECL_DECLARED_INLINE_P (decl) = 1;
2169-
21702158
if (flag_weak)
21712159
make_decl_one_only (decl, d_comdat_group (decl));
21722160
else if (TREE_CODE (decl) == FUNCTION_DECL

gcc/d/typeinfo.cc

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,28 @@ layout_classinfo_interfaces (ClassDeclaration *decl)
11871187
return type;
11881188
}
11891189

1190+
/* Returns true if the TypeInfo for type should be placed in
1191+
the runtime library. */
1192+
1193+
static bool
1194+
builtin_typeinfo_p (Type *type)
1195+
{
1196+
if (type->isTypeBasic () || type->ty == Tclass || type->ty == Tnull)
1197+
return !type->mod;
1198+
1199+
if (type->ty == Tarray)
1200+
{
1201+
/* Strings are so common, make them builtin. */
1202+
Type *next = type->nextOf ();
1203+
return !type->mod
1204+
&& ((next->isTypeBasic () != NULL && !next->mod)
1205+
|| (next->ty == Tchar && next->mod == MODimmutable)
1206+
|| (next->ty == Tchar && next->mod == MODconst));
1207+
}
1208+
1209+
return false;
1210+
}
1211+
11901212
/* Implements a visitor interface to create the decl tree for TypeInfo decls.
11911213
TypeInfo_Class objects differ in that they also have information about
11921214
the class type packed immediately after the TypeInfo symbol.
@@ -1213,7 +1235,11 @@ class TypeInfoDeclVisitor : public Visitor
12131235

12141236
/* Built-in typeinfo will be referenced as one-only. */
12151237
gcc_assert (!tid->isInstantiated ());
1216-
d_comdat_linkage (tid->csym);
1238+
1239+
if (builtin_typeinfo_p (tid->tinfo))
1240+
d_linkonce_linkage (tid->csym);
1241+
else
1242+
d_comdat_linkage (tid->csym);
12171243
}
12181244

12191245
void visit (TypeInfoClassDeclaration *tid)
@@ -1347,28 +1373,6 @@ get_cpp_typeinfo_decl (ClassDeclaration *decl)
13471373
return decl->cpp_type_info_ptr_sym;
13481374
}
13491375

1350-
/* Returns true if the TypeInfo for type should be placed in
1351-
the runtime library. */
1352-
1353-
static bool
1354-
builtin_typeinfo_p (Type *type)
1355-
{
1356-
if (type->isTypeBasic () || type->ty == Tclass || type->ty == Tnull)
1357-
return !type->mod;
1358-
1359-
if (type->ty == Tarray)
1360-
{
1361-
/* Strings are so common, make them builtin. */
1362-
Type *next = type->nextOf ();
1363-
return !type->mod
1364-
&& ((next->isTypeBasic () != NULL && !next->mod)
1365-
|| (next->ty == Tchar && next->mod == MODimmutable)
1366-
|| (next->ty == Tchar && next->mod == MODconst));
1367-
}
1368-
1369-
return false;
1370-
}
1371-
13721376
/* Get the exact TypeInfo for TYPE, if it doesn't exist, create it. */
13731377

13741378
void

0 commit comments

Comments
 (0)