http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56712
Bug #: 56712
Summary: constuctor function is called twice
Classification: Unclassified
Product: gcc
Version: 4.6.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: [email protected]
ReportedBy: [email protected]
Created attachment 29713
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29713
cnt++ is accidentally called twice at -O2 or higher
The attached test program has a constructor function
with the __attribute__((constructor)) that is split
up into two parts construct.part.0 and construct
construct.part.0 is the part after "if (xx != 0) return;"
The problem is that both are put into the .ctors section
first the construct.part.0 and then construct.
Unfortunately the construct function is called before
construct.part.0 which has the check removed.
Therefore basically the constuctor is called twice:
cnt=2 at -O2 or -O3, but cnt=1 at -O1 or less.