diff mbox series

d: Fix #error You must define PREFERRED_DEBUGGING_TYPE if DWARF is not supported (PR105659)

Message ID 20220816211627.209433-1-ibuclaw@gdcproject.org
State New
Headers show
Series d: Fix #error You must define PREFERRED_DEBUGGING_TYPE if DWARF is not supported (PR105659) | expand

Commit Message

Iain Buclaw Aug. 16, 2022, 9:16 p.m. UTC
Hi,

Because targetdm contains hooks pertaining to both the target platform
and cpu, it tries to pull in both platform and cpu headers via tm_d.h in
the source file where TARGETDM_INITIALIZER is used.

Since 12.0, this has caused problems when there is no platform (*-elf),
resulting in default-d.cc failing to build due to triggering a
PREFERRED_DEBUGGING_TYPE #error.

This patch removes the CPU-specific hooks from targetdm, documenting
them instead as target macros.  Also removing the generation of tm_d.h
as its role is redundant.

I also notice that Rust maintainers initially copied what I did in
devel/rust/master, but ended up reverting back to using macros to get at
target OS and CPU information as well, possibly because they ran into
the same problems as reported in PR105659.

I'm not sure whether calling these hooks via function-like macros is
really desirable, I do recall early on during the review process of the
D front-end that putting target-specific language features behind a
targetdm hook was the preferred/encouraged way to expose these things.

One alternative perhaps would be to break out CPU-specific hooks in
targetdm into a separate targetdm_cpu hook vector.  This would mean
there would be no need to include tm_p.h anywhere in D-specific target
sources (only tm.h where needed), and all D-specific prototypes in
$cpu_type-protos.h can be removed.  Though tm_d.h would still be
redundant, so either way it gets the chop.

OK? Thoughts?  I don't expect this to go in for 12.2, but backporting
some time before 12.3 would be nice.

Bootstrapped and regression tested on x86_64-linux-gnu, and checked that
it indeed fixes the referenced PR by building an aarch64-rtems cross.

Regards,
Iain.

---
	PR d/105659

gcc/ChangeLog:

	* Makefile.in (tm_d_file_list): Remove.
	(tm_d_include_list): Remove.
	(TM_D_H): Remove.
	(tm_d.h): Remove.
	(cs-tm_d.h): Remove.
	(generated_files): Remove TM_D_H.
	* config.gcc (tm_d_file): Remove.
	* config/darwin-d.cc: Include memmodel.h and tm_p.h instead of tm_d.h.
	* config/default-d.cc: Remove includes of memmodel.h and tm_d.h.
	* config/dragonfly-d.cc: Include tm_p.h instead of tm_d.h.
	* configure: Regenerate.
	* configure.ac (tm_d_file): Remove.
	(tm_d_file_list): Remove substitution.
	(tm_d_include_list): Remove substitution.
	* doc/tm.texi: Regenerate.
	* doc/tm.texi.in (TARGET_D_CPU_VERSIONS): Document hook as being a
	function-like macro.
	(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.

gcc/d/ChangeLog:

	* d-builtins.cc: Include memmodel.h and tm_p.h.
	(d_init_versions): Call TARGET_D_CPU_VERSIONS via macro.
	* d-target.cc (Target::_init): Call TARGET_D_REGISTER_CPU_TARGET_INFO
	via macro.
	* d-target.def (d_cpu_versions): Remove hook.
	(d_register_cpu_target_info): Remove hook.
---
 gcc/Makefile.in           | 11 +----------
 gcc/config.gcc            |  7 -------
 gcc/config/darwin-d.cc    |  3 ++-
 gcc/config/default-d.cc   |  9 +++++++--
 gcc/config/dragonfly-d.cc |  2 +-
 gcc/configure             | 32 ++++++++------------------------
 gcc/configure.ac          | 18 ------------------
 gcc/d/d-builtins.cc       |  6 +++++-
 gcc/d/d-target.cc         |  4 +++-
 gcc/d/d-target.def        | 22 ----------------------
 gcc/doc/tm.texi           | 22 ++++++++++++----------
 gcc/doc/tm.texi.in        | 18 ++++++++++++++++--
 12 files changed, 55 insertions(+), 99 deletions(-)

Comments

Richard Biener Aug. 26, 2022, 8:42 a.m. UTC | #1
On Tue, Aug 16, 2022 at 11:17 PM Iain Buclaw via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Hi,
>
> Because targetdm contains hooks pertaining to both the target platform
> and cpu, it tries to pull in both platform and cpu headers via tm_d.h in
> the source file where TARGETDM_INITIALIZER is used.
>
> Since 12.0, this has caused problems when there is no platform (*-elf),
> resulting in default-d.cc failing to build due to triggering a
> PREFERRED_DEBUGGING_TYPE #error.
>
> This patch removes the CPU-specific hooks from targetdm, documenting
> them instead as target macros.  Also removing the generation of tm_d.h
> as its role is redundant.
>
> I also notice that Rust maintainers initially copied what I did in
> devel/rust/master, but ended up reverting back to using macros to get at
> target OS and CPU information as well, possibly because they ran into
> the same problems as reported in PR105659.
>
> I'm not sure whether calling these hooks via function-like macros is
> really desirable, I do recall early on during the review process of the
> D front-end that putting target-specific language features behind a
> targetdm hook was the preferred/encouraged way to expose these things.
>
> One alternative perhaps would be to break out CPU-specific hooks in
> targetdm into a separate targetdm_cpu hook vector.  This would mean
> there would be no need to include tm_p.h anywhere in D-specific target
> sources (only tm.h where needed), and all D-specific prototypes in
> $cpu_type-protos.h can be removed.  Though tm_d.h would still be
> redundant, so either way it gets the chop.
>
> OK? Thoughts?  I don't expect this to go in for 12.2, but backporting
> some time before 12.3 would be nice.

I was hoping Joseph would chime in here - I recollect debugging this kind
of thing and a thread about this a while back but unfortunately I do not
remember the details here (IIRC some things get included where they
better should not be).

This is all D specific changes so I'd say OK for trunk unless Joseph has
any comments.  Please wait a while before backporting so we can see
if it breaks any configuration.

Thanks,
Richard.

> Bootstrapped and regression tested on x86_64-linux-gnu, and checked that
> it indeed fixes the referenced PR by building an aarch64-rtems cross.
>
> Regards,
> Iain.
>
> ---
>         PR d/105659
>
> gcc/ChangeLog:
>
>         * Makefile.in (tm_d_file_list): Remove.
>         (tm_d_include_list): Remove.
>         (TM_D_H): Remove.
>         (tm_d.h): Remove.
>         (cs-tm_d.h): Remove.
>         (generated_files): Remove TM_D_H.
>         * config.gcc (tm_d_file): Remove.
>         * config/darwin-d.cc: Include memmodel.h and tm_p.h instead of tm_d.h.
>         * config/default-d.cc: Remove includes of memmodel.h and tm_d.h.
>         * config/dragonfly-d.cc: Include tm_p.h instead of tm_d.h.
>         * configure: Regenerate.
>         * configure.ac (tm_d_file): Remove.
>         (tm_d_file_list): Remove substitution.
>         (tm_d_include_list): Remove substitution.
>         * doc/tm.texi: Regenerate.
>         * doc/tm.texi.in (TARGET_D_CPU_VERSIONS): Document hook as being a
>         function-like macro.
>         (TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
>
> gcc/d/ChangeLog:
>
>         * d-builtins.cc: Include memmodel.h and tm_p.h.
>         (d_init_versions): Call TARGET_D_CPU_VERSIONS via macro.
>         * d-target.cc (Target::_init): Call TARGET_D_REGISTER_CPU_TARGET_INFO
>         via macro.
>         * d-target.def (d_cpu_versions): Remove hook.
>         (d_register_cpu_target_info): Remove hook.
> ---
>  gcc/Makefile.in           | 11 +----------
>  gcc/config.gcc            |  7 -------
>  gcc/config/darwin-d.cc    |  3 ++-
>  gcc/config/default-d.cc   |  9 +++++++--
>  gcc/config/dragonfly-d.cc |  2 +-
>  gcc/configure             | 32 ++++++++------------------------
>  gcc/configure.ac          | 18 ------------------
>  gcc/d/d-builtins.cc       |  6 +++++-
>  gcc/d/d-target.cc         |  4 +++-
>  gcc/d/d-target.def        | 22 ----------------------
>  gcc/doc/tm.texi           | 22 ++++++++++++----------
>  gcc/doc/tm.texi.in        | 18 ++++++++++++++++--
>  12 files changed, 55 insertions(+), 99 deletions(-)
>
> diff --git a/gcc/Makefile.in b/gcc/Makefile.in
> index 203f0a15187..12d9b5a3be4 100644
> --- a/gcc/Makefile.in
> +++ b/gcc/Makefile.in
> @@ -571,8 +571,6 @@ tm_include_list=@tm_include_list@
>  tm_defines=@tm_defines@
>  tm_p_file_list=@tm_p_file_list@
>  tm_p_include_list=@tm_p_include_list@
> -tm_d_file_list=@tm_d_file_list@
> -tm_d_include_list=@tm_d_include_list@
>  build_xm_file_list=@build_xm_file_list@
>  build_xm_include_list=@build_xm_include_list@
>  build_xm_defines=@build_xm_defines@
> @@ -865,7 +863,6 @@ BCONFIG_H = bconfig.h $(build_xm_file_list)
>  CONFIG_H  = config.h  $(host_xm_file_list)
>  TCONFIG_H = tconfig.h $(xm_file_list)
>  TM_P_H    = tm_p.h    $(tm_p_file_list)
> -TM_D_H    = tm_d.h    $(tm_d_file_list)
>  GTM_H     = tm.h      $(tm_file_list) insn-constants.h
>  TM_H      = $(GTM_H) insn-flags.h $(OPTIONS_H)
>
> @@ -1937,7 +1934,6 @@ bconfig.h: cs-bconfig.h ; @true
>  tconfig.h: cs-tconfig.h ; @true
>  tm.h: cs-tm.h ; @true
>  tm_p.h: cs-tm_p.h ; @true
> -tm_d.h: cs-tm_d.h ; @true
>
>  cs-config.h: Makefile
>         TARGET_CPU_DEFAULT="" \
> @@ -1964,11 +1960,6 @@ cs-tm_p.h: Makefile
>         HEADERS="$(tm_p_include_list)" DEFINES="" \
>         $(SHELL) $(srcdir)/mkconfig.sh tm_p.h
>
> -cs-tm_d.h: Makefile
> -       TARGET_CPU_DEFAULT="" \
> -       HEADERS="$(tm_d_include_list)" DEFINES="" \
> -       $(SHELL) $(srcdir)/mkconfig.sh tm_d.h
> -
>  # Don't automatically run autoconf, since configure.ac might be accidentally
>  # newer than configure.  Also, this writes into the source directory which
>  # might be on a read-only file system.  If configured for maintainer mode
> @@ -2783,7 +2774,7 @@ s-gtype: $(EXTRA_GTYPE_DEPS) build/gengtype$(build_exeext) \
>                      -r gtype.state
>         $(STAMP) s-gtype
>
> -generated_files = config.h tm.h $(TM_P_H) $(TM_D_H) $(TM_H) multilib.h \
> +generated_files = config.h tm.h $(TM_P_H) $(TM_H) multilib.h \
>         $(simple_generated_h) specs.h \
>         tree-check.h genrtl.h insn-modes.h insn-modes-inline.h \
>         tm-preds.h tm-constrs.h \
> diff --git a/gcc/config.gcc b/gcc/config.gcc
> index 4e3b15bb5e9..927d50b4355 100644
> --- a/gcc/config.gcc
> +++ b/gcc/config.gcc
> @@ -87,9 +87,6 @@
>  #  tm_p_file           Location of file with declarations for functions
>  #                      in $out_file.
>  #
> -#  tm_d_file           A list of headers with definitions of target hook
> -#                      macros for the D compiler.
> -#
>  #  out_file            The name of the machine description C support
>  #                      file, if different from "$cpu_type/$cpu_type.c".
>  #
> @@ -559,11 +556,9 @@ xtensa*-*-*)
>  esac
>
>  tm_file=${cpu_type}/${cpu_type}.h
> -tm_d_file=${cpu_type}/${cpu_type}.h
>  if test -f ${srcdir}/config/${cpu_type}/${cpu_type}-protos.h
>  then
>         tm_p_file=${cpu_type}/${cpu_type}-protos.h
> -       tm_d_file="${tm_d_file} ${cpu_type}/${cpu_type}-protos.h"
>  fi
>
>  extra_modes=
> @@ -669,7 +664,6 @@ case ${target} in
>  *-*-darwin*)
>    tmake_file="t-darwin "
>    tm_file="${tm_file} darwin.h"
> -  tm_d_file="${tm_d_file} tm-dwarf2.h"
>    darwin_os=`echo ${target} | sed 's/.*darwin\([0-9.]*\).*$/\1/'`
>    darwin_maj=`expr "$darwin_os" : '\([0-9]*\).*'`
>    macos_min=`expr "$darwin_os" : '[0-9]*\.\([0-9]*\).*'`
> @@ -3524,7 +3518,6 @@ xstormy16-*-elf)
>         # For historical reasons, the target files omit the 'x'.
>         tm_file="dbxelf.h elfos.h newlib-stdint.h stormy16/stormy16.h"
>         tm_p_file=stormy16/stormy16-protos.h
> -       tm_d_file="elfos.h stormy16/stormy16.h"
>         md_file=stormy16/stormy16.md
>         out_file=stormy16/stormy16.cc
>         extra_options=stormy16/stormy16.opt
> diff --git a/gcc/config/darwin-d.cc b/gcc/config/darwin-d.cc
> index e983883dba6..e88ddc189c3 100644
> --- a/gcc/config/darwin-d.cc
> +++ b/gcc/config/darwin-d.cc
> @@ -18,9 +18,10 @@ along with GCC; see the file COPYING3.  If not see
>  #include "config.h"
>  #include "system.h"
>  #include "coretypes.h"
> -#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
> +#include "memmodel.h"
> +#include "tm_p.h"
>
>  /* Implement TARGET_D_OS_VERSIONS for Darwin targets.  */
>
> diff --git a/gcc/config/default-d.cc b/gcc/config/default-d.cc
> index 2d7abfcba96..6674373793c 100644
> --- a/gcc/config/default-d.cc
> +++ b/gcc/config/default-d.cc
> @@ -18,9 +18,14 @@ along with GCC; see the file COPYING3.  If not see
>  #include "config.h"
>  #include "system.h"
>  #include "coretypes.h"
> -#include "memmodel.h"
> -#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
>
> +/* Do not include tm.h or tm_p.h here; if it is useful for a target to
> +   define some macros for the initializer in a header without defining
> +   targetcm itself (for example, because of interactions with some
> +   hooks depending on the target OS and others on the target
> +   architecture), create a separate tm_d.h for only the relevant
> +   definitions.  */
> +
>  struct gcc_targetdm targetdm = TARGETDM_INITIALIZER;
> diff --git a/gcc/config/dragonfly-d.cc b/gcc/config/dragonfly-d.cc
> index d431638f7da..2ee35c42e99 100644
> --- a/gcc/config/dragonfly-d.cc
> +++ b/gcc/config/dragonfly-d.cc
> @@ -18,9 +18,9 @@ along with GCC; see the file COPYING3.  If not see
>  #include "config.h"
>  #include "system.h"
>  #include "coretypes.h"
> -#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
> +#include "tm_p.h"
>
>  /* Implement TARGET_D_OS_VERSIONS for DragonFly targets.  */
>
> diff --git a/gcc/configure b/gcc/configure
> index 05efa5b01ef..7d0445178bb 100755
> --- a/gcc/configure
> +++ b/gcc/configure
> @@ -652,8 +652,6 @@ use_gcc_stdint
>  xm_defines
>  xm_include_list
>  xm_file_list
> -tm_d_include_list
> -tm_d_file_list
>  tm_p_include_list
>  tm_p_file_list
>  tm_defines
> @@ -5226,12 +5224,16 @@ else
>    GNATMAKE="$ac_cv_prog_GNATMAKE"
>  fi
>
> -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether compiler driver understands Ada" >&5
> -$as_echo_n "checking whether compiler driver understands Ada... " >&6; }
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether compiler driver understands Ada and is recent enough" >&5
> +$as_echo_n "checking whether compiler driver understands Ada and is recent enough... " >&6; }
>  if ${acx_cv_cc_gcc_supports_ada+:} false; then :
>    $as_echo_n "(cached) " >&6
>  else
>    cat >conftest.adb <<EOF
> +pragma Warnings (Off);
> +with System.CRTL;
> +pragma Warnings (On);
> +use type System.CRTL.int64;
>  procedure conftest is begin null; end conftest;
>  EOF
>  acx_cv_cc_gcc_supports_ada=no
> @@ -13009,7 +13011,6 @@ fi
>
>  tm_file="${tm_file} defaults.h"
>  tm_p_file="${tm_p_file} tm-preds.h"
> -tm_d_file="${tm_d_file} defaults.h"
>  host_xm_file="auto-host.h ansidecl.h ${host_xm_file}"
>  build_xm_file="${build_auto} ansidecl.h ${build_xm_file}"
>  # We don't want ansidecl.h in target files, write code there in ISO/GNU C.
> @@ -13403,21 +13404,6 @@ for f in $tm_p_file; do
>    esac
>  done
>
> -tm_d_file_list=
> -tm_d_include_list="options.h insn-constants.h"
> -for f in $tm_d_file; do
> -  case $f in
> -    defaults.h )
> -       tm_d_file_list="${tm_d_file_list} \$(srcdir)/$f"
> -       tm_d_include_list="${tm_d_include_list} $f"
> -       ;;
> -    * )
> -       tm_d_file_list="${tm_d_file_list} \$(srcdir)/config/$f"
> -       tm_d_include_list="${tm_d_include_list} config/$f"
> -       ;;
> -  esac
> -done
> -
>  xm_file_list=
>  xm_include_list=
>  for f in $xm_file; do
> @@ -19674,7 +19660,7 @@ else
>    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
>    lt_status=$lt_dlunknown
>    cat > conftest.$ac_ext <<_LT_EOF
> -#line 19677 "configure"
> +#line 19663 "configure"
>  #include "confdefs.h"
>
>  #if HAVE_DLFCN_H
> @@ -19780,7 +19766,7 @@ else
>    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
>    lt_status=$lt_dlunknown
>    cat > conftest.$ac_ext <<_LT_EOF
> -#line 19783 "configure"
> +#line 19769 "configure"
>  #include "confdefs.h"
>
>  #if HAVE_DLFCN_H
> @@ -31731,8 +31717,6 @@ fi
>
>
>
> -
> -
>
>
>
> diff --git a/gcc/configure.ac b/gcc/configure.ac
> index f70b6c24fda..a9006885663 100644
> --- a/gcc/configure.ac
> +++ b/gcc/configure.ac
> @@ -2113,7 +2113,6 @@ AC_SUBST(HAVE_AUTO_BUILD)
>
>  tm_file="${tm_file} defaults.h"
>  tm_p_file="${tm_p_file} tm-preds.h"
> -tm_d_file="${tm_d_file} defaults.h"
>  host_xm_file="auto-host.h ansidecl.h ${host_xm_file}"
>  build_xm_file="${build_auto} ansidecl.h ${build_xm_file}"
>  # We don't want ansidecl.h in target files, write code there in ISO/GNU C.
> @@ -2356,21 +2355,6 @@ for f in $tm_p_file; do
>    esac
>  done
>
> -tm_d_file_list=
> -tm_d_include_list="options.h insn-constants.h"
> -for f in $tm_d_file; do
> -  case $f in
> -    defaults.h )
> -       tm_d_file_list="${tm_d_file_list} \$(srcdir)/$f"
> -       tm_d_include_list="${tm_d_include_list} $f"
> -       ;;
> -    * )
> -       tm_d_file_list="${tm_d_file_list} \$(srcdir)/config/$f"
> -       tm_d_include_list="${tm_d_include_list} config/$f"
> -       ;;
> -  esac
> -done
> -
>  xm_file_list=
>  xm_include_list=
>  for f in $xm_file; do
> @@ -7361,8 +7345,6 @@ AC_SUBST(tm_include_list)
>  AC_SUBST(tm_defines)
>  AC_SUBST(tm_p_file_list)
>  AC_SUBST(tm_p_include_list)
> -AC_SUBST(tm_d_file_list)
> -AC_SUBST(tm_d_include_list)
>  AC_SUBST(xm_file_list)
>  AC_SUBST(xm_include_list)
>  AC_SUBST(xm_defines)
> diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
> index c2ef0c836e1..a5491316599 100644
> --- a/gcc/d/d-builtins.cc
> +++ b/gcc/d/d-builtins.cc
> @@ -34,6 +34,8 @@ along with GCC; see the file COPYING3.  If not see
>  #include "diagnostic.h"
>  #include "langhooks.h"
>  #include "target.h"
> +#include "memmodel.h"
> +#include "tm_p.h"
>  #include "common/common-target.h"
>  #include "stringpool.h"
>  #include "stor-layout.h"
> @@ -508,7 +510,9 @@ d_init_versions (void)
>    VersionCondition::addPredefinedGlobalIdent ("all");
>
>    /* Emit all target-specific version identifiers.  */
> -  targetdm.d_cpu_versions ();
> +#ifdef TARGET_D_CPU_VERSIONS
> +  TARGET_D_CPU_VERSIONS ();
> +#endif
>    targetdm.d_os_versions ();
>
>    VersionCondition::addPredefinedGlobalIdent ("CppRuntime_Gcc");
> diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc
> index d4350e593e4..7632a0af37b 100644
> --- a/gcc/d/d-target.cc
> +++ b/gcc/d/d-target.cc
> @@ -200,7 +200,9 @@ Target::_init (const Param &)
>
>    /* Initialize target info tables, the keys required by the language are added
>       last, so that the OS and CPU handlers can override.  */
> -  targetdm.d_register_cpu_target_info ();
> +#ifdef TARGET_D_REGISTER_CPU_TARGET_INFO
> +  TARGET_D_REGISTER_CPU_TARGET_INFO ();
> +#endif
>    targetdm.d_register_os_target_info ();
>    d_add_target_info_handlers (d_language_target_info);
>  }
> diff --git a/gcc/d/d-target.def b/gcc/d/d-target.def
> index 7805942b91e..10b0fe8171a 100644
> --- a/gcc/d/d-target.def
> +++ b/gcc/d/d-target.def
> @@ -28,16 +28,6 @@ HOOK_VECTOR (TARGETDM_INITIALIZER, gcc_targetdm)
>  #undef HOOK_PREFIX
>  #define HOOK_PREFIX "TARGET_"
>
> -/* Environmental version identifiers relating to the target CPU.  */
> -DEFHOOK
> -(d_cpu_versions,
> - "Declare all environmental version identifiers relating to the target CPU\n\
> -using the function @code{builtin_version}, which takes a string representing\n\
> -the name of the version.  Version identifiers predefined by this hook apply\n\
> -to all modules that are being compiled and imported.",
> - void, (void),
> - hook_void_void)
> -
>  /* Environmental version identifiers relating to the target OS.  */
>  DEFHOOK
>  (d_os_versions,
> @@ -46,18 +36,6 @@ relating to the target operating system.",
>   void, (void),
>   hook_void_void)
>
> -/* getTargetInfo keys relating to the target CPU.  */
> -DEFHOOK
> -(d_register_cpu_target_info,
> - "Register all target information keys relating to the target CPU using the\n\
> -function @code{d_add_target_info_handlers}, which takes a\n\
> -@samp{struct d_target_info_spec} (defined in @file{d/d-target.h}).  The keys\n\
> -added by this hook are made available at compile time by the\n\
> -@code{__traits(getTargetInfo)} extension, the result is an expression\n\
> -describing the requested target information.",
> - void, (void),
> - hook_void_void)
> -
>  /* getTargetInfo keys relating to the target OS.  */
>  DEFHOOK
>  (d_register_os_target_info,
> diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
> index 92bda1a7e14..e2c4e98ed7c 100644
> --- a/gcc/doc/tm.texi
> +++ b/gcc/doc/tm.texi
> @@ -11005,26 +11005,28 @@ Return target-specific mangling context of @var{decl} or @code{NULL_TREE}.
>  @section D ABI parameters
>  @cindex parameters, d abi
>
> -@deftypefn {D Target Hook} void TARGET_D_CPU_VERSIONS (void)
> -Declare all environmental version identifiers relating to the target CPU
> -using the function @code{builtin_version}, which takes a string representing
> -the name of the version.  Version identifiers predefined by this hook apply
> -to all modules that are being compiled and imported.
> -@end deftypefn
> +@defmac TARGET_D_CPU_VERSIONS ()
> +This function-like macro expands to a block of code that declares all
> +environmental version identifiers relating to the target CPU using the function
> +@code{builtin_version}, which takes a string representing the name of the
> +version.  Version identifiers predefined by this hook apply to all modules that
> +are being compiled and imported.
> +@end defmac
>
>  @deftypefn {D Target Hook} void TARGET_D_OS_VERSIONS (void)
>  Similarly to @code{TARGET_D_CPU_VERSIONS}, but is used for versions
>  relating to the target operating system.
>  @end deftypefn
>
> -@deftypefn {D Target Hook} void TARGET_D_REGISTER_CPU_TARGET_INFO (void)
> -Register all target information keys relating to the target CPU using the
> -function @code{d_add_target_info_handlers}, which takes a
> +@defmac TARGET_D_REGISTER_CPU_TARGET_INFO ()
> +This function-like macro expands to a block of code that registers all target
> +information keys relating to the target CPU using the function
> +@code{d_add_target_info_handlers}, which takes a
>  @samp{struct d_target_info_spec} (defined in @file{d/d-target.h}).  The keys
>  added by this hook are made available at compile time by the
>  @code{__traits(getTargetInfo)} extension, the result is an expression
>  describing the requested target information.
> -@end deftypefn
> +@end defmac
>
>  @deftypefn {D Target Hook} void TARGET_D_REGISTER_OS_TARGET_INFO (void)
>  Same as @code{TARGET_D_CPU_TARGET_INFO}, but is used for keys relating to
> diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
> index 112462310b1..69a4188c4b2 100644
> --- a/gcc/doc/tm.texi.in
> +++ b/gcc/doc/tm.texi.in
> @@ -7309,11 +7309,25 @@ floating-point support; they are not included in this mechanism.
>  @section D ABI parameters
>  @cindex parameters, d abi
>
> -@hook TARGET_D_CPU_VERSIONS
> +@defmac TARGET_D_CPU_VERSIONS ()
> +This function-like macro expands to a block of code that declares all
> +environmental version identifiers relating to the target CPU using the function
> +@code{builtin_version}, which takes a string representing the name of the
> +version.  Version identifiers predefined by this hook apply to all modules that
> +are being compiled and imported.
> +@end defmac
>
>  @hook TARGET_D_OS_VERSIONS
>
> -@hook TARGET_D_REGISTER_CPU_TARGET_INFO
> +@defmac TARGET_D_REGISTER_CPU_TARGET_INFO ()
> +This function-like macro expands to a block of code that registers all target
> +information keys relating to the target CPU using the function
> +@code{d_add_target_info_handlers}, which takes a
> +@samp{struct d_target_info_spec} (defined in @file{d/d-target.h}).  The keys
> +added by this hook are made available at compile time by the
> +@code{__traits(getTargetInfo)} extension, the result is an expression
> +describing the requested target information.
> +@end defmac
>
>  @hook TARGET_D_REGISTER_OS_TARGET_INFO
>
> --
> 2.34.1
>
Joseph Myers Aug. 30, 2022, 9:53 p.m. UTC | #2
On Fri, 26 Aug 2022, Richard Biener via Gcc-patches wrote:

> I was hoping Joseph would chime in here - I recollect debugging this kind
> of thing and a thread about this a while back but unfortunately I do not
> remember the details here (IIRC some things get included where they
> better should not be).

See <https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582563.html>.  
Is there some reason it's problematic to avoid having defaults.h or 
${cpu_type}/${cpu_type}.h included in tm_d.h, and instead have tm_d.h only 
include D-specific headers?
Iain Buclaw Aug. 31, 2022, 12:10 p.m. UTC | #3
Excerpts from Joseph Myers's message of August 30, 2022 11:53 pm:
> On Fri, 26 Aug 2022, Richard Biener via Gcc-patches wrote:
> 
>> I was hoping Joseph would chime in here - I recollect debugging this kind
>> of thing and a thread about this a while back but unfortunately I do not
>> remember the details here (IIRC some things get included where they
>> better should not be).
> 
> See <https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582563.html>.  
> Is there some reason it's problematic to avoid having defaults.h or 
> ${cpu_type}/${cpu_type}.h included in tm_d.h, and instead have tm_d.h only 
> include D-specific headers?
> 

In targets such as arm-elf, we still need to pull in definitions from
${cpu_type}/${cpu_type}-d.cc into default-d.cc.

All I can think that might suffice is having D-specific prototype
headers in all targets as ${cpu_type}/${cpu_type}-d.h.

At this location:
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config.gcc;h=1104508488818ff589dbc0890cf3fc475ae5977a;hb=refs/heads/master#l560

	if test -f ${srcdir}/config/${cpu_type}/${cpu_type}-d.h
	then
		tm_d_file=${cpu_type}/${cpu_type}-d.h
	fi


Looks like RustFE ripped out their target support for now.

https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=1c8ebf66965509008329b6e0425ffda407265263
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=3cd9342634e38100a9fa6a4bec4d958ca3a4ab60
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=a15ee6c3e5d710556d145e6af499b09993c4ee64

Iain.
Joseph Myers Aug. 31, 2022, 5:16 p.m. UTC | #4
On Wed, 31 Aug 2022, Iain Buclaw via Gcc-patches wrote:

> Excerpts from Joseph Myers's message of August 30, 2022 11:53 pm:
> > On Fri, 26 Aug 2022, Richard Biener via Gcc-patches wrote:
> > 
> >> I was hoping Joseph would chime in here - I recollect debugging this kind
> >> of thing and a thread about this a while back but unfortunately I do not
> >> remember the details here (IIRC some things get included where they
> >> better should not be).
> > 
> > See <https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582563.html>.  
> > Is there some reason it's problematic to avoid having defaults.h or 
> > ${cpu_type}/${cpu_type}.h included in tm_d.h, and instead have tm_d.h only 
> > include D-specific headers?
> > 
> 
> In targets such as arm-elf, we still need to pull in definitions from
> ${cpu_type}/${cpu_type}-d.cc into default-d.cc.
> 
> All I can think that might suffice is having D-specific prototype
> headers in all targets as ${cpu_type}/${cpu_type}-d.h.

As long as those prototypes don't involve any types that depend on an 
inclusion of tm.h, that should be fine.
Iain Buclaw Aug. 31, 2022, 7:21 p.m. UTC | #5
Excerpts from Joseph Myers's message of August 31, 2022 7:16 pm:
> On Wed, 31 Aug 2022, Iain Buclaw via Gcc-patches wrote:
> 
>> Excerpts from Joseph Myers's message of August 30, 2022 11:53 pm:
>> > On Fri, 26 Aug 2022, Richard Biener via Gcc-patches wrote:
>> > 
>> >> I was hoping Joseph would chime in here - I recollect debugging this kind
>> >> of thing and a thread about this a while back but unfortunately I do not
>> >> remember the details here (IIRC some things get included where they
>> >> better should not be).
>> > 
>> > See <https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582563.html>.  
>> > Is there some reason it's problematic to avoid having defaults.h or 
>> > ${cpu_type}/${cpu_type}.h included in tm_d.h, and instead have tm_d.h only 
>> > include D-specific headers?
>> > 
>> 
>> In targets such as arm-elf, we still need to pull in definitions from
>> ${cpu_type}/${cpu_type}-d.cc into default-d.cc.
>> 
>> All I can think that might suffice is having D-specific prototype
>> headers in all targets as ${cpu_type}/${cpu_type}-d.h.
> 
> As long as those prototypes don't involve any types that depend on an 
> inclusion of tm.h, that should be fine.
> 

Updated patch that does what I described.

Bootstrapped on x86_64-linux-gnu and built an aarch64-rtems
cross-compiler without any errors, will kick off config-list.mk as well for
sanity checking a big list of targets in a while.

Iain.
---
	PR d/105659

gcc/ChangeLog:

	* config.gcc: Set tm_d_file to ${cpu_type}/${cpu_type}-d.h.
	* config/aarch64/aarch64-d.cc: Include tm_d.h.
	* config/aarch64/aarch64-protos.h (aarch64_d_target_versions): Move to
	config/aarch64/aarch64-d.h.
	(aarch64_d_register_target_info): Likewise.
	* config/aarch64/aarch64.h (TARGET_D_CPU_VERSIONS): Likewise.
	(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
	* config/arm/arm-d.cc: Include tm_d.h instead of tm_p.h.
	* config/arm/arm-protos.h (arm_d_target_versions): Move to
	config/arm/arm-d.h.
	(arm_d_register_target_info): Likewise.
	* config/arm/arm.h (TARGET_D_CPU_VERSIONS): Likewise.
	(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
	* config/default-d.cc: Remove memmodel.h include.
	* config/freebsd-d.cc: Include tm_d.h instead of tm_p.h.
	* config/glibc-d.cc: Likewise.
	* config/i386/i386-d.cc: Include tm_d.h.
	* config/i386/i386-protos.h (ix86_d_target_versions): Move to
	config/i386/i386-d.h.
	(ix86_d_register_target_info): Likewise.
	(ix86_d_has_stdcall_convention): Likewise.
	* config/i386/i386.h (TARGET_D_CPU_VERSIONS): Likewise.
	(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
	(TARGET_D_HAS_STDCALL_CONVENTION): Likewise.
	* config/i386/winnt-d.cc: Include tm_d.h instead of tm_p.h.
	* config/mips/mips-d.cc: Include tm_d.h.
	* config/mips/mips-protos.h (mips_d_target_versions): Move to
	config/mips/mips-d.h.
	(mips_d_register_target_info): Likewise.
	* config/mips/mips.h (TARGET_D_CPU_VERSIONS): Likewise.
	(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
	* config/netbsd-d.cc: Include tm_d.h instead of tm.h and memmodel.h.
	* config/openbsd-d.cc: Likewise.
	* config/pa/pa-d.cc: Include tm_d.h.
	* config/pa/pa-protos.h (pa_d_target_versions): Move to
	config/pa/pa-d.h.
	(pa_d_register_target_info): Likewise.
	* config/pa/pa.h (TARGET_D_CPU_VERSIONS): Likewise.
	(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
	* config/riscv/riscv-d.cc: Include tm_d.h.
	* config/riscv/riscv-protos.h (riscv_d_target_versions): Move to
	config/riscv/riscv-d.h.
	(riscv_d_register_target_info): Likewise.
	* config/riscv/riscv.h (TARGET_D_CPU_VERSIONS): Likewise.
	(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
	* config/rs6000/rs6000-d.cc: Include tm_d.h.
	* config/rs6000/rs6000-protos.h (rs6000_d_target_versions): Move to
	config/rs6000/rs6000-d.h.
	(rs6000_d_register_target_info): Likewise.
	* config/rs6000/rs6000.h (TARGET_D_CPU_VERSIONS) Likewise.:
	(TARGET_D_REGISTER_CPU_TARGET_INFO) Likewise.:
	* config/s390/s390-d.cc: Include tm_d.h.
	* config/s390/s390-protos.h (s390_d_target_versions): Move to
	config/s390/s390-d.h.
	(s390_d_register_target_info): Likewise.
	* config/s390/s390.h (TARGET_D_CPU_VERSIONS): Likewise.
	(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
	* config/sol2-d.cc: Include tm_d.h instead of tm.h and memmodel.h.
	* config/sparc/sparc-d.cc: Include tm_d.h.
	* config/sparc/sparc-protos.h (sparc_d_target_versions): Move to
	config/sparc/sparc-d.h.
	(sparc_d_register_target_info): Likewise.
	* config/sparc/sparc.h (TARGET_D_CPU_VERSIONS): Likewise.
	(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
	* configure: Regenerate.
	* configure.ac (tm_d_file): Remove defaults.h.
	(tm_d_include_list): Remove options.h and insn-constants.h.
	* config/aarch64/aarch64-d.h: New file.
	* config/arm/arm-d.h: New file.
	* config/i386/i386-d.h: New file.
	* config/mips/mips-d.h: New file.
	* config/pa/pa-d.h: New file.
	* config/riscv/riscv-d.h: New file.
	* config/rs6000/rs6000-d.h: New file.
	* config/s390/s390-d.h: New file.
	* config/sparc/sparc-d.h: New file.
---
 gcc/config.gcc                      | 10 ++++++----
 gcc/config/aarch64/aarch64-d.cc     |  1 +
 gcc/config/aarch64/aarch64-d.h      | 24 ++++++++++++++++++++++++
 gcc/config/aarch64/aarch64-protos.h |  4 ----
 gcc/config/aarch64/aarch64.h        |  4 ----
 gcc/config/arm/arm-d.cc             |  2 +-
 gcc/config/arm/arm-d.h              | 24 ++++++++++++++++++++++++
 gcc/config/arm/arm-protos.h         |  4 ----
 gcc/config/arm/arm.h                |  4 ----
 gcc/config/default-d.cc             |  1 -
 gcc/config/freebsd-d.cc             |  2 +-
 gcc/config/glibc-d.cc               |  2 +-
 gcc/config/i386/i386-d.cc           |  1 +
 gcc/config/i386/i386-d.h            | 26 ++++++++++++++++++++++++++
 gcc/config/i386/i386-protos.h       |  5 -----
 gcc/config/i386/i386.h              |  5 -----
 gcc/config/i386/winnt-d.cc          |  2 +-
 gcc/config/mips/mips-d.cc           |  1 +
 gcc/config/mips/mips-d.h            | 24 ++++++++++++++++++++++++
 gcc/config/mips/mips-protos.h       |  4 ----
 gcc/config/mips/mips.h              |  4 ----
 gcc/config/netbsd-d.cc              |  4 +---
 gcc/config/openbsd-d.cc             |  4 +---
 gcc/config/pa/pa-d.cc               |  1 +
 gcc/config/pa/pa-d.h                | 24 ++++++++++++++++++++++++
 gcc/config/pa/pa-protos.h           |  4 ----
 gcc/config/pa/pa.h                  |  4 ----
 gcc/config/riscv/riscv-d.cc         |  1 +
 gcc/config/riscv/riscv-d.h          | 24 ++++++++++++++++++++++++
 gcc/config/riscv/riscv-protos.h     |  4 ----
 gcc/config/riscv/riscv.h            |  4 ----
 gcc/config/rs6000/rs6000-d.cc       |  1 +
 gcc/config/rs6000/rs6000-d.h        | 24 ++++++++++++++++++++++++
 gcc/config/rs6000/rs6000-protos.h   |  4 ----
 gcc/config/rs6000/rs6000.h          |  4 ----
 gcc/config/s390/s390-d.cc           |  1 +
 gcc/config/s390/s390-d.h            | 24 ++++++++++++++++++++++++
 gcc/config/s390/s390-protos.h       |  4 ----
 gcc/config/s390/s390.h              |  4 ----
 gcc/config/sol2-d.cc                |  4 +---
 gcc/config/sparc/sparc-d.cc         |  1 +
 gcc/config/sparc/sparc-d.h          | 24 ++++++++++++++++++++++++
 gcc/config/sparc/sparc-protos.h     |  4 ----
 gcc/config/sparc/sparc.h            |  4 ----
 gcc/configure                       | 11 +++--------
 gcc/configure.ac                    |  7 +------
 46 files changed, 243 insertions(+), 106 deletions(-)
 create mode 100644 gcc/config/aarch64/aarch64-d.h
 create mode 100644 gcc/config/arm/arm-d.h
 create mode 100644 gcc/config/i386/i386-d.h
 create mode 100644 gcc/config/mips/mips-d.h
 create mode 100644 gcc/config/pa/pa-d.h
 create mode 100644 gcc/config/riscv/riscv-d.h
 create mode 100644 gcc/config/rs6000/rs6000-d.h
 create mode 100644 gcc/config/s390/s390-d.h
 create mode 100644 gcc/config/sparc/sparc-d.h

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 11045084888..ce8e433d283 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -557,11 +557,15 @@ xtensa*-*-*)
 esac
 
 tm_file=${cpu_type}/${cpu_type}.h
-tm_d_file=${cpu_type}/${cpu_type}.h
 if test -f ${srcdir}/config/${cpu_type}/${cpu_type}-protos.h
 then
 	tm_p_file=${cpu_type}/${cpu_type}-protos.h
-	tm_d_file="${tm_d_file} ${cpu_type}/${cpu_type}-protos.h"
+fi
+
+tm_d_file=
+if test -f ${srcdir}/config/${cpu_type}/${cpu_type}-d.h
+then
+	tm_d_file="${tm_d_file} ${cpu_type}/${cpu_type}-d.h"
 fi
 
 extra_modes=
@@ -667,7 +671,6 @@ case ${target} in
 *-*-darwin*)
   tmake_file="t-darwin "
   tm_file="${tm_file} darwin.h"
-  tm_d_file="${tm_d_file} tm-dwarf2.h"
   darwin_os=`echo ${target} | sed 's/.*darwin\([0-9.]*\).*$/\1/'`
   darwin_maj=`expr "$darwin_os" : '\([0-9]*\).*'`
   macos_min=`expr "$darwin_os" : '[0-9]*\.\([0-9]*\).*'`
@@ -3524,7 +3527,6 @@ xstormy16-*-elf)
 	# For historical reasons, the target files omit the 'x'.
 	tm_file="dbxelf.h elfos.h newlib-stdint.h stormy16/stormy16.h"
 	tm_p_file=stormy16/stormy16-protos.h
-	tm_d_file="elfos.h stormy16/stormy16.h"
 	md_file=stormy16/stormy16.md
 	out_file=stormy16/stormy16.cc
 	extra_options=stormy16/stormy16.opt
diff --git a/gcc/config/aarch64/aarch64-d.cc b/gcc/config/aarch64/aarch64-d.cc
index d3fcc0b881e..e0e0401631e 100644
--- a/gcc/config/aarch64/aarch64-d.cc
+++ b/gcc/config/aarch64/aarch64-d.cc
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/aarch64/aarch64-d.h b/gcc/config/aarch64/aarch64-d.h
new file mode 100644
index 00000000000..c605a68ef9f
--- /dev/null
+++ b/gcc/config/aarch64/aarch64-d.h
@@ -0,0 +1,24 @@
+/* Definitions for the D front end on the AArch64 architecture.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* Defined in aarch64-d.cc  */
+extern void aarch64_d_target_versions (void);
+extern void aarch64_d_register_target_info (void);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS aarch64_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO aarch64_d_register_target_info
diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h
index 19c9d3cb179..0bb4c9b0e28 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -1040,10 +1040,6 @@ enum aarch64_parse_opt_result aarch64_parse_extension (const char *,
 void aarch64_get_all_extension_candidates (auto_vec<const char *> *candidates);
 std::string aarch64_get_extension_string_for_isa_flags (uint64_t, uint64_t);
 
-/* Defined in aarch64-d.cc  */
-extern void aarch64_d_target_versions (void);
-extern void aarch64_d_register_target_info (void);
-
 rtl_opt_pass *make_pass_fma_steering (gcc::context *);
 rtl_opt_pass *make_pass_track_speculation (gcc::context *);
 rtl_opt_pass *make_pass_tag_collision_avoidance (gcc::context *);
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index 80cfe4b7407..e6855c64035 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -26,10 +26,6 @@
 #define TARGET_CPU_CPP_BUILTINS()	\
   aarch64_cpu_cpp_builtins (pfile)
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS aarch64_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO aarch64_d_register_target_info
-
 
 
 #define REGISTER_TARGET_PRAGMAS() aarch64_register_pragmas ()
diff --git a/gcc/config/arm/arm-d.cc b/gcc/config/arm/arm-d.cc
index d65b7524934..b03c6ffecf5 100644
--- a/gcc/config/arm/arm-d.cc
+++ b/gcc/config/arm/arm-d.cc
@@ -21,7 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
-#include "tm_p.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/arm/arm-d.h b/gcc/config/arm/arm-d.h
new file mode 100644
index 00000000000..479a89bb120
--- /dev/null
+++ b/gcc/config/arm/arm-d.h
@@ -0,0 +1,24 @@
+/* Definitions for the D front end on the ARM architecture.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* Defined in arm-d.cc  */
+extern void arm_d_target_versions (void);
+extern void arm_d_register_target_info (void);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS arm_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO arm_d_register_target_info
diff --git a/gcc/config/arm/arm-protos.h b/gcc/config/arm/arm-protos.h
index f8aabbdae37..ee226559bfb 100644
--- a/gcc/config/arm/arm-protos.h
+++ b/gcc/config/arm/arm-protos.h
@@ -402,10 +402,6 @@ extern void arm_lang_object_attributes_init (void);
 extern void arm_register_target_pragmas (void);
 extern void arm_cpu_cpp_builtins (struct cpp_reader *);
 
-/* Defined in arm-d.cc  */
-extern void arm_d_target_versions (void);
-extern void arm_d_register_target_info (void);
-
 extern bool arm_is_constant_pool_ref (rtx);
 
 /* The bits in this mask specify which instruction scheduling options should
diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
index f479540812a..e15722b0be3 100644
--- a/gcc/config/arm/arm.h
+++ b/gcc/config/arm/arm.h
@@ -47,10 +47,6 @@ extern char arm_arch_name[];
 /* Target CPU builtins.  */
 #define TARGET_CPU_CPP_BUILTINS() arm_cpu_cpp_builtins (pfile)
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS arm_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO arm_d_register_target_info
-
 #include "config/arm/arm-opts.h"
 
 /* The processor for which instructions should be scheduled.  */
diff --git a/gcc/config/default-d.cc b/gcc/config/default-d.cc
index 2d7abfcba96..ff722c5096d 100644
--- a/gcc/config/default-d.cc
+++ b/gcc/config/default-d.cc
@@ -18,7 +18,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "memmodel.h"
 #include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
diff --git a/gcc/config/freebsd-d.cc b/gcc/config/freebsd-d.cc
index 9f0f5e7b6ee..189e4a69e78 100644
--- a/gcc/config/freebsd-d.cc
+++ b/gcc/config/freebsd-d.cc
@@ -20,7 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "memmodel.h"
 #include "tm.h"
-#include "tm_p.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/glibc-d.cc b/gcc/config/glibc-d.cc
index f30af104db8..80ef27d19c6 100644
--- a/gcc/config/glibc-d.cc
+++ b/gcc/config/glibc-d.cc
@@ -20,7 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "tm.h"
 #include "memmodel.h"
-#include "tm_p.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/i386/i386-d.cc b/gcc/config/i386/i386-d.cc
index a62339cae30..27e2b75fc25 100644
--- a/gcc/config/i386/i386-d.cc
+++ b/gcc/config/i386/i386-d.cc
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/i386/i386-d.h b/gcc/config/i386/i386-d.h
new file mode 100644
index 00000000000..b9806889df9
--- /dev/null
+++ b/gcc/config/i386/i386-d.h
@@ -0,0 +1,26 @@
+/* Definitions for the D front end on the x86 architecture.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* In i386-d.cc  */
+extern void ix86_d_target_versions (void);
+extern void ix86_d_register_target_info (void);
+extern bool ix86_d_has_stdcall_convention (unsigned int *, unsigned int *);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS ix86_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO ix86_d_register_target_info
+#define TARGET_D_HAS_STDCALL_CONVENTION ix86_d_has_stdcall_convention
diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
index e27c14ff783..3b94efefa65 100644
--- a/gcc/config/i386/i386-protos.h
+++ b/gcc/config/i386/i386-protos.h
@@ -277,11 +277,6 @@ extern bool ix86_extract_perm_from_pool_constant (int*, rtx);
 extern void ix86_target_macros (void);
 extern void ix86_register_pragmas (void);
 
-/* In i386-d.cc  */
-extern void ix86_d_target_versions (void);
-extern void ix86_d_register_target_info (void);
-extern bool ix86_d_has_stdcall_convention (unsigned int *, unsigned int *);
-
 /* In winnt.cc  */
 extern void i386_pe_unique_section (tree, int);
 extern void i386_pe_declare_function_type (FILE *, const char *, int);
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 0de5c77bc7d..716bacef5f9 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -608,11 +608,6 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
 /* Target Pragmas.  */
 #define REGISTER_TARGET_PRAGMAS() ix86_register_pragmas ()
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS ix86_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO ix86_d_register_target_info
-#define TARGET_D_HAS_STDCALL_CONVENTION ix86_d_has_stdcall_convention
-
 #ifndef CC1_SPEC
 #define CC1_SPEC "%(cc1_cpu) "
 #endif
diff --git a/gcc/config/i386/winnt-d.cc b/gcc/config/i386/winnt-d.cc
index 3d990a12331..00c28c3964a 100644
--- a/gcc/config/i386/winnt-d.cc
+++ b/gcc/config/i386/winnt-d.cc
@@ -21,9 +21,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "target.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
-#include "tm_p.h"
 
 /* Implement TARGET_D_OS_VERSIONS for Windows targets.  */
 
diff --git a/gcc/config/mips/mips-d.cc b/gcc/config/mips/mips-d.cc
index 41a278a08fd..8b6ccd10604 100644
--- a/gcc/config/mips/mips-d.cc
+++ b/gcc/config/mips/mips-d.cc
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/mips/mips-d.h b/gcc/config/mips/mips-d.h
new file mode 100644
index 00000000000..7cb3ed9716e
--- /dev/null
+++ b/gcc/config/mips/mips-d.h
@@ -0,0 +1,24 @@
+/* Definitions for the D front end on the MIPS architecture.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* Routines implemented in mips-d.cc  */
+extern void mips_d_target_versions (void);
+extern void mips_d_register_target_info (void);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS mips_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO mips_d_register_target_info
diff --git a/gcc/config/mips/mips-protos.h b/gcc/config/mips/mips-protos.h
index 9d0f4d90fd9..86350523c1b 100644
--- a/gcc/config/mips/mips-protos.h
+++ b/gcc/config/mips/mips-protos.h
@@ -388,8 +388,4 @@ extern void mips_register_frame_header_opt (void);
 extern void mips_expand_vec_cond_expr (machine_mode, machine_mode, rtx *);
 extern void mips_expand_vec_cmp_expr (rtx *);
 
-/* Routines implemented in mips-d.cc  */
-extern void mips_d_target_versions (void);
-extern void mips_d_register_target_info (void);
-
 #endif /* ! GCC_MIPS_PROTOS_H */
diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h
index 0029864fdcd..6230c4aaac5 100644
--- a/gcc/config/mips/mips.h
+++ b/gcc/config/mips/mips.h
@@ -680,10 +680,6 @@ struct mips_cpu_info {
     }									\
   while (0)
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS mips_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO mips_d_register_target_info
-
 /* Default target_flags if no switches are specified  */
 
 #ifndef TARGET_DEFAULT
diff --git a/gcc/config/netbsd-d.cc b/gcc/config/netbsd-d.cc
index 286f010939f..cd0c95568a1 100644
--- a/gcc/config/netbsd-d.cc
+++ b/gcc/config/netbsd-d.cc
@@ -20,9 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "tm.h"
-#include "memmodel.h"
-#include "tm_p.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/openbsd-d.cc b/gcc/config/openbsd-d.cc
index c1a2a89807a..33c7e41ab62 100644
--- a/gcc/config/openbsd-d.cc
+++ b/gcc/config/openbsd-d.cc
@@ -20,9 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "memmodel.h"
-#include "tm.h"
-#include "tm_p.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/pa/pa-d.cc b/gcc/config/pa/pa-d.cc
index 122ad480447..077aeb5d634 100644
--- a/gcc/config/pa/pa-d.cc
+++ b/gcc/config/pa/pa-d.cc
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "target.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/pa/pa-d.h b/gcc/config/pa/pa-d.h
new file mode 100644
index 00000000000..9a9df108f61
--- /dev/null
+++ b/gcc/config/pa/pa-d.h
@@ -0,0 +1,24 @@
+/* Definitions for the D front end on the HPPA architecture.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* Routines implemented in pa-d.cc  */
+extern void pa_d_target_versions (void);
+extern void pa_d_register_target_info (void);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS pa_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO pa_d_register_target_info
diff --git a/gcc/config/pa/pa-protos.h b/gcc/config/pa/pa-protos.h
index d474d9efc91..fe8b7a5091e 100644
--- a/gcc/config/pa/pa-protos.h
+++ b/gcc/config/pa/pa-protos.h
@@ -111,7 +111,3 @@ extern void pa_output_function_label (FILE *);
 extern void hppa_profile_hook (int);
 
 extern const int pa_magic_milli[];
-
-/* Routines implemented in pa-d.cc  */
-extern void pa_d_target_versions (void);
-extern void pa_d_register_target_info (void);
diff --git a/gcc/config/pa/pa.h b/gcc/config/pa/pa.h
index 92d3d1841a9..1ce6635ae9b 100644
--- a/gcc/config/pa/pa.h
+++ b/gcc/config/pa/pa.h
@@ -1310,9 +1310,5 @@ do {									     \
 
 #define NEED_INDICATE_EXEC_STACK 0
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS pa_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO pa_d_register_target_info
-
 /* Output default function prologue for hpux.  */
 #define TARGET_ASM_FUNCTION_PROLOGUE pa_output_function_prologue
diff --git a/gcc/config/riscv/riscv-d.cc b/gcc/config/riscv/riscv-d.cc
index 729de96d398..a762a35778d 100644
--- a/gcc/config/riscv/riscv-d.cc
+++ b/gcc/config/riscv/riscv-d.cc
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "target.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/riscv/riscv-d.h b/gcc/config/riscv/riscv-d.h
new file mode 100644
index 00000000000..21a989edd8c
--- /dev/null
+++ b/gcc/config/riscv/riscv-d.h
@@ -0,0 +1,24 @@
+/* Definitions for the D front end on the RISC-V architecture.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* Routines implemented in riscv-d.cc  */
+extern void riscv_d_target_versions (void);
+extern void riscv_d_register_target_info (void);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS riscv_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO riscv_d_register_target_info
diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index 2bc0ef06f93..649c5c977e1 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -78,10 +78,6 @@ extern bool riscv_gpr_save_operation_p (rtx);
 /* Routines implemented in riscv-c.cc.  */
 void riscv_cpu_cpp_builtins (cpp_reader *);
 
-/* Routines implemented in riscv-d.cc  */
-extern void riscv_d_target_versions (void);
-extern void riscv_d_register_target_info (void);
-
 /* Routines implemented in riscv-builtins.cc.  */
 extern void riscv_atomic_assign_expand_fenv (tree *, tree *, tree *);
 extern rtx riscv_expand_builtin (tree, rtx, rtx, machine_mode, int);
diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
index 1d8139c2c9b..ba3d38e3cef 100644
--- a/gcc/config/riscv/riscv.h
+++ b/gcc/config/riscv/riscv.h
@@ -27,10 +27,6 @@ along with GCC; see the file COPYING3.  If not see
 /* Target CPU builtins.  */
 #define TARGET_CPU_CPP_BUILTINS() riscv_cpu_cpp_builtins (pfile)
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS riscv_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO riscv_d_register_target_info
-
 #ifdef TARGET_BIG_ENDIAN_DEFAULT
 #define DEFAULT_ENDIAN_SPEC    "b"
 #else
diff --git a/gcc/config/rs6000/rs6000-d.cc b/gcc/config/rs6000/rs6000-d.cc
index 74e78cf9e4d..7b9ca5a855e 100644
--- a/gcc/config/rs6000/rs6000-d.cc
+++ b/gcc/config/rs6000/rs6000-d.cc
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/rs6000/rs6000-d.h b/gcc/config/rs6000/rs6000-d.h
new file mode 100644
index 00000000000..c805b304245
--- /dev/null
+++ b/gcc/config/rs6000/rs6000-d.h
@@ -0,0 +1,24 @@
+/* Definitions for the D front end on the PowerPC architecture.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* Declare functions in rs6000-d.cc  */
+extern void rs6000_d_target_versions (void);
+extern void rs6000_d_register_target_info (void);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS rs6000_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO rs6000_d_register_target_info
diff --git a/gcc/config/rs6000/rs6000-protos.h b/gcc/config/rs6000/rs6000-protos.h
index b3c16e7448d..1c0f97edcc2 100644
--- a/gcc/config/rs6000/rs6000-protos.h
+++ b/gcc/config/rs6000/rs6000-protos.h
@@ -323,10 +323,6 @@ extern void rs6000_activate_target_options (tree new_tree);
 extern void rs6000_target_modify_macros (bool, HOST_WIDE_INT);
 extern void (*rs6000_target_modify_macros_ptr) (bool, HOST_WIDE_INT);
 
-/* Declare functions in rs6000-d.cc  */
-extern void rs6000_d_target_versions (void);
-extern void rs6000_d_register_target_info (void);
-
 #ifdef NO_DOLLAR_IN_LABEL
 const char * rs6000_xcoff_strip_dollar (const char *);
 #endif
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index ad9bf0f7358..5f1d5e494da 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -606,10 +606,6 @@ extern unsigned char rs6000_recip_bits[];
 #define TARGET_CPU_CPP_BUILTINS() \
   rs6000_cpu_cpp_builtins (pfile)
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS rs6000_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO rs6000_d_register_target_info
-
 /* This is used by rs6000_cpu_cpp_builtins to indicate the byte order
    we're compiling for.  Some configurations may need to override it.  */
 #define RS6000_CPU_CPP_ENDIAN_BUILTINS()	\
diff --git a/gcc/config/s390/s390-d.cc b/gcc/config/s390/s390-d.cc
index 8e631859e67..0dd4b5c999b 100644
--- a/gcc/config/s390/s390-d.cc
+++ b/gcc/config/s390/s390-d.cc
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/s390/s390-d.h b/gcc/config/s390/s390-d.h
new file mode 100644
index 00000000000..703031b3c81
--- /dev/null
+++ b/gcc/config/s390/s390-d.h
@@ -0,0 +1,24 @@
+/* Definitions for the D front end on the IBM S/390 and zSeries architectures.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* s390-d.cc routines */
+extern void s390_d_target_versions (void);
+extern void s390_d_register_target_info (void);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS s390_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO s390_d_register_target_info
diff --git a/gcc/config/s390/s390-protos.h b/gcc/config/s390/s390-protos.h
index 765d843a418..78117c36e03 100644
--- a/gcc/config/s390/s390-protos.h
+++ b/gcc/config/s390/s390-protos.h
@@ -175,10 +175,6 @@ extern void s390_register_target_pragmas (void);
 /* Routines for s390-c.cc */
 extern bool s390_const_operand_ok (tree, int, int, tree);
 
-/* s390-d.cc routines */
-extern void s390_d_target_versions (void);
-extern void s390_d_register_target_info (void);
-
 /* Pass management.  */
 namespace gcc { class context; }
 class rtl_opt_pass;
diff --git a/gcc/config/s390/s390.h b/gcc/config/s390/s390.h
index 2e1bc71e73a..1114222cd4a 100644
--- a/gcc/config/s390/s390.h
+++ b/gcc/config/s390/s390.h
@@ -247,10 +247,6 @@ enum processor_flags
 /* Target CPU builtins.  */
 #define TARGET_CPU_CPP_BUILTINS() s390_cpu_cpp_builtins (pfile)
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS s390_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO s390_d_register_target_info
-
 #ifdef DEFAULT_TARGET_64BIT
 #define TARGET_DEFAULT     (MASK_64BIT | MASK_ZARCH | MASK_HARD_DFP	\
 			    | MASK_OPT_HTM | MASK_OPT_VX)
diff --git a/gcc/config/sol2-d.cc b/gcc/config/sol2-d.cc
index 9caa82e8490..0ace79d5aae 100644
--- a/gcc/config/sol2-d.cc
+++ b/gcc/config/sol2-d.cc
@@ -18,9 +18,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "tm.h"
-#include "memmodel.h"
-#include "tm_p.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/sparc/sparc-d.cc b/gcc/config/sparc/sparc-d.cc
index 1f3a9666b97..f8a3cf30f25 100644
--- a/gcc/config/sparc/sparc-d.cc
+++ b/gcc/config/sparc/sparc-d.cc
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/sparc/sparc-d.h b/gcc/config/sparc/sparc-d.h
new file mode 100644
index 00000000000..b9d8ccf15ab
--- /dev/null
+++ b/gcc/config/sparc/sparc-d.h
@@ -0,0 +1,24 @@
+/* Definitions for the D front end on the SPARC architecture.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* Routines implemented in sparc-d.cc  */
+extern void sparc_d_target_versions (void);
+extern void sparc_d_register_target_info (void);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS sparc_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO sparc_d_register_target_info
diff --git a/gcc/config/sparc/sparc-protos.h b/gcc/config/sparc/sparc-protos.h
index f9e1c74554d..4ddd00c81e1 100644
--- a/gcc/config/sparc/sparc-protos.h
+++ b/gcc/config/sparc/sparc-protos.h
@@ -112,8 +112,4 @@ unsigned int sparc_regmode_natural_size (machine_mode);
 
 extern rtl_opt_pass *make_pass_work_around_errata (gcc::context *);
 
-/* Routines implemented in sparc-d.cc  */
-extern void sparc_d_target_versions (void);
-extern void sparc_d_register_target_info (void);
-
 #endif /* __SPARC_PROTOS_H__ */
diff --git a/gcc/config/sparc/sparc.h b/gcc/config/sparc/sparc.h
index 2e17fca197a..91917c3eaad 100644
--- a/gcc/config/sparc/sparc.h
+++ b/gcc/config/sparc/sparc.h
@@ -27,10 +27,6 @@ along with GCC; see the file COPYING3.  If not see
 
 #define TARGET_CPU_CPP_BUILTINS() sparc_target_macros ()
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS sparc_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO sparc_d_register_target_info
-
 /* Specify this in a cover file to provide bi-architecture (32/64) support.  */
 /* #define SPARC_BI_ARCH */
 
diff --git a/gcc/configure b/gcc/configure
index 80498e68e36..e39bc35484b 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -13038,7 +13038,6 @@ fi
 
 tm_file="${tm_file} defaults.h"
 tm_p_file="${tm_p_file} tm-preds.h"
-tm_d_file="${tm_d_file} defaults.h"
 host_xm_file="auto-host.h ansidecl.h ${host_xm_file}"
 build_xm_file="${build_auto} ansidecl.h ${build_xm_file}"
 # We don't want ansidecl.h in target files, write code there in ISO/GNU C.
@@ -13433,13 +13432,9 @@ for f in $tm_p_file; do
 done
 
 tm_d_file_list=
-tm_d_include_list="options.h insn-constants.h"
+tm_d_include_list=
 for f in $tm_d_file; do
   case $f in
-    defaults.h )
-       tm_d_file_list="${tm_d_file_list} \$(srcdir)/$f"
-       tm_d_include_list="${tm_d_include_list} $f"
-       ;;
     * )
        tm_d_file_list="${tm_d_file_list} \$(srcdir)/config/$f"
        tm_d_include_list="${tm_d_include_list} config/$f"
@@ -19703,7 +19698,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19706 "configure"
+#line 19701 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19809,7 +19804,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19812 "configure"
+#line 19807 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 819b490d1b6..fe4e6dfcfb6 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -2122,7 +2122,6 @@ AC_SUBST(HAVE_AUTO_BUILD)
 
 tm_file="${tm_file} defaults.h"
 tm_p_file="${tm_p_file} tm-preds.h"
-tm_d_file="${tm_d_file} defaults.h"
 host_xm_file="auto-host.h ansidecl.h ${host_xm_file}"
 build_xm_file="${build_auto} ansidecl.h ${build_xm_file}"
 # We don't want ansidecl.h in target files, write code there in ISO/GNU C.
@@ -2366,13 +2365,9 @@ for f in $tm_p_file; do
 done
 
 tm_d_file_list=
-tm_d_include_list="options.h insn-constants.h"
+tm_d_include_list=
 for f in $tm_d_file; do
   case $f in
-    defaults.h )
-       tm_d_file_list="${tm_d_file_list} \$(srcdir)/$f"
-       tm_d_include_list="${tm_d_include_list} $f"
-       ;;
     * )
        tm_d_file_list="${tm_d_file_list} \$(srcdir)/config/$f"
        tm_d_include_list="${tm_d_include_list} config/$f"
Richard Biener Sept. 1, 2022, 6:28 a.m. UTC | #6
On Wed, Aug 31, 2022 at 9:21 PM Iain Buclaw <ibuclaw@gdcproject.org> wrote:
>
> Excerpts from Joseph Myers's message of August 31, 2022 7:16 pm:
> > On Wed, 31 Aug 2022, Iain Buclaw via Gcc-patches wrote:
> >
> >> Excerpts from Joseph Myers's message of August 30, 2022 11:53 pm:
> >> > On Fri, 26 Aug 2022, Richard Biener via Gcc-patches wrote:
> >> >
> >> >> I was hoping Joseph would chime in here - I recollect debugging this kind
> >> >> of thing and a thread about this a while back but unfortunately I do not
> >> >> remember the details here (IIRC some things get included where they
> >> >> better should not be).
> >> >
> >> > See <https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582563.html>.
> >> > Is there some reason it's problematic to avoid having defaults.h or
> >> > ${cpu_type}/${cpu_type}.h included in tm_d.h, and instead have tm_d.h only
> >> > include D-specific headers?
> >> >
> >>
> >> In targets such as arm-elf, we still need to pull in definitions from
> >> ${cpu_type}/${cpu_type}-d.cc into default-d.cc.
> >>
> >> All I can think that might suffice is having D-specific prototype
> >> headers in all targets as ${cpu_type}/${cpu_type}-d.h.
> >
> > As long as those prototypes don't involve any types that depend on an
> > inclusion of tm.h, that should be fine.
> >
>
> Updated patch that does what I described.

Ah yes - I think, even if a bit verbose, this is exactly how it was supposed
to be?

OK from my side.

Thanks,
Richard.

> Bootstrapped on x86_64-linux-gnu and built an aarch64-rtems
> cross-compiler without any errors, will kick off config-list.mk as well for
> sanity checking a big list of targets in a while.
>
> Iain.
> ---
>         PR d/105659
>
> gcc/ChangeLog:
>
>         * config.gcc: Set tm_d_file to ${cpu_type}/${cpu_type}-d.h.
>         * config/aarch64/aarch64-d.cc: Include tm_d.h.
>         * config/aarch64/aarch64-protos.h (aarch64_d_target_versions): Move to
>         config/aarch64/aarch64-d.h.
>         (aarch64_d_register_target_info): Likewise.
>         * config/aarch64/aarch64.h (TARGET_D_CPU_VERSIONS): Likewise.
>         (TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
>         * config/arm/arm-d.cc: Include tm_d.h instead of tm_p.h.
>         * config/arm/arm-protos.h (arm_d_target_versions): Move to
>         config/arm/arm-d.h.
>         (arm_d_register_target_info): Likewise.
>         * config/arm/arm.h (TARGET_D_CPU_VERSIONS): Likewise.
>         (TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
>         * config/default-d.cc: Remove memmodel.h include.
>         * config/freebsd-d.cc: Include tm_d.h instead of tm_p.h.
>         * config/glibc-d.cc: Likewise.
>         * config/i386/i386-d.cc: Include tm_d.h.
>         * config/i386/i386-protos.h (ix86_d_target_versions): Move to
>         config/i386/i386-d.h.
>         (ix86_d_register_target_info): Likewise.
>         (ix86_d_has_stdcall_convention): Likewise.
>         * config/i386/i386.h (TARGET_D_CPU_VERSIONS): Likewise.
>         (TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
>         (TARGET_D_HAS_STDCALL_CONVENTION): Likewise.
>         * config/i386/winnt-d.cc: Include tm_d.h instead of tm_p.h.
>         * config/mips/mips-d.cc: Include tm_d.h.
>         * config/mips/mips-protos.h (mips_d_target_versions): Move to
>         config/mips/mips-d.h.
>         (mips_d_register_target_info): Likewise.
>         * config/mips/mips.h (TARGET_D_CPU_VERSIONS): Likewise.
>         (TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
>         * config/netbsd-d.cc: Include tm_d.h instead of tm.h and memmodel.h.
>         * config/openbsd-d.cc: Likewise.
>         * config/pa/pa-d.cc: Include tm_d.h.
>         * config/pa/pa-protos.h (pa_d_target_versions): Move to
>         config/pa/pa-d.h.
>         (pa_d_register_target_info): Likewise.
>         * config/pa/pa.h (TARGET_D_CPU_VERSIONS): Likewise.
>         (TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
>         * config/riscv/riscv-d.cc: Include tm_d.h.
>         * config/riscv/riscv-protos.h (riscv_d_target_versions): Move to
>         config/riscv/riscv-d.h.
>         (riscv_d_register_target_info): Likewise.
>         * config/riscv/riscv.h (TARGET_D_CPU_VERSIONS): Likewise.
>         (TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
>         * config/rs6000/rs6000-d.cc: Include tm_d.h.
>         * config/rs6000/rs6000-protos.h (rs6000_d_target_versions): Move to
>         config/rs6000/rs6000-d.h.
>         (rs6000_d_register_target_info): Likewise.
>         * config/rs6000/rs6000.h (TARGET_D_CPU_VERSIONS) Likewise.:
>         (TARGET_D_REGISTER_CPU_TARGET_INFO) Likewise.:
>         * config/s390/s390-d.cc: Include tm_d.h.
>         * config/s390/s390-protos.h (s390_d_target_versions): Move to
>         config/s390/s390-d.h.
>         (s390_d_register_target_info): Likewise.
>         * config/s390/s390.h (TARGET_D_CPU_VERSIONS): Likewise.
>         (TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
>         * config/sol2-d.cc: Include tm_d.h instead of tm.h and memmodel.h.
>         * config/sparc/sparc-d.cc: Include tm_d.h.
>         * config/sparc/sparc-protos.h (sparc_d_target_versions): Move to
>         config/sparc/sparc-d.h.
>         (sparc_d_register_target_info): Likewise.
>         * config/sparc/sparc.h (TARGET_D_CPU_VERSIONS): Likewise.
>         (TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
>         * configure: Regenerate.
>         * configure.ac (tm_d_file): Remove defaults.h.
>         (tm_d_include_list): Remove options.h and insn-constants.h.
>         * config/aarch64/aarch64-d.h: New file.
>         * config/arm/arm-d.h: New file.
>         * config/i386/i386-d.h: New file.
>         * config/mips/mips-d.h: New file.
>         * config/pa/pa-d.h: New file.
>         * config/riscv/riscv-d.h: New file.
>         * config/rs6000/rs6000-d.h: New file.
>         * config/s390/s390-d.h: New file.
>         * config/sparc/sparc-d.h: New file.
> ---
>  gcc/config.gcc                      | 10 ++++++----
>  gcc/config/aarch64/aarch64-d.cc     |  1 +
>  gcc/config/aarch64/aarch64-d.h      | 24 ++++++++++++++++++++++++
>  gcc/config/aarch64/aarch64-protos.h |  4 ----
>  gcc/config/aarch64/aarch64.h        |  4 ----
>  gcc/config/arm/arm-d.cc             |  2 +-
>  gcc/config/arm/arm-d.h              | 24 ++++++++++++++++++++++++
>  gcc/config/arm/arm-protos.h         |  4 ----
>  gcc/config/arm/arm.h                |  4 ----
>  gcc/config/default-d.cc             |  1 -
>  gcc/config/freebsd-d.cc             |  2 +-
>  gcc/config/glibc-d.cc               |  2 +-
>  gcc/config/i386/i386-d.cc           |  1 +
>  gcc/config/i386/i386-d.h            | 26 ++++++++++++++++++++++++++
>  gcc/config/i386/i386-protos.h       |  5 -----
>  gcc/config/i386/i386.h              |  5 -----
>  gcc/config/i386/winnt-d.cc          |  2 +-
>  gcc/config/mips/mips-d.cc           |  1 +
>  gcc/config/mips/mips-d.h            | 24 ++++++++++++++++++++++++
>  gcc/config/mips/mips-protos.h       |  4 ----
>  gcc/config/mips/mips.h              |  4 ----
>  gcc/config/netbsd-d.cc              |  4 +---
>  gcc/config/openbsd-d.cc             |  4 +---
>  gcc/config/pa/pa-d.cc               |  1 +
>  gcc/config/pa/pa-d.h                | 24 ++++++++++++++++++++++++
>  gcc/config/pa/pa-protos.h           |  4 ----
>  gcc/config/pa/pa.h                  |  4 ----
>  gcc/config/riscv/riscv-d.cc         |  1 +
>  gcc/config/riscv/riscv-d.h          | 24 ++++++++++++++++++++++++
>  gcc/config/riscv/riscv-protos.h     |  4 ----
>  gcc/config/riscv/riscv.h            |  4 ----
>  gcc/config/rs6000/rs6000-d.cc       |  1 +
>  gcc/config/rs6000/rs6000-d.h        | 24 ++++++++++++++++++++++++
>  gcc/config/rs6000/rs6000-protos.h   |  4 ----
>  gcc/config/rs6000/rs6000.h          |  4 ----
>  gcc/config/s390/s390-d.cc           |  1 +
>  gcc/config/s390/s390-d.h            | 24 ++++++++++++++++++++++++
>  gcc/config/s390/s390-protos.h       |  4 ----
>  gcc/config/s390/s390.h              |  4 ----
>  gcc/config/sol2-d.cc                |  4 +---
>  gcc/config/sparc/sparc-d.cc         |  1 +
>  gcc/config/sparc/sparc-d.h          | 24 ++++++++++++++++++++++++
>  gcc/config/sparc/sparc-protos.h     |  4 ----
>  gcc/config/sparc/sparc.h            |  4 ----
>  gcc/configure                       | 11 +++--------
>  gcc/configure.ac                    |  7 +------
>  46 files changed, 243 insertions(+), 106 deletions(-)
>  create mode 100644 gcc/config/aarch64/aarch64-d.h
>  create mode 100644 gcc/config/arm/arm-d.h
>  create mode 100644 gcc/config/i386/i386-d.h
>  create mode 100644 gcc/config/mips/mips-d.h
>  create mode 100644 gcc/config/pa/pa-d.h
>  create mode 100644 gcc/config/riscv/riscv-d.h
>  create mode 100644 gcc/config/rs6000/rs6000-d.h
>  create mode 100644 gcc/config/s390/s390-d.h
>  create mode 100644 gcc/config/sparc/sparc-d.h
>
> diff --git a/gcc/config.gcc b/gcc/config.gcc
> index 11045084888..ce8e433d283 100644
> --- a/gcc/config.gcc
> +++ b/gcc/config.gcc
> @@ -557,11 +557,15 @@ xtensa*-*-*)
>  esac
>
>  tm_file=${cpu_type}/${cpu_type}.h
> -tm_d_file=${cpu_type}/${cpu_type}.h
>  if test -f ${srcdir}/config/${cpu_type}/${cpu_type}-protos.h
>  then
>         tm_p_file=${cpu_type}/${cpu_type}-protos.h
> -       tm_d_file="${tm_d_file} ${cpu_type}/${cpu_type}-protos.h"
> +fi
> +
> +tm_d_file=
> +if test -f ${srcdir}/config/${cpu_type}/${cpu_type}-d.h
> +then
> +       tm_d_file="${tm_d_file} ${cpu_type}/${cpu_type}-d.h"
>  fi
>
>  extra_modes=
> @@ -667,7 +671,6 @@ case ${target} in
>  *-*-darwin*)
>    tmake_file="t-darwin "
>    tm_file="${tm_file} darwin.h"
> -  tm_d_file="${tm_d_file} tm-dwarf2.h"
>    darwin_os=`echo ${target} | sed 's/.*darwin\([0-9.]*\).*$/\1/'`
>    darwin_maj=`expr "$darwin_os" : '\([0-9]*\).*'`
>    macos_min=`expr "$darwin_os" : '[0-9]*\.\([0-9]*\).*'`
> @@ -3524,7 +3527,6 @@ xstormy16-*-elf)
>         # For historical reasons, the target files omit the 'x'.
>         tm_file="dbxelf.h elfos.h newlib-stdint.h stormy16/stormy16.h"
>         tm_p_file=stormy16/stormy16-protos.h
> -       tm_d_file="elfos.h stormy16/stormy16.h"
>         md_file=stormy16/stormy16.md
>         out_file=stormy16/stormy16.cc
>         extra_options=stormy16/stormy16.opt
> diff --git a/gcc/config/aarch64/aarch64-d.cc b/gcc/config/aarch64/aarch64-d.cc
> index d3fcc0b881e..e0e0401631e 100644
> --- a/gcc/config/aarch64/aarch64-d.cc
> +++ b/gcc/config/aarch64/aarch64-d.cc
> @@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "config.h"
>  #include "system.h"
>  #include "coretypes.h"
> +#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
>
> diff --git a/gcc/config/aarch64/aarch64-d.h b/gcc/config/aarch64/aarch64-d.h
> new file mode 100644
> index 00000000000..c605a68ef9f
> --- /dev/null
> +++ b/gcc/config/aarch64/aarch64-d.h
> @@ -0,0 +1,24 @@
> +/* Definitions for the D front end on the AArch64 architecture.
> +   Copyright (C) 2022 Free Software Foundation, Inc.
> +
> +GCC is free software; you can redistribute it and/or modify
> +it under the terms of the GNU General Public License as published by
> +the Free Software Foundation; either version 3, or (at your option)
> +any later version.
> +
> +GCC is distributed in the hope that it will be useful,
> +but WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +GNU General Public License for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with GCC; see the file COPYING3.  If not see
> +<http://www.gnu.org/licenses/>.  */
> +
> +/* Defined in aarch64-d.cc  */
> +extern void aarch64_d_target_versions (void);
> +extern void aarch64_d_register_target_info (void);
> +
> +/* Target hooks for D language.  */
> +#define TARGET_D_CPU_VERSIONS aarch64_d_target_versions
> +#define TARGET_D_REGISTER_CPU_TARGET_INFO aarch64_d_register_target_info
> diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h
> index 19c9d3cb179..0bb4c9b0e28 100644
> --- a/gcc/config/aarch64/aarch64-protos.h
> +++ b/gcc/config/aarch64/aarch64-protos.h
> @@ -1040,10 +1040,6 @@ enum aarch64_parse_opt_result aarch64_parse_extension (const char *,
>  void aarch64_get_all_extension_candidates (auto_vec<const char *> *candidates);
>  std::string aarch64_get_extension_string_for_isa_flags (uint64_t, uint64_t);
>
> -/* Defined in aarch64-d.cc  */
> -extern void aarch64_d_target_versions (void);
> -extern void aarch64_d_register_target_info (void);
> -
>  rtl_opt_pass *make_pass_fma_steering (gcc::context *);
>  rtl_opt_pass *make_pass_track_speculation (gcc::context *);
>  rtl_opt_pass *make_pass_tag_collision_avoidance (gcc::context *);
> diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
> index 80cfe4b7407..e6855c64035 100644
> --- a/gcc/config/aarch64/aarch64.h
> +++ b/gcc/config/aarch64/aarch64.h
> @@ -26,10 +26,6 @@
>  #define TARGET_CPU_CPP_BUILTINS()      \
>    aarch64_cpu_cpp_builtins (pfile)
>
> -/* Target hooks for D language.  */
> -#define TARGET_D_CPU_VERSIONS aarch64_d_target_versions
> -#define TARGET_D_REGISTER_CPU_TARGET_INFO aarch64_d_register_target_info
> -
>
>
>  #define REGISTER_TARGET_PRAGMAS() aarch64_register_pragmas ()
> diff --git a/gcc/config/arm/arm-d.cc b/gcc/config/arm/arm-d.cc
> index d65b7524934..b03c6ffecf5 100644
> --- a/gcc/config/arm/arm-d.cc
> +++ b/gcc/config/arm/arm-d.cc
> @@ -21,7 +21,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "system.h"
>  #include "coretypes.h"
>  #include "tm.h"
> -#include "tm_p.h"
> +#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
>
> diff --git a/gcc/config/arm/arm-d.h b/gcc/config/arm/arm-d.h
> new file mode 100644
> index 00000000000..479a89bb120
> --- /dev/null
> +++ b/gcc/config/arm/arm-d.h
> @@ -0,0 +1,24 @@
> +/* Definitions for the D front end on the ARM architecture.
> +   Copyright (C) 2022 Free Software Foundation, Inc.
> +
> +GCC is free software; you can redistribute it and/or modify
> +it under the terms of the GNU General Public License as published by
> +the Free Software Foundation; either version 3, or (at your option)
> +any later version.
> +
> +GCC is distributed in the hope that it will be useful,
> +but WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +GNU General Public License for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with GCC; see the file COPYING3.  If not see
> +<http://www.gnu.org/licenses/>.  */
> +
> +/* Defined in arm-d.cc  */
> +extern void arm_d_target_versions (void);
> +extern void arm_d_register_target_info (void);
> +
> +/* Target hooks for D language.  */
> +#define TARGET_D_CPU_VERSIONS arm_d_target_versions
> +#define TARGET_D_REGISTER_CPU_TARGET_INFO arm_d_register_target_info
> diff --git a/gcc/config/arm/arm-protos.h b/gcc/config/arm/arm-protos.h
> index f8aabbdae37..ee226559bfb 100644
> --- a/gcc/config/arm/arm-protos.h
> +++ b/gcc/config/arm/arm-protos.h
> @@ -402,10 +402,6 @@ extern void arm_lang_object_attributes_init (void);
>  extern void arm_register_target_pragmas (void);
>  extern void arm_cpu_cpp_builtins (struct cpp_reader *);
>
> -/* Defined in arm-d.cc  */
> -extern void arm_d_target_versions (void);
> -extern void arm_d_register_target_info (void);
> -
>  extern bool arm_is_constant_pool_ref (rtx);
>
>  /* The bits in this mask specify which instruction scheduling options should
> diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
> index f479540812a..e15722b0be3 100644
> --- a/gcc/config/arm/arm.h
> +++ b/gcc/config/arm/arm.h
> @@ -47,10 +47,6 @@ extern char arm_arch_name[];
>  /* Target CPU builtins.  */
>  #define TARGET_CPU_CPP_BUILTINS() arm_cpu_cpp_builtins (pfile)
>
> -/* Target hooks for D language.  */
> -#define TARGET_D_CPU_VERSIONS arm_d_target_versions
> -#define TARGET_D_REGISTER_CPU_TARGET_INFO arm_d_register_target_info
> -
>  #include "config/arm/arm-opts.h"
>
>  /* The processor for which instructions should be scheduled.  */
> diff --git a/gcc/config/default-d.cc b/gcc/config/default-d.cc
> index 2d7abfcba96..ff722c5096d 100644
> --- a/gcc/config/default-d.cc
> +++ b/gcc/config/default-d.cc
> @@ -18,7 +18,6 @@ along with GCC; see the file COPYING3.  If not see
>  #include "config.h"
>  #include "system.h"
>  #include "coretypes.h"
> -#include "memmodel.h"
>  #include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
> diff --git a/gcc/config/freebsd-d.cc b/gcc/config/freebsd-d.cc
> index 9f0f5e7b6ee..189e4a69e78 100644
> --- a/gcc/config/freebsd-d.cc
> +++ b/gcc/config/freebsd-d.cc
> @@ -20,7 +20,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "coretypes.h"
>  #include "memmodel.h"
>  #include "tm.h"
> -#include "tm_p.h"
> +#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
>
> diff --git a/gcc/config/glibc-d.cc b/gcc/config/glibc-d.cc
> index f30af104db8..80ef27d19c6 100644
> --- a/gcc/config/glibc-d.cc
> +++ b/gcc/config/glibc-d.cc
> @@ -20,7 +20,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "coretypes.h"
>  #include "tm.h"
>  #include "memmodel.h"
> -#include "tm_p.h"
> +#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
>
> diff --git a/gcc/config/i386/i386-d.cc b/gcc/config/i386/i386-d.cc
> index a62339cae30..27e2b75fc25 100644
> --- a/gcc/config/i386/i386-d.cc
> +++ b/gcc/config/i386/i386-d.cc
> @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "system.h"
>  #include "coretypes.h"
>  #include "tm.h"
> +#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
>
> diff --git a/gcc/config/i386/i386-d.h b/gcc/config/i386/i386-d.h
> new file mode 100644
> index 00000000000..b9806889df9
> --- /dev/null
> +++ b/gcc/config/i386/i386-d.h
> @@ -0,0 +1,26 @@
> +/* Definitions for the D front end on the x86 architecture.
> +   Copyright (C) 2022 Free Software Foundation, Inc.
> +
> +GCC is free software; you can redistribute it and/or modify
> +it under the terms of the GNU General Public License as published by
> +the Free Software Foundation; either version 3, or (at your option)
> +any later version.
> +
> +GCC is distributed in the hope that it will be useful,
> +but WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +GNU General Public License for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with GCC; see the file COPYING3.  If not see
> +<http://www.gnu.org/licenses/>.  */
> +
> +/* In i386-d.cc  */
> +extern void ix86_d_target_versions (void);
> +extern void ix86_d_register_target_info (void);
> +extern bool ix86_d_has_stdcall_convention (unsigned int *, unsigned int *);
> +
> +/* Target hooks for D language.  */
> +#define TARGET_D_CPU_VERSIONS ix86_d_target_versions
> +#define TARGET_D_REGISTER_CPU_TARGET_INFO ix86_d_register_target_info
> +#define TARGET_D_HAS_STDCALL_CONVENTION ix86_d_has_stdcall_convention
> diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
> index e27c14ff783..3b94efefa65 100644
> --- a/gcc/config/i386/i386-protos.h
> +++ b/gcc/config/i386/i386-protos.h
> @@ -277,11 +277,6 @@ extern bool ix86_extract_perm_from_pool_constant (int*, rtx);
>  extern void ix86_target_macros (void);
>  extern void ix86_register_pragmas (void);
>
> -/* In i386-d.cc  */
> -extern void ix86_d_target_versions (void);
> -extern void ix86_d_register_target_info (void);
> -extern bool ix86_d_has_stdcall_convention (unsigned int *, unsigned int *);
> -
>  /* In winnt.cc  */
>  extern void i386_pe_unique_section (tree, int);
>  extern void i386_pe_declare_function_type (FILE *, const char *, int);
> diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
> index 0de5c77bc7d..716bacef5f9 100644
> --- a/gcc/config/i386/i386.h
> +++ b/gcc/config/i386/i386.h
> @@ -608,11 +608,6 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
>  /* Target Pragmas.  */
>  #define REGISTER_TARGET_PRAGMAS() ix86_register_pragmas ()
>
> -/* Target hooks for D language.  */
> -#define TARGET_D_CPU_VERSIONS ix86_d_target_versions
> -#define TARGET_D_REGISTER_CPU_TARGET_INFO ix86_d_register_target_info
> -#define TARGET_D_HAS_STDCALL_CONVENTION ix86_d_has_stdcall_convention
> -
>  #ifndef CC1_SPEC
>  #define CC1_SPEC "%(cc1_cpu) "
>  #endif
> diff --git a/gcc/config/i386/winnt-d.cc b/gcc/config/i386/winnt-d.cc
> index 3d990a12331..00c28c3964a 100644
> --- a/gcc/config/i386/winnt-d.cc
> +++ b/gcc/config/i386/winnt-d.cc
> @@ -21,9 +21,9 @@ along with GCC; see the file COPYING3.  If not see
>  #include "system.h"
>  #include "coretypes.h"
>  #include "target.h"
> +#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
> -#include "tm_p.h"
>
>  /* Implement TARGET_D_OS_VERSIONS for Windows targets.  */
>
> diff --git a/gcc/config/mips/mips-d.cc b/gcc/config/mips/mips-d.cc
> index 41a278a08fd..8b6ccd10604 100644
> --- a/gcc/config/mips/mips-d.cc
> +++ b/gcc/config/mips/mips-d.cc
> @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "system.h"
>  #include "coretypes.h"
>  #include "tm.h"
> +#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
>
> diff --git a/gcc/config/mips/mips-d.h b/gcc/config/mips/mips-d.h
> new file mode 100644
> index 00000000000..7cb3ed9716e
> --- /dev/null
> +++ b/gcc/config/mips/mips-d.h
> @@ -0,0 +1,24 @@
> +/* Definitions for the D front end on the MIPS architecture.
> +   Copyright (C) 2022 Free Software Foundation, Inc.
> +
> +GCC is free software; you can redistribute it and/or modify
> +it under the terms of the GNU General Public License as published by
> +the Free Software Foundation; either version 3, or (at your option)
> +any later version.
> +
> +GCC is distributed in the hope that it will be useful,
> +but WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +GNU General Public License for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with GCC; see the file COPYING3.  If not see
> +<http://www.gnu.org/licenses/>.  */
> +
> +/* Routines implemented in mips-d.cc  */
> +extern void mips_d_target_versions (void);
> +extern void mips_d_register_target_info (void);
> +
> +/* Target hooks for D language.  */
> +#define TARGET_D_CPU_VERSIONS mips_d_target_versions
> +#define TARGET_D_REGISTER_CPU_TARGET_INFO mips_d_register_target_info
> diff --git a/gcc/config/mips/mips-protos.h b/gcc/config/mips/mips-protos.h
> index 9d0f4d90fd9..86350523c1b 100644
> --- a/gcc/config/mips/mips-protos.h
> +++ b/gcc/config/mips/mips-protos.h
> @@ -388,8 +388,4 @@ extern void mips_register_frame_header_opt (void);
>  extern void mips_expand_vec_cond_expr (machine_mode, machine_mode, rtx *);
>  extern void mips_expand_vec_cmp_expr (rtx *);
>
> -/* Routines implemented in mips-d.cc  */
> -extern void mips_d_target_versions (void);
> -extern void mips_d_register_target_info (void);
> -
>  #endif /* ! GCC_MIPS_PROTOS_H */
> diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h
> index 0029864fdcd..6230c4aaac5 100644
> --- a/gcc/config/mips/mips.h
> +++ b/gcc/config/mips/mips.h
> @@ -680,10 +680,6 @@ struct mips_cpu_info {
>      }                                                                  \
>    while (0)
>
> -/* Target hooks for D language.  */
> -#define TARGET_D_CPU_VERSIONS mips_d_target_versions
> -#define TARGET_D_REGISTER_CPU_TARGET_INFO mips_d_register_target_info
> -
>  /* Default target_flags if no switches are specified  */
>
>  #ifndef TARGET_DEFAULT
> diff --git a/gcc/config/netbsd-d.cc b/gcc/config/netbsd-d.cc
> index 286f010939f..cd0c95568a1 100644
> --- a/gcc/config/netbsd-d.cc
> +++ b/gcc/config/netbsd-d.cc
> @@ -20,9 +20,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "config.h"
>  #include "system.h"
>  #include "coretypes.h"
> -#include "tm.h"
> -#include "memmodel.h"
> -#include "tm_p.h"
> +#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
>
> diff --git a/gcc/config/openbsd-d.cc b/gcc/config/openbsd-d.cc
> index c1a2a89807a..33c7e41ab62 100644
> --- a/gcc/config/openbsd-d.cc
> +++ b/gcc/config/openbsd-d.cc
> @@ -20,9 +20,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "config.h"
>  #include "system.h"
>  #include "coretypes.h"
> -#include "memmodel.h"
> -#include "tm.h"
> -#include "tm_p.h"
> +#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
>
> diff --git a/gcc/config/pa/pa-d.cc b/gcc/config/pa/pa-d.cc
> index 122ad480447..077aeb5d634 100644
> --- a/gcc/config/pa/pa-d.cc
> +++ b/gcc/config/pa/pa-d.cc
> @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "system.h"
>  #include "coretypes.h"
>  #include "target.h"
> +#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
>
> diff --git a/gcc/config/pa/pa-d.h b/gcc/config/pa/pa-d.h
> new file mode 100644
> index 00000000000..9a9df108f61
> --- /dev/null
> +++ b/gcc/config/pa/pa-d.h
> @@ -0,0 +1,24 @@
> +/* Definitions for the D front end on the HPPA architecture.
> +   Copyright (C) 2022 Free Software Foundation, Inc.
> +
> +GCC is free software; you can redistribute it and/or modify
> +it under the terms of the GNU General Public License as published by
> +the Free Software Foundation; either version 3, or (at your option)
> +any later version.
> +
> +GCC is distributed in the hope that it will be useful,
> +but WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +GNU General Public License for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with GCC; see the file COPYING3.  If not see
> +<http://www.gnu.org/licenses/>.  */
> +
> +/* Routines implemented in pa-d.cc  */
> +extern void pa_d_target_versions (void);
> +extern void pa_d_register_target_info (void);
> +
> +/* Target hooks for D language.  */
> +#define TARGET_D_CPU_VERSIONS pa_d_target_versions
> +#define TARGET_D_REGISTER_CPU_TARGET_INFO pa_d_register_target_info
> diff --git a/gcc/config/pa/pa-protos.h b/gcc/config/pa/pa-protos.h
> index d474d9efc91..fe8b7a5091e 100644
> --- a/gcc/config/pa/pa-protos.h
> +++ b/gcc/config/pa/pa-protos.h
> @@ -111,7 +111,3 @@ extern void pa_output_function_label (FILE *);
>  extern void hppa_profile_hook (int);
>
>  extern const int pa_magic_milli[];
> -
> -/* Routines implemented in pa-d.cc  */
> -extern void pa_d_target_versions (void);
> -extern void pa_d_register_target_info (void);
> diff --git a/gcc/config/pa/pa.h b/gcc/config/pa/pa.h
> index 92d3d1841a9..1ce6635ae9b 100644
> --- a/gcc/config/pa/pa.h
> +++ b/gcc/config/pa/pa.h
> @@ -1310,9 +1310,5 @@ do {                                                                           \
>
>  #define NEED_INDICATE_EXEC_STACK 0
>
> -/* Target hooks for D language.  */
> -#define TARGET_D_CPU_VERSIONS pa_d_target_versions
> -#define TARGET_D_REGISTER_CPU_TARGET_INFO pa_d_register_target_info
> -
>  /* Output default function prologue for hpux.  */
>  #define TARGET_ASM_FUNCTION_PROLOGUE pa_output_function_prologue
> diff --git a/gcc/config/riscv/riscv-d.cc b/gcc/config/riscv/riscv-d.cc
> index 729de96d398..a762a35778d 100644
> --- a/gcc/config/riscv/riscv-d.cc
> +++ b/gcc/config/riscv/riscv-d.cc
> @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "system.h"
>  #include "coretypes.h"
>  #include "target.h"
> +#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
>
> diff --git a/gcc/config/riscv/riscv-d.h b/gcc/config/riscv/riscv-d.h
> new file mode 100644
> index 00000000000..21a989edd8c
> --- /dev/null
> +++ b/gcc/config/riscv/riscv-d.h
> @@ -0,0 +1,24 @@
> +/* Definitions for the D front end on the RISC-V architecture.
> +   Copyright (C) 2022 Free Software Foundation, Inc.
> +
> +GCC is free software; you can redistribute it and/or modify
> +it under the terms of the GNU General Public License as published by
> +the Free Software Foundation; either version 3, or (at your option)
> +any later version.
> +
> +GCC is distributed in the hope that it will be useful,
> +but WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +GNU General Public License for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with GCC; see the file COPYING3.  If not see
> +<http://www.gnu.org/licenses/>.  */
> +
> +/* Routines implemented in riscv-d.cc  */
> +extern void riscv_d_target_versions (void);
> +extern void riscv_d_register_target_info (void);
> +
> +/* Target hooks for D language.  */
> +#define TARGET_D_CPU_VERSIONS riscv_d_target_versions
> +#define TARGET_D_REGISTER_CPU_TARGET_INFO riscv_d_register_target_info
> diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
> index 2bc0ef06f93..649c5c977e1 100644
> --- a/gcc/config/riscv/riscv-protos.h
> +++ b/gcc/config/riscv/riscv-protos.h
> @@ -78,10 +78,6 @@ extern bool riscv_gpr_save_operation_p (rtx);
>  /* Routines implemented in riscv-c.cc.  */
>  void riscv_cpu_cpp_builtins (cpp_reader *);
>
> -/* Routines implemented in riscv-d.cc  */
> -extern void riscv_d_target_versions (void);
> -extern void riscv_d_register_target_info (void);
> -
>  /* Routines implemented in riscv-builtins.cc.  */
>  extern void riscv_atomic_assign_expand_fenv (tree *, tree *, tree *);
>  extern rtx riscv_expand_builtin (tree, rtx, rtx, machine_mode, int);
> diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
> index 1d8139c2c9b..ba3d38e3cef 100644
> --- a/gcc/config/riscv/riscv.h
> +++ b/gcc/config/riscv/riscv.h
> @@ -27,10 +27,6 @@ along with GCC; see the file COPYING3.  If not see
>  /* Target CPU builtins.  */
>  #define TARGET_CPU_CPP_BUILTINS() riscv_cpu_cpp_builtins (pfile)
>
> -/* Target hooks for D language.  */
> -#define TARGET_D_CPU_VERSIONS riscv_d_target_versions
> -#define TARGET_D_REGISTER_CPU_TARGET_INFO riscv_d_register_target_info
> -
>  #ifdef TARGET_BIG_ENDIAN_DEFAULT
>  #define DEFAULT_ENDIAN_SPEC    "b"
>  #else
> diff --git a/gcc/config/rs6000/rs6000-d.cc b/gcc/config/rs6000/rs6000-d.cc
> index 74e78cf9e4d..7b9ca5a855e 100644
> --- a/gcc/config/rs6000/rs6000-d.cc
> +++ b/gcc/config/rs6000/rs6000-d.cc
> @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "system.h"
>  #include "coretypes.h"
>  #include "tm.h"
> +#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
>
> diff --git a/gcc/config/rs6000/rs6000-d.h b/gcc/config/rs6000/rs6000-d.h
> new file mode 100644
> index 00000000000..c805b304245
> --- /dev/null
> +++ b/gcc/config/rs6000/rs6000-d.h
> @@ -0,0 +1,24 @@
> +/* Definitions for the D front end on the PowerPC architecture.
> +   Copyright (C) 2022 Free Software Foundation, Inc.
> +
> +GCC is free software; you can redistribute it and/or modify
> +it under the terms of the GNU General Public License as published by
> +the Free Software Foundation; either version 3, or (at your option)
> +any later version.
> +
> +GCC is distributed in the hope that it will be useful,
> +but WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +GNU General Public License for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with GCC; see the file COPYING3.  If not see
> +<http://www.gnu.org/licenses/>.  */
> +
> +/* Declare functions in rs6000-d.cc  */
> +extern void rs6000_d_target_versions (void);
> +extern void rs6000_d_register_target_info (void);
> +
> +/* Target hooks for D language.  */
> +#define TARGET_D_CPU_VERSIONS rs6000_d_target_versions
> +#define TARGET_D_REGISTER_CPU_TARGET_INFO rs6000_d_register_target_info
> diff --git a/gcc/config/rs6000/rs6000-protos.h b/gcc/config/rs6000/rs6000-protos.h
> index b3c16e7448d..1c0f97edcc2 100644
> --- a/gcc/config/rs6000/rs6000-protos.h
> +++ b/gcc/config/rs6000/rs6000-protos.h
> @@ -323,10 +323,6 @@ extern void rs6000_activate_target_options (tree new_tree);
>  extern void rs6000_target_modify_macros (bool, HOST_WIDE_INT);
>  extern void (*rs6000_target_modify_macros_ptr) (bool, HOST_WIDE_INT);
>
> -/* Declare functions in rs6000-d.cc  */
> -extern void rs6000_d_target_versions (void);
> -extern void rs6000_d_register_target_info (void);
> -
>  #ifdef NO_DOLLAR_IN_LABEL
>  const char * rs6000_xcoff_strip_dollar (const char *);
>  #endif
> diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
> index ad9bf0f7358..5f1d5e494da 100644
> --- a/gcc/config/rs6000/rs6000.h
> +++ b/gcc/config/rs6000/rs6000.h
> @@ -606,10 +606,6 @@ extern unsigned char rs6000_recip_bits[];
>  #define TARGET_CPU_CPP_BUILTINS() \
>    rs6000_cpu_cpp_builtins (pfile)
>
> -/* Target hooks for D language.  */
> -#define TARGET_D_CPU_VERSIONS rs6000_d_target_versions
> -#define TARGET_D_REGISTER_CPU_TARGET_INFO rs6000_d_register_target_info
> -
>  /* This is used by rs6000_cpu_cpp_builtins to indicate the byte order
>     we're compiling for.  Some configurations may need to override it.  */
>  #define RS6000_CPU_CPP_ENDIAN_BUILTINS()       \
> diff --git a/gcc/config/s390/s390-d.cc b/gcc/config/s390/s390-d.cc
> index 8e631859e67..0dd4b5c999b 100644
> --- a/gcc/config/s390/s390-d.cc
> +++ b/gcc/config/s390/s390-d.cc
> @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "system.h"
>  #include "coretypes.h"
>  #include "tm.h"
> +#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
>
> diff --git a/gcc/config/s390/s390-d.h b/gcc/config/s390/s390-d.h
> new file mode 100644
> index 00000000000..703031b3c81
> --- /dev/null
> +++ b/gcc/config/s390/s390-d.h
> @@ -0,0 +1,24 @@
> +/* Definitions for the D front end on the IBM S/390 and zSeries architectures.
> +   Copyright (C) 2022 Free Software Foundation, Inc.
> +
> +GCC is free software; you can redistribute it and/or modify
> +it under the terms of the GNU General Public License as published by
> +the Free Software Foundation; either version 3, or (at your option)
> +any later version.
> +
> +GCC is distributed in the hope that it will be useful,
> +but WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +GNU General Public License for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with GCC; see the file COPYING3.  If not see
> +<http://www.gnu.org/licenses/>.  */
> +
> +/* s390-d.cc routines */
> +extern void s390_d_target_versions (void);
> +extern void s390_d_register_target_info (void);
> +
> +/* Target hooks for D language.  */
> +#define TARGET_D_CPU_VERSIONS s390_d_target_versions
> +#define TARGET_D_REGISTER_CPU_TARGET_INFO s390_d_register_target_info
> diff --git a/gcc/config/s390/s390-protos.h b/gcc/config/s390/s390-protos.h
> index 765d843a418..78117c36e03 100644
> --- a/gcc/config/s390/s390-protos.h
> +++ b/gcc/config/s390/s390-protos.h
> @@ -175,10 +175,6 @@ extern void s390_register_target_pragmas (void);
>  /* Routines for s390-c.cc */
>  extern bool s390_const_operand_ok (tree, int, int, tree);
>
> -/* s390-d.cc routines */
> -extern void s390_d_target_versions (void);
> -extern void s390_d_register_target_info (void);
> -
>  /* Pass management.  */
>  namespace gcc { class context; }
>  class rtl_opt_pass;
> diff --git a/gcc/config/s390/s390.h b/gcc/config/s390/s390.h
> index 2e1bc71e73a..1114222cd4a 100644
> --- a/gcc/config/s390/s390.h
> +++ b/gcc/config/s390/s390.h
> @@ -247,10 +247,6 @@ enum processor_flags
>  /* Target CPU builtins.  */
>  #define TARGET_CPU_CPP_BUILTINS() s390_cpu_cpp_builtins (pfile)
>
> -/* Target hooks for D language.  */
> -#define TARGET_D_CPU_VERSIONS s390_d_target_versions
> -#define TARGET_D_REGISTER_CPU_TARGET_INFO s390_d_register_target_info
> -
>  #ifdef DEFAULT_TARGET_64BIT
>  #define TARGET_DEFAULT     (MASK_64BIT | MASK_ZARCH | MASK_HARD_DFP    \
>                             | MASK_OPT_HTM | MASK_OPT_VX)
> diff --git a/gcc/config/sol2-d.cc b/gcc/config/sol2-d.cc
> index 9caa82e8490..0ace79d5aae 100644
> --- a/gcc/config/sol2-d.cc
> +++ b/gcc/config/sol2-d.cc
> @@ -18,9 +18,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "config.h"
>  #include "system.h"
>  #include "coretypes.h"
> -#include "tm.h"
> -#include "memmodel.h"
> -#include "tm_p.h"
> +#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
>
> diff --git a/gcc/config/sparc/sparc-d.cc b/gcc/config/sparc/sparc-d.cc
> index 1f3a9666b97..f8a3cf30f25 100644
> --- a/gcc/config/sparc/sparc-d.cc
> +++ b/gcc/config/sparc/sparc-d.cc
> @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "system.h"
>  #include "coretypes.h"
>  #include "tm.h"
> +#include "tm_d.h"
>  #include "d/d-target.h"
>  #include "d/d-target-def.h"
>
> diff --git a/gcc/config/sparc/sparc-d.h b/gcc/config/sparc/sparc-d.h
> new file mode 100644
> index 00000000000..b9d8ccf15ab
> --- /dev/null
> +++ b/gcc/config/sparc/sparc-d.h
> @@ -0,0 +1,24 @@
> +/* Definitions for the D front end on the SPARC architecture.
> +   Copyright (C) 2022 Free Software Foundation, Inc.
> +
> +GCC is free software; you can redistribute it and/or modify
> +it under the terms of the GNU General Public License as published by
> +the Free Software Foundation; either version 3, or (at your option)
> +any later version.
> +
> +GCC is distributed in the hope that it will be useful,
> +but WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +GNU General Public License for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with GCC; see the file COPYING3.  If not see
> +<http://www.gnu.org/licenses/>.  */
> +
> +/* Routines implemented in sparc-d.cc  */
> +extern void sparc_d_target_versions (void);
> +extern void sparc_d_register_target_info (void);
> +
> +/* Target hooks for D language.  */
> +#define TARGET_D_CPU_VERSIONS sparc_d_target_versions
> +#define TARGET_D_REGISTER_CPU_TARGET_INFO sparc_d_register_target_info
> diff --git a/gcc/config/sparc/sparc-protos.h b/gcc/config/sparc/sparc-protos.h
> index f9e1c74554d..4ddd00c81e1 100644
> --- a/gcc/config/sparc/sparc-protos.h
> +++ b/gcc/config/sparc/sparc-protos.h
> @@ -112,8 +112,4 @@ unsigned int sparc_regmode_natural_size (machine_mode);
>
>  extern rtl_opt_pass *make_pass_work_around_errata (gcc::context *);
>
> -/* Routines implemented in sparc-d.cc  */
> -extern void sparc_d_target_versions (void);
> -extern void sparc_d_register_target_info (void);
> -
>  #endif /* __SPARC_PROTOS_H__ */
> diff --git a/gcc/config/sparc/sparc.h b/gcc/config/sparc/sparc.h
> index 2e17fca197a..91917c3eaad 100644
> --- a/gcc/config/sparc/sparc.h
> +++ b/gcc/config/sparc/sparc.h
> @@ -27,10 +27,6 @@ along with GCC; see the file COPYING3.  If not see
>
>  #define TARGET_CPU_CPP_BUILTINS() sparc_target_macros ()
>
> -/* Target hooks for D language.  */
> -#define TARGET_D_CPU_VERSIONS sparc_d_target_versions
> -#define TARGET_D_REGISTER_CPU_TARGET_INFO sparc_d_register_target_info
> -
>  /* Specify this in a cover file to provide bi-architecture (32/64) support.  */
>  /* #define SPARC_BI_ARCH */
>
> diff --git a/gcc/configure b/gcc/configure
> index 80498e68e36..e39bc35484b 100755
> --- a/gcc/configure
> +++ b/gcc/configure
> @@ -13038,7 +13038,6 @@ fi
>
>  tm_file="${tm_file} defaults.h"
>  tm_p_file="${tm_p_file} tm-preds.h"
> -tm_d_file="${tm_d_file} defaults.h"
>  host_xm_file="auto-host.h ansidecl.h ${host_xm_file}"
>  build_xm_file="${build_auto} ansidecl.h ${build_xm_file}"
>  # We don't want ansidecl.h in target files, write code there in ISO/GNU C.
> @@ -13433,13 +13432,9 @@ for f in $tm_p_file; do
>  done
>
>  tm_d_file_list=
> -tm_d_include_list="options.h insn-constants.h"
> +tm_d_include_list=
>  for f in $tm_d_file; do
>    case $f in
> -    defaults.h )
> -       tm_d_file_list="${tm_d_file_list} \$(srcdir)/$f"
> -       tm_d_include_list="${tm_d_include_list} $f"
> -       ;;
>      * )
>         tm_d_file_list="${tm_d_file_list} \$(srcdir)/config/$f"
>         tm_d_include_list="${tm_d_include_list} config/$f"
> @@ -19703,7 +19698,7 @@ else
>    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
>    lt_status=$lt_dlunknown
>    cat > conftest.$ac_ext <<_LT_EOF
> -#line 19706 "configure"
> +#line 19701 "configure"
>  #include "confdefs.h"
>
>  #if HAVE_DLFCN_H
> @@ -19809,7 +19804,7 @@ else
>    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
>    lt_status=$lt_dlunknown
>    cat > conftest.$ac_ext <<_LT_EOF
> -#line 19812 "configure"
> +#line 19807 "configure"
>  #include "confdefs.h"
>
>  #if HAVE_DLFCN_H
> diff --git a/gcc/configure.ac b/gcc/configure.ac
> index 819b490d1b6..fe4e6dfcfb6 100644
> --- a/gcc/configure.ac
> +++ b/gcc/configure.ac
> @@ -2122,7 +2122,6 @@ AC_SUBST(HAVE_AUTO_BUILD)
>
>  tm_file="${tm_file} defaults.h"
>  tm_p_file="${tm_p_file} tm-preds.h"
> -tm_d_file="${tm_d_file} defaults.h"
>  host_xm_file="auto-host.h ansidecl.h ${host_xm_file}"
>  build_xm_file="${build_auto} ansidecl.h ${build_xm_file}"
>  # We don't want ansidecl.h in target files, write code there in ISO/GNU C.
> @@ -2366,13 +2365,9 @@ for f in $tm_p_file; do
>  done
>
>  tm_d_file_list=
> -tm_d_include_list="options.h insn-constants.h"
> +tm_d_include_list=
>  for f in $tm_d_file; do
>    case $f in
> -    defaults.h )
> -       tm_d_file_list="${tm_d_file_list} \$(srcdir)/$f"
> -       tm_d_include_list="${tm_d_include_list} $f"
> -       ;;
>      * )
>         tm_d_file_list="${tm_d_file_list} \$(srcdir)/config/$f"
>         tm_d_include_list="${tm_d_include_list} config/$f"
> --
> 2.34.1
>
Iain Buclaw Sept. 2, 2022, 4:05 p.m. UTC | #7
Excerpts from Richard Biener's message of September 1, 2022 8:28 am:
> On Wed, Aug 31, 2022 at 9:21 PM Iain Buclaw <ibuclaw@gdcproject.org> wrote:
>>
>> Excerpts from Joseph Myers's message of August 31, 2022 7:16 pm:
>> > On Wed, 31 Aug 2022, Iain Buclaw via Gcc-patches wrote:
>> >
>> >> Excerpts from Joseph Myers's message of August 30, 2022 11:53 pm:
>> >> > On Fri, 26 Aug 2022, Richard Biener via Gcc-patches wrote:
>> >> >
>> >> >> I was hoping Joseph would chime in here - I recollect debugging this kind
>> >> >> of thing and a thread about this a while back but unfortunately I do not
>> >> >> remember the details here (IIRC some things get included where they
>> >> >> better should not be).
>> >> >
>> >> > See <https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582563.html>.
>> >> > Is there some reason it's problematic to avoid having defaults.h or
>> >> > ${cpu_type}/${cpu_type}.h included in tm_d.h, and instead have tm_d.h only
>> >> > include D-specific headers?
>> >> >
>> >>
>> >> In targets such as arm-elf, we still need to pull in definitions from
>> >> ${cpu_type}/${cpu_type}-d.cc into default-d.cc.
>> >>
>> >> All I can think that might suffice is having D-specific prototype
>> >> headers in all targets as ${cpu_type}/${cpu_type}-d.h.
>> >
>> > As long as those prototypes don't involve any types that depend on an
>> > inclusion of tm.h, that should be fine.
>> >
>>
>> Updated patch that does what I described.
> 
> Ah yes - I think, even if a bit verbose, this is exactly how it was supposed
> to be?
> 
> OK from my side.
> 

To access the TARGET macros from arm-d.cc, arm-protos.h had to be
included (after tm_p.h was removed).

All ~200 configurations in contrib/config-list.mk now build again with
the D front-end enabled.

Regards,
Iain.

---

gcc/ChangeLog:

	* config.gcc: Set tm_d_file to ${cpu_type}/${cpu_type}-d.h.
	* config/aarch64/aarch64-d.cc: Include tm_d.h.
	* config/aarch64/aarch64-protos.h (aarch64_d_target_versions): Move to
	config/aarch64/aarch64-d.h.
	(aarch64_d_register_target_info): Likewise.
	* config/aarch64/aarch64.h (TARGET_D_CPU_VERSIONS): Likewise.
	(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
	* config/arm/arm-d.cc: Include tm_d.h and arm-protos.h instead of
	tm_p.h.
	* config/arm/arm-protos.h (arm_d_target_versions): Move to
	config/arm/arm-d.h.
	(arm_d_register_target_info): Likewise.
	* config/arm/arm.h (TARGET_D_CPU_VERSIONS): Likewise.
	(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
	* config/default-d.cc: Remove memmodel.h include.
	* config/freebsd-d.cc: Include tm_d.h instead of tm_p.h.
	* config/glibc-d.cc: Likewise.
	* config/i386/i386-d.cc: Include tm_d.h.
	* config/i386/i386-protos.h (ix86_d_target_versions): Move to
	config/i386/i386-d.h.
	(ix86_d_register_target_info): Likewise.
	(ix86_d_has_stdcall_convention): Likewise.
	* config/i386/i386.h (TARGET_D_CPU_VERSIONS): Likewise.
	(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
	(TARGET_D_HAS_STDCALL_CONVENTION): Likewise.
	* config/i386/winnt-d.cc: Include tm_d.h instead of tm_p.h.
	* config/mips/mips-d.cc: Include tm_d.h.
	* config/mips/mips-protos.h (mips_d_target_versions): Move to
	config/mips/mips-d.h.
	(mips_d_register_target_info): Likewise.
	* config/mips/mips.h (TARGET_D_CPU_VERSIONS): Likewise.
	(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
	* config/netbsd-d.cc: Include tm_d.h instead of tm.h and memmodel.h.
	* config/openbsd-d.cc: Likewise.
	* config/pa/pa-d.cc: Include tm_d.h.
	* config/pa/pa-protos.h (pa_d_target_versions): Move to
	config/pa/pa-d.h.
	(pa_d_register_target_info): Likewise.
	* config/pa/pa.h (TARGET_D_CPU_VERSIONS): Likewise.
	(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
	* config/riscv/riscv-d.cc: Include tm_d.h.
	* config/riscv/riscv-protos.h (riscv_d_target_versions): Move to
	config/riscv/riscv-d.h.
	(riscv_d_register_target_info): Likewise.
	* config/riscv/riscv.h (TARGET_D_CPU_VERSIONS): Likewise.
	(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
	* config/rs6000/rs6000-d.cc: Include tm_d.h.
	* config/rs6000/rs6000-protos.h (rs6000_d_target_versions): Move to
	config/rs6000/rs6000-d.h.
	(rs6000_d_register_target_info): Likewise.
	* config/rs6000/rs6000.h (TARGET_D_CPU_VERSIONS) Likewise.:
	(TARGET_D_REGISTER_CPU_TARGET_INFO) Likewise.:
	* config/s390/s390-d.cc: Include tm_d.h.
	* config/s390/s390-protos.h (s390_d_target_versions): Move to
	config/s390/s390-d.h.
	(s390_d_register_target_info): Likewise.
	* config/s390/s390.h (TARGET_D_CPU_VERSIONS): Likewise.
	(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
	* config/sol2-d.cc: Include tm_d.h instead of tm.h and memmodel.h.
	* config/sparc/sparc-d.cc: Include tm_d.h.
	* config/sparc/sparc-protos.h (sparc_d_target_versions): Move to
	config/sparc/sparc-d.h.
	(sparc_d_register_target_info): Likewise.
	* config/sparc/sparc.h (TARGET_D_CPU_VERSIONS): Likewise.
	(TARGET_D_REGISTER_CPU_TARGET_INFO): Likewise.
	* configure: Regenerate.
	* configure.ac (tm_d_file): Remove defaults.h.
	(tm_d_include_list): Remove options.h and insn-constants.h.
	* config/aarch64/aarch64-d.h: New file.
	* config/arm/arm-d.h: New file.
	* config/i386/i386-d.h: New file.
	* config/mips/mips-d.h: New file.
	* config/pa/pa-d.h: New file.
	* config/riscv/riscv-d.h: New file.
	* config/rs6000/rs6000-d.h: New file.
	* config/s390/s390-d.h: New file.
	* config/sparc/sparc-d.h: New file.
---
 gcc/config.gcc                      | 10 ++++++----
 gcc/config/aarch64/aarch64-d.cc     |  1 +
 gcc/config/aarch64/aarch64-d.h      | 24 ++++++++++++++++++++++++
 gcc/config/aarch64/aarch64-protos.h |  4 ----
 gcc/config/aarch64/aarch64.h        |  4 ----
 gcc/config/arm/arm-d.cc             |  3 ++-
 gcc/config/arm/arm-d.h              | 24 ++++++++++++++++++++++++
 gcc/config/arm/arm-protos.h         |  4 ----
 gcc/config/arm/arm.h                |  4 ----
 gcc/config/default-d.cc             |  1 -
 gcc/config/freebsd-d.cc             |  2 +-
 gcc/config/glibc-d.cc               |  2 +-
 gcc/config/i386/i386-d.cc           |  1 +
 gcc/config/i386/i386-d.h            | 26 ++++++++++++++++++++++++++
 gcc/config/i386/i386-protos.h       |  5 -----
 gcc/config/i386/i386.h              |  5 -----
 gcc/config/i386/winnt-d.cc          |  2 +-
 gcc/config/mips/mips-d.cc           |  1 +
 gcc/config/mips/mips-d.h            | 24 ++++++++++++++++++++++++
 gcc/config/mips/mips-protos.h       |  4 ----
 gcc/config/mips/mips.h              |  4 ----
 gcc/config/netbsd-d.cc              |  4 +---
 gcc/config/openbsd-d.cc             |  4 +---
 gcc/config/pa/pa-d.cc               |  1 +
 gcc/config/pa/pa-d.h                | 24 ++++++++++++++++++++++++
 gcc/config/pa/pa-protos.h           |  4 ----
 gcc/config/pa/pa.h                  |  4 ----
 gcc/config/riscv/riscv-d.cc         |  1 +
 gcc/config/riscv/riscv-d.h          | 24 ++++++++++++++++++++++++
 gcc/config/riscv/riscv-protos.h     |  4 ----
 gcc/config/riscv/riscv.h            |  4 ----
 gcc/config/rs6000/rs6000-d.cc       |  1 +
 gcc/config/rs6000/rs6000-d.h        | 24 ++++++++++++++++++++++++
 gcc/config/rs6000/rs6000-protos.h   |  4 ----
 gcc/config/rs6000/rs6000.h          |  4 ----
 gcc/config/s390/s390-d.cc           |  1 +
 gcc/config/s390/s390-d.h            | 24 ++++++++++++++++++++++++
 gcc/config/s390/s390-protos.h       |  4 ----
 gcc/config/s390/s390.h              |  4 ----
 gcc/config/sol2-d.cc                |  4 +---
 gcc/config/sparc/sparc-d.cc         |  1 +
 gcc/config/sparc/sparc-d.h          | 24 ++++++++++++++++++++++++
 gcc/config/sparc/sparc-protos.h     |  4 ----
 gcc/config/sparc/sparc.h            |  4 ----
 gcc/configure                       | 11 +++--------
 gcc/configure.ac                    |  7 +------
 46 files changed, 244 insertions(+), 106 deletions(-)
 create mode 100644 gcc/config/aarch64/aarch64-d.h
 create mode 100644 gcc/config/arm/arm-d.h
 create mode 100644 gcc/config/i386/i386-d.h
 create mode 100644 gcc/config/mips/mips-d.h
 create mode 100644 gcc/config/pa/pa-d.h
 create mode 100644 gcc/config/riscv/riscv-d.h
 create mode 100644 gcc/config/rs6000/rs6000-d.h
 create mode 100644 gcc/config/s390/s390-d.h
 create mode 100644 gcc/config/sparc/sparc-d.h

diff --git a/gcc/config.gcc b/gcc/config.gcc
index f1391e26142..f4e757bd853 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -558,11 +558,15 @@ xtensa*-*-*)
 esac
 
 tm_file=${cpu_type}/${cpu_type}.h
-tm_d_file=${cpu_type}/${cpu_type}.h
 if test -f ${srcdir}/config/${cpu_type}/${cpu_type}-protos.h
 then
 	tm_p_file=${cpu_type}/${cpu_type}-protos.h
-	tm_d_file="${tm_d_file} ${cpu_type}/${cpu_type}-protos.h"
+fi
+
+tm_d_file=
+if test -f ${srcdir}/config/${cpu_type}/${cpu_type}-d.h
+then
+	tm_d_file="${tm_d_file} ${cpu_type}/${cpu_type}-d.h"
 fi
 
 extra_modes=
@@ -668,7 +672,6 @@ case ${target} in
 *-*-darwin*)
   tmake_file="t-darwin "
   tm_file="${tm_file} darwin.h"
-  tm_d_file="${tm_d_file} tm-dwarf2.h"
   darwin_os=`echo ${target} | sed 's/.*darwin\([0-9.]*\).*$/\1/'`
   darwin_maj=`expr "$darwin_os" : '\([0-9]*\).*'`
   macos_min=`expr "$darwin_os" : '[0-9]*\.\([0-9]*\).*'`
@@ -3445,7 +3448,6 @@ xstormy16-*-elf)
 	# For historical reasons, the target files omit the 'x'.
 	tm_file="elfos.h newlib-stdint.h stormy16/stormy16.h"
 	tm_p_file=stormy16/stormy16-protos.h
-	tm_d_file="elfos.h stormy16/stormy16.h"
 	md_file=stormy16/stormy16.md
 	out_file=stormy16/stormy16.cc
 	extra_options=stormy16/stormy16.opt
diff --git a/gcc/config/aarch64/aarch64-d.cc b/gcc/config/aarch64/aarch64-d.cc
index d3fcc0b881e..e0e0401631e 100644
--- a/gcc/config/aarch64/aarch64-d.cc
+++ b/gcc/config/aarch64/aarch64-d.cc
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/aarch64/aarch64-d.h b/gcc/config/aarch64/aarch64-d.h
new file mode 100644
index 00000000000..c605a68ef9f
--- /dev/null
+++ b/gcc/config/aarch64/aarch64-d.h
@@ -0,0 +1,24 @@
+/* Definitions for the D front end on the AArch64 architecture.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* Defined in aarch64-d.cc  */
+extern void aarch64_d_target_versions (void);
+extern void aarch64_d_register_target_info (void);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS aarch64_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO aarch64_d_register_target_info
diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h
index 19c9d3cb179..0bb4c9b0e28 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -1040,10 +1040,6 @@ enum aarch64_parse_opt_result aarch64_parse_extension (const char *,
 void aarch64_get_all_extension_candidates (auto_vec<const char *> *candidates);
 std::string aarch64_get_extension_string_for_isa_flags (uint64_t, uint64_t);
 
-/* Defined in aarch64-d.cc  */
-extern void aarch64_d_target_versions (void);
-extern void aarch64_d_register_target_info (void);
-
 rtl_opt_pass *make_pass_fma_steering (gcc::context *);
 rtl_opt_pass *make_pass_track_speculation (gcc::context *);
 rtl_opt_pass *make_pass_tag_collision_avoidance (gcc::context *);
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index 80cfe4b7407..e6855c64035 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -26,10 +26,6 @@
 #define TARGET_CPU_CPP_BUILTINS()	\
   aarch64_cpu_cpp_builtins (pfile)
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS aarch64_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO aarch64_d_register_target_info
-
 
 
 #define REGISTER_TARGET_PRAGMAS() aarch64_register_pragmas ()
diff --git a/gcc/config/arm/arm-d.cc b/gcc/config/arm/arm-d.cc
index d65b7524934..5c89f1b1079 100644
--- a/gcc/config/arm/arm-d.cc
+++ b/gcc/config/arm/arm-d.cc
@@ -21,9 +21,10 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
-#include "tm_p.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
+#include "arm-protos.h"
 
 /* Implement TARGET_D_CPU_VERSIONS for ARM targets.  */
 
diff --git a/gcc/config/arm/arm-d.h b/gcc/config/arm/arm-d.h
new file mode 100644
index 00000000000..479a89bb120
--- /dev/null
+++ b/gcc/config/arm/arm-d.h
@@ -0,0 +1,24 @@
+/* Definitions for the D front end on the ARM architecture.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* Defined in arm-d.cc  */
+extern void arm_d_target_versions (void);
+extern void arm_d_register_target_info (void);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS arm_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO arm_d_register_target_info
diff --git a/gcc/config/arm/arm-protos.h b/gcc/config/arm/arm-protos.h
index f8aabbdae37..ee226559bfb 100644
--- a/gcc/config/arm/arm-protos.h
+++ b/gcc/config/arm/arm-protos.h
@@ -402,10 +402,6 @@ extern void arm_lang_object_attributes_init (void);
 extern void arm_register_target_pragmas (void);
 extern void arm_cpu_cpp_builtins (struct cpp_reader *);
 
-/* Defined in arm-d.cc  */
-extern void arm_d_target_versions (void);
-extern void arm_d_register_target_info (void);
-
 extern bool arm_is_constant_pool_ref (rtx);
 
 /* The bits in this mask specify which instruction scheduling options should
diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
index f479540812a..e15722b0be3 100644
--- a/gcc/config/arm/arm.h
+++ b/gcc/config/arm/arm.h
@@ -47,10 +47,6 @@ extern char arm_arch_name[];
 /* Target CPU builtins.  */
 #define TARGET_CPU_CPP_BUILTINS() arm_cpu_cpp_builtins (pfile)
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS arm_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO arm_d_register_target_info
-
 #include "config/arm/arm-opts.h"
 
 /* The processor for which instructions should be scheduled.  */
diff --git a/gcc/config/default-d.cc b/gcc/config/default-d.cc
index 2d7abfcba96..ff722c5096d 100644
--- a/gcc/config/default-d.cc
+++ b/gcc/config/default-d.cc
@@ -18,7 +18,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "memmodel.h"
 #include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
diff --git a/gcc/config/freebsd-d.cc b/gcc/config/freebsd-d.cc
index 9f0f5e7b6ee..189e4a69e78 100644
--- a/gcc/config/freebsd-d.cc
+++ b/gcc/config/freebsd-d.cc
@@ -20,7 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "memmodel.h"
 #include "tm.h"
-#include "tm_p.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/glibc-d.cc b/gcc/config/glibc-d.cc
index f30af104db8..80ef27d19c6 100644
--- a/gcc/config/glibc-d.cc
+++ b/gcc/config/glibc-d.cc
@@ -20,7 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "tm.h"
 #include "memmodel.h"
-#include "tm_p.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/i386/i386-d.cc b/gcc/config/i386/i386-d.cc
index a62339cae30..27e2b75fc25 100644
--- a/gcc/config/i386/i386-d.cc
+++ b/gcc/config/i386/i386-d.cc
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/i386/i386-d.h b/gcc/config/i386/i386-d.h
new file mode 100644
index 00000000000..b9806889df9
--- /dev/null
+++ b/gcc/config/i386/i386-d.h
@@ -0,0 +1,26 @@
+/* Definitions for the D front end on the x86 architecture.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* In i386-d.cc  */
+extern void ix86_d_target_versions (void);
+extern void ix86_d_register_target_info (void);
+extern bool ix86_d_has_stdcall_convention (unsigned int *, unsigned int *);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS ix86_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO ix86_d_register_target_info
+#define TARGET_D_HAS_STDCALL_CONVENTION ix86_d_has_stdcall_convention
diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
index e27c14ff783..3b94efefa65 100644
--- a/gcc/config/i386/i386-protos.h
+++ b/gcc/config/i386/i386-protos.h
@@ -277,11 +277,6 @@ extern bool ix86_extract_perm_from_pool_constant (int*, rtx);
 extern void ix86_target_macros (void);
 extern void ix86_register_pragmas (void);
 
-/* In i386-d.cc  */
-extern void ix86_d_target_versions (void);
-extern void ix86_d_register_target_info (void);
-extern bool ix86_d_has_stdcall_convention (unsigned int *, unsigned int *);
-
 /* In winnt.cc  */
 extern void i386_pe_unique_section (tree, int);
 extern void i386_pe_declare_function_type (FILE *, const char *, int);
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 0de5c77bc7d..716bacef5f9 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -608,11 +608,6 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
 /* Target Pragmas.  */
 #define REGISTER_TARGET_PRAGMAS() ix86_register_pragmas ()
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS ix86_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO ix86_d_register_target_info
-#define TARGET_D_HAS_STDCALL_CONVENTION ix86_d_has_stdcall_convention
-
 #ifndef CC1_SPEC
 #define CC1_SPEC "%(cc1_cpu) "
 #endif
diff --git a/gcc/config/i386/winnt-d.cc b/gcc/config/i386/winnt-d.cc
index 3d990a12331..00c28c3964a 100644
--- a/gcc/config/i386/winnt-d.cc
+++ b/gcc/config/i386/winnt-d.cc
@@ -21,9 +21,9 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "target.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
-#include "tm_p.h"
 
 /* Implement TARGET_D_OS_VERSIONS for Windows targets.  */
 
diff --git a/gcc/config/mips/mips-d.cc b/gcc/config/mips/mips-d.cc
index 41a278a08fd..8b6ccd10604 100644
--- a/gcc/config/mips/mips-d.cc
+++ b/gcc/config/mips/mips-d.cc
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/mips/mips-d.h b/gcc/config/mips/mips-d.h
new file mode 100644
index 00000000000..7cb3ed9716e
--- /dev/null
+++ b/gcc/config/mips/mips-d.h
@@ -0,0 +1,24 @@
+/* Definitions for the D front end on the MIPS architecture.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* Routines implemented in mips-d.cc  */
+extern void mips_d_target_versions (void);
+extern void mips_d_register_target_info (void);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS mips_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO mips_d_register_target_info
diff --git a/gcc/config/mips/mips-protos.h b/gcc/config/mips/mips-protos.h
index 9d0f4d90fd9..86350523c1b 100644
--- a/gcc/config/mips/mips-protos.h
+++ b/gcc/config/mips/mips-protos.h
@@ -388,8 +388,4 @@ extern void mips_register_frame_header_opt (void);
 extern void mips_expand_vec_cond_expr (machine_mode, machine_mode, rtx *);
 extern void mips_expand_vec_cmp_expr (rtx *);
 
-/* Routines implemented in mips-d.cc  */
-extern void mips_d_target_versions (void);
-extern void mips_d_register_target_info (void);
-
 #endif /* ! GCC_MIPS_PROTOS_H */
diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h
index 85ea24c546e..74b6e11aabb 100644
--- a/gcc/config/mips/mips.h
+++ b/gcc/config/mips/mips.h
@@ -680,10 +680,6 @@ struct mips_cpu_info {
     }									\
   while (0)
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS mips_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO mips_d_register_target_info
-
 /* Default target_flags if no switches are specified  */
 
 #ifndef TARGET_DEFAULT
diff --git a/gcc/config/netbsd-d.cc b/gcc/config/netbsd-d.cc
index 286f010939f..cd0c95568a1 100644
--- a/gcc/config/netbsd-d.cc
+++ b/gcc/config/netbsd-d.cc
@@ -20,9 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "tm.h"
-#include "memmodel.h"
-#include "tm_p.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/openbsd-d.cc b/gcc/config/openbsd-d.cc
index c1a2a89807a..33c7e41ab62 100644
--- a/gcc/config/openbsd-d.cc
+++ b/gcc/config/openbsd-d.cc
@@ -20,9 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "memmodel.h"
-#include "tm.h"
-#include "tm_p.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/pa/pa-d.cc b/gcc/config/pa/pa-d.cc
index 122ad480447..077aeb5d634 100644
--- a/gcc/config/pa/pa-d.cc
+++ b/gcc/config/pa/pa-d.cc
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "target.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/pa/pa-d.h b/gcc/config/pa/pa-d.h
new file mode 100644
index 00000000000..9a9df108f61
--- /dev/null
+++ b/gcc/config/pa/pa-d.h
@@ -0,0 +1,24 @@
+/* Definitions for the D front end on the HPPA architecture.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* Routines implemented in pa-d.cc  */
+extern void pa_d_target_versions (void);
+extern void pa_d_register_target_info (void);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS pa_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO pa_d_register_target_info
diff --git a/gcc/config/pa/pa-protos.h b/gcc/config/pa/pa-protos.h
index d474d9efc91..fe8b7a5091e 100644
--- a/gcc/config/pa/pa-protos.h
+++ b/gcc/config/pa/pa-protos.h
@@ -111,7 +111,3 @@ extern void pa_output_function_label (FILE *);
 extern void hppa_profile_hook (int);
 
 extern const int pa_magic_milli[];
-
-/* Routines implemented in pa-d.cc  */
-extern void pa_d_target_versions (void);
-extern void pa_d_register_target_info (void);
diff --git a/gcc/config/pa/pa.h b/gcc/config/pa/pa.h
index 95787ab1df2..bafdf602138 100644
--- a/gcc/config/pa/pa.h
+++ b/gcc/config/pa/pa.h
@@ -1300,9 +1300,5 @@ do {									     \
 
 #define NEED_INDICATE_EXEC_STACK 0
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS pa_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO pa_d_register_target_info
-
 /* Output default function prologue for hpux.  */
 #define TARGET_ASM_FUNCTION_PROLOGUE pa_output_function_prologue
diff --git a/gcc/config/riscv/riscv-d.cc b/gcc/config/riscv/riscv-d.cc
index 729de96d398..a762a35778d 100644
--- a/gcc/config/riscv/riscv-d.cc
+++ b/gcc/config/riscv/riscv-d.cc
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "target.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/riscv/riscv-d.h b/gcc/config/riscv/riscv-d.h
new file mode 100644
index 00000000000..21a989edd8c
--- /dev/null
+++ b/gcc/config/riscv/riscv-d.h
@@ -0,0 +1,24 @@
+/* Definitions for the D front end on the RISC-V architecture.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* Routines implemented in riscv-d.cc  */
+extern void riscv_d_target_versions (void);
+extern void riscv_d_register_target_info (void);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS riscv_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO riscv_d_register_target_info
diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index 2bc0ef06f93..649c5c977e1 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -78,10 +78,6 @@ extern bool riscv_gpr_save_operation_p (rtx);
 /* Routines implemented in riscv-c.cc.  */
 void riscv_cpu_cpp_builtins (cpp_reader *);
 
-/* Routines implemented in riscv-d.cc  */
-extern void riscv_d_target_versions (void);
-extern void riscv_d_register_target_info (void);
-
 /* Routines implemented in riscv-builtins.cc.  */
 extern void riscv_atomic_assign_expand_fenv (tree *, tree *, tree *);
 extern rtx riscv_expand_builtin (tree, rtx, rtx, machine_mode, int);
diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
index e35aaa7cc14..eb1284e56d6 100644
--- a/gcc/config/riscv/riscv.h
+++ b/gcc/config/riscv/riscv.h
@@ -27,10 +27,6 @@ along with GCC; see the file COPYING3.  If not see
 /* Target CPU builtins.  */
 #define TARGET_CPU_CPP_BUILTINS() riscv_cpu_cpp_builtins (pfile)
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS riscv_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO riscv_d_register_target_info
-
 #ifdef TARGET_BIG_ENDIAN_DEFAULT
 #define DEFAULT_ENDIAN_SPEC    "b"
 #else
diff --git a/gcc/config/rs6000/rs6000-d.cc b/gcc/config/rs6000/rs6000-d.cc
index 74e78cf9e4d..7b9ca5a855e 100644
--- a/gcc/config/rs6000/rs6000-d.cc
+++ b/gcc/config/rs6000/rs6000-d.cc
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/rs6000/rs6000-d.h b/gcc/config/rs6000/rs6000-d.h
new file mode 100644
index 00000000000..c805b304245
--- /dev/null
+++ b/gcc/config/rs6000/rs6000-d.h
@@ -0,0 +1,24 @@
+/* Definitions for the D front end on the PowerPC architecture.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* Declare functions in rs6000-d.cc  */
+extern void rs6000_d_target_versions (void);
+extern void rs6000_d_register_target_info (void);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS rs6000_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO rs6000_d_register_target_info
diff --git a/gcc/config/rs6000/rs6000-protos.h b/gcc/config/rs6000/rs6000-protos.h
index b3c16e7448d..1c0f97edcc2 100644
--- a/gcc/config/rs6000/rs6000-protos.h
+++ b/gcc/config/rs6000/rs6000-protos.h
@@ -323,10 +323,6 @@ extern void rs6000_activate_target_options (tree new_tree);
 extern void rs6000_target_modify_macros (bool, HOST_WIDE_INT);
 extern void (*rs6000_target_modify_macros_ptr) (bool, HOST_WIDE_INT);
 
-/* Declare functions in rs6000-d.cc  */
-extern void rs6000_d_target_versions (void);
-extern void rs6000_d_register_target_info (void);
-
 #ifdef NO_DOLLAR_IN_LABEL
 const char * rs6000_xcoff_strip_dollar (const char *);
 #endif
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index ad9bf0f7358..5f1d5e494da 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -606,10 +606,6 @@ extern unsigned char rs6000_recip_bits[];
 #define TARGET_CPU_CPP_BUILTINS() \
   rs6000_cpu_cpp_builtins (pfile)
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS rs6000_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO rs6000_d_register_target_info
-
 /* This is used by rs6000_cpu_cpp_builtins to indicate the byte order
    we're compiling for.  Some configurations may need to override it.  */
 #define RS6000_CPU_CPP_ENDIAN_BUILTINS()	\
diff --git a/gcc/config/s390/s390-d.cc b/gcc/config/s390/s390-d.cc
index 8e631859e67..0dd4b5c999b 100644
--- a/gcc/config/s390/s390-d.cc
+++ b/gcc/config/s390/s390-d.cc
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/s390/s390-d.h b/gcc/config/s390/s390-d.h
new file mode 100644
index 00000000000..703031b3c81
--- /dev/null
+++ b/gcc/config/s390/s390-d.h
@@ -0,0 +1,24 @@
+/* Definitions for the D front end on the IBM S/390 and zSeries architectures.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* s390-d.cc routines */
+extern void s390_d_target_versions (void);
+extern void s390_d_register_target_info (void);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS s390_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO s390_d_register_target_info
diff --git a/gcc/config/s390/s390-protos.h b/gcc/config/s390/s390-protos.h
index 765d843a418..78117c36e03 100644
--- a/gcc/config/s390/s390-protos.h
+++ b/gcc/config/s390/s390-protos.h
@@ -175,10 +175,6 @@ extern void s390_register_target_pragmas (void);
 /* Routines for s390-c.cc */
 extern bool s390_const_operand_ok (tree, int, int, tree);
 
-/* s390-d.cc routines */
-extern void s390_d_target_versions (void);
-extern void s390_d_register_target_info (void);
-
 /* Pass management.  */
 namespace gcc { class context; }
 class rtl_opt_pass;
diff --git a/gcc/config/s390/s390.h b/gcc/config/s390/s390.h
index 2e1bc71e73a..1114222cd4a 100644
--- a/gcc/config/s390/s390.h
+++ b/gcc/config/s390/s390.h
@@ -247,10 +247,6 @@ enum processor_flags
 /* Target CPU builtins.  */
 #define TARGET_CPU_CPP_BUILTINS() s390_cpu_cpp_builtins (pfile)
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS s390_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO s390_d_register_target_info
-
 #ifdef DEFAULT_TARGET_64BIT
 #define TARGET_DEFAULT     (MASK_64BIT | MASK_ZARCH | MASK_HARD_DFP	\
 			    | MASK_OPT_HTM | MASK_OPT_VX)
diff --git a/gcc/config/sol2-d.cc b/gcc/config/sol2-d.cc
index 9caa82e8490..0ace79d5aae 100644
--- a/gcc/config/sol2-d.cc
+++ b/gcc/config/sol2-d.cc
@@ -18,9 +18,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "tm.h"
-#include "memmodel.h"
-#include "tm_p.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/sparc/sparc-d.cc b/gcc/config/sparc/sparc-d.cc
index 1f3a9666b97..f8a3cf30f25 100644
--- a/gcc/config/sparc/sparc-d.cc
+++ b/gcc/config/sparc/sparc-d.cc
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
+#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
diff --git a/gcc/config/sparc/sparc-d.h b/gcc/config/sparc/sparc-d.h
new file mode 100644
index 00000000000..b9d8ccf15ab
--- /dev/null
+++ b/gcc/config/sparc/sparc-d.h
@@ -0,0 +1,24 @@
+/* Definitions for the D front end on the SPARC architecture.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* Routines implemented in sparc-d.cc  */
+extern void sparc_d_target_versions (void);
+extern void sparc_d_register_target_info (void);
+
+/* Target hooks for D language.  */
+#define TARGET_D_CPU_VERSIONS sparc_d_target_versions
+#define TARGET_D_REGISTER_CPU_TARGET_INFO sparc_d_register_target_info
diff --git a/gcc/config/sparc/sparc-protos.h b/gcc/config/sparc/sparc-protos.h
index f9e1c74554d..4ddd00c81e1 100644
--- a/gcc/config/sparc/sparc-protos.h
+++ b/gcc/config/sparc/sparc-protos.h
@@ -112,8 +112,4 @@ unsigned int sparc_regmode_natural_size (machine_mode);
 
 extern rtl_opt_pass *make_pass_work_around_errata (gcc::context *);
 
-/* Routines implemented in sparc-d.cc  */
-extern void sparc_d_target_versions (void);
-extern void sparc_d_register_target_info (void);
-
 #endif /* __SPARC_PROTOS_H__ */
diff --git a/gcc/config/sparc/sparc.h b/gcc/config/sparc/sparc.h
index 987340392dd..155e1da7ad7 100644
--- a/gcc/config/sparc/sparc.h
+++ b/gcc/config/sparc/sparc.h
@@ -27,10 +27,6 @@ along with GCC; see the file COPYING3.  If not see
 
 #define TARGET_CPU_CPP_BUILTINS() sparc_target_macros ()
 
-/* Target hooks for D language.  */
-#define TARGET_D_CPU_VERSIONS sparc_d_target_versions
-#define TARGET_D_REGISTER_CPU_TARGET_INFO sparc_d_register_target_info
-
 /* Specify this in a cover file to provide bi-architecture (32/64) support.  */
 /* #define SPARC_BI_ARCH */
 
diff --git a/gcc/configure b/gcc/configure
index 2fd6b531862..39f7ed129a4 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -13023,7 +13023,6 @@ fi
 
 tm_file="${tm_file} defaults.h"
 tm_p_file="${tm_p_file} tm-preds.h"
-tm_d_file="${tm_d_file} defaults.h"
 host_xm_file="auto-host.h ansidecl.h ${host_xm_file}"
 build_xm_file="${build_auto} ansidecl.h ${build_xm_file}"
 # We don't want ansidecl.h in target files, write code there in ISO/GNU C.
@@ -13418,13 +13417,9 @@ for f in $tm_p_file; do
 done
 
 tm_d_file_list=
-tm_d_include_list="options.h insn-constants.h"
+tm_d_include_list=
 for f in $tm_d_file; do
   case $f in
-    defaults.h )
-       tm_d_file_list="${tm_d_file_list} \$(srcdir)/$f"
-       tm_d_include_list="${tm_d_include_list} $f"
-       ;;
     * )
        tm_d_file_list="${tm_d_file_list} \$(srcdir)/config/$f"
        tm_d_include_list="${tm_d_include_list} config/$f"
@@ -19694,7 +19689,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19697 "configure"
+#line 19692 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19800,7 +19795,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19803 "configure"
+#line 19798 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 12b5e934d1e..50bb61c1b61 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -2109,7 +2109,6 @@ AC_SUBST(HAVE_AUTO_BUILD)
 
 tm_file="${tm_file} defaults.h"
 tm_p_file="${tm_p_file} tm-preds.h"
-tm_d_file="${tm_d_file} defaults.h"
 host_xm_file="auto-host.h ansidecl.h ${host_xm_file}"
 build_xm_file="${build_auto} ansidecl.h ${build_xm_file}"
 # We don't want ansidecl.h in target files, write code there in ISO/GNU C.
@@ -2353,13 +2352,9 @@ for f in $tm_p_file; do
 done
 
 tm_d_file_list=
-tm_d_include_list="options.h insn-constants.h"
+tm_d_include_list=
 for f in $tm_d_file; do
   case $f in
-    defaults.h )
-       tm_d_file_list="${tm_d_file_list} \$(srcdir)/$f"
-       tm_d_include_list="${tm_d_include_list} $f"
-       ;;
     * )
        tm_d_file_list="${tm_d_file_list} \$(srcdir)/config/$f"
        tm_d_include_list="${tm_d_include_list} config/$f"
Rainer Orth Sept. 6, 2022, 7:42 a.m. UTC | #8
Hi Iain,

> Excerpts from Richard Biener's message of September 1, 2022 8:28 am:
>> On Wed, Aug 31, 2022 at 9:21 PM Iain Buclaw <ibuclaw@gdcproject.org> wrote:
>>>
>>> Excerpts from Joseph Myers's message of August 31, 2022 7:16 pm:
>>> > On Wed, 31 Aug 2022, Iain Buclaw via Gcc-patches wrote:
>>> >
>>> >> Excerpts from Joseph Myers's message of August 30, 2022 11:53 pm:
>>> >> > On Fri, 26 Aug 2022, Richard Biener via Gcc-patches wrote:
>>> >> >
>>> >> >> I was hoping Joseph would chime in here - I recollect debugging
>>> >> >> this kind
>>> >> >> of thing and a thread about this a while back but unfortunately I do not
>>> >> >> remember the details here (IIRC some things get included where they
>>> >> >> better should not be).
>>> >> >
>>> >> > See <https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582563.html>.
>>> >> > Is there some reason it's problematic to avoid having defaults.h or
>>> >> > ${cpu_type}/${cpu_type}.h included in tm_d.h, and instead have
>>> >> > tm_d.h only
>>> >> > include D-specific headers?
>>> >> >
>>> >>
>>> >> In targets such as arm-elf, we still need to pull in definitions from
>>> >> ${cpu_type}/${cpu_type}-d.cc into default-d.cc.
>>> >>
>>> >> All I can think that might suffice is having D-specific prototype
>>> >> headers in all targets as ${cpu_type}/${cpu_type}-d.h.
>>> >
>>> > As long as those prototypes don't involve any types that depend on an
>>> > inclusion of tm.h, that should be fine.
>>> >
>>>
>>> Updated patch that does what I described.
>> 
>> Ah yes - I think, even if a bit verbose, this is exactly how it was supposed
>> to be?
>> 
>> OK from my side.
>> 
>
> To access the TARGET macros from arm-d.cc, arm-protos.h had to be
> included (after tm_p.h was removed).
>
> All ~200 configurations in contrib/config-list.mk now build again with
> the D front-end enabled.

unfortunately, this patch broke all Solaris configs
(i386-pc-solaris2.11, sparc-sun-solaris2.11, sparcv9-sun-solaris2.11).
libphobos configure in stage2 fails with

can compile D sources
configure:5402: /var/gcc/regression/master/11.4-gcc/build/./gcc/gdc -B/var/gcc/regression/master/11.4-gcc/build/./gcc/ -B/vol/gcc/i386-pc-solaris2.11/bin/ -B/vol/gcc/i386-pc-solaris2.11/lib/ -isystem /vol/gcc/i386-pc-solaris2.11/include -isystem /vol/gcc/i386-pc-solaris2.11/sys-include   -fno-checking -c -fno-druntime -nostdinc -I /vol/gcc/src/hg/master/local/libphobos/libdruntime  -g -O2   conftest.d >&5
core.exception.ArrayIndexError@/vol/gcc/src/hg/master/local/gcc/d/dmd/root/stringtable.d(291): index [3530971477] is out of bounds for array of length 0
gcc.deh(505): uncaught exception

I don't yet see why, though.

	Rainer
Iain Buclaw Sept. 6, 2022, 10:51 a.m. UTC | #9
Excerpts from Rainer Orth's message of September 6, 2022 9:42 am:
> Hi Iain,
> 
>> Excerpts from Richard Biener's message of September 1, 2022 8:28 am:
>>> On Wed, Aug 31, 2022 at 9:21 PM Iain Buclaw <ibuclaw@gdcproject.org> wrote:
>>> 
>>> Ah yes - I think, even if a bit verbose, this is exactly how it was supposed
>>> to be?
>>> 
>>> OK from my side.
>>> 
>>
>> To access the TARGET macros from arm-d.cc, arm-protos.h had to be
>> included (after tm_p.h was removed).
>>
>> All ~200 configurations in contrib/config-list.mk now build again with
>> the D front-end enabled.
> 
> unfortunately, this patch broke all Solaris configs
> (i386-pc-solaris2.11, sparc-sun-solaris2.11, sparcv9-sun-solaris2.11).
> libphobos configure in stage2 fails with
> 
> can compile D sources
> configure:5402: /var/gcc/regression/master/11.4-gcc/build/./gcc/gdc -B/var/gcc/regression/master/11.4-gcc/build/./gcc/ -B/vol/gcc/i386-pc-solaris2.11/bin/ -B/vol/gcc/i386-pc-solaris2.11/lib/ -isystem /vol/gcc/i386-pc-solaris2.11/include -isystem /vol/gcc/i386-pc-solaris2.11/sys-include   -fno-checking -c -fno-druntime -nostdinc -I /vol/gcc/src/hg/master/local/libphobos/libdruntime  -g -O2   conftest.d >&5
> core.exception.ArrayIndexError@/vol/gcc/src/hg/master/local/gcc/d/dmd/root/stringtable.d(291): index [3530971477] is out of bounds for array of length 0
> gcc.deh(505): uncaught exception
> 
> I don't yet see why, though.

Hi Rainer,

Is there a difference in output from `./gcc/d21 -quiet -v` ?

Pay attention to any predefs that have suddenly appeared or disappeared.

Regards,
Iain.
Rainer Orth Sept. 6, 2022, 12:04 p.m. UTC | #10
Hi Iain,

> Is there a difference in output from `./gcc/d21 -quiet -v` ?
>
> Pay attention to any predefs that have suddenly appeared or disappeared.

there is indeed ;-)  The previous d21 emits

binary    ./266566/gcc/d21
version   v2.100.1

predefs   GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions GNU_StackGrowsDown GNU_InlineAsm assert D_PreConditions D_PostConditions D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo all X86 D_HardFloat Posix Solaris CppRuntime_Gcc

while the patched one gives

core.exception.ArrayIndexError@/var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d(291): index [3530971477] is out of bounds for array of length 0
gcc.deh(505): uncaught exception
<built-in>: internal compiler error: Abort
0x96d5b6c crash_signal
	/var/gcc/reghunt/master/gcc/toplev.cc:314

	Rainer
Iain Buclaw Sept. 6, 2022, 2:19 p.m. UTC | #11
Excerpts from Rainer Orth's message of September 6, 2022 2:04 pm:
> Hi Iain,
> 
>> Is there a difference in output from `./gcc/d21 -quiet -v` ?
>>
>> Pay attention to any predefs that have suddenly appeared or disappeared.
> 
> there is indeed ;-)  The previous d21 emits
> 
> binary    ./266566/gcc/d21
> version   v2.100.1
> 
> predefs   GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions GNU_StackGrowsDown GNU_InlineAsm assert D_PreConditions D_PostConditions D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo all X86 D_HardFloat Posix Solaris CppRuntime_Gcc
> 
> while the patched one gives
> 
> core.exception.ArrayIndexError@/var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d(291): index [3530971477] is out of bounds for array of length 0
> gcc.deh(505): uncaught exception
> <built-in>: internal compiler error: Abort
> 0x96d5b6c crash_signal
> 	/var/gcc/reghunt/master/gcc/toplev.cc:314
> 

Excellent, and the stage1 compiler?

Iain.
Rainer Orth Sept. 6, 2022, 2:25 p.m. UTC | #12
Hi Iain,

>> there is indeed ;-)  The previous d21 emits
>> 
>> binary    ./266566/gcc/d21
>> version   v2.100.1
>> 
>> predefs GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions
>> GNU_StackGrowsDown GNU_InlineAsm assert D_PreConditions D_PostConditions
>> D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo all X86 D_HardFloat
>> Posix Solaris CppRuntime_Gcc
>> 
>> while the patched one gives
>> 
>> core.exception.ArrayIndexError@/var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d(291):
>> index [3530971477] is out of bounds for array of length 0
>> gcc.deh(505): uncaught exception
>> <built-in>: internal compiler error: Abort
>> 0x96d5b6c crash_signal
>> 	/var/gcc/reghunt/master/gcc/toplev.cc:314
>> 
>
> Excellent, and the stage1 compiler?

binary    ./prev-gcc/d21
version   v2.100.1

predefs   GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions GNU_StackGrowsDown GNU_InlineAsm assert D_PreConditions D_PostConditions D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo all X86 D_HardFloat Posix Solaris CppRuntime_Gcc

So identical to the pre-patch one.

Just in case, here's the stacktrace of the crashing d21, filtered
through c++filt -s dlang:

Thread 2 received signal SIGABRT, Aborted.
[Switching to Thread 1 (LWP 1)]
0xfe1be2e5 in __lwp_sigqueue () from /lib/libc.so.1
(gdb) bt
#0  0xfe1be2e5 in __lwp_sigqueue () from /lib/libc.so.1
#1  0xfe1b62cf in thr_kill () from /lib/libc.so.1
#2  0xfe0ed662 in raise () from /lib/libc.so.1
#3  0xfe0bae74 in abort () from /lib/libc.so.1
#4  0x0a8e786d in gcc.deh.terminate(immutable(char)[], uint) (msg=..., line=<optimized out>) at /var/gcc/reghunt/master/libphobos/libdruntime/gcc/deh.d:414
#5  0x0a8e7ab3 in _d_throw (object=<optimized out>) at /var/gcc/reghunt/master/libphobos/libdruntime/gcc/deh.d:505
#6  0x0a8edf02 in onArrayIndexError (index=<optimized out>, length=<optimized out>, file=..., line=<optimized out>) at /var/gcc/reghunt/master/libphobos/libdruntime/core/exception.d:650
#7  0x0a8edf3d in _d_arraybounds_indexp (file=<optimized out>, line=<optimized out>, index=<optimized out>, length=<optimized out>) at /var/gcc/reghunt/master/libphobos/libdruntime/core/exception.d:848
#8  0x08ffc17a in dmd.root.stringtable.StringTable!(dmd.identifier.Identifier).StringTable.findSlot(uint, scope const(char)[]) const (this=..., hash=<optimized out>, str=...) at /var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d:291
#9  0x08ffc37e in dmd.root.stringtable.StringTable!(dmd.identifier.Identifier).StringTable.update(scope const(char)[]) (this=..., str=...) at /var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d:184
#10 0x08ffc7b9 in dmd.identifier.Identifier.idPool(const(char)[], bool) (isAnonymous=false, s=...) at /var/gc110
#16 toplev::main (this=<optimized out>, argc=<optimized out>, argv=<optimized out>) at /var/gcc/reghunt/master/gcc/toplev.cc:2277
#17 0x0a828851 in main (argc=3, argv=0xfeffdb98) at /var/gcc/reghunt/master/gcc/main.cc:39

	Rainer
Iain Buclaw Sept. 6, 2022, 5:02 p.m. UTC | #13
Excerpts from Rainer Orth's message of September 6, 2022 4:25 pm:
> Hi Iain,
> 
>>> there is indeed ;-)  The previous d21 emits
>>> 
>>> binary    ./266566/gcc/d21
>>> version   v2.100.1
>>> 
>>> predefs GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions
>>> GNU_StackGrowsDown GNU_InlineAsm assert D_PreConditions D_PostConditions
>>> D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo all X86 D_HardFloat
>>> Posix Solaris CppRuntime_Gcc
>>> 
>>> while the patched one gives
>>> 
>>> core.exception.ArrayIndexError@/var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d(291):
>>> index [3530971477] is out of bounds for array of length 0
>>> gcc.deh(505): uncaught exception
>>> <built-in>: internal compiler error: Abort
>>> 0x96d5b6c crash_signal
>>> 	/var/gcc/reghunt/master/gcc/toplev.cc:314
>>> 
>>
>> Excellent, and the stage1 compiler?
> 
> binary    ./prev-gcc/d21
> version   v2.100.1
> 
> predefs   GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions GNU_StackGrowsDown GNU_InlineAsm assert D_PreConditions D_PostConditions D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo all X86 D_HardFloat Posix Solaris CppRuntime_Gcc
> 
> So identical to the pre-patch one.
> 
> Just in case, here's the stacktrace of the crashing d21, filtered
> through c++filt -s dlang:
> 
> Thread 2 received signal SIGABRT, Aborted.
> [Switching to Thread 1 (LWP 1)]
> 0xfe1be2e5 in __lwp_sigqueue () from /lib/libc.so.1
> (gdb) bt
> #0  0xfe1be2e5 in __lwp_sigqueue () from /lib/libc.so.1
> #1  0xfe1b62cf in thr_kill () from /lib/libc.so.1
> #2  0xfe0ed662 in raise () from /lib/libc.so.1
> #3  0xfe0bae74 in abort () from /lib/libc.so.1
> #4  0x0a8e786d in gcc.deh.terminate(immutable(char)[], uint) (msg=..., line=<optimized out>) at /var/gcc/reghunt/master/libphobos/libdruntime/gcc/deh.d:414
> #5  0x0a8e7ab3 in _d_throw (object=<optimized out>) at /var/gcc/reghunt/master/libphobos/libdruntime/gcc/deh.d:505
> #6  0x0a8edf02 in onArrayIndexError (index=<optimized out>, length=<optimized out>, file=..., line=<optimized out>) at /var/gcc/reghunt/master/libphobos/libdruntime/core/exception.d:650
> #7  0x0a8edf3d in _d_arraybounds_indexp (file=<optimized out>, line=<optimized out>, index=<optimized out>, length=<optimized out>) at /var/gcc/reghunt/master/libphobos/libdruntime/core/exception.d:848
> #8  0x08ffc17a in dmd.root.stringtable.StringTable!(dmd.identifier.Identifier).StringTable.findSlot(uint, scope const(char)[]) const (this=..., hash=<optimized out>, str=...) at /var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d:291

Yeah, I don't see how that could trigger, as the value of `i` is always
adjusted to `i &= (table.length - 1)` (it uses quadratic probing to search
the hash table).

The logic of the compiler doesn't appear to have changed, but the data
layout may have, so I'm suspecting an issue that was always there has
now surfaced to the fore.

Iain.
Iain Buclaw Sept. 6, 2022, 9:41 p.m. UTC | #14
Excerpts from Iain Buclaw's message of September 6, 2022 7:02 pm:
> Excerpts from Rainer Orth's message of September 6, 2022 4:25 pm:
>> Hi Iain,
>> 
>>>> there is indeed ;-)  The previous d21 emits
>>>> 
>>>> binary    ./266566/gcc/d21
>>>> version   v2.100.1
>>>> 
>>>> predefs GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions
>>>> GNU_StackGrowsDown GNU_InlineAsm assert D_PreConditions D_PostConditions
>>>> D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo all X86 D_HardFloat
>>>> Posix Solaris CppRuntime_Gcc
>>>> 
>>>> while the patched one gives
>>>> 
>>>> core.exception.ArrayIndexError@/var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d(291):
>>>> index [3530971477] is out of bounds for array of length 0
>>>> gcc.deh(505): uncaught exception
>>>> <built-in>: internal compiler error: Abort
>>>> 0x96d5b6c crash_signal
>>>> 	/var/gcc/reghunt/master/gcc/toplev.cc:314
>>>> 
>>>
>>> Excellent, and the stage1 compiler?
>> 
>> binary    ./prev-gcc/d21
>> version   v2.100.1
>> 
>> predefs   GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions GNU_StackGrowsDown GNU_InlineAsm assert D_PreConditions D_PostConditions D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo all X86 D_HardFloat Posix Solaris CppRuntime_Gcc
>> 
>> So identical to the pre-patch one.
>> 
>> Just in case, here's the stacktrace of the crashing d21, filtered
>> through c++filt -s dlang:
>> 
>> Thread 2 received signal SIGABRT, Aborted.
>> [Switching to Thread 1 (LWP 1)]
>> 0xfe1be2e5 in __lwp_sigqueue () from /lib/libc.so.1
>> (gdb) bt
>> #0  0xfe1be2e5 in __lwp_sigqueue () from /lib/libc.so.1
>> #1  0xfe1b62cf in thr_kill () from /lib/libc.so.1
>> #2  0xfe0ed662 in raise () from /lib/libc.so.1
>> #3  0xfe0bae74 in abort () from /lib/libc.so.1
>> #4  0x0a8e786d in gcc.deh.terminate(immutable(char)[], uint) (msg=..., line=<optimized out>) at /var/gcc/reghunt/master/libphobos/libdruntime/gcc/deh.d:414
>> #5  0x0a8e7ab3 in _d_throw (object=<optimized out>) at /var/gcc/reghunt/master/libphobos/libdruntime/gcc/deh.d:505
>> #6  0x0a8edf02 in onArrayIndexError (index=<optimized out>, length=<optimized out>, file=..., line=<optimized out>) at /var/gcc/reghunt/master/libphobos/libdruntime/core/exception.d:650
>> #7  0x0a8edf3d in _d_arraybounds_indexp (file=<optimized out>, line=<optimized out>, index=<optimized out>, length=<optimized out>) at /var/gcc/reghunt/master/libphobos/libdruntime/core/exception.d:848
>> #8  0x08ffc17a in dmd.root.stringtable.StringTable!(dmd.identifier.Identifier).StringTable.findSlot(uint, scope const(char)[]) const (this=..., hash=<optimized out>, str=...) at /var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d:291
> 
> Yeah, I don't see how that could trigger, as the value of `i` is always
> adjusted to `i &= (table.length - 1)` (it uses quadratic probing to search
> the hash table).
> 
> The logic of the compiler doesn't appear to have changed, but the data
> layout may have, so I'm suspecting an issue that was always there has
> now surfaced to the fore.
> 

Yes, this is data related. The DSO registry picks up nothing in the
miscompiled stage2 compiler, leaving all data uninitialized.  The stage1
compiler works, and runs all module constructors ahead of compilation.

Iain.
Iain Buclaw Sept. 7, 2022, 7:34 a.m. UTC | #15
Excerpts from Iain Buclaw's message of September 6, 2022 11:41 pm:
> Excerpts from Iain Buclaw's message of September 6, 2022 7:02 pm:
>> Excerpts from Rainer Orth's message of September 6, 2022 4:25 pm:
>>> Hi Iain,
>>> 
>>>>> there is indeed ;-)  The previous d21 emits
>>>>> 
>>>>> binary    ./266566/gcc/d21
>>>>> version   v2.100.1
>>>>> 
>>>>> predefs GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions
>>>>> GNU_StackGrowsDown GNU_InlineAsm assert D_PreConditions D_PostConditions
>>>>> D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo all X86 D_HardFloat
>>>>> Posix Solaris CppRuntime_Gcc
>>>>> 
>>>>> while the patched one gives
>>>>> 
>>>>> core.exception.ArrayIndexError@/var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d(291):
>>>>> index [3530971477] is out of bounds for array of length 0
>>>>> gcc.deh(505): uncaught exception
>>>>> <built-in>: internal compiler error: Abort
>>>>> 0x96d5b6c crash_signal
>>>>> 	/var/gcc/reghunt/master/gcc/toplev.cc:314
>>>>> 
>>>>
>>>> Excellent, and the stage1 compiler?
>>> 
>>> binary    ./prev-gcc/d21
>>> version   v2.100.1
>>> 
>>> predefs   GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions GNU_StackGrowsDown GNU_InlineAsm assert D_PreConditions D_PostConditions D_Invariants D_ModuleInfo D_Exceptions D_TypeInfo all X86 D_HardFloat Posix Solaris CppRuntime_Gcc
>>> 
>>> So identical to the pre-patch one.
>>> 
>>> Just in case, here's the stacktrace of the crashing d21, filtered
>>> through c++filt -s dlang:
>>> 
>>> Thread 2 received signal SIGABRT, Aborted.
>>> [Switching to Thread 1 (LWP 1)]
>>> 0xfe1be2e5 in __lwp_sigqueue () from /lib/libc.so.1
>>> (gdb) bt
>>> #0  0xfe1be2e5 in __lwp_sigqueue () from /lib/libc.so.1
>>> #1  0xfe1b62cf in thr_kill () from /lib/libc.so.1
>>> #2  0xfe0ed662 in raise () from /lib/libc.so.1
>>> #3  0xfe0bae74 in abort () from /lib/libc.so.1
>>> #4  0x0a8e786d in gcc.deh.terminate(immutable(char)[], uint) (msg=..., line=<optimized out>) at /var/gcc/reghunt/master/libphobos/libdruntime/gcc/deh.d:414
>>> #5  0x0a8e7ab3 in _d_throw (object=<optimized out>) at /var/gcc/reghunt/master/libphobos/libdruntime/gcc/deh.d:505
>>> #6  0x0a8edf02 in onArrayIndexError (index=<optimized out>, length=<optimized out>, file=..., line=<optimized out>) at /var/gcc/reghunt/master/libphobos/libdruntime/core/exception.d:650
>>> #7  0x0a8edf3d in _d_arraybounds_indexp (file=<optimized out>, line=<optimized out>, index=<optimized out>, length=<optimized out>) at /var/gcc/reghunt/master/libphobos/libdruntime/core/exception.d:848
>>> #8  0x08ffc17a in dmd.root.stringtable.StringTable!(dmd.identifier.Identifier).StringTable.findSlot(uint, scope const(char)[]) const (this=..., hash=<optimized out>, str=...) at /var/gcc/reghunt/master/gcc/d/dmd/root/stringtable.d:291
>> 
>> Yeah, I don't see how that could trigger, as the value of `i` is always
>> adjusted to `i &= (table.length - 1)` (it uses quadratic probing to search
>> the hash table).
>> 
>> The logic of the compiler doesn't appear to have changed, but the data
>> layout may have, so I'm suspecting an issue that was always there has
>> now surfaced to the fore.
>> 
> 
> Yes, this is data related. The DSO registry picks up nothing in the
> miscompiled stage2 compiler, leaving all data uninitialized.  The stage1
> compiler works, and runs all module constructors ahead of compilation.
> 

Ohh, backtrack on that, analysis is correct, but it is a compiler regression.

The TARGET_D_MINFO_SECTION macros are in elfos.h, which of course no
longer get pulled in to sol2-d.cc after I removed the tm.h include.

Re-adding these two ought to fix the bootstrap for you.

    #include "tm.h"
    #include "memmodel.h"

Iain
Rainer Orth Sept. 7, 2022, 12:40 p.m. UTC | #16
Hi Iain,

>> Yes, this is data related. The DSO registry picks up nothing in the
>> miscompiled stage2 compiler, leaving all data uninitialized.  The stage1
>> compiler works, and runs all module constructors ahead of compilation.
>> 
>
> Ohh, backtrack on that, analysis is correct, but it is a compiler regression.
>
> The TARGET_D_MINFO_SECTION macros are in elfos.h, which of course no
> longer get pulled in to sol2-d.cc after I removed the tm.h include.
>
> Re-adding these two ought to fix the bootstrap for you.
>
>     #include "tm.h"
>     #include "memmodel.h"

it does indeed: with that patch, i386-pc-solaris2.11 and
sparc-sun-solaris2.11 bootstraps completed successfully and test results
are back to normal.

Thanks a lot.

	Rainer
Iain Buclaw Sept. 7, 2022, 1:11 p.m. UTC | #17
Excerpts from Rainer Orth's message of September 7, 2022 2:40 pm:
> Hi Iain,
> 
>>> Yes, this is data related. The DSO registry picks up nothing in the
>>> miscompiled stage2 compiler, leaving all data uninitialized.  The stage1
>>> compiler works, and runs all module constructors ahead of compilation.
>>> 
>>
>> Ohh, backtrack on that, analysis is correct, but it is a compiler regression.
>>
>> The TARGET_D_MINFO_SECTION macros are in elfos.h, which of course no
>> longer get pulled in to sol2-d.cc after I removed the tm.h include.
>>
>> Re-adding these two ought to fix the bootstrap for you.
>>
>>     #include "tm.h"
>>     #include "memmodel.h"
> 
> it does indeed: with that patch, i386-pc-solaris2.11 and
> sparc-sun-solaris2.11 bootstraps completed successfully and test results
> are back to normal.
> 
> Thanks a lot.
> 

I'm just running through various target configurations with memmodel.h
removed, I know it was used to be required for one of the targets
(probably SPARC), though that may have been because of the previously
included tm_p.h header.

Will have a think about a likely follow-up though.

Firstly fixing the outstanding issues with
https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598078.html

Secondly possibly using a different method to coax out the object format
to the D target hooks, or front-end.

Iain.
Rainer Orth Sept. 7, 2022, 1:21 p.m. UTC | #18
Hi Iain,

> Excerpts from Rainer Orth's message of September 7, 2022 2:40 pm:
>> Hi Iain,
>> 
>>>> Yes, this is data related. The DSO registry picks up nothing in the
>>>> miscompiled stage2 compiler, leaving all data uninitialized.  The stage1
>>>> compiler works, and runs all module constructors ahead of compilation.
>>>> 
>>>
>>> Ohh, backtrack on that, analysis is correct, but it is a compiler regression.
>>>
>>> The TARGET_D_MINFO_SECTION macros are in elfos.h, which of course no
>>> longer get pulled in to sol2-d.cc after I removed the tm.h include.
>>>
>>> Re-adding these two ought to fix the bootstrap for you.
>>>
>>>     #include "tm.h"
>>>     #include "memmodel.h"
>> 
>> it does indeed: with that patch, i386-pc-solaris2.11 and
>> sparc-sun-solaris2.11 bootstraps completed successfully and test results
>> are back to normal.
>> 
>> Thanks a lot.
>> 
>
> I'm just running through various target configurations with memmodel.h
> removed, I know it was used to be required for one of the targets
> (probably SPARC), though that may have been because of the previously

almost certainly.  It's in my initial patch to fix D compilation on
Solaris:

	https://gcc.gnu.org/ml/gcc-patches/2018-10/msg01890.html

> included tm_p.h header.
>
> Will have a think about a likely follow-up though.
>
> Firstly fixing the outstanding issues with
> https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598078.html

I belive I had it working on Solaris, at least...

> Secondly possibly using a different method to coax out the object format
> to the D target hooks, or front-end.

	Rainer
diff mbox series

Patch

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 203f0a15187..12d9b5a3be4 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -571,8 +571,6 @@  tm_include_list=@tm_include_list@
 tm_defines=@tm_defines@
 tm_p_file_list=@tm_p_file_list@
 tm_p_include_list=@tm_p_include_list@
-tm_d_file_list=@tm_d_file_list@
-tm_d_include_list=@tm_d_include_list@
 build_xm_file_list=@build_xm_file_list@
 build_xm_include_list=@build_xm_include_list@
 build_xm_defines=@build_xm_defines@
@@ -865,7 +863,6 @@  BCONFIG_H = bconfig.h $(build_xm_file_list)
 CONFIG_H  = config.h  $(host_xm_file_list)
 TCONFIG_H = tconfig.h $(xm_file_list)
 TM_P_H    = tm_p.h    $(tm_p_file_list)
-TM_D_H    = tm_d.h    $(tm_d_file_list)
 GTM_H     = tm.h      $(tm_file_list) insn-constants.h
 TM_H      = $(GTM_H) insn-flags.h $(OPTIONS_H)
 
@@ -1937,7 +1934,6 @@  bconfig.h: cs-bconfig.h ; @true
 tconfig.h: cs-tconfig.h ; @true
 tm.h: cs-tm.h ; @true
 tm_p.h: cs-tm_p.h ; @true
-tm_d.h: cs-tm_d.h ; @true
 
 cs-config.h: Makefile
 	TARGET_CPU_DEFAULT="" \
@@ -1964,11 +1960,6 @@  cs-tm_p.h: Makefile
 	HEADERS="$(tm_p_include_list)" DEFINES="" \
 	$(SHELL) $(srcdir)/mkconfig.sh tm_p.h
 
-cs-tm_d.h: Makefile
-	TARGET_CPU_DEFAULT="" \
-	HEADERS="$(tm_d_include_list)" DEFINES="" \
-	$(SHELL) $(srcdir)/mkconfig.sh tm_d.h
-
 # Don't automatically run autoconf, since configure.ac might be accidentally
 # newer than configure.  Also, this writes into the source directory which
 # might be on a read-only file system.  If configured for maintainer mode
@@ -2783,7 +2774,7 @@  s-gtype: $(EXTRA_GTYPE_DEPS) build/gengtype$(build_exeext) \
                     -r gtype.state
 	$(STAMP) s-gtype
 
-generated_files = config.h tm.h $(TM_P_H) $(TM_D_H) $(TM_H) multilib.h \
+generated_files = config.h tm.h $(TM_P_H) $(TM_H) multilib.h \
        $(simple_generated_h) specs.h \
        tree-check.h genrtl.h insn-modes.h insn-modes-inline.h \
        tm-preds.h tm-constrs.h \
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 4e3b15bb5e9..927d50b4355 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -87,9 +87,6 @@ 
 #  tm_p_file		Location of file with declarations for functions
 #			in $out_file.
 #
-#  tm_d_file		A list of headers with definitions of target hook
-#			macros for the D compiler.
-#
 #  out_file		The name of the machine description C support
 #			file, if different from "$cpu_type/$cpu_type.c".
 #
@@ -559,11 +556,9 @@  xtensa*-*-*)
 esac
 
 tm_file=${cpu_type}/${cpu_type}.h
-tm_d_file=${cpu_type}/${cpu_type}.h
 if test -f ${srcdir}/config/${cpu_type}/${cpu_type}-protos.h
 then
 	tm_p_file=${cpu_type}/${cpu_type}-protos.h
-	tm_d_file="${tm_d_file} ${cpu_type}/${cpu_type}-protos.h"
 fi
 
 extra_modes=
@@ -669,7 +664,6 @@  case ${target} in
 *-*-darwin*)
   tmake_file="t-darwin "
   tm_file="${tm_file} darwin.h"
-  tm_d_file="${tm_d_file} tm-dwarf2.h"
   darwin_os=`echo ${target} | sed 's/.*darwin\([0-9.]*\).*$/\1/'`
   darwin_maj=`expr "$darwin_os" : '\([0-9]*\).*'`
   macos_min=`expr "$darwin_os" : '[0-9]*\.\([0-9]*\).*'`
@@ -3524,7 +3518,6 @@  xstormy16-*-elf)
 	# For historical reasons, the target files omit the 'x'.
 	tm_file="dbxelf.h elfos.h newlib-stdint.h stormy16/stormy16.h"
 	tm_p_file=stormy16/stormy16-protos.h
-	tm_d_file="elfos.h stormy16/stormy16.h"
 	md_file=stormy16/stormy16.md
 	out_file=stormy16/stormy16.cc
 	extra_options=stormy16/stormy16.opt
diff --git a/gcc/config/darwin-d.cc b/gcc/config/darwin-d.cc
index e983883dba6..e88ddc189c3 100644
--- a/gcc/config/darwin-d.cc
+++ b/gcc/config/darwin-d.cc
@@ -18,9 +18,10 @@  along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
+#include "memmodel.h"
+#include "tm_p.h"
 
 /* Implement TARGET_D_OS_VERSIONS for Darwin targets.  */
 
diff --git a/gcc/config/default-d.cc b/gcc/config/default-d.cc
index 2d7abfcba96..6674373793c 100644
--- a/gcc/config/default-d.cc
+++ b/gcc/config/default-d.cc
@@ -18,9 +18,14 @@  along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "memmodel.h"
-#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
 
+/* Do not include tm.h or tm_p.h here; if it is useful for a target to
+   define some macros for the initializer in a header without defining
+   targetcm itself (for example, because of interactions with some
+   hooks depending on the target OS and others on the target
+   architecture), create a separate tm_d.h for only the relevant
+   definitions.  */
+
 struct gcc_targetdm targetdm = TARGETDM_INITIALIZER;
diff --git a/gcc/config/dragonfly-d.cc b/gcc/config/dragonfly-d.cc
index d431638f7da..2ee35c42e99 100644
--- a/gcc/config/dragonfly-d.cc
+++ b/gcc/config/dragonfly-d.cc
@@ -18,9 +18,9 @@  along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
+#include "tm_p.h"
 
 /* Implement TARGET_D_OS_VERSIONS for DragonFly targets.  */
 
diff --git a/gcc/configure b/gcc/configure
index 05efa5b01ef..7d0445178bb 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -652,8 +652,6 @@  use_gcc_stdint
 xm_defines
 xm_include_list
 xm_file_list
-tm_d_include_list
-tm_d_file_list
 tm_p_include_list
 tm_p_file_list
 tm_defines
@@ -5226,12 +5224,16 @@  else
   GNATMAKE="$ac_cv_prog_GNATMAKE"
 fi
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether compiler driver understands Ada" >&5
-$as_echo_n "checking whether compiler driver understands Ada... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether compiler driver understands Ada and is recent enough" >&5
+$as_echo_n "checking whether compiler driver understands Ada and is recent enough... " >&6; }
 if ${acx_cv_cc_gcc_supports_ada+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   cat >conftest.adb <<EOF
+pragma Warnings (Off);
+with System.CRTL;
+pragma Warnings (On);
+use type System.CRTL.int64;
 procedure conftest is begin null; end conftest;
 EOF
 acx_cv_cc_gcc_supports_ada=no
@@ -13009,7 +13011,6 @@  fi
 
 tm_file="${tm_file} defaults.h"
 tm_p_file="${tm_p_file} tm-preds.h"
-tm_d_file="${tm_d_file} defaults.h"
 host_xm_file="auto-host.h ansidecl.h ${host_xm_file}"
 build_xm_file="${build_auto} ansidecl.h ${build_xm_file}"
 # We don't want ansidecl.h in target files, write code there in ISO/GNU C.
@@ -13403,21 +13404,6 @@  for f in $tm_p_file; do
   esac
 done
 
-tm_d_file_list=
-tm_d_include_list="options.h insn-constants.h"
-for f in $tm_d_file; do
-  case $f in
-    defaults.h )
-       tm_d_file_list="${tm_d_file_list} \$(srcdir)/$f"
-       tm_d_include_list="${tm_d_include_list} $f"
-       ;;
-    * )
-       tm_d_file_list="${tm_d_file_list} \$(srcdir)/config/$f"
-       tm_d_include_list="${tm_d_include_list} config/$f"
-       ;;
-  esac
-done
-
 xm_file_list=
 xm_include_list=
 for f in $xm_file; do
@@ -19674,7 +19660,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19677 "configure"
+#line 19663 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19780,7 +19766,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19783 "configure"
+#line 19769 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -31731,8 +31717,6 @@  fi
 
 
 
-
-
 
 
 
diff --git a/gcc/configure.ac b/gcc/configure.ac
index f70b6c24fda..a9006885663 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -2113,7 +2113,6 @@  AC_SUBST(HAVE_AUTO_BUILD)
 
 tm_file="${tm_file} defaults.h"
 tm_p_file="${tm_p_file} tm-preds.h"
-tm_d_file="${tm_d_file} defaults.h"
 host_xm_file="auto-host.h ansidecl.h ${host_xm_file}"
 build_xm_file="${build_auto} ansidecl.h ${build_xm_file}"
 # We don't want ansidecl.h in target files, write code there in ISO/GNU C.
@@ -2356,21 +2355,6 @@  for f in $tm_p_file; do
   esac
 done
 
-tm_d_file_list=
-tm_d_include_list="options.h insn-constants.h"
-for f in $tm_d_file; do
-  case $f in
-    defaults.h )
-       tm_d_file_list="${tm_d_file_list} \$(srcdir)/$f"
-       tm_d_include_list="${tm_d_include_list} $f"
-       ;;
-    * )
-       tm_d_file_list="${tm_d_file_list} \$(srcdir)/config/$f"
-       tm_d_include_list="${tm_d_include_list} config/$f"
-       ;;
-  esac
-done
-
 xm_file_list=
 xm_include_list=
 for f in $xm_file; do
@@ -7361,8 +7345,6 @@  AC_SUBST(tm_include_list)
 AC_SUBST(tm_defines)
 AC_SUBST(tm_p_file_list)
 AC_SUBST(tm_p_include_list)
-AC_SUBST(tm_d_file_list)
-AC_SUBST(tm_d_include_list)
 AC_SUBST(xm_file_list)
 AC_SUBST(xm_include_list)
 AC_SUBST(xm_defines)
diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index c2ef0c836e1..a5491316599 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -34,6 +34,8 @@  along with GCC; see the file COPYING3.  If not see
 #include "diagnostic.h"
 #include "langhooks.h"
 #include "target.h"
+#include "memmodel.h"
+#include "tm_p.h"
 #include "common/common-target.h"
 #include "stringpool.h"
 #include "stor-layout.h"
@@ -508,7 +510,9 @@  d_init_versions (void)
   VersionCondition::addPredefinedGlobalIdent ("all");
 
   /* Emit all target-specific version identifiers.  */
-  targetdm.d_cpu_versions ();
+#ifdef TARGET_D_CPU_VERSIONS
+  TARGET_D_CPU_VERSIONS ();
+#endif
   targetdm.d_os_versions ();
 
   VersionCondition::addPredefinedGlobalIdent ("CppRuntime_Gcc");
diff --git a/gcc/d/d-target.cc b/gcc/d/d-target.cc
index d4350e593e4..7632a0af37b 100644
--- a/gcc/d/d-target.cc
+++ b/gcc/d/d-target.cc
@@ -200,7 +200,9 @@  Target::_init (const Param &)
 
   /* Initialize target info tables, the keys required by the language are added
      last, so that the OS and CPU handlers can override.  */
-  targetdm.d_register_cpu_target_info ();
+#ifdef TARGET_D_REGISTER_CPU_TARGET_INFO
+  TARGET_D_REGISTER_CPU_TARGET_INFO ();
+#endif
   targetdm.d_register_os_target_info ();
   d_add_target_info_handlers (d_language_target_info);
 }
diff --git a/gcc/d/d-target.def b/gcc/d/d-target.def
index 7805942b91e..10b0fe8171a 100644
--- a/gcc/d/d-target.def
+++ b/gcc/d/d-target.def
@@ -28,16 +28,6 @@  HOOK_VECTOR (TARGETDM_INITIALIZER, gcc_targetdm)
 #undef HOOK_PREFIX
 #define HOOK_PREFIX "TARGET_"
 
-/* Environmental version identifiers relating to the target CPU.  */
-DEFHOOK
-(d_cpu_versions,
- "Declare all environmental version identifiers relating to the target CPU\n\
-using the function @code{builtin_version}, which takes a string representing\n\
-the name of the version.  Version identifiers predefined by this hook apply\n\
-to all modules that are being compiled and imported.",
- void, (void),
- hook_void_void)
-
 /* Environmental version identifiers relating to the target OS.  */
 DEFHOOK
 (d_os_versions,
@@ -46,18 +36,6 @@  relating to the target operating system.",
  void, (void),
  hook_void_void)
 
-/* getTargetInfo keys relating to the target CPU.  */
-DEFHOOK
-(d_register_cpu_target_info,
- "Register all target information keys relating to the target CPU using the\n\
-function @code{d_add_target_info_handlers}, which takes a\n\
-@samp{struct d_target_info_spec} (defined in @file{d/d-target.h}).  The keys\n\
-added by this hook are made available at compile time by the\n\
-@code{__traits(getTargetInfo)} extension, the result is an expression\n\
-describing the requested target information.",
- void, (void),
- hook_void_void)
-
 /* getTargetInfo keys relating to the target OS.  */
 DEFHOOK
 (d_register_os_target_info,
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 92bda1a7e14..e2c4e98ed7c 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -11005,26 +11005,28 @@  Return target-specific mangling context of @var{decl} or @code{NULL_TREE}.
 @section D ABI parameters
 @cindex parameters, d abi
 
-@deftypefn {D Target Hook} void TARGET_D_CPU_VERSIONS (void)
-Declare all environmental version identifiers relating to the target CPU
-using the function @code{builtin_version}, which takes a string representing
-the name of the version.  Version identifiers predefined by this hook apply
-to all modules that are being compiled and imported.
-@end deftypefn
+@defmac TARGET_D_CPU_VERSIONS ()
+This function-like macro expands to a block of code that declares all
+environmental version identifiers relating to the target CPU using the function
+@code{builtin_version}, which takes a string representing the name of the
+version.  Version identifiers predefined by this hook apply to all modules that
+are being compiled and imported.
+@end defmac
 
 @deftypefn {D Target Hook} void TARGET_D_OS_VERSIONS (void)
 Similarly to @code{TARGET_D_CPU_VERSIONS}, but is used for versions
 relating to the target operating system.
 @end deftypefn
 
-@deftypefn {D Target Hook} void TARGET_D_REGISTER_CPU_TARGET_INFO (void)
-Register all target information keys relating to the target CPU using the
-function @code{d_add_target_info_handlers}, which takes a
+@defmac TARGET_D_REGISTER_CPU_TARGET_INFO ()
+This function-like macro expands to a block of code that registers all target
+information keys relating to the target CPU using the function
+@code{d_add_target_info_handlers}, which takes a
 @samp{struct d_target_info_spec} (defined in @file{d/d-target.h}).  The keys
 added by this hook are made available at compile time by the
 @code{__traits(getTargetInfo)} extension, the result is an expression
 describing the requested target information.
-@end deftypefn
+@end defmac
 
 @deftypefn {D Target Hook} void TARGET_D_REGISTER_OS_TARGET_INFO (void)
 Same as @code{TARGET_D_CPU_TARGET_INFO}, but is used for keys relating to
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 112462310b1..69a4188c4b2 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -7309,11 +7309,25 @@  floating-point support; they are not included in this mechanism.
 @section D ABI parameters
 @cindex parameters, d abi
 
-@hook TARGET_D_CPU_VERSIONS
+@defmac TARGET_D_CPU_VERSIONS ()
+This function-like macro expands to a block of code that declares all
+environmental version identifiers relating to the target CPU using the function
+@code{builtin_version}, which takes a string representing the name of the
+version.  Version identifiers predefined by this hook apply to all modules that
+are being compiled and imported.
+@end defmac
 
 @hook TARGET_D_OS_VERSIONS
 
-@hook TARGET_D_REGISTER_CPU_TARGET_INFO
+@defmac TARGET_D_REGISTER_CPU_TARGET_INFO ()
+This function-like macro expands to a block of code that registers all target
+information keys relating to the target CPU using the function
+@code{d_add_target_info_handlers}, which takes a
+@samp{struct d_target_info_spec} (defined in @file{d/d-target.h}).  The keys
+added by this hook are made available at compile time by the
+@code{__traits(getTargetInfo)} extension, the result is an expression
+describing the requested target information.
+@end defmac
 
 @hook TARGET_D_REGISTER_OS_TARGET_INFO