1 ; Test that PIC code can be linked into static binaries.
2 ; In this case the GOT entries will end up as internalized wasm globals with
4 ; RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/ret32.s -o %t.ret32.o
5 ; RUN: llc -relocation-model=pic -filetype=obj %s -o %t.o
6 ; RUN: wasm-ld --allow-undefined --export-all -o %t.wasm %t.o %t.ret32.o
7 ; RUN: obj2yaml %t.wasm | FileCheck %s
9 target triple = "wasm32-unknown-emscripten"
11 declare i32 @ret32(float)
12 declare i32 @missing_function(float)
13 @global_float = global float 1.0
14 @hidden_float = hidden global float 2.0
15 @missing_float = extern_weak global float
17 @ret32_ptr = global ptr @ret32, align 4
19 define ptr @getaddr_external() {
23 define ptr @getaddr_missing_function() {
24 ret ptr @missing_function;
27 define ptr @getaddr_hidden() {
31 define ptr @getaddr_missing_float() {
32 ret ptr @missing_float
35 define hidden i32 @hidden_func() {
39 define void @_start() {
41 %f = load float, ptr @hidden_float, align 4
42 %addr = load ptr, ptr @ret32_ptr, align 4
43 %arg = load float, ptr @global_float, align 4
44 call i32 %addr(float %arg)
46 %addr2 = call ptr @getaddr_external()
47 %arg2 = load float, ptr @hidden_float, align 4
48 call i32 %addr2(float %arg2)
50 %addr3 = call ptr @getaddr_hidden()
56 ; CHECK: - Type: GLOBAL
57 ; CHECK-NEXT: Globals:
60 ; CHECK-NEXT: - Index: 0
61 ; CHECK-NEXT: Type: I32
62 ; CHECK-NEXT: Mutable: true
63 ; CHECK-NEXT: InitExpr:
64 ; CHECK-NEXT: Opcode: I32_CONST
65 ; CHECK-NEXT: Value: 66576
68 ; CHECK-NEXT: - Index: 1
69 ; CHECK-NEXT: Type: I32
70 ; CHECK-NEXT: Mutable: false
71 ; CHECK-NEXT: InitExpr:
72 ; CHECK-NEXT: Opcode: I32_CONST
73 ; CHECK-NEXT: Value: 1
75 ; GOT.func.missing_function
76 ; CHECK-NEXT: - Index: 2
77 ; CHECK-NEXT: Type: I32
78 ; CHECK-NEXT: Mutable: false
79 ; CHECK-NEXT: InitExpr:
80 ; CHECK-NEXT: Opcode: I32_CONST
81 ; CHECK-NEXT: Value: 2
84 ; CHECK-NEXT: - Index: 3
85 ; CHECK-NEXT: Type: I32
86 ; CHECK-NEXT: Mutable: false
87 ; CHECK-NEXT: InitExpr:
88 ; CHECK-NEXT: Opcode: I32_CONST
89 ; CHECK-NEXT: Value: 1
91 ; GOT.mem.missing_float
92 ; CHECK-NEXT: - Index: 4
93 ; CHECK-NEXT: Type: I32
94 ; CHECK-NEXT: Mutable: false
95 ; CHECK-NEXT: InitExpr:
96 ; CHECK-NEXT: Opcode: I32_CONST
97 ; CHECK-NEXT: Value: 0
99 ; GOT.mem.global_float
100 ; CHECK-NEXT: - Index: 5
101 ; CHECK-NEXT: Type: I32
102 ; CHECK-NEXT: Mutable: false
103 ; CHECK-NEXT: InitExpr:
104 ; CHECK-NEXT: Opcode: I32_CONST
105 ; CHECK-NEXT: Value: 1024
108 ; CHECK-NEXT: - Index: 6
109 ; CHECK-NEXT: Type: I32
110 ; CHECK-NEXT: Mutable: false
111 ; CHECK-NEXT: InitExpr:
112 ; CHECK-NEXT: Opcode: I32_CONST
113 ; CHECK-NEXT: Value: 1032
116 ; CHECK-NEXT: - Index: 7
117 ; CHECK-NEXT: Type: I32
118 ; CHECK-NEXT: Mutable: false
119 ; CHECK-NEXT: InitExpr:
120 ; CHECK-NEXT: Opcode: I32_CONST
121 ; CHECK-NEXT: Value: 0