[comp.unix.i386] Patches for G++ 1.37.1 on SCO Unix 3.2

chip@tct.uucp (Chip Salzenberg) (08/07/90)

[ Contents: Patches for G++ under SCO Unix/386 using the SCO assembler
  and SDB debugging information. ]

This article consists of a patch for G++ 1.37.1 under SCO Unix/386.
This patch works with the standard SCO assembler.  It depends on the
presence of my already-posted patches for GCC.  Specifically, you will
need the configuration file "tm-i386v-sco.h" and the source files
"pragma.c" and "packtest.c".

This set of patches might be a good candidate for incorporation into
the standard G++ distribution.  There are a lot of SCO Unix users out
there.

Besides the typical porting modifications, this patch some cleanup of
the handling of "#pragma", motivated by the need to support the
Microsoft C "#pragma pack()" directive.  This pragma controls
structure packing on a structure-by-structure basis, which feature is
important under SCO Unix, and quite useful in its own right.  I lifted
the code from Steve Bleazard's Xenix patches.  Thanks, Steve.

The use of shared libraries ("-lc_s") under SCO Unix requires that the
linker be called, not with crt0.o as usual, but rather with crt1.o at
as the first object file and crtn.o as the last.  Therefore, I added a
new entry to the "spec" string of gcc: "%E", for ENDFILE_SPEC.  It is
defined appropriately in the SCO Unix configuration file; all versions
of Unix/386 should probably define it similarly.

I did not include one necessary Makefile change in the patch file.
The list of language-independent object files (the OBJS variable)
must include the new module "pragma.o".

Additional notes for SCO Unix users:

   SCO Unix sites should set "CC" and "OLDCC" to "rcc", the AT&T
   compiler, and make all other modifications to the Makefile that
   are suggested in the comments for SysV.  Specifically, include
   -lPW.

   The name "stamp-extract.c" is longer than 14 characters, so SCO
   Unix, in a fit of POSIX compliance, won't create it.  If this
   problem hits you, change Makefile to use the name "stamp-extract".

   SCO International Language support is included with the "-scointl"
   flag; otherwise, it is omitted.

SHAR AND ENJOY.
    -- Chip Salzenberg, <chip@tct.uucp> or  <chip%tct@pdn.paradyne.com>

Index: gcc.c
***************
*** 81,84 ****
--- 81,85 ----
   %L     process LIB_SPEC as a spec.
   %S     process STARTFILE_SPEC as a spec.  A capital S is actually used here.
+  %E     process ENDFILE_SPEC as a spec.  A capital E is actually used here.
   %c	process SIGNED_CHAR_SPEC as a spec.
   %C     process CPP_SPEC as a spec.  A capital C is actually used here.
***************
*** 194,197 ****
--- 195,203 ----
  #endif
  
+ /* config.h can define ENDFILE_SPEC to override the default crtn files.  */
+ #ifndef ENDFILE_SPEC
+ #define ENDFILE_SPEC ""
+ #endif
+ 
  /* This spec is used for telling cpp whether char is signed or not.  */
  #define SIGNED_CHAR_SPEC  \
***************
*** 225,229 ****
  };
  
! #define cplusplus_string \
    "cpp -+ %{nostdinc} %{C} %{v} %{D*} %{U*} %{I*} %{M*} %{i*} \
         -undef -D__GNUC__ -D__GNUG__ -D__cplusplus %p %P\
--- 231,235 ----
  };
  
! static char cplusplus_string[] =
    "cpp -+ %{nostdinc} %{C} %{v} %{D*} %{U*} %{I*} %{M*} %{i*} \
         -undef -D__GNUC__ -D__GNUG__ -D__cplusplus %p %P\
***************
*** 239,243 ****
  	     %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %{gg:-G %g.sym}\
  		%{c:%{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
!                    %{!pipe:%g.s}\n }}}"
  
  /* Here are the specs for compiling files with various known suffixes.
--- 245,249 ----
  	     %{!S:as %{R} %{j} %{J} %{h} %{d2} %a %{gg:-G %g.sym}\
  		%{c:%{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
!                    %{!pipe:%g.s}\n }}}";
  
  /* Here are the specs for compiling files with various known suffixes.
***************
*** 274,277 ****
--- 280,285 ----
    {".cxx",
     cplusplus_string},
+   {".cpp",
+    cplusplus_string},
  
    {".i",
***************
*** 303,307 ****
  char *collect_spec =
    "%{!c:%{!M*:%{!E:%{!S:collect -o %g.S %g.R\n\
! as %g.S -o %g.O\n\
  ld %{o*} %g.R %g.O\n\
  }}}}";
--- 311,315 ----
  char *collect_spec =
    "%{!c:%{!M*:%{!E:%{!S:collect -o %g.S %g.R\n\
! as %a %g.S -o %g.O\n\
  ld %{o*} %g.R %g.O\n\
  }}}}";
***************
*** 311,315 ****
   %{A} %{d} %{e*} %{N} %{n} %{r} %{s} %{S} %{T*} %{t} %{u*} %{X} %{x} %{z}\
   %{y*} %{!nostdlib:%S} \
!  %{L*} %o %{!nostdlib:-lg++ gnulib%s %{g:-lg} %L}\n }}}}";
  #else
  /* Here is the spec for running the linker, after compiling all files.  */
--- 319,323 ----
   %{A} %{d} %{e*} %{N} %{n} %{r} %{s} %{S} %{T*} %{t} %{u*} %{X} %{x} %{z}\
   %{y*} %{!nostdlib:%S} \
!  %{L*} %o %{!nostdlib:gnulib%s %{g:-lg} %L gnulib%s %E}\n }}}}";
  #else
  /* Here is the spec for running the linker, after compiling all files.  */
***************
*** 317,321 ****
   %{A} %{d} %{e*} %{N} %{n} %{r} %{s} %{S} %{T*} %{t} %{u*} %{X} %{x} %{z}\
   %{y*} %{!nostdlib:%S} \
!  %{L*} %o %{!nostdlib:-lg++ gnulib%s %{g:-lg} %L}\n }}}}";
  #endif
  
--- 325,329 ----
   %{A} %{d} %{e*} %{N} %{n} %{r} %{s} %{S} %{T*} %{t} %{u*} %{X} %{x} %{z}\
   %{y*} %{!nostdlib:%S} \
!  %{L*} %o %{!nostdlib:gnulib%s %{g:-lg} %L gnulib%s %E}\n }}}}";
  #endif
  
***************
*** 1358,1361 ****
--- 1366,1373 ----
  	  case 'S':
  	    do_spec_1 (STARTFILE_SPEC, 0);
+ 	    break;
+ 
+ 	  case 'E':
+ 	    do_spec_1 (ENDFILE_SPEC, 0);
  	    break;
  

Index: config.g++
***************
*** 109,112 ****
--- 109,117 ----
  		machine_type=i386gas
  		;;		
+ 	i386v-sco)
+ 		cpu_type=i386
+ 		configuration_file=xm-i386v.h
+ 		machine_type=${machine}
+ 		;;		
  	i860)
  		;;

Index: cplus-decl.c
***************
*** 2313,2317 ****
  }
  
! static int sigsegv ()
  {
    error ("Segmentation violation");
--- 2313,2317 ----
  }
  
! static void sigsegv ()
  {
    error ("Segmentation violation");

Index: cplus-lex.c
***************
*** 1126,1130 ****
        pending_inlines = pending_inlines->next;
        finput = finput2;
! #if defined(i386) && !defined(sequent) && !defined(sun386)
        finput2->_ptr = finput2->_base = t->buf;
        _bufend(finput2) = t->buf + t->len;
--- 1126,1130 ----
        pending_inlines = pending_inlines->next;
        finput = finput2;
! #if defined(i386) && !defined(sequent) && !defined(sun386) && !defined(M_UNIX)
        finput2->_ptr = finput2->_base = t->buf;
        _bufend(finput2) = t->buf + t->len;
***************
*** 1777,1822 ****
  	      && getch (finput) == 'g'
  	      && getch (finput) == 'm'
! 	      && getch (finput) == 'a')
! /* Change by Bryan Boreham, Kewill, Sun Jul 23 15:53:24 1989.
!    This whole section added to support dumping of
!    compilations in the middle. */
  	    {
! 	      /* Read first nonwhite char after the `#pragma'.  */
! 	      do
! 		c = getch (finput);
! 	      while (c == ' ' || c == '\t');
  
! #ifndef MERGED
! 	      /* See if it is "dump" */
  
! 	      if (c == 'd'
! 		  && getch (finput) == 'u'
! 		  && getch (finput) == 'm'
! 		  && getch (finput) == 'p'
! 		  && ((c = getch (finput)) == ' ' || c == '\t' || c == '\n'))
  		{
! #ifdef VMS
! 			;		/* Are you crazy? */
! #else
  		  ungetc (c, finput);
  		  dump_data();
  		  longjmp (toplevel, 1);
! #endif
  		}
  	      else
! #endif
! 		if (c == 'v'
! 		       && getch (finput) == 't'
! 		       && getch (finput) == 'a'
! 		       && getch (finput) == 'b'
! 		       && getch (finput) == 'l'
! 		       && getch (finput) == 'e'
! 		       && ((c = getch (finput)) == ' ' || c == '\t' || c == '\n'))
  		{
  		  extern tree pending_vtables;
  
! 		  /* More follows: it must be a string constant (class name).  */
  		  token = yylex ();
! 		  if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
  		    {
  		      error ("invalid #pragma vtable");
--- 1777,1848 ----
  	      && getch (finput) == 'g'
  	      && getch (finput) == 'm'
! 	      && getch (finput) == 'a'
! 	      && ((c = getc (finput)) == ' ' || c == '\t'))
  	    {
! 	      char pragma_name[32]; /* arbitrary pragma directive size */
! 	      int i;
  
! 	      while ((c = getc (finput)) == ' ' || c == '\t')
! 		;
! 	      ungetc (c, finput);
! 	      for (i = 0; i < sizeof(pragma_name) - 1; ++i) 
! 	      {
! 		if ((c = getc (finput)) < 'a' || c > 'z')
! 		  {
! 		    ungetc (c, finput);
! 		    break;
! 		  }
! 		pragma_name[i] = c;
! 	      }
! 	    pragma_name[i] = '\0';
! 
! #ifdef PRAGMA_PACK
! 	    if (strcmp(token_buffer, "pack") == 0)
! 	      {
! 		if ((c = getc (finput)) != '(')
! 		  {
! 		    ungetc (c, finput);
! 		    error ("invalid #pragma pack");
! 		    goto skipline;
! 		  }
! 
! 		if ((c = getc (finput)) == '1' || c == '2' || c == '4')
! 		  {
! 		    pragma_pack (c - '0');
! 		    c = getc (finput);
! 		  }
! 		else
! 		  pragma_pack_default ();
  
! 		if (c != ')')
! 		  {
! 		    ungetc (c, finput);
! 		    error ("invalid #pragma pack");
! 		    goto skipline;
! 		  }
! 	      }
! 	      else
! #endif /* PRAGMA_PACK */
! 
! #ifndef MERGED
! 	      if (strcmp(pragma_name, "dump") == 0)
  		{
! #ifndef VMS			/* Are you crazy? */
  		  ungetc (c, finput);
  		  dump_data();
  		  longjmp (toplevel, 1);
! #endif /* not VMS */
  		}
  	      else
! #endif /* not MERGED */
! 
! 	      if (strcmp(pragma_name, "vtable") == 0)
  		{
  		  extern tree pending_vtables;
  
! 		  /* More follows: it must be a string constant (class name).*/
  		  token = yylex ();
! 		  if (token != STRING
! 		   || TREE_CODE (yylval.ttype) != STRING_CST)
  		    {
  		      error ("invalid #pragma vtable");
***************
*** 1835,1845 ****
  		    warning ("trailing characters ignored");
  		}
! 	      else if (c == 'u'
! 		       && getch (finput) == 'n'
! 		       && getch (finput) == 'i'
! 		       && getch (finput) == 't'
! 		       && ((c = getch (finput)) == ' ' || c == '\t' || c == '\n'))
  		{
! 		  /* More follows: it must be a string constant (unit name).  */
  		  token = yylex ();
  		  if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
--- 1861,1867 ----
  		    warning ("trailing characters ignored");
  		}
! 	      else if (strcmp(pragma_name, "unit") == 0)
  		{
! 		  /* More follows: it must be a string constant (unit name). */
  		  token = yylex ();
  		  if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
***************
*** 2284,2288 ****
  		 end of this function.  */
  	      pending_inlines = pending_inlines->next;
! #if defined(i386) && !defined(sequent) && !defined(sun386)
  	      finput2->_ptr = finput2->_base = t->buf;
  	      _bufend(finput2) = t->buf + t->len;
--- 2306,2310 ----
  		 end of this function.  */
  	      pending_inlines = pending_inlines->next;
! #if defined(i386) && !defined(sequent) && !defined(sun386) && !defined(M_UNIX)
  	      finput2->_ptr = finput2->_base = t->buf;
  	      _bufend(finput2) = t->buf + t->len;

Index: gnulib3.c
***************
*** 24,30 ****
--- 24,35 ----
  #endif
  
+ #if __STDC__
+ #define ON_EXIT(PROCP, ARG) \
+   do { extern void PROCP (); atexit (PROCP, ARG); } while (0)
+ #else
  #if defined(sun)
  #define ON_EXIT(PROCP, ARG) \
    do { extern void PROCP (); on_exit (PROCP, ARG); } while (0)
+ #endif
  #endif
  

Index: stor-layout.c
***************
*** 471,474 ****
--- 471,478 ----
  
        layout_decl (field, var_size ? size_unit : const_size);
+ #ifdef PRAGMA_PACK
+       if (pragma_pack_seen())
+         DECL_ALIGN(field) = MIN(pragma_align_val(), DECL_ALIGN(field));
+ #endif
        desired_align = DECL_ALIGN (field);
  

Index: toplev.c
***************
*** 1986,1990 ****
  
    decl_printable_name = decl_name;
!   lang_expand_expr = fancy_abort;
  
    /* Initialize whether `char' is signed.  */
--- 1986,1990 ----
  
    decl_printable_name = decl_name;
!   lang_expand_expr = (struct rtx_def *(*)()) fancy_abort;
  
    /* Initialize whether `char' is signed.  */
-- 
Chip Salzenberg at ComDev/TCT     <chip@tct.uucp>, <uunet!ateng!tct!chip>