173
|
1 ; Test that global constructors and destructors are run:
|
|
2 ;
|
|
3 ; RUN: lli -jit-kind=orc-lazy -orc-lazy-debug=funcs-to-stdout -extra-module %s \
|
|
4 ; RUN: %S/Inputs/noop-main.ll | FileCheck %s
|
150
|
5 ;
|
173
|
6 ; Test that this is true for global constructors and destructors in other
|
|
7 ; JITDylibs.
|
|
8 ; RUN: lli -jit-kind=orc-lazy -orc-lazy-debug=funcs-to-stdout \
|
|
9 ; RUN: -jd extra -extra-module %s -jd main %S/Inputs/noop-main.ll | FileCheck %s
|
150
|
10 ;
|
236
|
11 ; CHECK: Hello from constructor
|
150
|
12 ; CHECK: Hello
|
|
13 ; CHECK: [ {{.*}}main{{.*}} ]
|
236
|
14 ; CHECK: Goodbye from atexit
|
|
15 ; CHECK: Goodbye from __cxa_atexit
|
|
16 ; CHECK: Goodbye from destructor
|
150
|
17
|
|
18 %class.Foo = type { i8 }
|
|
19
|
|
20 @f = global %class.Foo zeroinitializer, align 1
|
|
21 @__dso_handle = external global i8
|
236
|
22 @llvm.global_ctors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_hello.cpp, i8* null }, { i32, void ()*, i8* } { i32 1024, void ()* @constructor, i8* null }]
|
|
23 @llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @printf_wrapper, i8* null }]
|
150
|
24 @str = private unnamed_addr constant [6 x i8] c"Hello\00"
|
236
|
25 @str2 = private unnamed_addr constant [23 x i8] c"Hello from constructor\00"
|
|
26 @str3 = private unnamed_addr constant [24 x i8] c"Goodbye from destructor\00"
|
|
27 @str4 = global [26 x i8] c"Goodbye from __cxa_atexit\00"
|
|
28 @str5 = global [20 x i8] c"Goodbye from atexit\00"
|
|
29
|
150
|
30
|
|
31 define linkonce_odr void @_ZN3FooD1Ev(%class.Foo* nocapture readnone %this) unnamed_addr align 2 {
|
|
32 entry:
|
236
|
33 %puts.i = tail call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @str4, i64 0, i64 0))
|
|
34 ret void
|
|
35 }
|
|
36
|
|
37 define void @atexit_handler() {
|
|
38 entry:
|
|
39 %puts.i = tail call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @str5, i64 0, i64 0))
|
150
|
40 ret void
|
|
41 }
|
|
42
|
|
43 declare i32 @__cxa_atexit(void (i8*)*, i8*, i8*)
|
|
44
|
236
|
45 declare i32 @atexit(void ()*)
|
|
46
|
150
|
47 define internal void @_GLOBAL__sub_I_hello.cpp() {
|
|
48 entry:
|
|
49 %puts.i.i.i = tail call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
|
|
50 %0 = tail call i32 @__cxa_atexit(void (i8*)* bitcast (void (%class.Foo*)* @_ZN3FooD1Ev to void (i8*)*), i8* getelementptr inbounds (%class.Foo, %class.Foo* @f, i64 0, i32 0), i8* @__dso_handle)
|
236
|
51 %1 = tail call i32 @atexit(void ()* @atexit_handler)
|
|
52 ret void
|
|
53 }
|
|
54
|
|
55 define void @printf_wrapper() {
|
|
56 entry:
|
|
57 %0 = tail call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @str3, i64 0, i64 0))
|
150
|
58 ret void
|
|
59 }
|
|
60
|
|
61 declare i32 @puts(i8* nocapture readonly)
|
236
|
62
|
|
63 define void @constructor() {
|
|
64 entry:
|
|
65 %0 = tail call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @str2, i64 0, i64 0))
|
|
66 ret void
|
|
67 }
|