[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

system/1394: shared C++ libs not initialized.




>Number:         1394
>Category:       system
>Synopsis:       Global constructors of shared libraries are not called.
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Sep  7 10:30:01 MDT 2000
>Last-Modified:
>Originator:     Carlo Wood
>Organization:
net
>Release:        
>Environment:
	
	System      : OpenBSD 2.7
	Architecture: OpenBSD.i386
	Machine     : i386
	Compiler    : gcc version 2.95.2 19991024 (release)
>Description:
	A shared C++ library containing global objects is unusable
	since the constructors of that library are not called.
	It seems that .init is not called, or that .init doesn't
	call the needed functions to initialize the global constructors.
	This was tested by two different people on two different
	machines.  The problem first occured to me for a library
	created by libtool (which I suppose knows how to create
	shared libs).
	
>How-To-Repeat:
	Create two files:
	1) global.cc:
	#include <string>
	string s;
	2) main.cc:
	#include <iostream>
	#include <string>
	extern string s;
	int main(void)
	{
	  s = "Hello World";
	  cout << s << '\n';
	  return 0;
	}

	Then run the following commands:
	setenv LD_LIBRARY_PATH ".:/usr/lib:/usr/local/lib"
	g++ -g -fPIC -o global.o -c global.cc
	g++ -g -o main.o -c main.cc
	ld -Bshareable global.o /usr/lib/c++rt0.o -o libglobal.so.0
	g++ main.o -L. -lglobal
	./a.out

	This will core dump in "s = "Hello World"" because 's' is
	not initialized.
	
>Fix:
	

>Audit-Trail:
>Unformatted: