llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.53k stars 11.79k forks source link

Please insert "-fno-use-cxa-atexit" as default for Win32 #9576

Open llvmbot opened 13 years ago

llvmbot commented 13 years ago
Bugzilla Link 9204
Version trunk
OS Windows NT
Reporter LLVM Bugzilla Contributor

Extended Description

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

This bug still happens for native Win32. So, C++ code causes link errors:

error LNK2019: unresolved external symbol _dsohandle referenced error LNK2019: unresolved external symbol cxa_atexit referenced

The fix would be very simple: just put '--fno-use-cxa-atexit' as default argument. Please fix "tools\clang\lib\Driver\Tools.cpp" as follows (sorry I don't have permit to commit yet):

// -fuse-cxa-atexit is default. if (KernelOrKext || !Args.hasFlag(options::OPT_fuse_cxa_atexit, options::OPT_fno_use_cxa_atexit, getToolChain().getTriple().getOS() != llvm::Triple::Win32 && getToolChain().getTriple().getOS() != llvm::Triple::Cygwin && getToolChain().getTriple().getOS() != llvm::Triple::MinGW32 && getToolChain().getTriple().getOS() != llvm::Triple::MinGW64)) CmdArgs.push_back("-fno-use-cxa-atexit");

llvmbot commented 11 years ago

Sorry, closed wrong bug.

llvmbot commented 11 years ago

To reproduce, build clang on Windows with Visual Studio 2010 using the instructions at http://clang.llvm.org/get_started.html, then compile this program:

class A { public: ~A() { } } a;

int main() { return 0; }

the output:

c:> clang++ t.cpp t-031021.o : error LNK2019: unresolved external symbol _dsohandle referenced in function cxx_global_var_init t-031021.o : error LNK2019: unresolved external symbol _cxaatexit referenced in function cxx_global_var_init a.out : fatal error LNK1120: 2 unresolved externals clang++: error: linker command failed with exit code 1120 (use -v to see invocation)