Subject: port-i386/8463: problem with construtors for globals in shared libraries
To: None <gnats-bugs@gnats.netbsd.org>
From: Mark Davies <mark@MCS.VUW.AC.NZ>
List: netbsd-bugs
Date: 09/21/1999 04:49:06
>Number:         8463
>Category:       port-i386
>Synopsis:       Constructors not run for globals in shared libraries
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-i386-maintainer (NetBSD/i386 Portmaster)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Sep 21 04:35:01 1999
>Last-Modified:
>Originator:     Mark Davies
>Organization:
Comp. Sci., Victoria Uni. of Wellington, New Zealand.
>Release:        NetBSD-1.4.1
>Environment:
	
System: NetBSD city-art.mcs.vuw.ac.nz 1.4.1 NetBSD 1.4.1 (MCS_WORKSTATION) #0: Thu Sep 2 16:42:54 PDT 1999 root@pigeon:/usr/src/sys/arch/i386/compile/MCS_WORKSTATION i386


>Description:
	Global variables that need constructers, declared in shared libraries,
	fail to have the constructer run on program startup causing seg faults
	when the variable is referenced.

	This was noticed building KDE-1.1.2.  The application "kab" core dumps
	at the following point:

int main(int argc, char** argv)
{
  register bool GUARD; GUARD=true;
  LG(GUARD, "addressbook main: starting.\n");
  // ########################################################  
  KApplication *app=new KApplication(argc, argv, "kab");
  int rc;
  // -----
  AuthorEmailAddress="mirko@kde.org"; // static, public  <<< Core dumps here

Core dumps as "AuthorEmailAddress" has not had its constructor applied so
dereferences a NULL pointer.
"AuthorEmailAddress" is declared as a global in "libkab" as follows:

	string AuthorEmailAddress;

Moving this declaration into the program source (rather than the library) fixes
the problem, as does building the library statically.

	
>How-To-Repeat:
	Build a shared library that declares a global that requires a C++
constructor to initialise then reference it from a sample program.

>Fix:
	My workaround at the moment is to build the library static :-(


cheers
mark
>Audit-Trail:
>Unformatted: