|
| 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 | + |
0 commit comments