Index: config.gcc
===================================================================
--- config.gcc	(revision 173240)
+++ config.gcc	(working copy)
@@ -1063,10 +1063,14 @@
 		 pa/pa64-regs.h pa/pa-hpux.h pa/pa-hpux1010.h \
 		 pa/pa-hpux11.h"
 	case ${target} in
-	*-*-hpux11.[1-9]*)
+	*-*-hpux11.[12]*)
 		tm_file="${tm_file} pa/pa-hpux1111.h pa/pa-64.h pa/pa64-hpux.h"
 		extra_options="${extra_options} pa/pa-hpux1111.opt"
 		;;
+	*-*-hpux11.[3-9]*)
+		tm_file="${tm_file} pa/pa-hpux1131.h pa/pa-64.h pa/pa64-hpux.h"
+		extra_options="${extra_options} pa/pa-hpux1131.opt"
+		;;
 	*)
 		tm_file="${tm_file} pa/pa-64.h pa/pa64-hpux.h"
 		;;
@@ -1111,10 +1115,14 @@
 	extra_options="${extra_options} pa/pa-hpux.opt pa/pa-hpux1010.opt \
 		       hpux11.opt"
 	case ${target} in
-	*-*-hpux11.[1-9]*)
+	*-*-hpux11.[12]*)
 		tm_file="${tm_file} pa/pa-hpux1111.h"
 		extra_options="${extra_options} pa/pa-hpux1111.opt"
 		;;
+	*-*-hpux11.[3-9]*)
+		tm_file="${tm_file} pa/pa-hpux1131.h"
+		extra_options="${extra_options} pa/pa-hpux1131.opt"
+		;;
 	esac
 	tmake_file="pa/t-pa-hpux11 pa/t-pa-hpux pa/t-hpux-shlib"
 	# Set the libgcc version number
@@ -1580,6 +1588,11 @@
 	extra_options="${extra_options} ia64/ilp32.opt hpux11.opt"
 	use_gcc_stdint=wrap
 	tm_file="${tm_file} hpux-stdint.h"
+	case ${target} in
+	*-*-hpux11.3*)
+		tm_file="${tm_file} ia64/hpux-unix2003.h"
+		;;
+	esac
 	;;
 ia64-hp-*vms*)
 	tm_file="${tm_file} elfos.h ia64/sysv4.h ia64/elf.h ia64/vms.h ia64/vms64.h"
Index: config/ia64/hpux-unix2003.h
===================================================================
--- config/ia64/hpux-unix2003.h	(revision 0)
+++ config/ia64/hpux-unix2003.h	(revision 0)
@@ -0,0 +1,8 @@
+
+/* For HP-UX 11.31 and greater, use unix2003.o instead of unix98.o to
+   get correct C99 snprintf behaviour with buffer overflow.  */
+
+#undef STARTFILE_SPEC
+#define STARTFILE_SPEC "%{!shared:%{static:crt0%O%s} \
+			  %{mlp64:/usr/lib/hpux64/unix2003%O%s} \
+			  %{!mlp64:/usr/lib/hpux32/unix2003%O%s}}"
Index: config/pa/pa64-hpux.h
===================================================================
--- config/pa/pa64-hpux.h	(revision 173240)
+++ config/pa/pa64-hpux.h	(working copy)
@@ -304,8 +304,15 @@
 /* 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
+#if TARGET_HPUX_11_31
 #define STARTFILE_SPEC \
+  "%{!shared: %{!symbolic: crt0%O%s} \
+     %{munix=95:unix95.o%s} %{munix=98:unix98.o%s} \
+     %{!munix=93:%{!munix=95:%{!munix=98:unix2003%O%s}}}} \
+     %{static:crtbeginT%O%s} \
+   %{!static:%{!shared:crtbegin%O%s} %{shared:crtbeginS%O%s}}"
+#elif TARGET_HPUX_11_11
+#define STARTFILE_SPEC \
   "%{!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}}"
Index: config/pa/pa-hpux.opt
===================================================================
--- config/pa/pa-hpux.opt	(revision 173240)
+++ config/pa/pa-hpux.opt	(working copy)
@@ -20,7 +20,7 @@
 
 ; The UNIX standard to use for predefines and linking.
 Variable
-int flag_pa_unix = TARGET_HPUX_11_11 ? 1998 : TARGET_HPUX_10_10 ? 1995 : 1993
+int flag_pa_unix = TARGET_HPUX_11_31 ? 2003 : TARGET_HPUX_11_11 ? 1998 : TARGET_HPUX_10_10 ? 1995 : 1993
 
 msio
 Target RejectNegative Mask(SIO) MaskExists
Index: config/pa/pa-hpux1131.opt
===================================================================
--- config/pa/pa-hpux1131.opt	(revision 0)
+++ config/pa/pa-hpux1131.opt	(revision 0)
@@ -0,0 +1,23 @@
+; Options for the HP PA-RISC port of the compiler.
+
+; Copyright (C) 2005, 2007, 2011 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 3, 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 COPYING3.  If not see
+; <http://www.gnu.org/licenses/>.
+
+munix=2003
+Target RejectNegative Var(flag_pa_unix, 2003)
+Specify UNIX standard for predefines and linking
Index: config/pa/pa-hpux1131.h
===================================================================
--- config/pa/pa-hpux1131.h	(revision 0)
+++ config/pa/pa-hpux1131.h	(revision 0)
@@ -0,0 +1,29 @@
+/* Definitions of target machine for GNU compiler, for HP PA-RISC
+   Copyright (C) 2004, 2007 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 3, 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 COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* HP-UX 11i multibyte and UNIX 98 extensions.  */
+#undef TARGET_HPUX_11_11
+#define TARGET_HPUX_11_11 1
+#undef TARGET_HPUX_11_31
+#define TARGET_HPUX_11_31 1
+
+#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=98:unix98%O%s}%{!munix=93:%{!munix=95:%{!munix=98:unix2003%O%s}}}}"
Index: config/pa/pa.h
===================================================================
--- config/pa/pa.h	(revision 173240)
+++ config/pa/pa.h	(working copy)
@@ -64,6 +64,11 @@
 #define TARGET_HPUX_11_11 0
 #endif
 
+/* HP-UX 11i multibyte and UNIX 2003 extensions.  */
+#ifndef TARGET_HPUX_11_31
+#define TARGET_HPUX_11_31 0
+#endif
+
 /* HP-UX long double library.  */
 #ifndef HPUX_LONG_DOUBLE_LIBRARY
 #define HPUX_LONG_DOUBLE_LIBRARY 0
