[PATCH] Defaulting to -fno-use-cxa-atexit on Windows

Aaron Ballman aaron at aaronballman.com
Mon Mar 11 18:13:57 PDT 2013


The way MSVC handles it is by registering an atexit handler:

; 6    : C c;

push OFFSET ??__Fc@@YAXXZ ; `dynamic atexit destructor for 'c''
call _atexit
pop ecx
ret 0

This is analogous to what clang does when passing -fno-use-cxa-atexit, which is:

define internal void @__cxx_global_var_init() {
entry:
  %0 = call i32 @atexit(void ()* @__dtor_c) #1
  ret void
}

~Aaron

On Mon, Mar 11, 2013 at 8:55 PM, John McCall <rjmccall at apple.com> wrote:
> On Mar 11, 2013, at 5:30 PM, Aaron Ballman <aaron at aaronballman.com> wrote:
>> When building for Windows, using cxa-atexit causes link errors.  We
>> already set this flag to false for Cygywin, MinGW and hexagon targets.
>> This patch also sets it to false for Windows targets.
>
> Cygwin, MinGW, and hexagon targets are Itanium ABI targets;  they're
> just Itanium ABI targets that don't provide __cxa_atexit (although I've
> never understood why not).  So the flag is still meaningful for them.
> It's meaningless for MS ABI targets.
>
> Rather than papering over the problem, I would like someone to
> investigate what the right code to emit is for MS ABI targets.  Specifically,
> will the destructor get executed correctly if we just register it with LLVM
> as a global destructor?
>
> John.



More information about the cfe-commits mailing list