Skip to content

Commit fc8ef56

Browse files
Add testing for all handled relocs
1 parent 34e2f30 commit fc8ef56

File tree

3 files changed

+223
-26
lines changed

3 files changed

+223
-26
lines changed

lld/test/wasm/compress-relocs.ll

Lines changed: 0 additions & 26 deletions
This file was deleted.

lld/test/wasm/compress-relocs.s

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# RUN: llvm-mc -mattr=+reference-types,+exception-handling -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o
2+
# RUN: wasm-ld --export-dynamic -o %t.wasm %t.o
3+
# RUN: llvm-objdump -d %t.wasm | FileCheck %s
4+
# RUN: wasm-ld --export-dynamic -O2 -o %t-opt.wasm %t.o
5+
# RUN: llvm-objdump -d %t-opt.wasm | FileCheck %s
6+
# RUN: not wasm-ld --compress-relocations -o %t-compressed.wasm %t.o 2>&1 | FileCheck %s -check-prefix=ERROR
7+
# RUN: wasm-ld --export-dynamic --strip-debug --compress-relocations -o %t-compressed.wasm %t.o
8+
# RUN: llvm-objdump -d %t-compressed.wasm | FileCheck %s -check-prefix=COMPRESS
9+
10+
.globl _start
11+
_start:
12+
.functype _start () -> ()
13+
end_function
14+
15+
.globl func_ret_i64
16+
func_ret_i64:
17+
.functype func_ret_i64 () -> (i64)
18+
i64.const 1
19+
end_function
20+
21+
.globl func_ret_i32
22+
func_ret_i32:
23+
.functype func_ret_i32 () -> (i32)
24+
i32.const 2
25+
end_function
26+
27+
i32_global:
28+
.globaltype i32_global, i32
29+
30+
i32_tag:
31+
.tagtype i32_tag i32
32+
33+
.globl test_memory_and_indirect_call_relocs
34+
test_memory_and_indirect_call_relocs:
35+
.functype test_memory_and_indirect_call_relocs () -> ()
36+
i32.const indirect_func_ret_i64 # R_WASM_MEMORY_ADDR_SLEB
37+
i32.load 0
38+
call_indirect () -> (i64) # R_WASM_TYPE_INDEX_LEB, R_WASM_TABLE_NUMBER_LEB
39+
drop
40+
i32.const 0
41+
i32.load indirect_func_ret_i32 # R_WASM_MEMORY_ADDR_LEB
42+
call_indirect () -> (i32)
43+
drop
44+
i32.const func_ret_i64 # R_WASM_TABLE_INDEX_SLEB
45+
call_indirect () -> (i64)
46+
drop
47+
end_function
48+
49+
# CHECK: test_memory_and_indirect_call_relocs
50+
# CHECK: 41 90 88 80 80 00 i32.const 1040
51+
# CHECK: 11 80 80 80 80 00 80 80 80 80 00 call_indirect 0
52+
# CHECK: 28 02 94 88 80 80 00 i32.load 1044
53+
# CHECK: 11 81 80 80 80 00 80 80 80 80 00 call_indirect 1
54+
# CHECK: 41 81 80 80 80 00 i32.const 1
55+
# CHECK: 11 80 80 80 80 00 80 80 80 80 00 call_indirect 0
56+
# COMPRESS: test_memory_and_indirect_call_relocs
57+
# COMPRESS: 41 90 08 i32.const 1040
58+
# COMPRESS: 11 00 00 call_indirect 0
59+
# COMPRESS: 28 02 94 08 i32.load 1044
60+
# COMPRESS: 11 01 00 call_indirect 1
61+
# COMPRESS: 41 01 i32.const 1
62+
# COMPRESS: 11 00 00 call_indirect 0
63+
64+
.globl test_simple_index_relocs
65+
test_simple_index_relocs:
66+
.functype test_simple_index_relocs () -> ()
67+
call func_ret_i32 # R_WASM_FUNCTION_INDEX_LEB
68+
global.set i32_global # R_WASM_GLOBAL_INDEX_LEB
69+
i32.const 0
70+
throw i32_tag # R_WASM_TAG_INDEX_LEB
71+
end_function
72+
73+
# CHECK: test_simple_index_relocs
74+
# CHECK: 10 82 80 80 80 00 call 2
75+
# CHECK: 24 81 80 80 80 00 global.set 1
76+
# CHECK: 08 80 80 80 80 00 throw 0
77+
# COMPRESS: test_simple_index_relocs
78+
# COMPRESS: 10 02 call 2
79+
# COMPRESS: 24 01 global.set 1
80+
# COMPRESS: 08 00 throw 0
81+
82+
.globl test_special_relocs
83+
test_special_relocs:
84+
.functype test_special_relocs () -> ()
85+
i32.const indirect_func_ret_i64@MBREL # R_WASM_MEMORY_ADDR_REL_SLEB
86+
drop
87+
i32.const func_ret_i32@TBREL # R_WASM_TABLE_INDEX_REL_SLEB
88+
drop
89+
i32.const i32_tls_data@TLSREL # R_WASM_MEMORY_ADDR_TLS_SLEB
90+
drop
91+
end_function
92+
93+
# CHECK: test_special_relocs
94+
# CHECK: 41 90 88 80 80 00 i32.const 1040
95+
# CHECK: 41 81 80 80 80 00 i32.const 1
96+
# CHECK: 41 83 80 80 80 00 i32.const 3
97+
# COMPRESS: test_special_relocs
98+
# COMPRESS: 41 90 08 i32.const 1040
99+
# COMPRESS: 41 01 i32.const 1
100+
# COMPRESS: 41 03 i32.const 3
101+
102+
# ERROR: wasm-ld: error: --compress-relocations is incompatible with output debug information. Please pass --strip-debug or --strip-all
103+
104+
.section .tdata,"T",@
105+
.int8 0
106+
.int8 0
107+
.int8 0
108+
i32_tls_data:
109+
.int32 65
110+
.size i32_tls_data, 4
111+
112+
.section .data,"",@
113+
.p2align 4
114+
indirect_func_ret_i64:
115+
.int32 func_ret_i64
116+
.size indirect_func_ret_i64, 4
117+
118+
indirect_func_ret_i32:
119+
.int32 func_ret_i32
120+
.size indirect_func_ret_i32, 4
121+
122+
.section .custom_section.target_features,"",@
123+
.int8 2
124+
.int8 43
125+
.int8 7
126+
.ascii "atomics"
127+
.int8 43
128+
.int8 11
129+
.ascii "bulk-memory"
130+

lld/test/wasm/compress-relocs64.s

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# RUN: llvm-mc -filetype=obj -triple=wasm64-unknown-unknown %s -o %t.o
2+
# RUN: wasm-ld -mwasm64 --export-dynamic -o %t.wasm %t.o
3+
# RUN: llvm-objdump -d %t.wasm | FileCheck %s
4+
# RUN: wasm-ld -mwasm64 --export-dynamic -O2 -o %t-opt.wasm %t.o
5+
# RUN: llvm-objdump -d %t-opt.wasm | FileCheck %s
6+
# RUN: wasm-ld -mwasm64 --export-dynamic --strip-debug --compress-relocations -o %t-compressed.wasm %t.o
7+
# RUN: llvm-objdump -d %t-compressed.wasm | FileCheck %s -check-prefix=COMPRESS
8+
9+
.globl _start
10+
_start:
11+
.functype _start () -> ()
12+
end_function
13+
14+
.globl func_ret_i64
15+
func_ret_i64:
16+
.functype func_ret_i64 () -> (i64)
17+
i64.const 1
18+
end_function
19+
20+
.globl func_ret_i32
21+
func_ret_i32:
22+
.functype func_ret_i32 () -> (i32)
23+
i32.const 2
24+
end_function
25+
26+
.globl test_memory_and_indirect_call_relocs
27+
test_memory_and_indirect_call_relocs:
28+
.functype test_memory_and_indirect_call_relocs () -> ()
29+
i64.const indirect_func_ret_i64 # R_WASM_MEMORY_ADDR_SLEB64
30+
drop
31+
i64.const 0
32+
i64.load indirect_func_ret_i32 # R_WASM_MEMORY_ADDR_LEB64
33+
drop
34+
i64.const func_ret_i64 # R_WASM_TABLE_INDEX_SLEB64
35+
drop
36+
end_function
37+
38+
# CHECK: test_memory_and_indirect_call_relocs
39+
# CHECK: 42 90 88 80 80 80 80 80 80 80 00 i64.const 1040
40+
# CHECK: 29 03 98 88 80 80 80 80 80 80 80 00 i64.load 1048
41+
# CHECK: 42 81 80 80 80 80 80 80 80 80 00 i64.const 1
42+
# COMPRESS: test_memory_and_indirect_call_relocs
43+
# COMPRESS: 42 90 08 i64.const 1040
44+
# COMPRESS: 29 03 98 08 i64.load 1048
45+
# COMPRESS: 42 01 i64.const 1
46+
47+
.globl test_special_relocs
48+
test_special_relocs:
49+
.functype test_special_relocs () -> ()
50+
i64.const indirect_func_ret_i64@MBREL # R_WASM_MEMORY_ADDR_REL_SLEB64
51+
drop
52+
i64.const func_ret_i32@TBREL # R_WASM_TABLE_INDEX_REL_SLEB64
53+
drop
54+
i64.const i32_tls_data@TLSREL # R_WASM_MEMORY_ADDR_TLS_SLEB64
55+
drop
56+
end_function
57+
58+
# CHECK: test_special_relocs
59+
# CHECK: 42 90 88 80 80 80 80 80 80 80 00 i64.const 1040
60+
# CHECK: 42 81 80 80 80 80 80 80 80 80 00 i64.const 1
61+
# CHECK: 42 83 80 80 80 80 80 80 80 80 00 i64.const 3
62+
# COMPRESS: test_special_relocs
63+
# COMPRESS: 42 90 08 i64.const 1040
64+
# COMPRESS: 42 01 i64.const 1
65+
# COMPRESS: 42 03 i64.const 3
66+
67+
.section .tdata,"T",@
68+
.int8 0
69+
.int8 0
70+
.int8 0
71+
i32_tls_data:
72+
.int32 65
73+
.size i32_tls_data, 4
74+
75+
.section .data,"",@
76+
.p2align 4
77+
indirect_func_ret_i64:
78+
.int64 func_ret_i64
79+
.size indirect_func_ret_i64, 8
80+
81+
indirect_func_ret_i32:
82+
.int64 func_ret_i32
83+
.size indirect_func_ret_i32, 8
84+
85+
.section .custom_section.target_features,"",@
86+
.int8 2
87+
.int8 43
88+
.int8 7
89+
.ascii "atomics"
90+
.int8 43
91+
.int8 11
92+
.ascii "bulk-memory"
93+

0 commit comments

Comments
 (0)