This patch improves unix 2003 conformance on HP-UX 11.31 systems by linking in the unix2003.o object instead of the unix98.o object. The only difference I am aware of between the two is that linking in unix2003.o alters the behaviour of snprintf when the buffer is not large enough to hold the string being printed. It used to return -1, but with unix2003.o linked in it will return the number of characters that would have been printed if it hadn't been truncated.
For IA64 HP-UX 11.31 I just link in this file instead of unix98.o. This is similar to how I handled unix98.o before, it just gets linked in and there are no options to choose one vs. the other. For HPPA HP-UX 11.31 I added -munix=2003 to match the existing -munix=93 and -munix=95 flags and made 2003 the default for 11.31 systems. I already ran the PA changes past Dave Anglin and will check this in later this week if there are no objections. Tested on 11.31 PA and IA64 systems. Steve Ellcey s...@cup.hp.com 2011-05-02 Steve Ellcey <s...@cup.hp.com> * config.gcc (hppa*64*-*-hpux11*): Modify tm_file and extra_options for 11.31. (hppa[12]*-*-hpux11*): Ditto. (ia64*-*-hpux*): Add ia64/hpux-unix2003.h to tm_file. * config/ia64/hpux-unix2003.h: New. * config/pa/pa-hpux1131.opt: New. * config/pa/pa-hpux1131.h: New. * config/pa/pa64-hpux.h (STARTFILE_SPEC): Use unix2003.o if requested. * config/pa/pa-hpux.opt (flag_pa_unix): Check TARGET_HPUX_11_31 value. config/pa/pa.h (TARGET_HPUX_11_31): Provide default (0) value. 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