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]

[committed] HP-UX 10 one-only support


The enclosed patch fixes PR c++/14607 by adding one-only support under
HP-UX 10.  It also fixes -falign-functions with gas.

The HP-UX linker supports multiple subspaces with the same name.  We
have used this capability for many years to improve stub placement.
It's also now possible to create subspaces with differing attributes,
such as COMDAT.  This patch adds that capability.

Management of the subspaces is a bit tricky.  It's not possible
to switch out and back into these subspaces.  This can be done
only with the original default subspaces.  However, the only time
we switch back into a text section is to output debug information
and this doesn't end up in the text section anyway.

In order to have som_text_section_asm_op called when we need it,
we have to play games and forget from time to time which section
we are in.  It would be somewhat cleaner to have a target macro
for function section selection.  However, I took the path of least
resistance.

Tested on hppa1.1-hp-hpux10.20, hppa2.0w-hp-hpux11.11 and
hppa64-hp-hpux11.11.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc-cnrc.gc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6602)

2004-07-20  John David Anglin  <dava.anglin@nrc-cnrc.gc.ca>

	PR c++/14607
	* config/pa/pa-hpux10.h (SUPPORTS_ONE_ONLY): Define.
	(MAKE_DECL_ONE_ONLY): Undefine.
	* pa-protos.h (som_text_section_asm_op, one_only_readonly_data_section,
	readonly_data, one_only_data_section, forget_section): New prototypes.
	* pa.c (pa_init_machine_status, som_text_section_asm_op): New
	functions.
	(pa_select_section): Add one-only (COMDAT) support.
	* pa.h (struct machine_function): Define.
	* som.h (ASM_OUTPUT_FUNCTION_PREFIX): Delete.
	(TEXT_SECTION_ASM_OP): Call som_text_section_asm_op.
	(DEFAULT_TEXT_SECTION_ASM_OP, NEW_TEXT_SECTION_ASM_OP,
	ONE_ONLY_TEXT_SECTION_ASM_OP, ONE_ONLY_READONLY_DATA_SECTION_ASM_OP,
	ONE_ONLY_DATA_SECTION_ASM_OP): New defines.
	(EXTRA_SECTIONS): Add in_one_only_readonly_data and in_one_only_data.
	(EXTRA_SECTION_FUNCTIONS): Rework to use individual function macros.
	(READONLY_DATA_FUNCTION, ONE_ONLY_READONLY_DATA_SECTION_FUNCTION,
	ONE_ONLY_DATA_SECTION_FUNCTION, FORGET_SECTION_FUNCTION): New defines
	for EXTRA_SECTION_FUNCTIONS.
	* doc/install.texi: Update binutils requirements.

Index: config/pa/pa-hpux10.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/pa/pa-hpux10.h,v
retrieving revision 1.19
diff -u -3 -p -r1.19 pa-hpux10.h
--- config/pa/pa-hpux10.h	27 Apr 2004 00:12:28 -0000	1.19
+++ config/pa/pa-hpux10.h	20 Jul 2004 16:45:25 -0000
@@ -136,3 +136,10 @@ Boston, MA 02111-1307, USA.  */
    better than the assembler shipped with older versions of hpux.  */
 #undef NEW_HP_ASSEMBLER
 #define NEW_HP_ASSEMBLER 1
+
+/* CVS GAS as of 4/28/04 supports a comdat parameter for the .nsubspa
+   directive.  This provides one only linkage semantics even though we
+   don't have weak support.  */
+#undef SUPPORTS_ONE_ONLY
+#define SUPPORTS_ONE_ONLY (TARGET_GAS)
+#undef MAKE_DECL_ONE_ONLY
Index: config/pa/pa-protos.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/pa/pa-protos.h,v
retrieving revision 1.34
diff -u -3 -p -r1.34 pa-protos.h
--- config/pa/pa-protos.h	9 Jul 2004 09:55:51 -0000	1.34
+++ config/pa/pa-protos.h	20 Jul 2004 16:45:25 -0000
@@ -135,6 +135,7 @@ extern int zdepi_cint_p (unsigned HOST_W
 
 extern void override_options (void);
 extern void output_ascii (FILE *, const char *, int);
+extern const char * som_text_section_asm_op (void);
 extern HOST_WIDE_INT compute_frame_size (HOST_WIDE_INT, int *);
 extern int and_mask_p (unsigned HOST_WIDE_INT);
 extern int cint_ok_for_move (HOST_WIDE_INT);
@@ -151,7 +152,6 @@ extern int cmpib_comparison_operator (rt
 #endif
 
 
-
 #ifdef TREE_CODE
 extern int reloc_needed (tree);
 #ifdef RTX_CODE
@@ -164,3 +164,9 @@ extern int function_arg_partial_nregs (C
 				       tree, int);
 extern bool pa_return_in_memory (tree, tree);
 #endif /* TREE_CODE */
+
+/* Functions in varasm.c used by pa.c.  */
+extern void readonly_data (void);
+extern void one_only_readonly_data_section (void);
+extern void one_only_data_section (void);
+extern void forget_section (void);
Index: config/pa/pa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/pa/pa.c,v
retrieving revision 1.265
diff -u -3 -p -r1.265 pa.c
--- config/pa/pa.c	20 Jul 2004 07:27:12 -0000	1.265
+++ config/pa/pa.c	20 Jul 2004 16:45:25 -0000
@@ -143,6 +143,7 @@ static void pa_hpux_init_libfuncs (void)
 static rtx pa_struct_value_rtx (tree, int);
 static bool pa_pass_by_reference (CUMULATIVE_ARGS *ca, enum machine_mode,
 				  tree, bool);
+static struct machine_function * pa_init_machine_status (void);
 
 
 /* Save the operands last given to a compare for use when we
@@ -464,6 +465,8 @@ override_options (void)
       targetm.asm_out.unaligned_op.si = NULL;
       targetm.asm_out.unaligned_op.di = NULL;
     }
+
+  init_machine_status = pa_init_machine_status;
 }
 
 static void
@@ -475,6 +478,16 @@ pa_init_builtins (void)
 #endif
 }
 
+/* Function to init struct machine_function.
+   This will be called, via a pointer variable,
+   from push_function_context.  */
+
+static struct machine_function *
+pa_init_machine_status (void)
+{
+  return ggc_alloc_cleared (sizeof (machine_function));
+}
+
 /* If FROM is a probable pointer register, mark TO as a probable
    pointer register with the same pointer alignment as FROM.  */
 
@@ -4210,6 +4223,14 @@ pa_output_function_epilogue (FILE *file,
 
   fputs ("\t.EXIT\n\t.PROCEND\n", file);
 
+  if (TARGET_SOM && TARGET_GAS)
+    {
+      /* We done with this subspace except possibly for some additional
+	 debug information.  Forget that we are in this subspace to ensure
+	 that the next function is output in its own subspace.  */
+      forget_section ();
+    }
+
   if (INSN_ADDRESSES_SET_P ())
     {
       insn = get_last_nonnote_insn ();
@@ -7995,8 +8016,9 @@ pa_asm_output_mi_thunk (FILE *file, tree
       fprintf (file, "\t.align 4\n");
       ASM_OUTPUT_LABEL (file, label);
       fprintf (file, "\t.word P'%s\n", fname);
-      function_section (thunk_fndecl);
     }
+  else if (TARGET_SOM && TARGET_GAS)
+    forget_section ();
 
   current_thunk_number++;
   nbytes = ((nbytes + FUNCTION_BOUNDARY / BITS_PER_UNIT - 1)
@@ -9144,6 +9166,58 @@ cmpib_comparison_operator (rtx op, enum 
 	      || GET_CODE (op) == LEU));
 }
 
+#ifndef ONE_ONLY_TEXT_SECTION_ASM_OP
+#define ONE_ONLY_TEXT_SECTION_ASM_OP ""
+#endif
+
+#ifndef NEW_TEXT_SECTION_ASM_OP
+#define NEW_TEXT_SECTION_ASM_OP ""
+#endif
+
+#ifndef DEFAULT_TEXT_SECTION_ASM_OP
+#define DEFAULT_TEXT_SECTION_ASM_OP ""
+#endif
+
+/* Select and return a TEXT_SECTION_ASM_OP for the current function.
+
+   This function is only used with SOM.  Because we don't support
+   named subspaces, we can only create a new subspace or switch back
+   into the default text subspace.  */
+const char *
+som_text_section_asm_op (void)
+{
+  if (TARGET_SOM && TARGET_GAS)
+    {
+      if (cfun && !cfun->machine->in_nsubspa)
+	{
+	  /* We only want to emit a .nsubspa directive once at the
+	     start of the function.  */
+	  cfun->machine->in_nsubspa = 1;
+
+	  /* Create a new subspace for the text.  This provides
+	     better stub placement and one-only functions.  */
+	  if (cfun->decl
+	      && DECL_ONE_ONLY (cfun->decl)
+	      && !DECL_WEAK (cfun->decl))
+	    return ONE_ONLY_TEXT_SECTION_ASM_OP;
+
+	  return NEW_TEXT_SECTION_ASM_OP;
+	}
+      else
+	{
+	  /* There isn't a current function or the body of the current
+	     function has been completed.  So, we are changing to the
+	     text section to output debugging information.  Do this in
+	     the default text section.  We need to forget that we are
+	     in the text section so that text_section will call us the
+	     next time around.  */
+	  forget_section ();
+	}
+    }
+
+  return DEFAULT_TEXT_SECTION_ASM_OP;
+}
+
 /* On hpux10, the linker will give an error if we have a reference
    in the read-only data section to a symbol defined in a shared
    library.  Therefore, expressions that might require a reloc can
@@ -9160,10 +9234,23 @@ pa_select_section (tree exp, int reloc,
       && (DECL_INITIAL (exp) == error_mark_node
           || TREE_CONSTANT (DECL_INITIAL (exp)))
       && !reloc)
-    readonly_data_section ();
+    {
+      if (TARGET_SOM
+	  && DECL_ONE_ONLY (exp)
+	  && !DECL_WEAK (exp))
+	one_only_readonly_data_section ();
+      else
+	readonly_data_section ();
+    }
   else if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'c'
 	   && !reloc)
     readonly_data_section ();
+  else if (TARGET_SOM
+	   && TREE_CODE (exp) == VAR_DECL
+	   && DECL_ONE_ONLY (exp)
+	   && !DECL_WEAK (exp)
+	   && DECL_INITIAL (exp))
+    one_only_data_section ();
   else
     data_section ();
 }
Index: config/pa/pa.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/pa/pa.h,v
retrieving revision 1.227
diff -u -3 -p -r1.227 pa.h
--- config/pa/pa.h	14 Jul 2004 16:27:37 -0000	1.227
+++ config/pa/pa.h	20 Jul 2004 16:45:26 -0000
@@ -430,6 +430,12 @@ do {								\
 #define CAN_DEBUG_WITHOUT_FP
 
 /* target machine storage layout */
+typedef struct machine_function GTY(())
+{
+  /* Flag indicating that a .NSUBSPA directive has been output for
+     this function.  */
+  int in_nsubspa;
+} machine_function;
 
 /* Define this macro if it is advisable to hold scalars in registers
    in a wider mode than that declared by the program.  In such cases, 
Index: config/pa/som.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/pa/som.h,v
retrieving revision 1.47
diff -u -3 -p -r1.47 som.h
--- config/pa/som.h	2 Nov 2003 01:01:24 -0000	1.47
+++ config/pa/som.h	20 Jul 2004 16:45:26 -0000
@@ -1,5 +1,5 @@
 /* Definitions for SOM assembler support.
-   Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -129,19 +129,6 @@ do {								\
 #endif
 
 
-/* NAME refers to the function's name.  If we are placing each function into
-   its own section, we need to switch to the section for this function.  Note
-   that the section name will have a "." prefix.  */
-#define ASM_OUTPUT_FUNCTION_PREFIX(FILE, NAME) \
-  {									\
-    const char *name = (*targetm.strip_name_encoding) (NAME);		\
-    if (TARGET_GAS && in_section == in_text) 				\
-      fputs ("\t.NSUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY\n", FILE); \
-    else if (TARGET_GAS)						\
-      fprintf (FILE,							\
-	       "\t.SUBSPA .%s\n", name);				\
-  }
-    
 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
     do { tree fntype = TREE_TYPE (TREE_TYPE (DECL));			\
 	 tree tree_type = TREE_TYPE (DECL);				\
@@ -219,30 +206,84 @@ do {								\
 
 #define TARGET_ASM_FILE_START pa_som_file_start
 
-/* Output before code.  */
+/* Select and return a TEXT_SECTION_ASM_OP string.  */
+#define TEXT_SECTION_ASM_OP som_text_section_asm_op ()
 
-/* Supposedly the assembler rejects the command if there is no tab!  */
-#define TEXT_SECTION_ASM_OP "\t.SPACE $TEXT$\n\t.SUBSPA $CODE$\n"
+/* Output before code in the default text section.  */
+#define DEFAULT_TEXT_SECTION_ASM_OP "\t.SPACE $TEXT$\n\t.SUBSPA $CODE$"
 
-/* Output before read-only data.  */
+/* Output before text in a new subspace.  This allows the linker to
+   place stubs between functions.  */
+#define NEW_TEXT_SECTION_ASM_OP "\t.SPACE $TEXT$\n\t.NSUBSPA $CODE$"
+    
+/* Output before text in a new one-only subspace.  */
+#define ONE_ONLY_TEXT_SECTION_ASM_OP "\t.SPACE $TEXT$\n\
+\t.NSUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,SORT=24,COMDAT"
 
-/* Supposedly the assembler rejects the command if there is no tab!  */
+/* Output before read-only data.  */
 #define READONLY_DATA_ASM_OP "\t.SPACE $TEXT$\n\t.SUBSPA $LIT$\n"
 
-#define EXTRA_SECTIONS in_readonly_data
+/* Output before one-only readonly data.  We make readonly data one only
+   by creating a new $LIT$ subspace in $TEXT$ with the comdat flag.  */
+#define ONE_ONLY_READONLY_DATA_SECTION_ASM_OP "\t.SPACE $TEXT$\n\
+\t.NSUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=0x2c,SORT=16,COMDAT\n"
+
+/* Output before writable data.  */
+#define DATA_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\t.SUBSPA $DATA$\n"
+
+/* Output before one-only data.  We make data one only by creating
+   a new $DATA$ subspace in $PRIVATE$ with the comdat flag.  */
+#define ONE_ONLY_DATA_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\
+\t.NSUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31,SORT=24,COMDAT\n"
+
+/* Output before uninitialized data.  */
+#define BSS_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\t.SUBSPA $BSS$\n"
+
+#define EXTRA_SECTIONS							\
+  in_readonly_data,							\
+  in_one_only_readonly_data,						\
+  in_one_only_data
 
 #define EXTRA_SECTION_FUNCTIONS						\
-extern void readonly_data (void);					\
+  READONLY_DATA_FUNCTION						\
+  ONE_ONLY_READONLY_DATA_SECTION_FUNCTION				\
+  ONE_ONLY_DATA_SECTION_FUNCTION					\
+  FORGET_SECTION_FUNCTION
+
+#define READONLY_DATA_FUNCTION						\
 void									\
 readonly_data (void)							\
 {									\
   if (in_section != in_readonly_data)					\
     {									\
       in_section = in_readonly_data;					\
-      fprintf (asm_out_file, "%s\n", READONLY_DATA_ASM_OP);		\
+      fputs (READONLY_DATA_ASM_OP, asm_out_file);			\
     }									\
+}									\
+
+#define ONE_ONLY_READONLY_DATA_SECTION_FUNCTION				\
+void									\
+one_only_readonly_data_section (void)					\
+{									\
+  in_section = in_one_only_readonly_data;				\
+  fputs (ONE_ONLY_READONLY_DATA_SECTION_ASM_OP, asm_out_file);		\
+}									\
+
+#define ONE_ONLY_DATA_SECTION_FUNCTION					\
+void									\
+one_only_data_section (void)						\
+{									\
+  in_section = in_one_only_data;					\
+  fputs (ONE_ONLY_DATA_SECTION_ASM_OP, asm_out_file);			\
 }
 
+#define FORGET_SECTION_FUNCTION						\
+void									\
+forget_section (void)							\
+{									\
+  in_section = no_section;						\
+}									\
+
 /* FIXME: HPUX ld generates incorrect GOT entries for "T" fixups
    which reference data within the $TEXT$ space (for example constant
    strings in the $LIT$ subspace).
@@ -255,18 +296,8 @@ readonly_data (void)							\
    $TEXT$ space during PIC generation.  Instead place all constant
    data into the $PRIVATE$ subspace (this reduces sharing, but it
    works correctly).  */
-
 #define READONLY_DATA_SECTION (flag_pic ? data_section : readonly_data)
 
-/* Output before writable data.  */
-
-/* Supposedly the assembler rejects the command if there is no tab!  */
-#define DATA_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\t.SUBSPA $DATA$\n"
-
-/* Output before uninitialized data.  */
-
-#define BSS_SECTION_ASM_OP "\t.SPACE $PRIVATE$\n\t.SUBSPA $BSS$\n"
-
 /* We must not have a reference to an external symbol defined in a
    shared library in a readonly section, else the SOM linker will
    complain.
Index: doc/install.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/install.texi,v
retrieving revision 1.298
diff -u -3 -p -r1.298 install.texi
--- doc/install.texi	11 Jul 2004 05:36:40 -0000	1.298
+++ doc/install.texi	20 Jul 2004 16:45:27 -0000
@@ -2607,9 +2607,8 @@ longer a multiple of 2 bytes.
 @heading @anchor{hppa*-hp-hpux*}hppa*-hp-hpux*
 Support for HP-UX version 9 and older was discontinued in GCC 3.4.
 
-We @emph{highly} recommend using gas/binutils 2.8 or newer on all hppa
-platforms; you may encounter a variety of problems when using the HP
-assembler.
+We @emph{highly} recommend using gas/binutils on all hppa platforms;
+you may encounter a variety of problems when using the HP assembler.
 
 Specifically, @option{-g} does not work on HP-UX (since that system
 uses a peculiar debugging format which GCC does not know about), unless you
@@ -2664,6 +2663,13 @@ the 3-stage comparison test to fail duri
 You should be able to continue by saying @samp{make all} after getting
 the failure from @samp{make bootstrap}.
 
+GCC 3.5 requires CVS binutils as of April 28, 2004 or later.  Earlier
+versions require binutils 2.8 or later.
+
+The C++ ABI has changed incompatibly in GCC 3.5.  COMDAT subspaces are
+used for one-only code and data.  This resolves many of the previous
+problems in using C++ on this target.  However, the ABI is not compatible
+with the one implemented under HP-UX 11 using secondary definitions.
 
 @html
 <hr />
@@ -2732,8 +2738,8 @@ result, it's not possible to switch link
 This has been been reported to sometimes occur in unified builds of
 binutils and GCC.
 
-With GCC 3.0 through 3.2, you must use binutils 2.11 or above.  As of
-GCC 3.3, binutils 2.14 or later is required.
+GCC 3.0 through 3.2 require binutils 2.11 or above.  GCC 3.3 through
+GCC 3.5 require binutils 2.14 or later.
 
 Although the HP assembler can be used for an initial build, it shouldn't
 be used with any languages other than C and perhaps Fortran due to its


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