[Bug libstdc++/17005] wide character strings don't work on HP-UX 11i using gcc 3.4.1

John David Anglin dave@hiauly1.hia.nrc.ca
Sat Aug 21 18:58:00 GMT 2004


This is a work in progress.  In one sense, the patch is complete
except for documenting the -munix= option.  However, it's dangerous
to use other than default for this option.

The start file selection adds unix95.o or unix98.o when using
UNIX 95 and 98, respectively.  The sole function of these files
is to provide a start of value for the int __xpg4_extended_mask.
The supported values are:

UNIX		__xpg4_extended_mask
93		0
95		0xf
98		0x6f

The mask value alters the behavior of various functions (e.g.,
wcsftime -- third argument changes from const char * to const
wchar_t *).

I'm trying to decide if further work is needed.  If no one uses
anything but the default values, there's no problem.  However,
library code that uses the xpg4 extended support really needs
to save, set and restore the __xpg4_extended_mask when it uses
functions affected by the mask value.

I'm trying to decide whether this should be done automatically.
However, the list is fairly long and it's a bit tricky to determine
all the interactions.

Comments?

Dave
-- 
J. David Anglin                                  dave.anglin@nrc-cnrc.gc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6602)
-------------- next part --------------
? config/pa/pa-hpux11i.h
? config/pa/xxx.h
Index: config/pa/pa-hpux.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/pa/pa-hpux.h,v
retrieving revision 1.14
diff -u -3 -p -r1.14 pa-hpux.h
--- config/pa/pa-hpux.h	27 Feb 2004 14:50:46 -0000	1.14
+++ config/pa/pa-hpux.h	21 Aug 2004 14:54:28 -0000
@@ -99,7 +99,7 @@ Boston, MA 02111-1307, USA.  */
 #undef LINK_SPEC
 #if ((TARGET_DEFAULT | TARGET_CPU_DEFAULT) & MASK_PA_11)
 #define LINK_SPEC \
-  "%{!mpa-risc-1-0:%{!shared:-L/lib/pa1.1 -L/usr/lib/pa1.1 }}%{mlinker-opt:-O} %{!shared:-u main} %{static:-a archive} %{g*:-a archive} %{shared:-b}"
+  "%{!mpa-risc-1-0:%{!march=1.0:%{!shared:-L/lib/pa1.1 -L/usr/lib/pa1.1 }}}%{mlinker-opt:-O} %{!shared:-u main} %{static:-a archive} %{g*:-a archive} %{shared:-b}"
 #else
 #define LINK_SPEC \
   "%{mlinker-opt:-O} %{!shared:-u main} %{static:-a archive} %{g*:-a archive} %{shared:-b}"
@@ -113,6 +113,10 @@ Boston, MA 02111-1307, USA.  */
    transformation of fputs_unlocked and fprintf_unlocked to fputc_unlocked.  */
 #define DONT_HAVE_FPUTC_UNLOCKED
 
+/* We lack support for many functions defined by the C99 standard.  */
+#undef TARGET_C99_FUNCTIONS
+#define TARGET_C99_FUNCTIONS 0
+
 /* We want the entry value of SP saved in the frame marker for
    compatibility with the HP-UX unwind library.  */
 #undef TARGET_HPUX_UNWIND_LIBRARY
Index: config/pa/pa-hpux10.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/pa/pa-hpux10.h,v
retrieving revision 1.20
diff -u -3 -p -r1.20 pa-hpux10.h
--- config/pa/pa-hpux10.h	20 Jul 2004 19:52:10 -0000	1.20
+++ config/pa/pa-hpux10.h	21 Aug 2004 14:54:28 -0000
@@ -80,7 +80,7 @@ Boston, MA 02111-1307, USA.  */
 #undef LINK_SPEC
 #if ((TARGET_DEFAULT | TARGET_CPU_DEFAULT) & MASK_PA_11)
 #define LINK_SPEC \
-  "%{!mpa-risc-1-0:%{!shared:-L/lib/pa1.1 -L/usr/lib/pa1.1 }}\
+  "%{!mpa-risc-1-0:%{!march=1.0:%{!shared:-L/lib/pa1.1 -L/usr/lib/pa1.1 }}}\
    %{!shared:%{p:-L/lib/libp %{!static:\
      %nWarning: consider linking with `-static' as system libraries with\n\
      %n  profiling support are only provided in archive format}}}\
Index: config/pa/pa-hpux11.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/pa/pa-hpux11.h,v
retrieving revision 1.15
diff -u -3 -p -r1.15 pa-hpux11.h
--- config/pa/pa-hpux11.h	14 Aug 2004 19:02:58 -0000	1.15
+++ config/pa/pa-hpux11.h	21 Aug 2004 14:54:28 -0000
@@ -24,69 +24,77 @@ Boston, MA 02111-1307, USA.  */
    the definition of __cplusplus.  We define _INCLUDE_LONGLONG
    to prevent nlist.h from defining __STDC_32_MODE__ (no longlong
    support).  We define __STDCPP__ to get certain system headers
-   (notably assert.h) to assume standard preprocessor behavior in C++.
-
-   The C99 support is incomplete.  We define _INCLUDE__STDC_A1_SOURCE
-   to provide the extended multibyte and wide-character utilities available
-   under HP-UX 11i.  Defining _HPUX_SOURCE would give us some more
-   features but it also adds stuff that isn't in C99.  */
+   (notably assert.h) to assume standard preprocessor behavior in C++.  */
 #undef TARGET_OS_CPP_BUILTINS
-#define TARGET_OS_CPP_BUILTINS()				\
-  do								\
-    {								\
-	builtin_assert ("system=hpux");				\
-	builtin_assert ("system=unix");				\
-	builtin_define ("__hp9000s800");			\
-	builtin_define ("__hp9000s800__");			\
-	builtin_define ("__hpux");				\
-	builtin_define ("__hpux__");				\
-	builtin_define ("__unix");				\
-	builtin_define ("__unix__");				\
-	if (c_dialect_cxx ())					\
-	  {							\
-	    builtin_define ("_HPUX_SOURCE");			\
-	    builtin_define ("_INCLUDE_LONGLONG");		\
-	    builtin_define ("_INCLUDE__STDC_A1_SOURCE");	\
-	    builtin_define ("__STDC_EXT__");			\
-	    builtin_define ("__STDCPP__");			\
-	  }							\
-	else							\
-	  {							\
-	    if (!flag_iso)					\
-	      {							\
-		builtin_define ("_HPUX_SOURCE");		\
-		builtin_define ("_INCLUDE__STDC_A1_SOURCE");	\
-		if (preprocessing_trad_p ())			\
-		  {						\
-		    builtin_define ("hp9000s800");		\
-		    builtin_define ("hppa");			\
-		    builtin_define ("hpux");			\
-		    builtin_define ("unix");			\
-		    builtin_define ("__CLASSIC_C__");		\
-		    builtin_define ("_PWB");			\
-		    builtin_define ("PWB");			\
-		  }						\
-		else						\
-		  builtin_define ("__STDC_EXT__");		\
-	      }							\
-	    else if (flag_isoc99)				\
-	      {							\
-		builtin_define ("_INCLUDE__STDC_A1_SOURCE");	\
-	      }							\
-	    if (!TARGET_64BIT)					\
-	      builtin_define ("_ILP32");			\
-	  }							\
-	if (TARGET_SIO)						\
-	  builtin_define ("_SIO");				\
-	else							\
-	  {							\
-	    builtin_define ("__hp9000s700");			\
-	    builtin_define ("__hp9000s700__");			\
-	    builtin_define ("_WSIO");				\
-	  }							\
-    }								\
+#define TARGET_OS_CPP_BUILTINS()					\
+  do									\
+    {									\
+	builtin_assert ("system=hpux");					\
+	builtin_assert ("system=unix");					\
+	builtin_define ("__hp9000s800");				\
+	builtin_define ("__hp9000s800__");				\
+	builtin_define ("__hpux");					\
+	builtin_define ("__hpux__");					\
+	builtin_define ("__unix");					\
+	builtin_define ("__unix__");					\
+	if (c_dialect_cxx ())						\
+	  {								\
+	    builtin_define ("_HPUX_SOURCE");				\
+	    builtin_define ("_INCLUDE_LONGLONG");			\
+	    builtin_define ("__STDC_EXT__");				\
+	    builtin_define ("__STDCPP__");				\
+	  }								\
+	else								\
+	  {								\
+	    if (!flag_iso)						\
+	      {								\
+		builtin_define ("_HPUX_SOURCE");			\
+		if (preprocessing_trad_p ())				\
+		  {							\
+		    builtin_define ("hp9000s800");			\
+		    builtin_define ("hppa");				\
+		    builtin_define ("hpux");				\
+		    builtin_define ("unix");				\
+		    builtin_define ("__CLASSIC_C__");			\
+		    builtin_define ("_PWB");				\
+		    builtin_define ("PWB");				\
+		  }							\
+		else							\
+		  builtin_define ("__STDC_EXT__");			\
+	      }								\
+	  }								\
+	if (!TARGET_64BIT)						\
+	  builtin_define ("_ILP32");					\
+	if (flag_pa_unix >= 1995)					\
+	  builtin_define ("_XOPEN_UNIX");				\
+	if (TARGET_HPUX_11_11)						\
+	  {								\
+	    if (flag_pa_unix >= 1998)					\
+	      {								\
+		builtin_define ("_INCLUDE__STDC_A1_SOURCE");		\
+		builtin_define ("_INCLUDE_XOPEN_SOURCE_500");		\
+	      }								\
+	    else if (flag_isoc94 || flag_isoc99 || c_dialect_cxx ())	\
+	      warning ("-munix=98 option required for C89 "		\
+		       "Amendment 1 features.\n");			\
+	  }								\
+	if (TARGET_SIO)							\
+	  builtin_define ("_SIO");					\
+	else								\
+	  {								\
+	    builtin_define ("__hp9000s700");				\
+	    builtin_define ("__hp9000s700__");				\
+	    builtin_define ("_WSIO");					\
+	  }								\
+    }									\
   while (0)
 
+#undef SUBTARGET_OPTIONS
+#define SUBTARGET_OPTIONS						\
+  { "unix=",			&pa_unix_string,			\
+    N_("Specify UNIX standard for predefines and linking.\n"		\
+       "Supported values are 93 and 95."), 0}
+
 #undef CPP_SPEC
 #define CPP_SPEC \
   "%{mt|pthread:-D_REENTRANT -D_THREAD_SAFE -D_POSIX_C_SOURCE=199506L}"
@@ -99,7 +107,7 @@ Boston, MA 02111-1307, USA.  */
 #undef LINK_SPEC
 #if ((TARGET_DEFAULT | TARGET_CPU_DEFAULT) & MASK_PA_11)
 #define LINK_SPEC \
-  "%{!mpa-risc-1-0:%{!shared:-L/lib/pa1.1 -L/usr/lib/pa1.1 }}\
+  "%{!mpa-risc-1-0:%{!march=1.0:%{!shared:-L/lib/pa1.1 -L/usr/lib/pa1.1 }}}\
    %{!shared:%{p:-L/lib/libp -L/usr/lib/libp %{!static:\
      %nWarning: consider linking with `-static' as system libraries with\n\
      %n  profiling support are only provided in archive format}}}\
@@ -127,6 +135,11 @@ Boston, MA 02111-1307, USA.  */
      %{mt|pthread:-lpthread} -lc \
      %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}"
 
+#undef STARTFILE_SPEC
+#define STARTFILE_SPEC  \
+  "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}} \
+     %{munix=95:unix95%O%s}}"
+
 /* Under hpux11, the normal location of the `ld' and `as' programs is the
    /usr/ccs/bin directory.  */
 
Index: config/pa/pa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/pa/pa.c,v
retrieving revision 1.273
diff -u -3 -p -r1.273 pa.c
--- config/pa/pa.c	20 Aug 2004 15:11:42 -0000	1.273
+++ config/pa/pa.c	21 Aug 2004 14:54:29 -0000
@@ -166,6 +166,12 @@ enum processor_type pa_cpu;
 /* String to hold which cpu we are scheduling for.  */
 const char *pa_cpu_string;
 
+/* String used with the -munix= option.  */
+const char *pa_unix_string;
+
+/* The UNIX standard to use for predefines and linking.  */
+int flag_pa_unix;
+
 /* Counts for the number of callee-saved general and floating point
    registers which were saved by the current function's prologue.  */
 static int gr_saved, fr_saved;
@@ -421,6 +427,25 @@ override_options (void)
       warning ("unknown -march= option (%s).\nValid options are 1.0, 1.1, and 2.0\n", pa_arch_string);
     }
 
+  /* Set the default UNIX standard.  This option is only used under HP-UX.
+     It affects the generated predefines and the starting value for the
+     __xpg4_extended_mask.  */
+  if (pa_unix_string == NULL)
+    pa_unix_string = TARGET_HPUX_11_11 ? "98" : "93";
+
+  if (!strcmp (pa_unix_string, "93"))
+    flag_pa_unix = 1993;
+  else if (!strcmp (pa_unix_string, "95"))
+    flag_pa_unix = 1995;
+  else if (TARGET_HPUX_11_11 && !strcmp (pa_unix_string, "98"))
+    flag_pa_unix = 1998;
+  else if (TARGET_HPUX_11_11)
+    warning ("unknown -munix= option (%s).\nValid options are 93, 95 and 98\n",
+	     pa_unix_string);
+  else
+    warning ("unknown -munix= option (%s).\nValid options are 93 and 95\n",
+	     pa_unix_string);
+
   if (pa_fixed_range_string)
     fix_range (pa_fixed_range_string);
 
Index: config/pa/pa.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/pa/pa.h,v
retrieving revision 1.232
diff -u -3 -p -r1.232 pa.h
--- config/pa/pa.h	20 Aug 2004 15:11:43 -0000	1.232
+++ config/pa/pa.h	21 Aug 2004 14:54:30 -0000
@@ -67,6 +67,10 @@ extern const char *pa_fixed_range_string
 extern const char *pa_cpu_string;
 extern enum processor_type pa_cpu;
 
+/* For -munix= option.  */
+extern const char *pa_unix_string;
+extern int flag_pa_unix;
+
 #define pa_cpu_attr ((enum attr_cpu)pa_cpu)
 
 /* Print subsidiary information on the compiler version in use.  */
@@ -188,6 +192,11 @@ extern int target_flags;
 #define TARGET_SOM 0
 #endif
 
+/* HP-UX 11i multibyte and UNIX 98 extensions.  */
+#ifndef TARGET_HPUX_11_11
+#define TARGET_HPUX_11_11 0
+#endif
+
 /* The following three defines are potential target switches.  The current
    defines are optimal given the current capabilities of GAS and GNU ld.  */
 
@@ -310,14 +319,19 @@ extern int target_flags;
 #define TARGET_OPTIONS							\
 {									\
   { "arch=",			&pa_arch_string,			\
-    N_("Specify PA-RISC architecture for code generation.  "		\
+    N_("Specify PA-RISC architecture for code generation.\n"		\
        "Values are 1.0, 1.1 and 2.0."), 0},				\
   { "fixed-range=",		&pa_fixed_range_string,			\
-    N_("Specify range of registers to make fixed"), 0},			\
+    N_("Specify range of registers to make fixed."), 0},		\
   { "schedule=",		&pa_cpu_string,				\
-    N_("Specify CPU for scheduling purposes"), 0}			\
+    N_("Specify CPU for scheduling purposes."), 0},			\
+  SUBTARGET_OPTIONS							\
 }
 
+#ifndef SUBTARGET_OPTIONS
+#define SUBTARGET_OPTIONS
+#endif
+
 /* Support for a compile-time default CPU, et cetera.  The rules are:
    --with-schedule is ignored if -mschedule is specified.
    --with-arch is ignored if -march is specified.  */
Index: config/pa/pa64-hpux.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/pa/pa64-hpux.h,v
retrieving revision 1.35
diff -u -3 -p -r1.35 pa64-hpux.h
--- config/pa/pa64-hpux.h	5 Aug 2004 20:57:06 -0000	1.35
+++ config/pa/pa64-hpux.h	21 Aug 2004 14:54:30 -0000
@@ -265,11 +265,19 @@ do {								\
 /* The following STARTFILE_SPEC and ENDFILE_SPEC defines provide the
    magic needed to run initializers and finalizers.  */
 #undef STARTFILE_SPEC
+#if TARGET_HPUX_11_11
 #define STARTFILE_SPEC \
-  "%{!shared: %{!symbolic: crt0.o%s}} %{static:crtbeginT.o%s} \
-   %{!static:%{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}}"
+  "%{!shared: %{!symbolic: crt0%O%s} %{munix=95:unix95%O%s} \
+     %{!munix=93:%{!munix=95:unix98%O%s}}} %{static:crtbeginT%O%s} \
+   %{!static:%{!shared:crtbegin%O%s} %{shared:crtbeginS%O%s}}"
+#else
+#define STARTFILE_SPEC \
+  "%{!shared: %{!symbolic: crt0%O%s} %{munix=95:unix95%O%s}} \
+   %{static:crtbeginT%O%s} %{!static:%{!shared:crtbegin%O%s} \
+   %{shared:crtbeginS%O%s}}"
+#endif
 #undef ENDFILE_SPEC
-#define ENDFILE_SPEC "%{!shared:crtend.o%s} %{shared:crtendS.o%s}"
+#define ENDFILE_SPEC "%{!shared:crtend%O%s} %{shared:crtendS%O%s}"
 
 /* Since HP uses the .init and .fini sections for array initializers
    and finalizers, we need different defines for INIT_SECTION_ASM_OP
--- /dev/null	Sat Aug 21 09:59:40 2004
+++ config/pa/pa-hpux11i.h	Sat Aug 21 03:13:30 2004
@@ -0,0 +1,34 @@
+/* Definitions of target machine for GNU compiler, for HP PA-RISC
+   Copyright (C) 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.  */
+
+/* HP-UX 11i multibyte and UNIX 98 extensions.  */
+#undef TARGET_HPUX_11_11
+#define TARGET_HPUX_11_11 1
+
+#undef SUBTARGET_OPTIONS
+#define SUBTARGET_OPTIONS						\
+  { "unix=",			&pa_unix_string,			\
+    N_("Specify UNIX standard for predefines and linking.\n"		\
+       "Supported values are 93, 95 and 98."), 0}
+
+#undef STARTFILE_SPEC
+#define STARTFILE_SPEC  \
+  "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}} \
+     %{munix=95:unix95%O%s}%{!munix=93:%{!munix=95:unix98%O%s}}}"


More information about the Gcc mailing list