16717 – [3.4 Regression] [unit-at-a-time] __attribute__((constructor)) broken in C++

Description Andris Pavenis 2004-07-26 16:32:48 UTC

__attribute__((constructor)) doesn't work in C++ for both gcc-3.4.1 and
gcc-3.5.0 20040725 when optimization level -O2 is being used. 

All seems to work Ok with gcc-3.3.4.

-------------------- bug.cc ----------------------
#include <stdio.h>

void hello (void) __attribute__ ((constructor));

void hello (void) { printf ("Hello world\n"); }

int main (void) { return 0; }
---------------------------------------------------

g++ -O2 bug.cc -o bug
./bug

works with gcc-3.3.4, but not with gcc-3.4.1 and 3.5.0 20040725

(Initially bug were reported for target i586-pc-msdosdjgpp)