From a8e68029244bf2bcafbb82c7419438d185dc4c5d Mon Sep 17 00:00:00 2001
From: Daniel Jacobowitz <dan@codesourcery.com>
Date: Thu, 18 Nov 2004 01:07:18 +0000
Subject: [PATCH] configure.ac (i[34567]86-*-solaris2.1[0-9]*): Set
 need_64bit_hwint=yes.

libcpp:
2004-11-18  Daniel Jacobowitz  <dan@codesourcery.com>
            Mark Mitchell  <mark@codesourcery.com>

	* configure.ac (i[34567]86-*-solaris2.1[0-9]*): Set
	need_64bit_hwint=yes.
	* configure: Regenerate.

gcc:
2004-11-18  Daniel Jacobowitz  <dan@codesourcery.com>
            Mark Mitchell  <mark@codesourcery.com>

	* config/i386/sol2-10.h, config/i386/t-sol2-10: New files.
	* config/i386/i386.c (i386_solaris_elf_named_section): New
	function.
	* config.gcc (i[34567]86-*-solaris2*): Handle Solaris 2.10.
	* config/i386/sol2.h (ASM_PREFERRED_EH_DATA_FORMAT): Handle
	64-bit.
	(ASM_QUAD): Don't undefine for biarch targets.
	* config/i386/t-sol2: Introduce multilib support.

gcc/testsuite:
2004-11-18  Daniel Jacobowitz  <dan@codesourcery.com>
            Mark Mitchell  <mark@codesourcery.com>

	* testsuite/gcc.dg/pragma-init-fini-2.c: New test.

Co-Authored-By: Mark Mitchell <mark@codesourcery.com>

From-SVN: r90839
---
 gcc/ChangeLog                             | 12 +++
 gcc/config.gcc                            | 16 +++-
 gcc/config/i386/i386.c                    | 21 +++++
 gcc/config/i386/sol2-10.h                 | 99 +++++++++++++++++++++++
 gcc/config/i386/sol2.h                    | 13 +--
 gcc/config/i386/t-sol2                    | 22 ++---
 gcc/config/i386/t-sol2-10                 | 11 +++
 gcc/testsuite/ChangeLog                   |  5 ++
 gcc/testsuite/gcc.dg/pragma-init-fini-2.c | 15 ++++
 libcpp/ChangeLog                          |  7 ++
 libcpp/configure                          |  1 +
 libcpp/configure.ac                       |  1 +
 12 files changed, 206 insertions(+), 17 deletions(-)
 create mode 100644 gcc/config/i386/sol2-10.h
 create mode 100644 gcc/config/i386/t-sol2-10
 create mode 100644 gcc/testsuite/gcc.dg/pragma-init-fini-2.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 47390067194b..310f99b414e5 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,15 @@
+2004-11-18  Daniel Jacobowitz  <dan@codesourcery.com>
+            Mark Mitchell  <mark@codesourcery.com>
+
+	* config/i386/sol2-10.h, config/i386/t-sol2-10: New files.
+	* config/i386/i386.c (i386_solaris_elf_named_section): New
+	function.
+	* config.gcc (i[34567]86-*-solaris2*): Handle Solaris 2.10.
+	* config/i386/sol2.h (ASM_PREFERRED_EH_DATA_FORMAT): Handle
+	64-bit.
+	(ASM_QUAD): Don't undefine for biarch targets.
+	* config/i386/t-sol2: Introduce multilib support.
+
 2004-11-18  Ben Elliston  <bje@au.ibm.com>
 
 	* cgraphunit.c: Replace "it's" with "its" and fix a typo.
diff --git a/gcc/config.gcc b/gcc/config.gcc
index c1820ccb8315..0a1e5f471add 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1020,6 +1020,7 @@ i[34567]86-*-solaris2*)
 	tm_p_file="${tm_p_file} sol2-protos.h"
 	if test x$gnu_ld = xyes; then
 		tmake_file="$tmake_file t-slibgcc-elf-ver"
+		tm_defines="${tm_defines} TARGET_GNU_LD=1"
 	else
 		tmake_file="$tmake_file t-slibgcc-sld"
 	fi
@@ -1028,7 +1029,20 @@ i[34567]86-*-solaris2*)
 		tm_file="$tm_file tm-dwarf2.h"
 		;;
 	esac
-	extra_parts="crt1.o crti.o crtn.o gcrt1.o gmon.o crtbegin.o crtend.o"
+	case ${target} in
+	*-*-solaris2.1[0-9])
+		tm_file="${tm_file} i386/x86-64.h i386/sol2-10.h"
+		tm_defines="${tm_defines} TARGET_BI_ARCH=1"
+		tmake_file="$tmake_file i386/t-sol2-10"
+		need_64bit_hwint=yes
+		# Solaris 2.10 provides crt1.o, crti.o, crtn.o, and gcrt1.o as 
+		# part of the base system.
+		extra_parts="gmon.o crtbegin.o crtend.o"
+		;;
+	*)
+		extra_parts="crt1.o crti.o crtn.o gcrt1.o gmon.o crtbegin.o crtend.o"
+		;;
+	esac
 	case ${enable_threads}:${have_pthread_h}:${have_thread_h} in
 	  "":yes:* | yes:yes:* ) thread_file=posix ;;
 	  "":*:yes | yes:*:yes ) thread_file=solaris ;;
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 71c9d9838e0f..cb807b05ee50 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -927,6 +927,7 @@ static bool ix86_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
 #if defined (DO_GLOBAL_CTORS_BODY) && defined (HAS_INIT_SECTION)
 static void ix86_svr3_asm_out_constructor (rtx, int);
 #endif
+static void i386_solaris_elf_named_section (const char *, unsigned int, tree);
 
 /* Register class used for passing given 64bit part of the argument.
    These represent classes as documented by the PS ABI, with the exception
@@ -15270,4 +15271,24 @@ void ix86_emit_i387_log1p (rtx op0, rtx op1)
   emit_label (label2);
 }
 
+/* Solaris named-section hook.  Parameters are as for
+   named_section_real.  */
+
+static void
+i386_solaris_elf_named_section (const char *name, unsigned int flags,
+				tree decl)
+{
+  /* With Binutils 2.15, the "@unwind" marker must be specified on
+     every occurrence of the ".eh_frame" section, not just the first
+     one.  */
+  if (TARGET_64BIT
+      && strcmp (name, ".eh_frame") == 0)
+    {
+      fprintf (asm_out_file, "\t.section\t%s,\"%s\",@unwind\n", name,
+	       flags & SECTION_WRITE ? "aw" : "a");
+      return;
+    }
+  default_elf_asm_named_section (name, flags, decl);
+}
+
 #include "gt-i386.h"
diff --git a/gcc/config/i386/sol2-10.h b/gcc/config/i386/sol2-10.h
new file mode 100644
index 000000000000..3576678589b9
--- /dev/null
+++ b/gcc/config/i386/sol2-10.h
@@ -0,0 +1,99 @@
+/* Solaris 10 configuration.
+   Copyright (C) 2004 Free Software Foundation, Inc.
+   Contributed by CodeSourcery, LLC.
+
+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, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#undef ASM_COMMENT_START
+#define ASM_COMMENT_START "/"
+
+#undef ASM_SPEC
+#define ASM_SPEC "%{v:-V} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Yd,*} " \
+		 "%{Wa,*:%*} %{m32:--32} %{m64:--64} -s %(asm_cpu)"
+
+#undef NO_PROFILE_COUNTERS
+
+#undef MCOUNT_NAME
+#define MCOUNT_NAME "_mcount"
+
+#undef WCHAR_TYPE
+#define WCHAR_TYPE (TARGET_64BIT ? "int" : "long int")
+#undef WCHAR_TYPE_SIZE
+#define WCHAR_TYPE_SIZE 32
+
+#undef WINT_TYPE
+#define WINT_TYPE (TARGET_64BIT ? "int" : "long int")
+#undef WINT_TYPE_SIZE
+#define WINT_TYPE_SIZE 32
+
+#define SUBTARGET_OVERRIDE_OPTIONS				\
+  do								\
+    {								\
+      if (flag_omit_frame_pointer == 2)				\
+	flag_omit_frame_pointer = 0;				\
+    }								\
+  while (0)
+
+#undef TARGET_SUBTARGET_DEFAULT
+#define TARGET_SUBTARGET_DEFAULT (MASK_80387 | MASK_IEEE_FP	\
+				  | MASK_FLOAT_RETURNS		\
+				  | MASK_OMIT_LEAF_FRAME_POINTER)
+
+#define MULTILIB_DEFAULTS { "m32" }
+
+#undef LINK_ARCH64_SPEC_BASE
+#define LINK_ARCH64_SPEC_BASE \
+  "%{G:-G} \
+   %{YP,*} \
+   %{R*} \
+   %{compat-bsd: \
+     %{!YP,*:%{p|pg:-Y P,/usr/ucblib/64:/usr/lib/libp/64:/lib/64:/usr/lib/64} \
+             %{!p:%{!pg:-Y P,/usr/ucblib/64:/lib:/usr/lib/64}}} \
+             -R /usr/ucblib/64} \
+   %{!compat-bsd: \
+     %{!YP,*:%{p|pg:-Y P,/usr/lib/libp/64:/lib/64:/usr/lib/64} \
+             %{!p:%{!pg:-Y P,/lib/64:/usr/lib/64}}}}"
+
+#undef LINK_ARCH64_SPEC
+#define LINK_ARCH64_SPEC LINK_ARCH64_SPEC_BASE
+
+#ifdef TARGET_GNU_LD
+#define TARGET_LD_EMULATION "%{m64:-m elf_x86_64}%{!m64:-m elf_i386} "
+#else
+#define TARGET_LD_EMULATION ""
+#endif
+
+#undef LINK_ARCH_SPEC
+#define LINK_ARCH_SPEC TARGET_LD_EMULATION \
+		       "%{m64:" LINK_ARCH64_SPEC "}%{!m64:" LINK_ARCH32_SPEC "}"
+
+/* We do not need to search a special directory for startup files.  */
+#undef MD_STARTFILE_PREFIX
+
+#undef TARGET_ASM_NAMED_SECTION
+#define TARGET_ASM_NAMED_SECTION i386_solaris_elf_named_section
+
+/* In 32-bit mode, follow the SVR4 ABI definition; in 64-bit mode, use
+   the AMD64 ABI definition.  */
+#undef RETURN_IN_MEMORY
+#define RETURN_IN_MEMORY(TYPE)			\
+  (TARGET_64BIT 				\
+   ? ix86_return_in_memory (TYPE)		\
+   : (TYPE_MODE (TYPE) == BLKmode		\
+      || (VECTOR_MODE_P (TYPE_MODE (TYPE)) 	\
+	  && int_size_in_bytes (TYPE) == 8)))
diff --git a/gcc/config/i386/sol2.h b/gcc/config/i386/sol2.h
index ab81c82fd7d8..dd82d762a862 100644
--- a/gcc/config/i386/sol2.h
+++ b/gcc/config/i386/sol2.h
@@ -31,12 +31,13 @@ Boston, MA 02111-1307, USA.  */
    it knows what it is doing.  */
 #define FORCE_CODE_SECTION_ALIGN  asm(ALIGN_ASM_OP "16");
 
-/* Select a format to encode pointers in exception handling data.  CODE
-   is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
-   true if the symbol may be affected by dynamic relocations.  */
+/* Old versions of the Solaris assembler can not handle the difference of
+   labels in different sections, so force DW_EH_PE_datarel.  */
 #undef ASM_PREFERRED_EH_DATA_FORMAT
 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE,GLOBAL)			\
-  (flag_pic ? (GLOBAL ? DW_EH_PE_indirect : 0) | DW_EH_PE_datarel	\
+  (flag_pic ? ((GLOBAL ? DW_EH_PE_indirect : 0)				\
+	       | (TARGET_64BIT ? DW_EH_PE_pcrel | DW_EH_PE_sdata4	\
+		  : DW_EH_PE_datarel))					\
    : DW_EH_PE_absptr)
 
 /* Solaris 2/Intel as chokes on #line directives.  */
@@ -63,8 +64,10 @@ Boston, MA 02111-1307, USA.  */
 #undef LOCAL_LABEL_PREFIX
 #define LOCAL_LABEL_PREFIX "."
 
-/* The Solaris assembler does not support .quad.  Do not use it.  */
+/* The 32-bit Solaris assembler does not support .quad.  Do not use it.  */
+#ifndef TARGET_BI_ARCH
 #undef ASM_QUAD
+#endif
 
 /* The Solaris assembler wants a .local for non-exported aliases.  */
 #define ASM_OUTPUT_DEF_FROM_DECLS(FILE, DECL, TARGET)	\
diff --git a/gcc/config/i386/t-sol2 b/gcc/config/i386/t-sol2
index 5d7522c3dab4..0eec96f1f05d 100644
--- a/gcc/config/i386/t-sol2
+++ b/gcc/config/i386/t-sol2
@@ -1,24 +1,24 @@
 # gmon build rule:
-gmon.o:	$(srcdir)/config/i386/gmon-sol2.c $(GCC_PASSES) $(CONFIG_H)
-	$(GCC_FOR_TARGET) $(GCC_CFLAGS) $(INCLUDES) \
-		-c $(srcdir)/config/i386/gmon-sol2.c -o gmon.o
+$(T)gmon.o:	$(srcdir)/config/i386/gmon-sol2.c $(GCC_PASSES) $(CONFIG_H)
+	$(GCC_FOR_TARGET) $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) \
+		-c $(srcdir)/config/i386/gmon-sol2.c -o $(T)gmon.o
 
 # Assemble startup files.
 # Apparently Sun believes that assembler files don't need comments, because no
 # single ASCII character is valid (tried them all).  So we manually strip out
 # the comments with sed.  This bug may only be in the Early Access releases.
-gcrt1.o: $(srcdir)/config/i386/sol2-gc1.asm
+$(T)gcrt1.o: $(srcdir)/config/i386/sol2-gc1.asm $(GCC_PASSES)
 	sed -e '/^!/d' <$(srcdir)/config/i386/sol2-gc1.asm >gcrt1.s
-	$(AS) -o gcrt1.o gcrt1.s
-crt1.o: $(srcdir)/config/i386/sol2-c1.asm $(GCC_PASSES)
+	$(GCC_FOR_TARGET) $(MULTILIB_CFLAGS) -c -o $(T)gcrt1.o gcrt1.s
+$(T)crt1.o: $(srcdir)/config/i386/sol2-c1.asm $(GCC_PASSES)
 	sed -e '/^!/d' <$(srcdir)/config/i386/sol2-c1.asm >crt1.s
-	$(GCC_FOR_TARGET) -c -o crt1.o crt1.s
-crti.o: $(srcdir)/config/i386/sol2-ci.asm $(GCC_PASSES)
+	$(GCC_FOR_TARGET) $(MULTILIB_CFLAGS) -c -o $(T)crt1.o crt1.s
+$(T)crti.o: $(srcdir)/config/i386/sol2-ci.asm $(GCC_PASSES)
 	sed -e '/^!/d' <$(srcdir)/config/i386/sol2-ci.asm >crti.s
-	$(GCC_FOR_TARGET) -c -o crti.o crti.s
-crtn.o: $(srcdir)/config/i386/sol2-cn.asm $(GCC_PASSES)
+	$(GCC_FOR_TARGET) $(MULTILIB_CFLAGS) -c -o $(T)crti.o crti.s
+$(T)crtn.o: $(srcdir)/config/i386/sol2-cn.asm $(GCC_PASSES)
 	sed -e '/^!/d' <$(srcdir)/config/i386/sol2-cn.asm >crtn.s
-	$(GCC_FOR_TARGET) -c -o crtn.o crtn.s
+	$(GCC_FOR_TARGET) $(MULTILIB_CFLAGS) -c -o $(T)crtn.o crtn.s
 
 # We need to use -fPIC when we are using gcc to compile the routines in
 # crtstuff.c.  This is only really needed when we are going to use gcc/g++
diff --git a/gcc/config/i386/t-sol2-10 b/gcc/config/i386/t-sol2-10
new file mode 100644
index 000000000000..b7f6df72289f
--- /dev/null
+++ b/gcc/config/i386/t-sol2-10
@@ -0,0 +1,11 @@
+MULTILIB_OPTIONS = m32/m64
+MULTILIB_DIRNAMES = 32 64
+MULTILIB_OSDIRNAMES = . 64
+
+LIBGCC = stmp-multilib
+INSTALL_LIBGCC = install-multilib
+
+# GCC contains i386 assembler sources for some of the startfiles
+# which aren't appropriate for amd64.  Just use the installed
+# versions of: crt1.o crti.o crtn.o gcrt1.o
+EXTRA_MULTILIB_PARTS=gmon.o crtbegin.o crtend.o
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5a23be6c3ab0..318343316bf4 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2004-11-18  Daniel Jacobowitz  <dan@codesourcery.com>
+            Mark Mitchell  <mark@codesourcery.com>
+
+	* testsuite/gcc.dg/pragma-init-fini-2.c: New test.
+
 2004-11-17  Janis Johnson  <janis187@us.ibm.com>
             Aldy Hernandez  <aldyh@redhat.com>
 
diff --git a/gcc/testsuite/gcc.dg/pragma-init-fini-2.c b/gcc/testsuite/gcc.dg/pragma-init-fini-2.c
new file mode 100644
index 000000000000..91bc622a20c5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pragma-init-fini-2.c
@@ -0,0 +1,15 @@
+/* Tests for #pragma init and #pragma fini.  */
+
+/* { dg-do link { target *-*-solaris2.* } } */
+/* { dg-options "-fpic" } */
+
+#include <stdio.h>
+
+#pragma fini (f)
+
+void f() {
+  fprintf (stderr, "f\n");
+}
+
+int main () {
+}
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 5a4614987675..eb5d76f7b333 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,10 @@
+2004-11-18  Daniel Jacobowitz  <dan@codesourcery.com>
+            Mark Mitchell  <mark@codesourcery.com>
+
+	* configure.ac (i[34567]86-*-solaris2.1[0-9]*): Set
+	need_64bit_hwint=yes.
+	* configure: Regenerate.
+
 2004-11-09  Joseph S. Myers  <joseph@codesourcery.com>
 
 	* Makefile.in ($(PACKAGE).pot): New rule.  Depend on
diff --git a/libcpp/configure b/libcpp/configure
index 7a1bc914a5ed..978296b461f6 100755
--- a/libcpp/configure
+++ b/libcpp/configure
@@ -7044,6 +7044,7 @@ case $target in
 	x86_64-*-* | \
 	ia64-*-* | \
 	hppa*64*-*-* | parisc*64*-*-* | \
+	i[34567]86-*-solaris2.1[0-9]* | \
 	mips*-*-* | \
 	mmix-*-* | \
 	powerpc*-*-* | \
diff --git a/libcpp/configure.ac b/libcpp/configure.ac
index 0bcf1711b03a..f088ac80b298 100644
--- a/libcpp/configure.ac
+++ b/libcpp/configure.ac
@@ -110,6 +110,7 @@ case $target in
 	x86_64-*-* | \
 	ia64-*-* | \
 	hppa*64*-*-* | parisc*64*-*-* | \
+	i[34567]86-*-solaris2.1[0-9]* | \
 	mips*-*-* | \
 	mmix-*-* | \
 	powerpc*-*-* | \
-- 
GitLab