From: mrs@cygnus.com (Mike Stump)
Subject: Re:  G++ 2.1 Bug SunOS4.1.1 Constructor not called for global variables.
Organization: GNUs Not Usenet
Distribution: gnu
Date: Tue, 14 Apr 1992 17:13:10 GMT

This is a ``user'' problem, not a compiler problem.  One MUST use
gas and GNU ld.

> Newsgroups: gnu.g++.bug
> From: harlan@physik.tu-muenchen.de (Magnus Harlander)
> Subject: G++ 2.1 Bug SunOS4.1.1 Constructor not called for global variables.
> Organization: Technische Universitaet Muenchen, Germany
> Date: 	Mon, 13 Apr 92 16:50:17 +0200
> Message-Id: <harlan.703173017@Physik.TU-Muenchen.DE>
> To: bug-g++@prep.ai.mit.edu

> I've some problems with g++ 2.1 on a Sparc with SunOS 4.1.1. String.{h,cc}
> is from libg++-2.0.

> Here is what's going on.
> The file :
> ===============================================
> x.cc
> ===============================================
> #include <String.h>

> String y("xxxxx");

> main(){
>     cout << y << "\n";
> }
> ===============================================

> g++ -g -v -I. -o x x.cc String.cc
> Reading specs from /usr/local/gnu/lib/gcc-lib/sun4-sunos4.1/2.1/specs
> gcc version 2.1
>  /usr/local/gnu/lib/gcc-lib/sun4-sunos4.1/2.1/cpp -lang-c++ -v -I.
> -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix
> -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -g x.cc
> /usr/tmp/cc002586.i
> GNU CPP version 2.1 (sparc)
>  /usr/local/gnu/lib/gcc-lib/sun4-sunos4.1/2.1/cc1plus
> /usr/tmp/cc002586.i -quiet -dumpbase x.cc -g -version -o
> /usr/tmp/cc002586.s
> GNU C++ version 2.1 (sparc) compiled by GNU C version 2.1.
>  as -o x.o /usr/tmp/cc002586.s
>  /usr/local/gnu/lib/gcc-lib/sun4-sunos4.1/2.1/cpp -lang-c++ -v -I.
> -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix
> -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -g
> String.cc /usr/tmp/cc002586.i
> GNU CPP version 2.1 (sparc)
>  /usr/local/gnu/lib/gcc-lib/sun4-sunos4.1/2.1/cc1plus
> /usr/tmp/cc002586.i -quiet -dumpbase String.cc -g -version -o
> /usr/tmp/cc002586.s
> GNU C++ version 2.1 (sparc) compiled by GNU C version 2.1.
>  as -o String.o /usr/tmp/cc002586.s
>  ld -e start -dc -dp -o x /lib/crt0.o
> -L/usr/local/gnu/lib/gcc-lib/sun4-sunos4.1/2.1/ -L/usr/local/gnu/lib/
> x.o String.o -lg++ -lgcc -lc -lg -lgcc
> harlan@ss6 1094 c/cctest > ./x 
> Segmentation fault (core dumped)

> harlan@ss6 1095 c/cctest > gdb x
> GDB is free software and you are welcome to distribute copies of it
>  under certain conditions; type "show copying" to see the conditions.
> There is absolutely no warranty for GDB; type "show warranty" for
> details.
> GDB 4.4, Copyright 1991 Free Software Foundation, Inc...
> Function default_doubleVec_error_handler not defined.
> (gdb) r
> Starting program: /home/t30b/lvh/harlan/c/cctest/x 

> Program received signal 11, Segmentation fault
> 0xf77323c0 in strlen ()
> (gdb) up
> #1  0x1a08c in operator<< ()
> (gdb) 
> #2  0x4bb4 in operator<< (s=@0x2a450, x=@0x2a210) at ./String.h:1120
> 1120       s << x.chars(); return s;
> (gdb) 
> #3  0x22c8 in main () at x.cc:6
> 6           cout << y << "\n";
> (gdb) do
> #2  0x4bb4 in operator<< (s=@0x2a450, x=@0x2a210) at ./String.h:1120
> 1120       s << x.chars(); return s;
> (gdb) p x
> $1 = (String &) @0x2a210: {rep = 0x0}
> (gdb)  
> (gdb) b String::String
> [0] cancel
> [1] all
> [2] file:./String.h; line number:477
> [3] file:./String.h; line number:475
> [4] file:./String.h; line number:471
> [5] file:./String.h; line number:469
> [6] file:./String.h; line number:473
> [7] file:./String.h; line number:467
> [8] file:./String.h; line number:465
> > 1
> Breakpoint 1 at 0x2620: file ./String.h, line 477.
> Breakpoint 2 at 0x260c: file ./String.h, line 475.
> Breakpoint 3 at 0x2564: file ./String.h, line 471.
> Breakpoint 4 at 0x2524: file ./String.h, line 469.
> Breakpoint 5 at 0x25cc: file ./String.h, line 473.
> Breakpoint 6 at 0x24e8: file ./String.h, line 467.
> Breakpoint 7 at 0x24b4: file ./String.h, line 465.
> Multiple breakpoints were set.
> Use the "delete" command to delete unwanted breakpoints.
> (gdb) r
> Starting program: /home/t30b/lvh/harlan/c/cctest/x 

> Program received signal 11, Segmentation fault
> 0xf77323c0 in strlen ()
> (gdb) 


> It seems that for the variable y a constructor was never
> called. It made me a bit puzzled that g++ uses /lib/crt0.o. Is
> this the problem? How do I make g++ use a differnt crt0.o (1.40 used a
> different one if I remember it correct.) and where can I get one!
> There is no Problem with this with gcc 2.1 on dec-mips-ultrix-4.2. 

> Any fix or explanation or flame is welcome....

Newsgroups: gnu.g++.bug