91 lines · plain
1# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s2# RUN: wasm-ld -r -o %t.wasm %t.o3# RUN: obj2yaml %t.wasm | FileCheck %s4# RUN: llvm-objdump --disassemble-symbols=_start --no-show-raw-insn --no-leading-addr %t.wasm | FileCheck %s --check-prefixes DIS5 6.hidden foo7.hidden bar8.globl foo9.globl bar10 11# Similar to what would be generated from: `int foo[76]`12 .section .bss.foo,"",@13 .p2align 414foo:15 .skip 30416 .size foo, 30417 18# bar contains a pointer to the 16th element of foo, which happens to be 6419# bytes in. This generates an addend of 64 which is the value at which signed20# and unsigned LEB encodes will differ.21 .section .data.bar,"",@22 .p2align 223bar:24 .int32 foo+6425 .size bar, 426 27# Check that negative addends also work here28 .section .data.negative_addend,"",@29 .p2align 230negative_addend:31 .int32 foo-1632 .size negative_addend, 433 34.globl _start35.section .text,"",@36_start:37 .functype _start () -> ()38 i32.const 039 i32.load foo + 1040 drop41 i32.const 042 i32.load foo - 1043 drop44 i32.const 045 # This will underflow because i32.load (and the46 # corresponding relocation type) take an unsgiend (U32)47 # immediate.48 i32.load foo - 204849 drop50 end_function51 52# CHECK: - Type: CODE53# CHECK-NEXT: Relocations:54# CHECK-NEXT: - Type: R_WASM_MEMORY_ADDR_LEB55# CHECK-NEXT: Index: 056# CHECK-NEXT: Offset: 0x757# CHECK-NEXT: Addend: 1058# CHECK-NEXT: - Type: R_WASM_MEMORY_ADDR_LEB59# CHECK-NEXT: Index: 060# CHECK-NEXT: Offset: 0x1161# CHECK-NEXT: Addend: -1062# CHECK-NEXT: - Type: R_WASM_MEMORY_ADDR_LEB63# CHECK-NEXT: Index: 064# CHECK-NEXT: Offset: 0x1B65# CHECK-NEXT: Addend: -204866 67# CHECK: - Type: DATA68# CHECK-NEXT: Relocations:69# CHECK-NEXT: - Type: R_WASM_MEMORY_ADDR_I3270# CHECK-NEXT: Index: 071# CHECK-NEXT: Offset: 0x672# CHECK-NEXT: Addend: 6473# CHECK-NEXT: - Type: R_WASM_MEMORY_ADDR_I3274# CHECK-NEXT: Index: 075# CHECK-NEXT: Offset: 0xF76# CHECK-NEXT: Addend: -1677 78# DIS: <_start>:79# DIS-EMPTY:80# DIS-NEXT: i32.const 081# DIS-NEXT: i32.load 2682# DIS-NEXT: drop83# DIS-NEXT: i32.const 084# DIS-NEXT: i32.load 685# DIS-NEXT: drop86# DIS-NEXT: i32.const 087# TODO(sbc): We should probably error here rather than allowing u32 to wrap88# DIS-NEXT: i32.load 429496526489# DIS-NEXT: drop90# DIS-NEXT: end91