This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [csl-sol210-branch] Add some Solaris #pragmas


On Thu, Jul 15, 2004 at 07:04:45PM -0700, Mark Mitchell wrote:
> Rainer Orth wrote:
> 
> >Daniel Jacobowitz writes:
> >
> > 
> >
> >>I've got no problem with enabling the #pragmas for all Solaris 2
> >>targets.  Would this be acceptable?  They are not vitally necessary,
> >>and the general trend in GCC is away from #pragma/_Pragma, but they are
> >>for compatibility with the vendor's compiler and documentation.
> >>   
> >>
> >
> >In that case, I cannot see any rationale for supporting them only on
> >Solaris 10/x86 and up if the vendor compiler provides them on both SPARC
> >and x86 and well before Solaris 10.  That would be even more confusing to
> >users than not supporting them at all.
> >
> Yes, I think that if the vendor compiler has supported them for a long 
> time, we should just put them into generic Solaris 2 support.

Here is a patch which adds #pragma align, #pragma init, and #pragma
fini to all Solaris targets.

This patch has been only minimally tested.  I can build (just "make") a
compiler on sparc-sun-solaris2.8, but I can't bootstrap in the last few
days (I have no idea when this started):

stage1/xgcc -Bstage1/ -B/usr/local/sparc-sun-solaris2.8/bin/ -c   -g
 -O2 -DIN_GCC   -W -Wall -Wwrite-strings -Wstrict-prototypes
 -Wmissing-prototypes -pedantic -Wno-long-long -Wno-variadic-macros
 -Wold-style-definition -Werror -fno-common   -DHAVE_CONFIG_H
 -DGENERATOR_FILE    -I. -I. -I/scratch/dan/gcc/gcc
 -I/scratch/dan/gcc/gcc/. -I/scratch/dan/gcc/gcc/../include -I./../intl
 -I/scratch/dan/gcc/gcc/../libcpp/include
 -I/scratch/dan/gcc/gcc/../libbanshee/libcompat
 -I/scratch/dan/gcc/gcc/../libbanshee
 -I/scratch/dan/gcc/gcc/../libbanshee/points-to
 /scratch/dan/gcc/gcc/gengtype.c -o gengtype.o

/scratch/dan/gcc/gcc/gengtype.c: In function `do_scalar_typedef':
/scratch/dan/gcc/gcc/gengtype.c:134: internal compiler error: in schedule_insns, at sched-rgn.c:2744
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
make[2]: *** [gengtype.o] Error 1

I have never bootstrapped on this machine before so I figure I'll poll
in case that error looks familiar to anyone else before I start poking
at it; that appears to be a mismatch in the number of death notes in a
region.

-- 
Daniel Jacobowitz

2004-07-19  Daniel Jacobowitz  <dan@debian.org>

	* config.gcc (i[34567]86-*-solaris2*, sparc64-*-solaris2*)
	(sparc-*-solaris2*): Include sol2.o and sol2-protos.h.
	* config/sol2-c.c: Include "tm.h", "tm_p.h", "toplev.h",
	"cpplib.h", "c-pragma.h", "c-common.h".
	(solaris_pragma_align, solaris_pragma_init, solaris_pragma_fini)
	(solaris_register_pragmas): New functions.
	* config/sol2-protos.h: New file.
	* config/sol2.c: New file.
	* config/sol2.h (SOLARIS_ATTRIBUTE_TABLE, ASM_DECLARE_FUNCTION_SIZE)
	(REGISTER_TARGET_PRAGMAS): New macros.
	(solaris_pending_aligns, solaris_pending_inits)
	(solaris_pending_finis): New variables.
	* config/t-sol2 (sol2-c.o): Update dependencies.
	(sol2.o): New rule.
	* config/i386/i386.c (TARGET_INSERT_ATTRIBUTES): Define in terms of
	SUBTARGET_INSERT_ATTRIBUTES.
	(ix86_attribute_table): Include SUBTARGET_ATTRIBUTE_TABLE.
	* config/i386/sol2.h (SUBTARGET_INSERT_ATTRIBUTES)
	(SUBTARGET_ATTRIBUTE_TABLE, ASM_OUTPUT_CALL): Define.
	* config/sparc/elf.h (ASM_DECLARE_FUNCTION_SIZE): Redefine.
	* config/sparc/sp64-elf.h (ASM_DECLARE_FUNCTION_SIZE): Redefine.
	* config/sparc/sol2.h (SUBTARGET_INSERT_ATTRIBUTES)
	(SUBTARGET_ATTRIBUTE_TABLE, ASM_OUTPUT_CALL): Define.
	* config/sparc/sparc.c (sparc_attribute_table): New.
	(TARGET_INSERT_ATTRIBUTES): Define in terms of
	SUBTARGET_INSERT_ATTRIBUTES.
	(TARGET_ATTRIBUTE_TABLE): Define if SUBTARGET_ATTRIBUTE_TABLE
	is defined.
	* doc/extend.texi (Solaris Pragmas): New section.

2004-07-19  Daniel Jacobowitz  <dan@debian.org>

	* testsuite/gcc.dg/pragma-align-2.c: New test.
	* testsuite/gcc.dg/pragma-init-fini.c: New test.
	* testsuite/gcc.dg/pragma-align.c: Change from compile to run.
	Run on Solaris targets.

Index: gcc/config.gcc
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config.gcc,v
retrieving revision 1.468
diff -u -p -r1.468 config.gcc
--- gcc/config.gcc	19 Jul 2004 14:47:53 -0000	1.468
+++ gcc/config.gcc	19 Jul 2004 22:36:30 -0000
@@ -975,6 +975,8 @@ i[34567]86-*-solaris2*)
 	tmake_file="t-sol2 i386/t-sol2 t-svr4"
 	c_target_objs="sol2-c.o"
 	cxx_target_objs="sol2-c.o"
+	extra_objs="sol2.o"
+	tm_p_file="${tm_p_file} sol2-protos.h"
 	if test x$gnu_ld = xyes; then
 		tmake_file="$tmake_file t-slibgcc-elf-ver"
 	else
@@ -1861,6 +1863,8 @@ sparc64-*-solaris2* | sparcv9-*-solaris2
 	fi
 	c_target_objs="sol2-c.o"
 	cxx_target_objs="sol2-c.o"
+	extra_objs="sol2.o"
+	tm_p_file="${tm_p_file} sol2-protos.h"
 	extra_parts="crt1.o crti.o crtn.o gcrt1.o crtbegin.o crtend.o"
 	case ${enable_threads}:${have_pthread_h}:${have_thread_h} in
 	  no:*:*) ;;
@@ -1900,6 +1904,8 @@ sparc-*-solaris2*)
 	esac
 	c_target_objs="sol2-c.o"
 	cxx_target_objs="sol2-c.o"
+	extra_objs="sol2.o"
+	tm_p_file="${tm_p_file} sol2-protos.h"
 	extra_parts="crt1.o crti.o crtn.o gcrt1.o gmon.o crtbegin.o crtend.o"
 	case ${enable_threads}:${have_pthread_h}:${have_thread_h} in
 	  no:*:*) ;;
Index: gcc/config/sol2-c.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/sol2-c.c,v
retrieving revision 1.1
diff -u -p -r1.1 sol2-c.c
--- gcc/config/sol2-c.c	19 Jul 2004 14:47:54 -0000	1.1
+++ gcc/config/sol2-c.c	19 Jul 2004 22:36:30 -0000
@@ -23,10 +23,17 @@ Boston, MA 02111-1307, USA.  */
 #include "system.h"
 #include "coretypes.h"
 #include "tree.h"
+#include "tm.h"
+#include "tm_p.h"
+#include "toplev.h"
 
 #include "c-format.h"
 #include "intl.h"
 
+#include "cpplib.h"
+#include "c-pragma.h"
+#include "c-common.h"
+
 /* cmn_err only accepts "l" and "ll".  */
 static const format_length_info cmn_err_length_specs[] =
 {
@@ -70,3 +77,195 @@ const format_kind_info solaris_format_ty
     &integer_type_node, &integer_type_node
   }
 };
+
+/* Handle #pragma align ALIGNMENT (VAR [, VAR]...)  */
+
+static void
+solaris_pragma_align (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+  tree t, x;
+  enum cpp_ttype ttype;
+  HOST_WIDE_INT low;
+
+  if (c_lex (&x) != CPP_NUMBER
+      || c_lex (&t) != CPP_OPEN_PAREN)
+    {
+      warning ("malformed %<#pragma align%>, ignoring");
+      return;
+    }
+
+  low = TREE_INT_CST_LOW (x);
+  if (TREE_INT_CST_HIGH (x) != 0
+      || (low != 1 && low != 2 && low != 4 && low != 8 && low != 16
+	  && low != 32 && low != 64 && low != 128))
+    {
+      warning ("invalid alignment for %<#pragma align%>, ignoring");
+      return;
+    }
+
+  ttype = c_lex (&t);
+  if (ttype != CPP_NAME)
+    {
+      warning ("malformed %<#pragma align%>, ignoring");
+      return;
+    }
+
+  while (1)
+    {
+      tree decl = identifier_global_value (t);
+      if (decl && TREE_CODE_CLASS (TREE_CODE (decl)) == 'd')
+	warning ("%<#pragma align%> must appear before the declaration of "
+		 "%D, ignoring", decl);
+      else
+	solaris_pending_aligns = tree_cons (t, build_tree_list (NULL, x),
+					    solaris_pending_aligns);
+
+      ttype = c_lex (&t);
+      if (ttype == CPP_COMMA)
+	{
+	  ttype = c_lex (&t);
+	  if (ttype != CPP_NAME)
+	    {
+	      warning ("malformed %<#pragma align%>");
+	      return;
+	    }
+	}
+      else if (ttype == CPP_CLOSE_PAREN)
+	{
+	  if (c_lex (&t) != CPP_EOF)
+	    warning ("junk at end of %<#pragma align%>");
+	  return;
+	}
+      else
+	{
+	  warning ("malformed %<#pragma align%>");
+	  return;
+	}
+    }
+}
+
+/* Handle #pragma init (function [, function]...)  */
+
+static void
+solaris_pragma_init (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+  tree t;
+  enum cpp_ttype ttype;
+
+  if (c_lex (&t) != CPP_OPEN_PAREN)
+    {
+      warning ("malformed %<#pragma init%>, ignoring");
+      return;
+    }
+
+  ttype = c_lex (&t);
+  if (ttype != CPP_NAME)
+    {
+      warning ("malformed %<#pragma init%>, ignoring");
+      return;
+    }
+
+  while (1)
+    {
+      tree decl = identifier_global_value (t);
+      if (decl && TREE_CODE_CLASS (TREE_CODE (decl)) == 'd')
+	{
+	  tree init_list = build_tree_list (get_identifier ("init"),
+					    NULL);
+	  tree attrs = tree_cons (get_identifier ("used"), NULL, init_list);
+	  decl_attributes (&decl, attrs, 0);
+	}
+      else
+	solaris_pending_inits = tree_cons (t, NULL, solaris_pending_inits);
+
+      ttype = c_lex (&t);
+      if (ttype == CPP_COMMA)
+	{
+	  ttype = c_lex (&t);
+	  if (ttype != CPP_NAME)
+	    {
+	      warning ("malformed %<#pragma init%>");
+	      return;
+	    }
+	}
+      else if (ttype == CPP_CLOSE_PAREN)
+	{
+	  if (c_lex (&t) != CPP_EOF)
+	    warning ("junk at end of %<#pragma init%>");
+	  return;
+	}
+      else
+	{
+	  warning ("malformed %<#pragma init%>");
+	  return;
+	}
+    }
+}
+
+/* Handle #pragma fini (function [, function]...)  */
+
+static void
+solaris_pragma_fini (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+  tree t;
+  enum cpp_ttype ttype;
+
+  if (c_lex (&t) != CPP_OPEN_PAREN)
+    {
+      warning ("malformed %<#pragma fini%>, ignoring");
+      return;
+    }
+
+  ttype = c_lex (&t);
+  if (ttype != CPP_NAME)
+    {
+      warning ("malformed %<#pragma fini%>, ignoring");
+      return;
+    }
+
+  while (1)
+    {
+      tree decl = identifier_global_value (t);
+      if (decl && TREE_CODE_CLASS (TREE_CODE (decl)) == 'd')
+	{
+	  tree fini_list = build_tree_list (get_identifier ("fini"),
+					    NULL);
+	  tree attrs = tree_cons (get_identifier ("used"), NULL, fini_list);
+	  decl_attributes (&decl, attrs, 0);
+	}
+      else
+	solaris_pending_finis = tree_cons (t, NULL, solaris_pending_finis);
+
+      ttype = c_lex (&t);
+      if (ttype == CPP_COMMA)
+	{
+	  ttype = c_lex (&t);
+	  if (ttype != CPP_NAME)
+	    {
+	      warning ("malformed %<#pragma fini%>");
+	      return;
+	    }
+	}
+      else if (ttype == CPP_CLOSE_PAREN)
+	{
+	  if (c_lex (&t) != CPP_EOF)
+	    warning ("junk at end of %<#pragma fini%>");
+	  return;
+	}
+      else
+	{
+	  warning ("malformed %<#pragma fini%>");
+	  return;
+	}
+    }
+}
+
+/* Register Solaris-specific #pragma directives.  */
+
+void
+solaris_register_pragmas (void)
+{
+  c_register_pragma (0, "align", solaris_pragma_align);
+  c_register_pragma (0, "init", solaris_pragma_init);
+  c_register_pragma (0, "fini", solaris_pragma_fini);
+}
Index: gcc/config/sol2-protos.h
===================================================================
RCS file: gcc/config/sol2-protos.h
diff -N gcc/config/sol2-protos.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/config/sol2-protos.h	19 Jul 2004 22:36:30 -0000
@@ -0,0 +1,24 @@
+/* Operating system specific prototypes to be used when targeting GCC for any
+   Solaris 2 system.
+   Copyright 2004 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, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+extern void solaris_insert_attributes (tree, tree *);
+extern void solaris_register_pragmas (void);
+extern void solaris_output_init_fini (FILE *, tree);
Index: gcc/config/sol2.c
===================================================================
RCS file: gcc/config/sol2.c
diff -N gcc/config/sol2.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/config/sol2.c	19 Jul 2004 22:36:30 -0000
@@ -0,0 +1,119 @@
+/* General Solaris system support.
+   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.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tree.h"
+#include "tm.h"
+#include "tm_p.h"
+#include "toplev.h"
+#include "ggc.h"
+
+tree solaris_pending_aligns, solaris_pending_inits, solaris_pending_finis;
+
+/* Attach any pending attributes for DECL to the list in *ATTRIBUTES.
+   Pending attributes come from #pragma or _Pragma, so this code is
+   only useful in the C family front ends, but it is included in
+   all languages to avoid changing the target machine initializer
+   depending on the language.  */
+
+void
+solaris_insert_attributes (tree decl, tree *attributes)
+{
+  tree *x, next;
+
+  if (solaris_pending_aligns != NULL && TREE_CODE (decl) == VAR_DECL)
+    for (x = &solaris_pending_aligns; *x; x = &TREE_CHAIN (*x))
+      {
+	tree name = TREE_PURPOSE (*x);
+	tree value = TREE_VALUE (*x);
+	if (DECL_NAME (decl) == name)
+	  {
+	    if (lookup_attribute ("aligned", DECL_ATTRIBUTES (decl))
+		|| lookup_attribute ("aligned", *attributes))
+	      warning ("%Jignoring %<#pragma align%> for explicitly "
+		       "aligned %<%D%>", decl, decl);
+	    else
+	      *attributes = tree_cons (get_identifier ("aligned"), value,
+				       *attributes);
+	    next = TREE_CHAIN (*x);
+	    ggc_free (*x);
+	    *x = next;
+	    break;
+	  }
+      }
+
+  if (solaris_pending_inits != NULL && TREE_CODE (decl) == FUNCTION_DECL)
+    for (x = &solaris_pending_inits; *x; x = &TREE_CHAIN (*x))
+      {
+	tree name = TREE_PURPOSE (*x);
+	if (DECL_NAME (decl) == name)
+	  {
+	    *attributes = tree_cons (get_identifier ("init"), NULL,
+				     *attributes);
+	    *attributes = tree_cons (get_identifier ("used"), NULL,
+				     *attributes);
+	    next = TREE_CHAIN (*x);
+	    ggc_free (*x);
+	    *x = next;
+	    break;
+	  }
+      }
+
+  if (solaris_pending_finis != NULL && TREE_CODE (decl) == FUNCTION_DECL)
+    for (x = &solaris_pending_finis; *x; x = &TREE_CHAIN (*x))
+      {
+	tree name = TREE_PURPOSE (*x);
+	if (DECL_NAME (decl) == name)
+	  {
+	    *attributes = tree_cons (get_identifier ("fini"), NULL,
+				     *attributes);
+	    *attributes = tree_cons (get_identifier ("used"), NULL,
+				     *attributes);
+	    next = TREE_CHAIN (*x);
+	    ggc_free (*x);
+	    *x = next;
+	    break;
+	  }
+      }
+}
+
+/* Output initializer or finalizer entries for DECL to FILE.  */
+
+void
+solaris_output_init_fini (FILE *file, tree decl)
+{
+  if (lookup_attribute ("init", DECL_ATTRIBUTES (decl)))
+    {
+      fprintf (file, "\t.pushsection\t\".init\"\n");
+      ASM_OUTPUT_CALL (file, IDENTIFIER_POINTER (DECL_NAME (decl)));
+      fprintf (file, "\t.popsection\n");
+    }
+
+  if (lookup_attribute ("fini", DECL_ATTRIBUTES (decl)))
+    {
+      fprintf (file, "\t.pushsection\t\".fini\"\n");
+      ASM_OUTPUT_CALL (file, IDENTIFIER_POINTER (DECL_NAME (decl)));
+      fprintf (file, "\t.popsection\n");
+    }
+}
+
Index: gcc/config/sol2.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/sol2.h,v
retrieving revision 1.13
diff -u -p -r1.13 sol2.h
--- gcc/config/sol2.h	19 Jul 2004 14:47:54 -0000	1.13
+++ gcc/config/sol2.h	19 Jul 2004 22:36:31 -0000
@@ -1,6 +1,6 @@
 /* Operating system specific defines to be used when targeting GCC for any
    Solaris 2 system.
-   Copyright 2002, 2003 Free Software Foundation, Inc.
+   Copyright 2002, 2003, 2004 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -206,5 +206,31 @@ __enable_execute_stack (void *addr)					
   }									\
 }
 
+/* Support Solaris-specific format checking for cmn_err.  */
 #define TARGET_N_FORMAT_TYPES 1
 #define TARGET_FORMAT_TYPES solaris_format_types
+
+/* #pragma init and #pragma fini are implemented on top of init and
+   fini attributes.  */
+#define SOLARIS_ATTRIBUTE_TABLE						\
+  { "init",      0, 0, true,  false,  false, NULL },			\
+  { "fini",      0, 0, true,  false,  false, NULL }
+
+/* This is how to declare the size of a function.  For Solaris, we output
+   any .init or .fini entries here.  */
+#undef ASM_DECLARE_FUNCTION_SIZE
+#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)		\
+  do								\
+    {								\
+      if (!flag_inhibit_size_directive)				\
+	ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);			\
+      solaris_output_init_fini (FILE, DECL);			\
+    }								\
+  while (0)
+
+/* Register the Solaris-specific #pragma directives.  */
+#define REGISTER_TARGET_PRAGMAS() solaris_register_pragmas ()
+
+extern GTY(()) tree solaris_pending_aligns;
+extern GTY(()) tree solaris_pending_inits;
+extern GTY(()) tree solaris_pending_finis;
Index: gcc/config/t-sol2
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/t-sol2,v
retrieving revision 1.1
diff -u -p -r1.1 t-sol2
--- gcc/config/t-sol2	19 Jul 2004 14:47:54 -0000	1.1
+++ gcc/config/t-sol2	19 Jul 2004 22:36:31 -0000
@@ -1,5 +1,12 @@
-# Solaris-specific format checking
+# Solaris-specific format checking and pragmas
 sol2-c.o: $(srcdir)/config/sol2-c.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
-  tree.h c-format.h intl.h
+  tree.h c-format.h intl.h $(CPPLIB_H) c-pragma.h $(TM_H) $(TM_P_H) \
+  toplev.h $(C_COMMON_H)
 	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
 	  $(srcdir)/config/sol2-c.c
+
+# Solaris-specific attributes
+sol2.o: $(srcdir)/config/sol2.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
+  tree.h $(TM_H) $(TM_P_H) toplev.h $(GGC_H)
+	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
+	  $(srcdir)/config/sol2.c
Index: gcc/config/i386/i386.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.c,v
retrieving revision 1.694
diff -u -p -r1.694 i386.c
--- gcc/config/i386/i386.c	17 Jul 2004 21:09:11 -0000	1.694
+++ gcc/config/i386/i386.c	19 Jul 2004 22:36:32 -0000
@@ -1082,6 +1082,11 @@ static void init_ext_80387_constants (vo
 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
 #define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg
 
+#ifdef SUBTARGET_INSERT_ATTRIBUTES
+#undef TARGET_INSERT_ATTRIBUTES
+#define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
+#endif
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 
@@ -1613,6 +1618,9 @@ const struct attribute_spec ix86_attribu
 #endif
   { "ms_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
   { "gcc_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute },
+#ifdef SUBTARGET_ATTRIBUTE_TABLE
+  SUBTARGET_ATTRIBUTE_TABLE,
+#endif
   { NULL,        0, 0, false, false, false, NULL }
 };
 
Index: gcc/config/i386/sol2.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/sol2.h,v
retrieving revision 1.29
diff -u -p -r1.29 sol2.h
--- gcc/config/i386/sol2.h	14 Jun 2004 17:31:27 -0000	1.29
+++ gcc/config/i386/sol2.h	19 Jul 2004 22:36:32 -0000
@@ -79,3 +79,12 @@ Boston, MA 02111-1307, USA.  */
 	fprintf ((FILE), "\n");				\
       }							\
   } while (0)
+
+/* Solaris-specific #pragmas are implemented on top of attributes.  Hook in
+   the bits from config/sol2.c.  */
+#define SUBTARGET_INSERT_ATTRIBUTES solaris_insert_attributes
+#define SUBTARGET_ATTRIBUTE_TABLE SOLARIS_ATTRIBUTE_TABLE
+
+/* Output a simple call for .init/.fini.  */
+#define ASM_OUTPUT_CALL(FILE, NAME)			\
+  fprintf (FILE, "\tcall\t%s\n", NAME)
Index: gcc/config/sparc/elf.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/sparc/elf.h,v
retrieving revision 1.11
diff -u -p -r1.11 elf.h
--- gcc/config/sparc/elf.h	19 Jul 2004 14:47:55 -0000	1.11
+++ gcc/config/sparc/elf.h	19 Jul 2004 22:36:32 -0000
@@ -52,3 +52,13 @@ Boston, MA 02111-1307, USA.  */
 /* Don't include Solaris-specific format checks.  */
 #undef TARGET_N_FORMAT_TYPES
 #undef TARGET_FORMAT_TYPES
+
+/* Don't include Solaris-specific .init / .fini support.  */
+#undef ASM_DECLARE_FUNCTION_SIZE
+#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)		\
+  do								\
+    {								\
+      if (!flag_inhibit_size_directive)				\
+	ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);			\
+    }								\
+  while (0)
Index: gcc/config/sparc/sol2.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/sparc/sol2.h,v
retrieving revision 1.63
diff -u -p -r1.63 sol2.h
--- gcc/config/sparc/sol2.h	1 Apr 2004 16:05:20 -0000	1.63
+++ gcc/config/sparc/sol2.h	19 Jul 2004 22:36:32 -0000
@@ -156,3 +156,12 @@ Boston, MA 02111-1307, USA.  */
    sparc_override_options will disable V8+ if not generating V9 code.  */
 #undef TARGET_DEFAULT
 #define TARGET_DEFAULT (MASK_V8PLUS + MASK_FPU + MASK_LONG_DOUBLE_128)
+
+/* Solaris-specific #pragmas are implemented on top of attributes.  Hook in
+   the bits from config/sol2.c.  */
+#define SUBTARGET_INSERT_ATTRIBUTES solaris_insert_attributes
+#define SUBTARGET_ATTRIBUTE_TABLE SOLARIS_ATTRIBUTE_TABLE
+
+/* Output a simple call for .init/.fini.  */
+#define ASM_OUTPUT_CALL(FILE, NAME)			\
+  fprintf (FILE, "\tcall\t%s\n\t nop\n", NAME)
Index: gcc/config/sparc/sp64-elf.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/sparc/sp64-elf.h,v
retrieving revision 1.30
diff -u -p -r1.30 sp64-elf.h
--- gcc/config/sparc/sp64-elf.h	19 Jul 2004 14:47:55 -0000	1.30
+++ gcc/config/sparc/sp64-elf.h	19 Jul 2004 22:36:33 -0000
@@ -126,3 +126,13 @@ crtbegin.o%s \
 /* Don't include Solaris-specific format checks.  */
 #undef TARGET_N_FORMAT_TYPES
 #undef TARGET_FORMAT_TYPES
+
+/* Don't include Solaris-specific .init / .fini support.  */
+#undef ASM_DECLARE_FUNCTION_SIZE
+#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)		\
+  do								\
+    {								\
+      if (!flag_inhibit_size_directive)				\
+	ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME);			\
+    }								\
+  while (0)
Index: gcc/config/sparc/sparc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/sparc/sparc.c,v
retrieving revision 1.323
diff -u -p -r1.323 sparc.c
--- gcc/config/sparc/sparc.c	17 Jul 2004 21:09:13 -0000	1.323
+++ gcc/config/sparc/sparc.c	19 Jul 2004 22:36:33 -0000
@@ -334,6 +334,9 @@ static bool sparc_strict_argument_naming
 static tree sparc_gimplify_va_arg (tree, tree, tree *, tree *);
 static bool sparc_pass_by_reference (CUMULATIVE_ARGS *,
 				     enum machine_mode, tree, bool);
+#ifdef SUBTARGET_ATTRIBUTE_TABLE
+const struct attribute_spec sparc_attribute_table[];
+#endif
 
 /* Option handling.  */
 
@@ -452,6 +455,16 @@ enum processor_type sparc_cpu;
 #undef TARGET_LATE_RTL_PROLOGUE_EPILOGUE
 #define TARGET_LATE_RTL_PROLOGUE_EPILOGUE true
 
+#ifdef SUBTARGET_INSERT_ATTRIBUTES
+#undef TARGET_INSERT_ATTRIBUTES
+#define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
+#endif
+
+#ifdef SUBTARGET_ATTRIBUTE_TABLE
+#undef TARGET_ATTRIBUTE_TABLE
+#define TARGET_ATTRIBUTE_TABLE sparc_attribute_table
+#endif
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 /* Validate and override various options, and do some machine dependent
@@ -688,6 +701,16 @@ sparc_override_options (void)
     };
 }
 
+#ifdef SUBTARGET_ATTRIBUTE_TABLE
+/* Table of valid machine attributes.  */
+const struct attribute_spec sparc_attribute_table[] =
+{
+  /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
+  SUBTARGET_ATTRIBUTE_TABLE,
+  { NULL,        0, 0, false, false, false, NULL }
+};
+#endif
+
 /* Miscellaneous utilities.  */
 
 /* Nonzero if CODE, a comparison, is suitable for use in v9 conditional move
Index: gcc/doc/extend.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/extend.texi,v
retrieving revision 1.202
diff -u -p -r1.202 extend.texi
--- gcc/doc/extend.texi	19 Jul 2004 14:47:55 -0000	1.202
+++ gcc/doc/extend.texi	19 Jul 2004 22:36:35 -0000
@@ -7247,6 +7247,7 @@ for further explanation.
 * ARM Pragmas::
 * RS/6000 and PowerPC Pragmas::
 * Darwin Pragmas::
+* Solaris Pragmas::
 * Symbol-Renaming Pragmas::
 @end menu
 
@@ -7331,6 +7332,37 @@ that of the @code{unused} attribute, exc
 anywhere within the variables' scopes.
 @end table
 
+@node Solaris Pragmas
+@subsection Solaris Pragmas
+
+The Solaris target supports @code{#pragma redefine_extname}
+(@pxref{Symbol-Renaming Pragmas}).  It also supports additional
+@code{#pragma} directives for compatibility with the system compiler.
+
+@table @code
+@item align @var{alignment} (@var{variable} [, @var{variable}]...)
+@cindex pragma, align
+
+Increase the minimum alignment of each @var{variable} to @var{alignment}.
+This is the same as GCC's @code{aligned} attribute @pxref{Variable
+Attributes}).
+
+@item fini (@var{function} [, @var{function}]...)
+@cindex pragma, fini
+
+This pragma causes each listed @var{function} to be called after
+main, or during shared module unloading, by adding a call to the
+@code{.fini} section.
+
+@item init (@var{function} [, @var{function}]...)
+@cindex pragma, init
+
+This pragma causes each listed @var{function} to be called during
+initialization (before @code{main}) or during shared module loading, by
+adding a call to the @code{.init} section.
+
+@end table
+
 @node Symbol-Renaming Pragmas
 @subsection Symbol-Renaming Pragmas
 
Index: gcc/testsuite/gcc.dg/pragma-align-2.c
===================================================================
RCS file: gcc/testsuite/gcc.dg/pragma-align-2.c
diff -N gcc/testsuite/gcc.dg/pragma-align-2.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/gcc.dg/pragma-align-2.c	19 Jul 2004 22:36:36 -0000
@@ -0,0 +1,54 @@
+/* { dg-do run { target *-*-solaris2.* } } */
+
+void abort (void);
+
+#pragma align 1(x1)
+#pragma align 2(x2)
+#pragma align 4(x4)
+#pragma align 8(x8,y8,z8)
+#pragma align 16(x16)
+#pragma align 32(x32)
+#pragma align 64(x64)
+#pragma align 128(x128)
+
+#pragma align 8(not_defined)
+
+#pragma align 9(odd_align)	/* { dg-error "invalid alignment" } */
+#pragma align 256(high_align)	/* { dg-error "invalid alignment" } */
+#pragma align -1(neg_align)	/* { dg-error "malformed" } */
+#pragma align bad_align		/* { dg-error "malformed" } */
+#pragma align 1(bad_align	/* { dg-error "malformed" } */
+
+int x, x1, x2, x4, x8, y8, z8, x16, x32, x64, x128;
+
+#pragma align 16(x)		/* { dg-error "must appear before" } */
+
+int
+main ()
+{
+  if (__alignof__ (x4) < 4)
+    abort ();
+
+  if (__alignof__ (x8) < 8)
+    abort ();
+
+  if (__alignof__ (y8) < 8)
+    abort ();
+
+  if (__alignof__ (z8) < 8)
+    abort ();
+
+  if (__alignof__ (x16) < 16)
+    abort ();
+
+  if (__alignof__ (x32) < 32)
+    abort ();
+
+  if (__alignof__ (x64) < 64)
+    abort ();
+
+  if (__alignof__ (x128) < 128)
+    abort ();
+
+  return 0;
+}
Index: gcc/testsuite/gcc.dg/pragma-align.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/pragma-align.c,v
retrieving revision 1.2
diff -u -p -r1.2 pragma-align.c
--- gcc/testsuite/gcc.dg/pragma-align.c	11 Sep 2000 22:47:05 -0000	1.2
+++ gcc/testsuite/gcc.dg/pragma-align.c	19 Jul 2004 22:36:36 -0000
@@ -1,6 +1,6 @@
 /* Prove that HANDLE_SYSTEMV_PRAGMA alignment handling works somewhat. */
 
-/* { dg-do compile { target i?86-*-linux* i?86-*-*bsd* i?86-*-sco3.2v5* } } */
+/* { dg-do run { target i?86-*-linux* i?86-*-*bsd* i?86-*-sco3.2v5* *-*-solaris2.* } } */
 
 struct {
         char one;
@@ -39,4 +39,3 @@ main()
         if(sizeof(resetalign) != sizeof(defaultalign)) abort();
 	return 0;
 }
-
Index: gcc/testsuite/gcc.dg/pragma-init-fini.c
===================================================================
RCS file: gcc/testsuite/gcc.dg/pragma-init-fini.c
diff -N gcc/testsuite/gcc.dg/pragma-init-fini.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/gcc.dg/pragma-init-fini.c	19 Jul 2004 22:36:36 -0000
@@ -0,0 +1,50 @@
+/* Tests for #pragma init and #pragma fini.  */
+
+/* { dg-do run { target *-*-solaris2.* } } */
+
+extern void abort ();
+
+#pragma init		/* { dg-error "malformed" } */
+#pragma init ()		/* { dg-error "malformed" } */
+#pragma init init_func	/* { dg-error "malformed" } */
+
+#pragma fini		/* { dg-error "malformed" } */
+#pragma fini ()		/* { dg-error "malformed" } */
+#pragma fini fini_func	/* { dg-error "malformed" } */
+
+#pragma init (init_func, init_static_func)
+
+int glob_1, glob_2;
+
+void init_func (void)
+{
+  glob_1 = 1;
+}
+
+static void init_static_func (void)
+{
+  glob_2 = 2;
+}
+
+#pragma fini (fini_func, fini_static_func)
+
+void fini_func (void)
+{
+
+}
+
+static void fini_static_func (void)
+{
+
+}
+
+int main()
+{
+  if (glob_1 != 1)
+    abort ();
+
+  if (glob_2 != 2)
+    abort ();
+
+  return 0;
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]