Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

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

Open Quuxplusone opened 13 years ago

Quuxplusone commented 13 years ago
Bugzilla Link PR9204
Status REOPENED
Importance P normal
Reported by Minjang Kim (art.oriented@gmail.com)
Reported on 2011-02-12 00:57:29 -0800
Last modified on 2013-09-19 23:01:38 -0700
Version trunk
Hardware PC Windows NT
CC geek4civic@gmail.com, llvm-bugs@lists.llvm.org, p_hampson@wargaming.net
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
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 ___dso_handle 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");
Quuxplusone 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 ___dso_handle referenced
in function ___cxx_global_var_init
t-031021.o : error LNK2019: unresolved external symbol ___cxa_atexit 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)
Quuxplusone commented 11 years ago

Sorry, closed wrong bug.