[LLD][COFF] Ignore DEBUG_S_XFGHASH_TYPE/VIRTUAL
[llvm-project.git] / lld / test / wasm / reloc-addend.s
blob4b23ed1120faae0be215e10ddd1c1fe7a4f4eb5f
1 # RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
2 # RUN: wasm-ld -r -o %t.wasm %t.o
3 # RUN: obj2yaml %t.wasm | FileCheck %s
4 # RUN: llvm-objdump --disassemble-symbols=_start --no-show-raw-insn --no-leading-addr %t.wasm | FileCheck %s --check-prefixes DIS
6 .hidden foo
7 .hidden bar
8 .globl foo
9 .globl bar
11 # Similar to what would be generated from: `int foo[76]`
12 .section .bss.foo,"",@
13 .p2align 4
14 foo:
15 .skip 304
16 .size foo, 304
18 # bar contains a pointer to the 16th element of foo, which happens to be 64
19 # bytes in. This generates an addend of 64 which is the value at which signed
20 # and unsigned LEB encodes will differ.
21 .section .data.bar,"",@
22 .p2align 2
23 bar:
24 .int32 foo+64
25 .size bar, 4
27 # Check that negative addends also work here
28 .section .data.negative_addend,"",@
29 .p2align 2
30 negative_addend:
31 .int32 foo-16
32 .size negative_addend, 4
34 .globl _start
35 .section .text,"",@
36 _start:
37 .functype _start () -> ()
38 i32.const 0
39 i32.load foo + 10
40 drop
41 i32.const 0
42 i32.load foo - 10
43 drop
44 i32.const 0
45 # This will underflow because i32.load (and the
46 # corresponding relocation type) take an unsgiend (U32)
47 # immediate.
48 i32.load foo - 2048
49 drop
50 end_function
52 # CHECK: - Type: CODE
53 # CHECK-NEXT: Relocations:
54 # CHECK-NEXT: - Type: R_WASM_MEMORY_ADDR_LEB
55 # CHECK-NEXT: Index: 0
56 # CHECK-NEXT: Offset: 0x7
57 # CHECK-NEXT: Addend: 10
58 # CHECK-NEXT: - Type: R_WASM_MEMORY_ADDR_LEB
59 # CHECK-NEXT: Index: 0
60 # CHECK-NEXT: Offset: 0x11
61 # CHECK-NEXT: Addend: -10
62 # CHECK-NEXT: - Type: R_WASM_MEMORY_ADDR_LEB
63 # CHECK-NEXT: Index: 0
64 # CHECK-NEXT: Offset: 0x1B
65 # CHECK-NEXT: Addend: -2048
67 # CHECK: - Type: DATA
68 # CHECK-NEXT: Relocations:
69 # CHECK-NEXT: - Type: R_WASM_MEMORY_ADDR_I32
70 # CHECK-NEXT: Index: 0
71 # CHECK-NEXT: Offset: 0x6
72 # CHECK-NEXT: Addend: 64
73 # CHECK-NEXT: - Type: R_WASM_MEMORY_ADDR_I32
74 # CHECK-NEXT: Index: 0
75 # CHECK-NEXT: Offset: 0xF
76 # CHECK-NEXT: Addend: -16
78 # DIS: <_start>:
79 # DIS-EMPTY:
80 # DIS-NEXT: i32.const 0
81 # DIS-NEXT: i32.load 26
82 # DIS-NEXT: drop
83 # DIS-NEXT: i32.const 0
84 # DIS-NEXT: i32.load 6
85 # DIS-NEXT: drop
86 # DIS-NEXT: i32.const 0
87 # TODO(sbc): We should probably error here rather than allowing u32 to wrap
88 # DIS-NEXT: i32.load 4294965264
89 # DIS-NEXT: drop
90 # DIS-NEXT: end