From nobody@FreeBSD.ORG  Tue Jul 18 01:43:26 2000
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id C023937BCA3; Tue, 18 Jul 2000 01:43:26 -0700 (PDT)
Message-Id: <20000718084326.C023937BCA3@hub.freebsd.org>
Date: Tue, 18 Jul 2000 01:43:26 -0700 (PDT)
From: xyf@stocke.com
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@FreeBSD.org
Subject: FBSD4 gcc __attribute__(constructor) not work
X-Send-Pr-Version: www-1.0

>Number:         20004
>Category:       gnu
>Synopsis:       FBSD4 gcc __attribute__(constructor) not work
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    gerald
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jul 18 01:50:01 PDT 2000
>Closed-Date:    Fri Mar 28 12:19:09 PST 2003
>Last-Modified:  Fri Mar 28 12:19:09 PST 2003
>Originator:     xuyifeng
>Release:        FreeBSD 4.0-stable
>Organization:
stocke.com
>Environment:
FreeBSD xyf.websoft.com.cn 4.0-RELEASE FreeBSD 4.0-RELEASE #1:Mon Jul 
17 13:22:57 CST 2000 root@xyf.websoft.com.cn:/usr/src/sys/compile/TEST i386
>Description:
the GNU C++ compiler in FreeBSD doesn't correctly handles "__attribute__((constructor))", but it works if I use C compiler instead.


>How-To-Repeat:
this is the demo program:

#include <stdio.h>
int g_int = 0;
void init() __attribute__((constructor));
void init()
{
    g_int = 1;
}

int main(int argc, char** argv)
{
    if (g_int == 1)
        printf("__attribute__((constructor)) work!\n");
    else
        printf("__attribute__((constructor)) not work!\n");

    return 0;
}

if the source program name is test.cpp and use command "c++ test.cpp" to compile it, "__attribute__((constructor))" hasn't effect,  but if the source program name is test.c, then use command "cc test.c" the compile it, it works!

>Fix:
I think some utilities in FreeBSD are inconsistent, it has different version of utilities for C and C++, need update these utilities.



>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->obrien 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Tue Jul 18 02:34:23 PDT 2000 
Responsible-Changed-Why:  
David's baby. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=20004 
Responsible-Changed-From-To: obrien->freebsd-bugs 
Responsible-Changed-By: obrien 
Responsible-Changed-When: Mon Sep 10 09:31:41 PDT 2001 
Responsible-Changed-Why:  

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=20004 
State-Changed-From-To: open->feedback 
State-Changed-By: gerald 
State-Changed-When: Wed Mar 26 09:59:16 PST 2003 
State-Changed-Why:  
Would you mind reporting this problem to the GCC folks following 
<http://gcc.gnu.org/bugs.html>?  Please let us know when you have
done so, or in case it is not feasible for you.
(I verified that this is not a FreeBSD-specific issue.)

http://www.freebsd.org/cgi/query-pr.cgi?pr=20004 
Responsible-Changed-From-To: freebsd-bugs->gerald 
Responsible-Changed-By: gerald 
Responsible-Changed-When: Wed Mar 26 10:00:44 PST 2003 
Responsible-Changed-Why:  
I'm tracking this now. 

Would you mind reporting this problem to the GCC folks following 
<http://gcc.gnu.org/bugs.html>?  Please let us know when you have 
done so, or in case it is not feasible for you. 
(I verified that this is not a FreeBSD-specific issue.) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=20004 
State-Changed-From-To: feedback->closed 
State-Changed-By: gerald 
State-Changed-When: Fri Mar 28 12:14:36 PST 2003 
State-Changed-Why:  
I have forwarded this bug report to the GCC folks, and it got fixed on the 
main GCC development branch within less than two days, which means it will 
be imported to FreeBSD in the future. 
As a workaround for your problem you could use a current snapshot of GCC, 
but given the fact that this is not FreeBSD-specific, this bug does not 
constitute a portability problem, so I don't think it's worth diverging 
from official GCC sources by importing this in the system compiler --  
though I'll inform our compiler maintainers so they can decide. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=20004 
>Unformatted:
