From bc12f65932a4bc41495e46d2faa81ee7bf6a2bd1 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Thu, 29 Jul 2010 19:58:35 +0200
Subject: [PATCH] First stab at a port to DragonFly BSD. It builds but fails linking stuff.

---
 GCC/gcc/config.gcc                    |   58 ++++++++++++++
 GCC/gcc/config/dragonfly-nthr.h       |   22 +++++
 GCC/gcc/config/dragonfly-spec.h       |  139 ++++++++++++++++++++++++++++++++
 GCC/gcc/config/dragonfly.h            |   85 ++++++++++++++++++++
 GCC/gcc/config/i386/dragonfly.h       |  140 +++++++++++++++++++++++++++++++++
 GCC/gcc/config/i386/dragonfly64.h     |   43 ++++++++++
 GCC/include/libiberty.h               |    2 +-
 src/common/com/config_host.h          |    2 +-
 src/common/com/em_elf.cxx             |    2 +-
 src/common/util/memory.c              |    2 +-
 src/ipa/local/ipl_main.h              |    2 +-
 src/ipa_link/bfd/targets.c            |    4 +
 src/ipa_link/bfd/targmatch.h          |   18 ++++
 src/ipa_link/ld/configure.host        |    5 +
 src/libelf/config.h                   |    2 +-
 src/libelfutil/xlate_init_elf.c       |    2 +-
 src/libelfutil/xlate_named_init_elf.c |    2 +-
 src/libopenmp/affinity.h              |    2 +-
 src/linux/include/elf_stuff.h         |    2 +-
 19 files changed, 524 insertions(+), 10 deletions(-)
 create mode 100644 GCC/gcc/config/dragonfly-nthr.h
 create mode 100644 GCC/gcc/config/dragonfly-spec.h
 create mode 100644 GCC/gcc/config/dragonfly.h
 create mode 100644 GCC/gcc/config/i386/dragonfly.h
 create mode 100644 GCC/gcc/config/i386/dragonfly64.h

diff --git a/GCC/gcc/config.gcc b/GCC/gcc/config.gcc
index 7cebb52..dd8feac 100755
--- a/GCC/gcc/config.gcc
+++ b/GCC/gcc/config.gcc
@@ -383,6 +383,58 @@ case ${target} in
     "" | yes | posix) thread_file='posix' ;;
   esac
   ;;
+*-*-dragonfly*)
+  # This is the generic ELF configuration of DragonFly.  Later
+  # machine-specific sections may refine and add to this
+  # configuration.
+  #
+  # Due to tm_file entry ordering issues that vary between cpu
+  # architectures, we only define dfly_tm_file to allow the
+  # machine-specific section to dictate the final order of all
+  # entries of tm_file with the minor exception that components
+  # of the tm_file set here will always be of the form:
+  #
+  # dragonfly<version_number>.h [dragonfly-<conf_option>.h ...] dragonfly-spec.h dragonfly.h
+  #
+  # The machine-specific section should not tamper with this
+  # ordering but may order all other entries of tm_file as it
+  # pleases around the provided core setting.
+  gas=yes
+  gnu_ld=yes
+  extra_parts="crtbegin.o crtend.o crtbeginS.o crtendS.o"
+  case ${target} in
+    *-*-dragonfly1 | *-*-dragonfly[1].*)
+      tm_defines="${tm_defines} DFLY_MAJOR=1" ;;
+    *-*-dragonfly2 | *-*-dragonfly[2].*)
+      tm_defines="${tm_defines} DFLY_MAJOR=2" ;;
+    *)
+      echo 'Please update *-*-dragonfly* in gcc/config.gcc'
+      exit 1
+      ;;
+  esac
+  tmake_file="t-slibgcc-elf-ver t-dragonfly"
+  case ${enable_threads} in
+    no)
+      dfly_tm_file="${dfly_tm_file} dragonfly-nthr.h"
+      ;;
+    "" | yes | posix)
+      thread_file='posix'
+      tmake_file="${tmake_file} t-dragonfly-thread"
+#      # Before 5.0, FreeBSD can't bind shared libraries to -lc
+#      # when "optionally" threaded via weak pthread_* checks.
+#      case ${target} in
+#        *-*-freebsd[34] | *-*-freebsd[34].*)
+#          tmake_file="${tmake_file} t-slibgcc-nolc-override"
+#          ;;
+#      esac
+      ;;
+    *)
+      echo 'Unknown thread configuration for DragonFly'
+      exit 1
+      ;;
+  esac
+  dfly_tm_file="${dfly_tm_file} dragonfly-spec.h dragonfly.h"
+  ;;
 *-*-freebsd[12] | *-*-freebsd[12].* | *-*-freebsd*aout*)
   # This is the place-holder for the generic a.out configuration
   # of FreeBSD.  No actual configuration resides here since
@@ -1053,6 +1105,12 @@ i[34567]86-*-beoself* | i[34567]86-*-beos*)
         tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h svr4.h i386/beos-elf.h"
         extra_parts='crtbegin.o crtend.o'
         ;;
+i[34567]86-*-dragonfly*)
+        tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h ${dfly_tm_file} i386/dragonfly.h"
+        ;;
+x86_64-*-dragonfly*)
+        tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h ${dfly_tm_file} i386/x86-64.h i386/dragonfly.h i386/dragonfly64.h"
+        ;;
 i[34567]86-*-freebsd*)
         tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h ${fbsd_tm_file} i386/freebsd.h"
         ;;
diff --git a/GCC/gcc/config/dragonfly-nthr.h b/GCC/gcc/config/dragonfly-nthr.h
new file mode 100644
index 0000000..c50aaec
--- /dev/null
+++ b/GCC/gcc/config/dragonfly-nthr.h
@@ -0,0 +1,22 @@
+/* DragonFly configuration setting for DragonFly systems.
+   Copyright (C) 2001 Free Software Foundation, Inc.
+   Contributed by Loren J. Rittle <ljrittle@acm.org>
+
+This file is part of GCC.
+
+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 2, 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 COPYING.  If not, write to
+the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
+
+#define DFLY_NO_THREADS
diff --git a/GCC/gcc/config/dragonfly-spec.h b/GCC/gcc/config/dragonfly-spec.h
new file mode 100644
index 0000000..b123d48
--- /dev/null
+++ b/GCC/gcc/config/dragonfly-spec.h
@@ -0,0 +1,139 @@
+/* Base configuration file for all DragonFly targets.
+   Copyright (C) 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+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 2, 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 COPYING.  If not, write to
+the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
+
+/* Common DragonFly configuration. 
+   All DragonFly architectures should include this file, which will specify
+   their commonalities.
+   Adapted from gcc/config/freebsd-spec.h by 
+   Sascha Wildner <swildner@dragonflybsd.org>.  */
+
+
+/* In case we need to know.  */
+#define USING_CONFIG_DRAGONFLY_SPEC 1
+
+/* This defines which switch letters take arguments.  On DragonFly, most of
+   the normal cases (defined in gcc.c) apply, and we also have -h* and
+   -z* options (for the linker) (coming from SVR4).
+   We also have -R (alias --rpath), no -z, --soname (-h), --assert etc.  */
+
+#define DFLY_SWITCH_TAKES_ARG(CHAR)					\
+  (DEFAULT_SWITCH_TAKES_ARG (CHAR)					\
+    || (CHAR) == 'h'							\
+    || (CHAR) == 'z' /* ignored by ld */				\
+    || (CHAR) == 'R')
+
+/* This defines which multi-letter switches take arguments.  */
+
+#define DFLY_WORD_SWITCH_TAKES_ARG(STR)					\
+  (DEFAULT_WORD_SWITCH_TAKES_ARG (STR)					\
+   || !strcmp ((STR), "rpath") || !strcmp ((STR), "rpath-link")		\
+   || !strcmp ((STR), "soname") || !strcmp ((STR), "defsym") 		\
+   || !strcmp ((STR), "assert") || !strcmp ((STR), "dynamic-linker"))
+
+#define DFLY_TARGET_OS_CPP_BUILTINS()					\
+  do									\
+    {									\
+	builtin_define_with_int_value ("__DragonFly__", DFLY_MAJOR);	\
+	builtin_define_with_int_value ("__DragonFly_cc_version", "100001"); \
+	builtin_define ("__ELF__");					\
+	builtin_define_std ("unix");					\
+	builtin_define ("__KPRINTF_ATTRIBUTE__");		       	\
+	builtin_define ("__tune_i386__");				\
+	builtin_assert ("system=unix");					\
+	builtin_assert ("system=bsd");					\
+	builtin_assert ("system=DragonFly");				\
+	DFLY_TARGET_CPU_CPP_BUILTINS();					\
+    }									\
+  while (0)
+
+/* Define the default DragonFly-specific per-CPU hook code.  */
+#define DFLY_TARGET_CPU_CPP_BUILTINS() do {} while (0)
+
+/* Provide a CPP_SPEC appropriate for DragonBSD.  We just deal with the GCC 
+   option `-posix', and PIC issues.  */
+
+#define DFLY_CPP_SPEC "							\
+  %(cpp_cpu)								\
+  %(cpp_arch)								\
+  %{posix:-D_POSIX_SOURCE}"
+
+/* Provide a STARTFILE_SPEC appropriate for DragonFly.  Here we add
+   the magical crtbegin.o file (see crtstuff.c) which provides part 
+	of the support for getting C++ file-scope static object constructed 
+	before entering `main'.  */
+   
+#define DFLY_STARTFILE_SPEC \
+  "%{!shared: \
+     %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} \
+		       %{!p:%{profile:gcrt1.o%s} \
+			 %{!profile:crt1.o%s}}}} \
+   crti.o%s %{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}"
+
+/* Provide a ENDFILE_SPEC appropriate for DragonFly.  Here we tack on
+   the magical crtend.o file (see crtstuff.c) which provides part of 
+	the support for getting C++ file-scope static object constructed 
+	before entering `main', followed by a normal "finalizer" file, 
+	`crtn.o'.  */
+
+#define DFLY_ENDFILE_SPEC \
+  "%{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s"
+
+/* Provide a LIB_SPEC appropriate for DragonFly as configured and as
+   required by the user-land thread model.  */
+
+/* XXX Handle our old -libc_r?
+
+/* Provide a LIB_SPEC appropriate for DragonFly.  Just select the appropriate
+   libc, depending on whether we're doing profiling or need threads support.
+   (similar to the default, except no -lg, and no -p).  */
+
+#ifdef DFLY_NO_THREADS
+#define DFLY_LIB_SPEC "							\
+  %{pthread: %eThe -pthread option is only supported on DragonFly when gcc \
+is built with the --enable-threads configure-time option.}		\
+  %{!shared:								\
+    %{!pg: -lc}								\
+    %{pg:  -lc_p}							\
+  }"
+#else
+#if 0 /* XXX DFLY_MAJOR < xx */
+#define FBSD_LIB_SPEC "							\
+  %{!shared:								\
+    %{!pg:								\
+      %{!pthread:-lc}							\
+      %{pthread:-lc_r}}							\
+    %{pg:								\
+      %{!pthread:-lc_p}							\
+      %{pthread:-lc_r_p}}						\
+  }"
+#else
+#define DFLY_LIB_SPEC "							\
+  %{!shared:								\
+    %{!pg: %{pthread:-lpthread} -lc}					\
+    %{pg:  %{pthread:-lpthread_p} -lc_p}				\
+  }"
+#endif
+#endif
+
+#if 0 /* XXX DFLY_MAJOR < xx */
+#define DFLY_DYNAMIC_LINKER "/usr/libexec/ld-elf.so.1"
+#else
+#define DFLY_DYNAMIC_LINKER "/usr/libexec/ld-elf.so.2"
+#endif
diff --git a/GCC/gcc/config/dragonfly.h b/GCC/gcc/config/dragonfly.h
new file mode 100644
index 0000000..be92d9f
--- /dev/null
+++ b/GCC/gcc/config/dragonfly.h
@@ -0,0 +1,85 @@
+/* Base configuration file for all DragonFly targets.
+   Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+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 2, 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 COPYING.  If not, write to
+the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
+
+/* Common DragonFly configuration. 
+   All DragonFly architectures should include this file, which will specify
+   their commonalities.
+   Adapted from gcc/config/freebsd.h by 
+   Sascha Wildner <swildner@dragonflybsd.org>.  */
+
+
+/* In case we need to know.  */
+#define USING_CONFIG_DRAGONFLY 1
+
+/* This defines which switch letters take arguments.  On DragonFly, most of
+   the normal cases (defined in gcc.c) apply, and we also have -h* and
+   -z* options (for the linker) (coming from SVR4).
+   We also have -R (alias --rpath), no -z, --soname (-h), --assert etc.  */
+
+#undef  SWITCH_TAKES_ARG
+#define SWITCH_TAKES_ARG(CHAR) (DFLY_SWITCH_TAKES_ARG(CHAR))
+
+#undef  WORD_SWITCH_TAKES_ARG
+#define WORD_SWITCH_TAKES_ARG(STR) (DFLY_WORD_SWITCH_TAKES_ARG(STR))
+
+#undef  TARGET_OS_CPP_BUILTINS
+#define TARGET_OS_CPP_BUILTINS() DFLY_TARGET_OS_CPP_BUILTINS()
+
+#undef  CPP_SPEC
+#define CPP_SPEC DFLY_CPP_SPEC
+
+#undef  STARTFILE_SPEC
+#define STARTFILE_SPEC DFLY_STARTFILE_SPEC
+
+#undef  ENDFILE_SPEC
+#define ENDFILE_SPEC DFLY_ENDFILE_SPEC
+
+#undef  LIB_SPEC
+#define LIB_SPEC DFLY_LIB_SPEC
+
+
+/************************[  Target stuff  ]***********************************/
+
+/* All DragonFly Architectures support the ELF object file format.  */
+#undef  OBJECT_FORMAT_ELF
+#define OBJECT_FORMAT_ELF
+
+/* Don't assume anything about the header files.  */
+#undef  NO_IMPLICIT_EXTERN_C
+#define NO_IMPLICIT_EXTERN_C	1
+
+/* Make gcc agree with DragonFly's standard headers (<machine/ansi.h>, etc...)  */
+
+#undef  WCHAR_TYPE
+#define WCHAR_TYPE "int"
+
+#define MATH_LIBRARY_PROFILE    "-lm_p"
+
+/* Code generation parameters.  */
+
+/* Use periods rather than dollar signs in special g++ assembler names.
+   This ensures the configuration knows our system correctly so we can link
+   with libraries compiled with the native cc.  */
+#undef NO_DOLLAR_IN_LABEL
+
+/* Used by libgcc2.c.  We support file locking with fcntl / F_SETLKW.
+   This enables the test coverage code to use file locking when exiting a
+   program, which avoids race conditions if the program has forked.  */
+#define TARGET_POSIX_IO
diff --git a/GCC/gcc/config/i386/dragonfly.h b/GCC/gcc/config/i386/dragonfly.h
new file mode 100644
index 0000000..79bf69a
--- /dev/null
+++ b/GCC/gcc/config/i386/dragonfly.h
@@ -0,0 +1,140 @@
+/* Definitions for Intel 386 running DragonFly with ELF format
+   Copyright (C) 1996, 2000, 2002, 2004 Free Software Foundation, Inc.
+   Contributed by Eric Youngdale.
+   Modified for stabs-in-ELF by H.J. Lu.
+   Adapted from FreeBSD version by Sascha Wildner <swildner@dragonflybsd.org>.
+
+This file is part of GCC.
+
+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 2, 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 COPYING.  If not, write to
+the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
+
+
+#define TARGET_VERSION fprintf (stderr, " (i386 DragonFly/ELF)");
+
+/* Override the default comment-starter of "/".  */
+#undef  ASM_COMMENT_START
+#define ASM_COMMENT_START "#"
+
+#undef  ASM_APP_ON
+#define ASM_APP_ON "#APP\n"
+
+#undef  ASM_APP_OFF
+#define ASM_APP_OFF "#NO_APP\n"
+
+#undef  DBX_REGISTER_NUMBER
+#define DBX_REGISTER_NUMBER(n) \
+  (TARGET_64BIT ? dbx64_register_map[n] : svr4_dbx_register_map[n])
+
+#undef  NO_PROFILE_COUNTERS
+#define NO_PROFILE_COUNTERS	1
+
+/* Tell final.c that we don't need a label passed to mcount.  */
+
+#undef  MCOUNT_NAME
+#define MCOUNT_NAME ".mcount"
+
+/* Make gcc agree with <machine/ansi.h>.  */
+
+#undef  SIZE_TYPE
+#define SIZE_TYPE	(TARGET_64BIT ? "long unsigned int" : "unsigned int")
+ 
+#undef  PTRDIFF_TYPE
+#define PTRDIFF_TYPE	(TARGET_64BIT ? "long int" : "int")
+  
+#undef  WCHAR_TYPE_SIZE
+#define WCHAR_TYPE_SIZE	(TARGET_64BIT ? 32 : BITS_PER_WORD)
+
+#undef  SUBTARGET_EXTRA_SPECS	/* i386.h bogusly defines it.  */
+#define SUBTARGET_EXTRA_SPECS \
+  { "dfly_dynamic_linker", DFLY_DYNAMIC_LINKER }
+    
+/* Provide a STARTFILE_SPEC appropriate for DragonFly.  Here we add
+   the magical crtbegin.o file (see crtstuff.c) which provides part 
+	of the support for getting C++ file-scope static object constructed 
+	before entering `main'.  */
+   
+#undef	STARTFILE_SPEC
+#define STARTFILE_SPEC \
+  "%{!shared: \
+     %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} \
+		       %{!p:%{profile:gcrt1.o%s} \
+			 %{!profile:crt1.o%s}}}} \
+   crti.o%s %{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}"
+
+/* Provide a ENDFILE_SPEC appropriate for DragonFly.  Here we tack on
+   the magical crtend.o file (see crtstuff.c) which provides part of 
+	the support for getting C++ file-scope static object constructed 
+	before entering `main', followed by a normal "finalizer" file, 
+	`crtn.o'.  */
+
+#undef	ENDFILE_SPEC
+#define ENDFILE_SPEC \
+  "%{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s"
+
+/* Provide a LINK_SPEC appropriate for DragonFly.  Here we provide support
+   for the special GCC options -static and -shared, which allow us to
+   link things in one of these three modes by applying the appropriate
+   combinations of options at link-time. We like to support here for
+   as many of the other GNU linker options as possible. But I don't
+   have the time to search for those flags. I am sure how to add
+   support for -soname shared_object_name. H.J.
+
+   I took out %{v:%{!V:-V}}. It is too much :-(. They can use
+   -Wl,-V.
+
+   When the -shared link option is used a final link is not being
+   done.  */
+
+#undef	LINK_SPEC
+#define LINK_SPEC "\
+  %{p:%nconsider using `-pg' instead of `-p' with gprof(1)} \
+  %{v:-V} \
+  %{assert*} %{R*} %{rpath*} %{defsym*} \
+  %{shared:-Bshareable %{h*} %{soname*}} \
+    %{!shared: \
+      %{!static: \
+        %{rdynamic:-export-dynamic} \
+        %{!dynamic-linker:-dynamic-linker %(dfly_dynamic_linker) }} \
+    %{static:-Bstatic}} \
+  %{symbolic:-Bsymbolic}"
+
+/* A C statement to output to the stdio stream FILE an assembler
+   command to advance the location counter to a multiple of 1<<LOG
+   bytes if it is within MAX_SKIP bytes.
+
+   This is used to align code labels according to Intel recommendations.  */
+
+#ifdef HAVE_GAS_MAX_SKIP_P2ALIGN
+#undef  ASM_OUTPUT_MAX_SKIP_ALIGN
+#define ASM_OUTPUT_MAX_SKIP_ALIGN(FILE, LOG, MAX_SKIP)					\
+  if ((LOG) != 0) {														\
+    if ((MAX_SKIP) == 0) fprintf ((FILE), "\t.p2align %d\n", (LOG));	\
+    else fprintf ((FILE), "\t.p2align %d,,%d\n", (LOG), (MAX_SKIP));	\
+  }
+#endif
+
+/* Don't default to pcc-struct-return, we want to retain compatibility with
+   older gcc versions AND pcc-struct-return is nonreentrant.
+   (even though the SVR4 ABI for the i386 says that records and unions are
+   returned in memory).  */
+
+#undef  DEFAULT_PCC_STRUCT_RETURN
+#define DEFAULT_PCC_STRUCT_RETURN 0
+
+/* DragonFly sets the rounding precision of the FPU to 53 bits.  Let the
+   compiler get the contents of <float.h> and std::numeric_limits correct.  */
+#undef TARGET_96_ROUND_53_LONG_DOUBLE
+#define TARGET_96_ROUND_53_LONG_DOUBLE (!TARGET_64BIT)
diff --git a/GCC/gcc/config/i386/dragonfly64.h b/GCC/gcc/config/i386/dragonfly64.h
new file mode 100644
index 0000000..f39e200
--- /dev/null
+++ b/GCC/gcc/config/i386/dragonfly64.h
@@ -0,0 +1,43 @@
+/* Definitions for AMD x86-64 running DragonFly with ELF format
+   Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+   Adapted from FreeBSD version by Sascha Wildner <swildner@dragonflybsd.org>.
+
+This file is part of GCC.
+
+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 2, 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 COPYING.  If not, write to
+the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
+
+
+#undef  TARGET_VERSION
+#define TARGET_VERSION fprintf (stderr, " (DragonFly/x86-64 ELF)");
+
+#define SUBTARGET_EXTRA_SPECS \
+  { "dfly_dynamic_linker", dfly_DYNAMIC_LINKER }
+
+/* Provide a LINK_SPEC appropriate for the FreeBSD/x86-64 ELF target.
+   Adapted from FreeBSD version.  */
+
+#undef	LINK_SPEC
+#define LINK_SPEC "\
+  %{m32:-m elf_i386_dfly} \
+  %{v:-V} \
+  %{assert*} %{R*} %{rpath*} %{defsym*} \
+  %{shared:-Bshareable %{h*} %{soname*}} \
+    %{!shared: \
+      %{!static: \
+        %{rdynamic:-export-dynamic} \
+	%{!dynamic-linker:-dynamic-linker %(dfly_dynamic_linker) }} \
+    %{static:-Bstatic}} \
+  %{symbolic:-Bsymbolic}"
diff --git a/GCC/include/libiberty.h b/GCC/include/libiberty.h
index c25667c..a23bc51 100644
--- a/GCC/include/libiberty.h
+++ b/GCC/include/libiberty.h
@@ -97,7 +97,7 @@ extern void expandargv PARAMS ((int *, char ***));
    to find the declaration so provide a fully prototyped one.  If it
    is 1, we found it so don't provide any declaration at all.  */
 #if !HAVE_DECL_BASENAME
-#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (__MINGW32__) || defined (HAVE_DECL_BASENAME)
+#if defined (__GNU_LIBRARY__ ) || defined (__linux__) || defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__NetBSD__) || defined (__DragonFly__) || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (__MINGW32__) || defined (HAVE_DECL_BASENAME)
 extern char *basename (const char *);
 #else
 /* Do not allow basename to be used if there is no prototype seen.  We
diff --git a/src/common/com/config_host.h b/src/common/com/config_host.h
index 71444b1..5ab2403 100644
--- a/src/common/com/config_host.h
+++ b/src/common/com/config_host.h
@@ -66,7 +66,7 @@ static char *config_host_rcs_id = "$Source$ $Revision$";
 /* What is the byte sex of the host?  Note that the variable
  * Host_Byte_Sex is set based on this definition in config_host.c.
  */
-#if !(defined(linux) || defined(BUILD_OS_DARWIN) || defined(__FreeBSD__) || defined(__sun))
+#if !(defined(linux) || defined(BUILD_OS_DARWIN) || defined(__FreeBSD__) || defined(__sun) || defined(__DragonFly__))
 #define HOST_IS_BIG_ENDIAN	1
 #define HOST_IS_LITTLE_ENDIAN	0
 #else
diff --git a/src/common/com/em_elf.cxx b/src/common/com/em_elf.cxx
index f0fbcc6..1537cfd 100644
--- a/src/common/com/em_elf.cxx
+++ b/src/common/com/em_elf.cxx
@@ -72,7 +72,7 @@
 #include "em_elf.h"
 #include "targ_em_elf.h"
 
-#if defined(__FreeBSD__) || defined(__sun)
+#if defined(__FreeBSD__) || defined(__sun) || defined(__DragonFly__)
 /* from mips.h */
 #define SHF_MIPS_NOSTRIP	0x08000000
 #define EF_MIPS_XGOT		0x00000008
diff --git a/src/common/util/memory.c b/src/common/util/memory.c
index 09450c5..781a8c2 100644
--- a/src/common/util/memory.c
+++ b/src/common/util/memory.c
@@ -31,7 +31,7 @@
 
 
 #include <sys/types.h>
-#if defined(BUILD_OS_DARWIN) || defined(__FreeBSD__)
+#if defined(BUILD_OS_DARWIN) || defined(__FreeBSD__) || defined(__DragonFly__)
 #include <stdlib.h>
 #else /* defined(BUILD_OS_DARWIN) */
 #include <malloc.h>
diff --git a/src/ipa/local/ipl_main.h b/src/ipa/local/ipl_main.h
index 6fadca8..fb486fd 100644
--- a/src/ipa/local/ipl_main.h
+++ b/src/ipa/local/ipl_main.h
@@ -58,7 +58,7 @@ extern BOOL DoPreopt;
 extern WN_MAP Summary_Map;
 extern WN_MAP Stmt_Map;
 
-#if defined(__linux__) || defined(BUILD_OS_DARWIN) || defined(__FreeBSD__) || defined(__sun) || defined(__NetBSD__) || defined(__OpenBSD__)
+#if defined(__linux__) || defined(BUILD_OS_DARWIN) || defined(__FreeBSD__) || defined(__sun) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
 #define USE_ELF_SYMBOL_TABLE
 #endif
 
diff --git a/src/ipa_link/bfd/targets.c b/src/ipa_link/bfd/targets.c
index 96fab09..e8f27f7 100644
--- a/src/ipa_link/bfd/targets.c
+++ b/src/ipa_link/bfd/targets.c
@@ -580,6 +580,7 @@ extern const bfd_target bfd_elf32_hppa_linux_vec;
 extern const bfd_target bfd_elf32_hppa_nbsd_vec;
 extern const bfd_target bfd_elf32_hppa_vec;
 extern const bfd_target bfd_elf32_i370_vec;
+extern const bfd_target bfd_elf32_i386_dragonfly_vec;
 extern const bfd_target bfd_elf32_i386_freebsd_vec;
 extern const bfd_target bfd_elf32_i386_vxworks_vec;
 extern const bfd_target bfd_elf32_i386_vec;
@@ -677,6 +678,7 @@ extern const bfd_target bfd_elf64_sparc_vec;
 extern const bfd_target bfd_elf64_sparc_freebsd_vec;
 extern const bfd_target bfd_elf64_tradbigmips_vec;
 extern const bfd_target bfd_elf64_tradlittlemips_vec;
+extern const bfd_target bfd_elf64_x86_64_dragonfly_vec;
 extern const bfd_target bfd_elf64_x86_64_freebsd_vec;
 extern const bfd_target bfd_elf64_x86_64_vec;
 extern const bfd_target bfd_mmo_vec;
@@ -900,6 +902,7 @@ static const bfd_target * const _bfd_target_vector[] =
 	&bfd_elf32_hppa_nbsd_vec,
 	&bfd_elf32_hppa_vec,
 	&bfd_elf32_i370_vec,
+	&bfd_elf32_i386_dragonfly_vec,
 	&bfd_elf32_i386_freebsd_vec,
 	&bfd_elf32_i386_vxworks_vec,
 	&bfd_elf32_i386_vec,
@@ -1006,6 +1009,7 @@ static const bfd_target * const _bfd_target_vector[] =
 	&bfd_elf64_sparc_freebsd_vec,
 	&bfd_elf64_tradbigmips_vec,
 	&bfd_elf64_tradlittlemips_vec,
+	&bfd_elf64_x86_64_dragonfly_vec,
 	&bfd_elf64_x86_64_freebsd_vec,
 	&bfd_elf64_x86_64_vec,
 	&bfd_mmo_vec,
diff --git a/src/ipa_link/bfd/targmatch.h b/src/ipa_link/bfd/targmatch.h
index 8004c33..902cd6c 100644
--- a/src/ipa_link/bfd/targmatch.h
+++ b/src/ipa_link/bfd/targmatch.h
@@ -713,6 +713,15 @@
 
 
     
+#if !defined (SELECT_VECS) || defined (HAVE_bfd_elf32_i386_dragonfly_vec)
+
+{ "i[3-7]86-*-dragonfly*",
+&bfd_elf32_i386_dragonfly_vec },
+#endif
+
+
+
+    
 #if !defined (SELECT_VECS) || defined (HAVE_bfd_elf32_i386_vec)
 
 { "i[3-7]86-*-netbsdelf*", NULL },{ "i[3-7]86-*-netbsd*-gnu*", NULL },{ "i[3-7]86-*-knetbsd*-gnu",
@@ -793,6 +802,15 @@
 
 
     
+#if !defined (SELECT_VECS) || defined (HAVE_bfd_elf64_x86_64_dragonfly_vec)
+
+{ "x86_64-*-dragonfly*",
+&bfd_elf64_x86_64_dragonfly_vec },
+#endif
+
+
+
+    
 #if !defined (SELECT_VECS) || defined (HAVE_bfd_elf64_x86_64_vec)
 
 { "x86_64-*-netbsd*", NULL },{ "x86_64-*-openbsd*",
diff --git a/src/ipa_link/ld/configure.host b/src/ipa_link/ld/configure.host
index f9f080f..4715fe6 100644
--- a/src/ipa_link/ld/configure.host
+++ b/src/ipa_link/ld/configure.host
@@ -23,6 +23,11 @@ case "${host}" in
   HOSTING_LIBS='-L`dirname \`${CC} --print-file-name=libc.so\`` '"$HOSTING_LIBS"' `if [ -f ../gcc/crtend.o ]; then echo ../gcc/crtend.o; else ${CC} --print-file-name=crtend.o; fi` `${CC} --print-file-name=crtn.o`'
   ;;
 
+*-*-dragonfly*)
+  HOSTING_CRT0='-dynamic-linker `[ -f \`${CC} --print-prog-name=ld-elf.so.2\` ] || echo /usr/libexec/``${CC} --print-prog-name=ld-elf.so.2` `${CC} --print-file-name=crt1.o` `${CC} --print-file-name=crti.o` `${CC} --print-file-name=crtbegin.o`'
+  HOSTING_LIBS='-L`dirname \`${CC} --print-file-name=libc.so\`` '"$HOSTING_LIBS"' `if [ -f ../gcc41/crtend.o ]; then echo ../gcc41/crtend.o; else ${CC} --print-file-name=crtend.o; fi` `${CC} --print-file-name=crtn.o`'
+  ;;
+
 *-*-linux*aout* | *-*-linux*oldld)
   HOSTING_CRT0=/usr/lib/crt0.o
   ;;
diff --git a/src/libelf/config.h b/src/libelf/config.h
index a3caea4..21f2834 100644
--- a/src/libelf/config.h
+++ b/src/libelf/config.h
@@ -29,7 +29,7 @@
 /* #undef HAVE_CATGETS */
 
 /* Define if you have the gettext function. */
-#if defined(BUILD_OS_DARWIN) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(BUILD_OS_DARWIN) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
 #undef HAVE_GETTEXT
 #else /* defined(BUILD_OS_DARWIN) */
 #define HAVE_GETTEXT 1
diff --git a/src/libelfutil/xlate_init_elf.c b/src/libelfutil/xlate_init_elf.c
index 611a52b..0872a29 100644
--- a/src/libelfutil/xlate_init_elf.c
+++ b/src/libelfutil/xlate_init_elf.c
@@ -33,7 +33,7 @@ $Date$
 */
 #include "xlateincl.h"
 
-#if defined(__FreeBSD__) || defined(__sun)
+#if defined(__FreeBSD__) || defined(__sun) || defined(__DragonFly__)
 /* from elf_stuff.h */
 #define SHT_MIPS_XLATE		0x70000024
 #define SHT_MIPS_XLATE_DEBUG	0x70000025
diff --git a/src/libelfutil/xlate_named_init_elf.c b/src/libelfutil/xlate_named_init_elf.c
index 89c48ef..1e42904 100644
--- a/src/libelfutil/xlate_named_init_elf.c
+++ b/src/libelfutil/xlate_named_init_elf.c
@@ -35,7 +35,7 @@ $Date$
 */
 #include "xlateincl.h"
 
-#if defined(__FreeBSD__) || defined(__sun)
+#if defined(__FreeBSD__) || defined(__sun) || defined(__DragonFly__)
 /* from elf_stuff.h */
 #define SHT_MIPS_XLATE		0x70000024
 #define SHT_MIPS_XLATE_DEBUG	0x70000025
diff --git a/src/libopenmp/affinity.h b/src/libopenmp/affinity.h
index be5bdd3..fd764af 100644
--- a/src/libopenmp/affinity.h
+++ b/src/libopenmp/affinity.h
@@ -24,7 +24,7 @@
 #ifndef __pmp_affinity_h
 #define __pmp_affinity_h
 
-#if defined(BUILD_OS_DARWIN) || defined(__FreeBSD__)
+#if defined(BUILD_OS_DARWIN) || defined(__FreeBSD__) || defined(__DragonFly__)
 #include <unistd.h>
 #else /* defined(BUILD_OS_DARWIN) */
 #include <linux/unistd.h>
diff --git a/src/linux/include/elf_stuff.h b/src/linux/include/elf_stuff.h
index 0ecb240..d6dd2f1 100644
--- a/src/linux/include/elf_stuff.h
+++ b/src/linux/include/elf_stuff.h
@@ -1700,7 +1700,7 @@ extern Elf64_Conflict   _ConflictList64 [];
 }
 #endif /* __cplusplus */
 
-#if defined(__FreeBSD__) || defined(__sun)
+#if defined(__FreeBSD__) || defined(__sun) || defined(__DragonFly__)
 
 #define SHF_IA_64_SHORT		0x10000000	/* section near gp */
 #define SHF_MIPS_NAMES		0x02000000
-- 
1.7.0.5

