From Bugzilla Helper: User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 95) Description of problem: Code which uses the __attribute__((constructor)) fails to work properly with g++ Version-Release number of selected component (if applicable): How reproducible: Always Steps to Reproduce: 1. Compile the below code using g++ 2. Run the resulting program Actual Results: Using g++, the program prints the value 0, indicating that the constructor function was NOT called. Compiling against gcc shows the correct behaviour. The above code sample has been tested with RedHat releases 6.2, 7.1, 7.2 and 7.3. Only version 6.2 shows the correct behaviour. Additional info: gcc versions: RedHat 6.2: gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) RedHat 7.1: gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81) RedHat 7.2: gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-98) RedHat 7.3: gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-112) Sample code: #include <stdio.h> static int constructor_called = 0; static void __attribute((constructor)) call_before_main(void) { constructor_called = 1; } int main(int, char **) { printf("constructor called = %d\n", constructor_called); return 0; }
Verified still the case in 8.0
When compiled with gcc-c++-3.4.2-2 or 3.3.4, it prints constructor called = 1