diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2021-04-13 22:28:55 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2021-04-17 12:50:25 +0200 |
commit | bda519596543e49f77914b5677693e86be5d01d0 (patch) | |
tree | 70d41323c49a2dbddef9b55e57fb8784fba78922 /gcc/d/decl.cc | |
parent | d81bc495a426b0020e44a9764fd904462a39983b (diff) | |
download | gcc-bda519596543e49f77914b5677693e86be5d01d0.zip gcc-bda519596543e49f77914b5677693e86be5d01d0.tar.gz gcc-bda519596543e49f77914b5677693e86be5d01d0.tar.bz2 |
d: Add TARGET_D_TEMPLATES_ALWAYS_COMDAT
Following up on the fix for PR99914, when testing on MinGW, it was found
not to support weak in the same way as on ELF or Mach-O targets.
So the linkage has been reverted back to COMDAT for that target, however
in order to properly support overriding functions and variables, all
declarations with external linkage must be put on COMDAT. For this a
new target hook has been added to control the behavior.
gcc/ChangeLog:
PR d/99914
* config/i386/winnt-d.c (TARGET_D_TEMPLATES_ALWAYS_COMDAT): Define.
* doc/tm.texi: Regenerate.
* doc/tm.texi.in (D language and ABI): Add @hook for
TARGET_D_TEMPLATES_ALWAYS_COMDAT.
gcc/d/ChangeLog:
PR d/99914
* d-target.def (d_templates_always_comdat): New hook.
* d-tree.h (mark_needed): Remove prototype.
* decl.cc: Include d-target.h.
(mark_needed): Rename to...
(d_mark_needed): ...this. Make static.
(set_linkage_for_decl): Put variables in comdat if
d_templates_always_comdat.
Diffstat (limited to 'gcc/d/decl.cc')
-rw-r--r-- | gcc/d/decl.cc | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index 8948e40..7d13782 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -59,6 +59,7 @@ along with GCC; see the file COPYING3. If not see #include "symtab-thunks.h" #include "d-tree.h" +#include "d-target.h" /* Return identifier for the external mangled name of DECL. */ @@ -1960,8 +1961,8 @@ finish_function (tree old_context) /* Mark DECL, which is a VAR_DECL or FUNCTION_DECL as a symbol that must be emitted in this, output module. */ -void -mark_needed (tree decl) +static void +d_mark_needed (tree decl) { TREE_USED (decl) = 1; @@ -2380,6 +2381,18 @@ set_linkage_for_decl (tree decl) if (TREE_CODE (decl) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (decl)) return d_comdat_linkage (decl); + /* If all instantiations must go in COMDAT, give them that linkage. + This also applies to other extern declarations, so that it is possible + for them to override template declarations. */ + if (targetdm.d_templates_always_comdat) + { + /* Make sure that instantiations are not removed. */ + if (flag_weak_templates && DECL_INSTANTIATED (decl)) + d_mark_needed (decl); + + return d_comdat_linkage (decl); + } + /* Instantiated variables and functions need to be overridable by any other symbol with the same name, so give them weak linkage. */ if (DECL_INSTANTIATED (decl)) |