[gnu.g++.bug] An old problem with "Hello world"

andrew@comp.vuw.ac.nz (Andrew Vignaux) (09/25/88)

Hi, I have a problem with GNU C++ version 1.22.1 (vax) compiled by GNU C
version 1.22 with GNU as and ld++.  This is not a bug report -- it should
be old news :-).

The problem has been reported in bug-g++ but I missed any fix (if it was
posted) before I had to unsubscribe due to the volume.  I would like to
know the way this has been fixed in later versions.

hello.cc
	#include <stream.h>
	main()
	{
	    cout << "Hello world\n";
	}

/usr/local/lib/gcc-c++ /tmp/cc020557.cpp -quiet -dumpbase hello.cc -noreg \
                       -version -o /tmp/cc020557.s

produces no output [GUESS ALERT] because the constructor for cout is not
being run.  This is because the only symbol connecting "hello.o" with
"stream.o" in "libg++.a" is the Common symbol "cout" and the loader does
not force stream.o to be linked in this case.  The ld++ ctor collecter
misses the fact that __GLOBAL_$I$stream_cc needs to be included in the
___CTOR_LIST__.  Things work fine if you write:
	    cout << "You are number " << 6;
because ld++ has to link in stream.o.  Ok, ok... you knew all that :-)

My questions is "what was the fix".  If it can be described in a few
paragraphs of english or a few pages of code I would love to see it.  I
already know that the best way to solve my problem is to upgrade to the
latest version.

Please respond by email as I am no longer subscribed to the list/group.

Thanks.

Andrew.
------------------------------------------------------------------------------
Domain address: andrew@comp.vuw.ac.nz   Path address: ...!uunet!vuwcomp!andrew

tiemann@LURCH.STANFORD.EDU (Michael Tiemann) (10/07/88)

The problem was in varasm.c.  The trick is to make variables which
need to be initialized at the file level appear to be in initialized
data, rather than in uninitialized data.  GNU ld will not load the
contents of a library file just for .bss space.

Michael