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

Commit dea60d0

Browse files
authored
Merge pull request #608 from ibuclaw/optfweak
Add -fweak command-line flag to compiler
2 parents f22199d + 6256cd7 commit dea60d0

File tree

6 files changed

+48
-2
lines changed

6 files changed

+48
-2
lines changed

gcc/d/ChangeLog

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

27+
2018-01-21 Iain Buclaw <ibuclaw@gdcproject.org>
28+
29+
* d-lang.cc (d_init): Disable flag_weak if not supported.
30+
* decl.cc (d_comdat_linkage): Use flag_weak to guard setting
31+
DECL_ONE_ONLY on decls.
32+
(d_linkonce_linkage): New function.
33+
* gdc.texi (Runtime Options): Document -fweak.
34+
* lang.opt (fweak): Declare.
35+
2736
2018-01-21 Iain Buclaw <ibuclaw@gdcproject.org>
2837

2938
* decls.cc (get_symbol_decl): Use attribute to mark naked functions.

gcc/d/d-lang.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ along with GCC; see the file COPYING3. If not see
3838
#include "target.h"
3939
#include "stringpool.h"
4040
#include "stor-layout.h"
41+
#include "varasm.h"
4142
#include "output.h"
4243
#include "print-tree.h"
4344
#include "gimple-expr.h"
@@ -361,6 +362,9 @@ d_init (void)
361362
if (flag_exceptions)
362363
using_eh_for_cleanups ();
363364

365+
if (!supports_one_only ())
366+
flag_weak = 0;
367+
364368
/* This is the C main, not the D main. */
365369
main_identifier_node = get_identifier ("main");
366370

gcc/d/d-tree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ extern tree build_artificial_decl (tree, tree, const char * = NULL);
604604
extern tree create_field_decl (tree, const char *, int, int);
605605
extern void build_type_decl (tree, Dsymbol *);
606606
extern void d_comdat_linkage (tree);
607+
extern void d_linkonce_linkage (tree);
607608

608609
/* In expr.cc. */
609610
extern tree build_expr (Expression *, bool = false);

gcc/d/decl.cc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,15 +2159,15 @@ d_comdat_group (tree decl)
21592159
void
21602160
d_comdat_linkage (tree decl)
21612161
{
2162-
/* Weak definitions have to be public. */
2162+
/* COMDAT definitions have to be public. */
21632163
if (!TREE_PUBLIC (decl))
21642164
return;
21652165

21662166
/* Necessary to allow DECL_ONE_ONLY or DECL_WEAK functions to be inlined. */
21672167
if (TREE_CODE (decl) == FUNCTION_DECL)
21682168
DECL_DECLARED_INLINE_P (decl) = 1;
21692169

2170-
if (supports_one_only ())
2170+
if (flag_weak)
21712171
make_decl_one_only (decl, d_comdat_group (decl));
21722172
else if (TREE_CODE (decl) == FUNCTION_DECL
21732173
|| (VAR_P (decl) && DECL_ARTIFICIAL (decl)))
@@ -2182,3 +2182,23 @@ d_comdat_linkage (tree decl)
21822182
if (TREE_PUBLIC (decl))
21832183
DECL_COMDAT (decl) = 1;
21842184
}
2185+
2186+
/* Set DECL up to have the closest approximation of "linkonce" linkage. */
2187+
2188+
void
2189+
d_linkonce_linkage (tree decl)
2190+
{
2191+
/* Weak definitions have to be public. */
2192+
if (!TREE_PUBLIC (decl))
2193+
return;
2194+
2195+
/* Necessary to allow DECL_ONE_ONLY or DECL_WEAK functions to be inlined. */
2196+
if (TREE_CODE (decl) == FUNCTION_DECL)
2197+
DECL_DECLARED_INLINE_P (decl) = 1;
2198+
2199+
/* No weak support, fallback to COMDAT linkage. */
2200+
if (!flag_weak)
2201+
return d_comdat_linkage (decl);
2202+
2203+
make_decl_one_only (decl, d_comdat_group (decl));
2204+
}

gcc/d/gdc.texi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,14 @@ is compiled into the program.
329329
Turns on compilation of @code{version} code identified by @var{ident}.
330330
@end table
331331

332+
@item -fno-weak
333+
@cindex @option{-fweak}
334+
@cindex @option{-fno-weak}
335+
Turns off emission of instantiated declarations that can be defined in multiple
336+
objects as weak or one-only symbols. The default is to emit all public symbols
337+
as weak, unless there lacks target support. Disabling this options means that
338+
common symbols are instead put in COMDAT or become private.
339+
332340
@end table
333341

334342
@node Directory Options

gcc/d/lang.opt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ fversion=
344344
D Joined RejectNegative
345345
-fversion=<level|ident> Compile in version code >= <level> or identified by <ident>.
346346

347+
fweak
348+
D Var(flag_weak) Init(1)
349+
Emit common-like symbols as weak symbols.
350+
347351
fXf=
348352
D Joined RejectNegative Alias(Xf)
349353
; Deprecated in favor of -Xf

0 commit comments

Comments
 (0)