Skip to content

Static initializers (C++) are not called with Microsoft Visual Studio Linker #9585

@llvmbot

Description

@llvmbot
Bugzilla Link 9213
Resolution FIXED
Resolved on May 06, 2012 21:50
Version trunk
OS Windows NT
Blocks llvm/llvm-bugzilla-archive#12477
Attachments A simple C++ initialization example
Reporter LLVM Bugzilla Contributor
CC @asl,@jckarter,@tritao

Extended Description

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzilla

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions