summaryrefslogtreecommitdiffstats
path: root/lld/test/wasm/pic-static.ll
blob: 65b47175865ee8b4ff374711bae022681ed42981 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
; Test that PIC code can be linked into static binaries.
; In this case the GOT entries will end up as internalized wasm globals with
; fixed values.
; RUN: llc -relocation-model=pic -filetype=obj %p/Inputs/ret32.ll -o %t.ret32.o
; RUN: llc -relocation-model=pic -filetype=obj %s -o %t.o
; RUN: wasm-ld --allow-undefined --export-all -o %t.wasm %t.o %t.ret32.o
; RUN: obj2yaml %t.wasm | FileCheck %s

target triple = "wasm32-unknown-emscripten"

declare i32 @ret32(float)
declare i32 @missing_function(float)
@global_float = global float 1.0
@hidden_float = hidden global float 2.0
@missing_float = extern_weak global float

@ret32_ptr = global i32 (float)* @ret32, align 4

define i32 (float)* @getaddr_external() {
  ret i32 (float)* @ret32;
}

define i32 (float)* @getaddr_missing_function() {
  ret i32 (float)* @missing_function;
}

define i32 ()* @getaddr_hidden() {
  ret i32 ()* @hidden_func;
}

define float* @getaddr_missing_float() {
  ret float* @missing_float
}

define hidden i32 @hidden_func() {
  ret i32 1
}

define void @_start() {
entry:
  %f = load float, float* @hidden_float, align 4
  %addr = load i32 (float)*, i32 (float)** @ret32_ptr, align 4
  %arg = load float, float* @global_float, align 4
  call i32 %addr(float %arg)

  %addr2 = call i32 (float)* @getaddr_external()
  %arg2 = load float, float* @hidden_float, align 4
  call i32 %addr2(float %arg2)

  %addr3 = call i32 ()* @getaddr_hidden()
  call i32 %addr3()

  ret void
}

; CHECK:        - Type:            GLOBAL
; CHECK-NEXT:     Globals:

; __stack_pointer
; CHECK-NEXT:       - Index:           0
; CHECK-NEXT:         Type:            I32
; CHECK-NEXT:         Mutable:         true
; CHECK-NEXT:         InitExpr:
; CHECK-NEXT:           Opcode:          I32_CONST
; CHECK-NEXT:           Value:           66576

; GOT.func.ret32
; CHECK-NEXT:       - Index:           1
; CHECK-NEXT:         Type:            I32
; CHECK-NEXT:         Mutable:         false
; CHECK-NEXT:         InitExpr:
; CHECK-NEXT:           Opcode:          I32_CONST
; CHECK-NEXT:           Value:           1

; GOT.func.missing_function
; CHECK-NEXT:       - Index:           2
; CHECK-NEXT:         Type:            I32
; CHECK-NEXT:         Mutable:         false
; CHECK-NEXT:         InitExpr:
; CHECK-NEXT:           Opcode:          I32_CONST
; CHECK-NEXT:           Value:           2

; __table_base
; CHECK-NEXT:       - Index:           3
; CHECK-NEXT:         Type:            I32
; CHECK-NEXT:         Mutable:         false
; CHECK-NEXT:         InitExpr:
; CHECK-NEXT:           Opcode:          I32_CONST
; CHECK-NEXT:           Value:           1

; GOT.mem.missing_float
; CHECK-NEXT:       - Index:           4
; CHECK-NEXT:         Type:            I32
; CHECK-NEXT:         Mutable:         false
; CHECK-NEXT:         InitExpr:
; CHECK-NEXT:           Opcode:          I32_CONST
; CHECK-NEXT:           Value:           0

; GOT.mem.global_float
; CHECK-NEXT:       - Index:           5
; CHECK-NEXT:         Type:            I32
; CHECK-NEXT:         Mutable:         false
; CHECK-NEXT:         InitExpr:
; CHECK-NEXT:           Opcode:          I32_CONST
; CHECK-NEXT:           Value:           1024

; GOT.mem.ret32_ptr
; CHECK-NEXT:       - Index:           6
; CHECK-NEXT:         Type:            I32
; CHECK-NEXT:         Mutable:         false
; CHECK-NEXT:         InitExpr:
; CHECK-NEXT:           Opcode:          I32_CONST
; CHECK-NEXT:           Value:           1032

; __memory_base
; CHECK-NEXT:       - Index:           7
; CHECK-NEXT:         Type:            I32
; CHECK-NEXT:         Mutable:         false
; CHECK-NEXT:         InitExpr:
; CHECK-NEXT:           Opcode:          I32_CONST
; CHECK-NEXT:           Value:           0
OpenPOWER on IntegriCloud