[LLVMbugs] [Bug 9213] New: Static initializers (C++) are not called with Microsoft Visual Studio Linker

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Feb 13 21:10:02 PST 2011


http://llvm.org/bugs/show_bug.cgi?id=9213

           Summary: Static initializers (C++) are not called with
                    Microsoft Visual Studio Linker
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Linker
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: art.oriented at gmail.com
                CC: llvmbugs at cs.uiuc.edu


Static initializers in C++, defined by @llvm.global_ctors are not called when
object files are linked by MSVC linker. I've attached a simple test file. Other
tool chains (MinGW gcc) are okay in Windows.

The attached file should print out:
"foo_initializer"
"11"

I'm unclear which component is culprit for this bug. Please move this bug
reporting if better component section fits.



[1] MSVC C++ - Okay
>cl ctor.cpp  (Calling MSVC C++ compiler and linker)
>ctor.exe
foo_initializer
11


[2] MinGW-gcc - Okay
>gcc ctor.cpp -o ctor.exe (MinGW gcc)
>ctor.exe
foo_initializer
11


[3] MinGW-llvm-gcc - Okay
>llvm-gcc ctor.cpp -o ctor.exe (MinGW gcc)
Z:\dev\MinGW\bin/ld.exe: Warning: type of symbol `_main' changed from 32 to 512
in R:\temp/ccMNSXGt.o

>ctor.exe
foo_initializer
11


[4] Clang - NOT okay (Clang will call MSVC's "link.exe")
>clang ctor.cpp -o ctor.exe
>ctor.exe
1
===> Static initializer wasn't called.

>clang ctor.cpp -c -o ctor.o
>gcc -o ctor.exe ctor.o
>ctor.exe
foo_initializer
11

===> However, linking with gcc's is okay.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list