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]

GNU and HP assembler fix for hppa64-hp-hpux11


The hppa64-hp-hpux11 port was failing a variety of weak alias tests.
This was because SET_ASM_OP and ASM_OUTPUT_DEF were not defined.
The HP assembler doesn't have this operation while the GNU assembler
does.  As I looked further into this, it became clear that the HP
assembler really was never designed for ELF.  In adding weak support
to the port, we had broken compatibility with the HP assembler but
we were still trying to mainly use HP assembler directives.

I decided that we needed to give up the capability of generating code
for the two assemblers based on the "-mgas" runtime switch.  We also
should be using GNU semantics with the GNU assembler and HP semantics
with the HP assembler.

I started by including elfos.h instead of pa/elf.h with the GNU assembler.
I then worked out a minimal set of changes in pa64-hpux.h to make us
compatible with the pa version of GAS.  Unfortunately, the 32-bit port
uses a special syntax for .comm and this was carried over to the 64-bit
hpux port.  We should have used the standard gnu syntax.  We still have
to type undefined symbols as the HP linker and dynamic loader require this.

Then, I added a minimal set of defines for use with the HP assembler
when we don't use elfos.h.

The patch fixes about forty weak/alias fails.  There are no regressions.
It is now possible to bootstrap with the HP compiler, although the build
of libstdc++-v3 fails due to an unexported symbol (PR c++/8512).

Applied to mainline.

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

2002-11-09  John David Anglin  <dave@hiauly1.hia.nrc.ca>

	* config.gcc (hppa*64*-*-linux*): Shorten lines in tm_file define.
	(hppa*64*-*-hpux11*): Likewise.  Use elfos.h with gas.
	* pa.c (output_millicode_call): Use symbol difference rather than
	$PIC_pcrel$0 when using HP assembler.
	* pa64-hpux.h (TARGET_GAS): Define to 1 or 0 depending on whether or
	not elfos.h (i.e., gas) is being used.
	(ASM_FILE_START, STRING_ASM_OP, TEXT_SECTION_ASM_OP,
	DATA_SECTION_ASM_OP, BSS_SECTION_ASM_OP, ASM_OUTPUT_ALIGNED_COMMON,
	ASM_OUTPUT_ALIGNED_LOCAL, GLOBAL_ASM_OP, ASM_DECLARE_FUNCTION_NAME,
	ASM_OUTPUT_EXTERNAL, ASM_OUTPUT_EXTERNAL_LIBCALL,
	ASM_OUTPUT_INTERNAL_LABEL, ASM_GENERATE_INTERNAL_LABEL): Define when
	using elfos.h.
	(TARGET_ASM_GLOBALIZE_LABEL): Undefine when using elfos.h.
	(DWARF2_ASM_LINE_DEBUG_INFO): Delete.
	(ASM_FILE_START): Add standard .SPACE and .SUBSPA defines when not
	using elfos.h.
	(TEXT_SECTION_ASM_OP, READONLY_DATA_SECTION_ASM_OP, DATA_SECTION_ASM_OP,
	BSS_SECTION_ASM_OP): New HP style defines when not using elfos.h.
	(TARGET_ASM_NAMED_SECTION, MAKE_DECL_ONE_ONLY, ASM_WEAKEN_LABEL):
	Don't define when not using elfos.h.
	(ASM_DECLARE_RESULT): Don't define.
	* doc/install.texi (hppa*-hp-hpux*): Remove statement that HP assembler
	doesn't work on hppa64-hp-hpux11.
	(hppa*-hp-hpux11): Update.

Index: config.gcc
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config.gcc,v
retrieving revision 1.258
diff -u -3 -p -r1.258 config.gcc
--- config.gcc	7 Nov 2002 06:00:04 -0000	1.258
+++ config.gcc	9 Nov 2002 18:54:47 -0000
@@ -733,8 +733,8 @@ h8300-*-*)
 	;;
 hppa*64*-*-linux* | parisc*64*-*-linux*)
 	target_cpu_default="(MASK_PA_11 | MASK_PA_20)"
-	tm_file="pa/pa64-start.h ${tm_file} dbxelf.h elfos.h svr4.h linux.h pa/pa-linux.h \
-		 pa/pa64-regs.h pa/pa-64.h pa/pa64-linux.h"
+	tm_file="pa/pa64-start.h ${tm_file} dbxelf.h elfos.h svr4.h linux.h \
+		 pa/pa-linux.h pa/pa64-regs.h pa/pa-64.h pa/pa64-linux.h"
 	tmake_file=pa/t-linux64
 	gas=yes gnu_ld=yes
 	;;
@@ -867,7 +867,16 @@ hppa1.0-*-hpux10*)
 	;;
 hppa*64*-*-hpux11*)
 	xm_defines=POSIX
-	tm_file="pa/pa64-start.h ${tm_file} pa/pa64-regs.h pa/long_double.h pa/elf.h pa/pa-hpux.h pa/pa-hpux11.h pa/pa-64.h pa/pa64-hpux.h"
+	if test x$gas = xyes
+	then
+		tm_file="pa/pa64-start.h ${tm_file} dbxelf.h elfos.h  \
+			 pa/pa64-regs.h pa/long_double.h pa/pa-hpux.h \
+			 pa/pa-hpux11.h pa/pa-64.h pa/pa64-hpux.h"
+	else
+		tm_file="pa/pa64-start.h ${tm_file} dbxelf.h pa/elf.h \
+			 pa/pa64-regs.h pa/long_double.h pa/pa-hpux.h \
+			 pa/pa-hpux11.h pa/pa-64.h pa/pa64-hpux.h"
+	fi
 	tmake_file="pa/t-pa64 pa/t-pa-hpux"
 	xmake_file="pa/x-ada"
 	target_cpu_default="(MASK_PA_11|MASK_PA_20|MASK_GAS)"
Index: config/pa/pa.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/pa/pa.c,v
retrieving revision 1.185
diff -u -3 -p -r1.185 pa.c
--- config/pa/pa.c	31 Oct 2002 03:13:43 -0000	1.185
+++ config/pa/pa.c	9 Nov 2002 18:54:48 -0000
@@ -6238,8 +6238,21 @@ output_millicode_call (insn, call_dest)
 	     loaded objects.  Using a pc-relative sequence also avoids
 	     problems related to the implicit use of the gp register.  */
 	  output_asm_insn ("b,l .+8,%%r1", xoperands);
-	  output_asm_insn ("addil L'%0-$PIC_pcrel$0+4,%%r1", xoperands);
-	  output_asm_insn ("ldo R'%0-$PIC_pcrel$0+8(%%r1),%%r1", xoperands);
+
+	  if (TARGET_GAS)
+	    {
+	      output_asm_insn ("addil L'%0-$PIC_pcrel$0+4,%%r1", xoperands);
+	      output_asm_insn ("ldo R'%0-$PIC_pcrel$0+8(%%r1),%%r1", xoperands);
+	    }
+	  else
+	    {
+	      xoperands[1] = gen_label_rtx ();
+	      output_asm_insn ("addil L'%0-%l1,%%r1", xoperands);
+	      ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L",
+					 CODE_LABEL_NUMBER (xoperands[1]));
+	      output_asm_insn ("ldo R'%0-%l1(%%r1),%%r1", xoperands);
+	    }
+
 	  output_asm_insn ("bve,l (%%r1),%%r2", xoperands);
 	}
       else if (TARGET_PORTABLE_RUNTIME)
@@ -6269,6 +6282,9 @@ output_millicode_call (insn, call_dest)
 	}
       else
 	{
+	  output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
+	  output_asm_insn ("addi 16,%%r1,%%r31", xoperands);
+
 	  if (TARGET_SOM || !TARGET_GAS)
 	    {
 	      /* The HP assembler can generate relocations for the
@@ -6276,8 +6292,6 @@ output_millicode_call (insn, call_dest)
 		 millicode symbol but not an arbitrary external
 		 symbol when generating SOM output.  */
 	      xoperands[1] = gen_label_rtx ();
-	      output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
-	      output_asm_insn ("addi 16,%%r1,%%r31", xoperands);
 	      ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "L",
 					 CODE_LABEL_NUMBER (xoperands[1]));
 	      output_asm_insn ("addil L'%0-%l1,%%r1", xoperands);
@@ -6285,8 +6299,6 @@ output_millicode_call (insn, call_dest)
 	    }
 	  else
 	    {
-	      output_asm_insn ("{bl|b,l} .+8,%%r1", xoperands);
-	      output_asm_insn ("addi 16,%%r1,%%r31", xoperands);
 	      output_asm_insn ("addil L'%0-$PIC_pcrel$0+8,%%r1", xoperands);
 	      output_asm_insn ("ldo R'%0-$PIC_pcrel$0+12(%%r1),%%r1",
 			       xoperands);
Index: config/pa/pa64-hpux.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/pa/pa64-hpux.h,v
retrieving revision 1.17
diff -u -3 -p -r1.17 pa64-hpux.h
--- config/pa/pa64-hpux.h	6 Nov 2002 19:13:34 -0000	1.17
+++ config/pa/pa64-hpux.h	9 Nov 2002 18:54:48 -0000
@@ -72,50 +72,165 @@ Boston, MA 02111-1307, USA.  */
 #define MD_STARTFILE_PREFIX_1 "/opt/langtools/lib/pa20_64/"
 #endif
 
-/* hpux11 has the new HP assembler.  It's still lousy, but it's a whole lot
-   better than the assembler shipped with older versions of hpux.  */
-#undef NEW_HP_ASSEMBLER
-#define NEW_HP_ASSEMBLER 1
+/* Due to limitations in the target structure, it isn't currently possible
+   to dynamically switch between the GNU and HP assemblers.  */
+#undef TARGET_GAS
+
+/* Configure selects the standard ELFOS defines for use with GAS.  */
+#ifdef USING_ELFOS_H
+
+/* We are using GAS.  */
+#define TARGET_GAS 1
 
 #undef ASM_FILE_START
 #define ASM_FILE_START(FILE) \
-do {  \
-     if (TARGET_64BIT) \
-       fputs("\t.LEVEL 2.0w\n", FILE); \
-     else if (TARGET_PA_20) \
-       fputs("\t.LEVEL 2.0\n", FILE); \
-     else if (TARGET_PA_11) \
-       fputs("\t.LEVEL 1.1\n", FILE); \
-     else \
-       fputs("\t.LEVEL 1.0\n", FILE); \
-     if (profile_flag)\
-       fprintf (FILE, "\t.IMPORT _mcount, CODE\n");\
-     if (write_symbols != NO_DEBUG) \
-       output_file_directive ((FILE), main_input_filename); \
-   } while (0)
+do {								\
+  if (TARGET_64BIT)						\
+    fputs("\t.LEVEL 2.0w\n", FILE);				\
+  else if (TARGET_PA_20)					\
+    fputs("\t.LEVEL 2.0\n", FILE);				\
+  else if (TARGET_PA_11)					\
+    fputs("\t.LEVEL 1.1\n", FILE);				\
+  else								\
+    fputs("\t.LEVEL 1.0\n", FILE);				\
+  if (profile_flag)						\
+    ASM_OUTPUT_TYPE_DIRECTIVE (FILE, "_mcount", "function");	\
+  if (write_symbols != NO_DEBUG)				\
+    {								\
+      output_file_directive ((FILE), main_input_filename);	\
+      fputs ("\t.version\t\"01.01\"\n", FILE);			\
+    }								\
+} while (0)
+
+/* This is how we output a null terminated string.  */
+#undef STRING_ASM_OP
+#define STRING_ASM_OP	"\t.stringz\t"
+
+#define TEXT_SECTION_ASM_OP	"\t.text"
+#define DATA_SECTION_ASM_OP	"\t.data"
+#define BSS_SECTION_ASM_OP	"\t.section\t.bss"
+
+#undef ASM_OUTPUT_ALIGNED_COMMON
+#define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN)		\
+do {									\
+  bss_section ();							\
+  assemble_name ((FILE), (NAME));					\
+  fputs ("\t.comm ", (FILE));						\
+  fprintf ((FILE), "%d\n", MAX ((SIZE), ((ALIGN) / BITS_PER_UNIT)));	\
+} while (0)
+
+#undef ASM_OUTPUT_ALIGNED_LOCAL
+#define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN)		\
+do {									\
+  bss_section ();							\
+  fprintf ((FILE), "\t.align %d\n", ((ALIGN) / BITS_PER_UNIT));		\
+  assemble_name ((FILE), (NAME));					\
+  fprintf ((FILE), "\n\t.block %d\n", (SIZE));				\
+} while (0)
+
+/* The define in pa.h doesn't work with the alias attribute.  The
+   default is ok with the following define for GLOBAL_ASM_OP.  */
+#undef TARGET_ASM_GLOBALIZE_LABEL
+
+/* This is how we globalize a label.  */
+#define GLOBAL_ASM_OP	"\t.globl\t"
+
+/* Hacked version from elfos.h that doesn't output a label.  */
+#undef ASM_DECLARE_FUNCTION_NAME
+#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)		\
+do {								\
+  ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function");		\
+  ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL));		\
+} while (0)
+
+/* The type of external references must be set correctly for the
+   dynamic loader to work correctly.  This is equivalent to the
+   HP assembler's .IMPORT directive but relates more directly to
+   ELF object file types.  */
+#define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME)				\
+do {									\
+  int save_referenced;							\
+  save_referenced = TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (DECL));\
+  if (FUNCTION_NAME_P (NAME))						\
+    ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function");			\
+  else									\
+    ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object");			\
+  TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (DECL)) = save_referenced;\
+} while (0)
+
+/* We need set the type for external libcalls.  Also note that not all
+   libcall names are passed to targetm.encode_section_info (e.g., __main).
+   Thus, we also have to do the section encoding if it hasn't been done
+   already.  */
+#undef ASM_OUTPUT_EXTERNAL_LIBCALL
+#define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN)			\
+do {								\
+  if (!FUNCTION_NAME_P (XSTR (FUN, 0)))				\
+    hppa_encode_label (FUN);					\
+  ASM_OUTPUT_TYPE_DIRECTIVE (FILE, XSTR (FUN, 0), "function");	\
+} while (0)
+
+/* We need to use the HP style for internal labels.  */
+#undef  ASM_OUTPUT_INTERNAL_LABEL
+#define ASM_OUTPUT_INTERNAL_LABEL(FILE, PREFIX, NUM)	\
+  fprintf (FILE, "%c$%s%04d\n", (PREFIX)[0], (PREFIX) + 1, NUM)
+
+#undef ASM_GENERATE_INTERNAL_LABEL
+#define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM)	\
+  sprintf (LABEL, "*%c$%s%04ld", (PREFIX)[0], (PREFIX) + 1, (long)(NUM))
+
+#else /* USING_ELFOS_H */
+
+/* We are not using GAS.  */
+#define TARGET_GAS 0
+
+/* HPUX 11 has the "new" HP assembler.  It's still lousy, but it's a whole
+   lot better than the assembler shipped with older versions of hpux.
+   However, it doesn't support weak symbols and is a bad fit with ELF.  */
+#undef NEW_HP_ASSEMBLER
+#define NEW_HP_ASSEMBLER 1
 
 /* It looks like DWARF2 will be the easiest debug format to handle on this
    platform.  */
-#define OBJECT_FORMAT_ELF
 #define DWARF2_DEBUGGING_INFO 1
 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
-/* This isn't quite ready yet.  I'm seeing it mess up some line
-   tables.  For example, we're getting lines starting/ending at
-   impossible addresses.  */
-#define DWARF2_ASM_LINE_DEBUG_INFO 1
-
-
-/* The rest of this file is copied from the generic svr4.h.  One day we
-   would like to simply include svr4.h instead of copying all these
-   definitions.  */
-
-#define READONLY_DATA_SECTION_ASM_OP	"\t.section\t.rodata"
-
-/* On svr4, we *do* have support for the .init and .fini sections, and we
-   can put stuff in there to be executed before and after `main'.  We let
-   crtstuff.c and other files know this by defining the following symbols.
-   The definitions say how to change sections to the .init and .fini
-   sections.  This is the same for all known svr4 assemblers.  */
+
+/* This target uses the ELF object file format.  */
+#define OBJECT_FORMAT_ELF
+
+#undef ASM_FILE_START
+#define ASM_FILE_START(FILE)					\
+do {								\
+  if (TARGET_64BIT)						\
+    fputs("\t.LEVEL 2.0w\n", FILE);				\
+  else if (TARGET_PA_20)					\
+    fputs("\t.LEVEL 2.0\n", FILE);				\
+  else if (TARGET_PA_11)					\
+    fputs("\t.LEVEL 1.1\n", FILE);				\
+  else								\
+    fputs("\t.LEVEL 1.0\n", FILE);				\
+  fputs("\t.SPACE $PRIVATE$,SORT=16\n\
+\t.SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31\n\
+\t.SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82\n\
+\t.SPACE $TEXT$,SORT=8\n\
+\t.SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44\n\
+\t.SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY\n", FILE);	\
+  if (profile_flag)						\
+    fprintf (FILE, "\t.IMPORT _mcount, CODE\n");		\
+  if (write_symbols != NO_DEBUG)				\
+    output_file_directive ((FILE), main_input_filename);	\
+} while (0)
+
+#undef TEXT_SECTION_ASM_OP
+#define TEXT_SECTION_ASM_OP "\t.SUBSPA $CODE$\n"
+#undef READONLY_DATA_SECTION_ASM_OP
+#define READONLY_DATA_SECTION_ASM_OP "\t.SUBSPA $LIT$\n"
+#undef DATA_SECTION_ASM_OP
+#define DATA_SECTION_ASM_OP "\t.SUBSPA $DATA$\n"
+#undef BSS_SECTION_ASM_OP
+#define BSS_SECTION_ASM_OP "\t.SUBSPA $BSS$\n"
+
+#endif /* USING_ELFOS_H */
 
 /* For the time being, we aren't using init sections.  `P' relocations
    are currently used for function references.  However, P relocations are
@@ -124,10 +239,9 @@ do {  \
    weak symbols in crtbegin.o (e.g., __register_frame_info).  Possibly
    Q relocations might avoid this problem but the GNU assembler doesn't
    support them.  */
-#if 0
-#define INIT_SECTION_ASM_OP	"\t.section\t.init"
-#define FINI_SECTION_ASM_OP	"\t.section\t.fini"
-#else
+#undef INIT_SECTION_ASM_OP
+#undef FINI_SECTION_ASM_OP
+
 #define EH_FRAME_IN_DATA_SECTION 1
 
 #undef ENDFILE_SPEC
@@ -144,32 +258,13 @@ do {  \
    of running ldd, but unfortunately the options are different for
    the two linkers.  */
 #define LDD_SUFFIX "/usr/ccs/bin/ldd"
+
 /* Skip to first '>' then advance to '/' at the beginning of the filename.  */
 #define PARSE_LDD_OUTPUT(PTR)					\
 do {								\
   while (*PTR != '>') PTR++;					\
   while (*PTR != '/') PTR++;					\
 } while (0)
-#endif
-
-/* Switch into a generic section.  */
-#define TARGET_ASM_NAMED_SECTION  default_elf_asm_named_section
-
-#define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
-
-/* This is how we tell the assembler that a symbol is weak.  */
-
-#define ASM_WEAKEN_LABEL(FILE,NAME) \
-  do { fputs ("\t.weak\t", FILE); assemble_name (FILE, NAME); \
-       fputc ('\n', FILE); } while (0)
-
-/* Write the extra assembler code needed to declare a function's result.
-   Most svr4 assemblers don't require any special declaration of the
-   result value, but there are exceptions.  */
-
-#ifndef ASM_DECLARE_RESULT
-#define ASM_DECLARE_RESULT(FILE, RESULT)
-#endif
 
 /* If using HP ld do not call pxdb.  Use size as a program that does nothing
    and returns 0.  /bin/true cannot be used because it is a script without
Index: doc/install.texi
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/doc/install.texi,v
retrieving revision 1.147
diff -u -3 -p -r1.147 install.texi
--- doc/install.texi	7 Nov 2002 22:48:10 -0000	1.147
+++ doc/install.texi	9 Nov 2002 18:54:48 -0000
@@ -2059,8 +2059,7 @@ longer a multiple of 2 bytes.
 
 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.  The HP assembler does not work with the @samp{hppa64-hp-hpux11*}
-port.
+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
@@ -2162,16 +2161,27 @@ compile GCC 3.0 and up.  Refer to @uref{
 information about obtaining precompiled GCC binaries for HP-UX.
 
 GNU binutils 2.13 or later is recommended with the 64-bit port.
-The HP assembler is not supported.  It is @emph{highly} recommended
-that the GNU linker be used as well.  Either binutils must be built
-prior to gcc, or a binary distribution of gcc or binutils must be
-obtained for the initial builds.  When starting with a HP compiler,
-it is preferable to use the ANSI compiler as the bundled compiler
-only supports traditional C.  Bootstrapping with the bundled compiler
-is tested infrequently and problems often arise because of the subtle
-differences in semantics between traditional and ISO C.  There also
-have been problems reported with various binary distributions.  This
-port still is undergoing significant development.
+The HP assembler has many limitations and is not recommended.  For
+example, it does not support weak symbols or alias definitions.
+As a result, explicit template instantiations are required when
+using C++.  Either the HP or GNU linker can be used but it may be
+necessary to use the GNU linker when dwarf2 exception support is
+implemented.
+
+There are several possible approaches to building the distribution.
+Binutils can be built first using the HP tools.  Then, the GCC
+distribution can be built.  The second approach is to build GCC
+first using the HP tools, then build binutils, then rebuild GCC.
+There have been problems with various binary distributions, so
+it is best not to start from a binary distribution.
+
+When starting with a HP compiler, it is preferable to use the ANSI
+compiler as the bundled compiler only supports traditional C.
+Bootstrapping with the bundled compiler is tested infrequently and
+problems often arise because of the subtle differences in semantics
+between traditional and ISO C.
+
+This port still is undergoing significant development.
 
 @html
 <hr />


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