Add comdat key field to llvm.global_ctors and llvm.global_dtors
[oota-llvm.git] / test / MC / COFF / global_ctors_dtors.ll
1 ; Test that global ctors are emitted into the proper COFF section for the
2 ; target. Mingw uses .ctors, whereas MSVC uses .CRT$XC*.
3 ; RUN: llc < %s -mtriple i686-pc-win32 | FileCheck %s --check-prefix WIN32
4 ; RUN: llc < %s -mtriple x86_64-pc-win32 | FileCheck %s --check-prefix WIN32
5 ; RUN: llc < %s -mtriple i686-pc-mingw32 | FileCheck %s --check-prefix MINGW32
6 ; RUN: llc < %s -mtriple x86_64-pc-mingw32 | FileCheck %s --check-prefix MINGW32
7
8 @.str = private unnamed_addr constant [13 x i8] c"constructing\00", align 1
9 @.str2 = private unnamed_addr constant [12 x i8] c"destructing\00", align 1
10 @.str3 = private unnamed_addr constant [5 x i8] c"main\00", align 1
11
12 %ini = type { i32, void()*, i8* }
13
14 @llvm.global_ctors = appending global [2 x %ini ] [
15   %ini { i32 65535, void ()* @a_global_ctor, i8* null },
16   %ini { i32 65535, void ()* @b_global_ctor, i8* bitcast (i32* @b to i8*) }
17 ]
18 @llvm.global_dtors = appending global [1 x %ini ] [%ini { i32 65535, void ()* @a_global_dtor, i8* null }]
19
20 declare i32 @puts(i8*)
21
22 define void @a_global_ctor() nounwind {
23   %1 = call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @.str, i32 0, i32 0))
24   ret void
25 }
26
27 @b = global i32 zeroinitializer
28
29 define void @b_global_ctor() nounwind {
30   store i32 42, i32* @b
31   ret void
32 }
33
34 define void @a_global_dtor() nounwind {
35   %1 = call i32 @puts(i8* getelementptr inbounds ([12 x i8]* @.str2, i32 0, i32 0))
36   ret void
37 }
38
39 define i32 @main() nounwind {
40   %1 = call i32 @puts(i8* getelementptr inbounds ([5 x i8]* @.str3, i32 0, i32 0))
41   ret i32 0
42 }
43
44 ; WIN32: .section .CRT$XCU,"rd"
45 ; WIN32: a_global_ctor
46 ; WIN32: .section .CRT$XCU,"rd",associative .bss,{{_?}}b
47 ; WIN32: b_global_ctor
48 ; WIN32: .section .CRT$XTX,"rd"
49 ; WIN32: a_global_dtor
50 ; MINGW32: .section .ctors,"wd"
51 ; MINGW32: a_global_ctor
52 ; MINGW32: .section .ctors,"wd",associative .bss,{{_?}}b
53 ; MINGW32: b_global_ctor
54 ; MINGW32: .section .dtors,"wd"
55 ; MINGW32: a_global_dtor