Files
clang-p2996/llvm/test/MC/WebAssembly/reloc-relative.ll
Yuta Saito aa0c571a5f [WebAssembly] Add new relocation for location relative data
This `R_WASM_MEMORY_ADDR_SELFREL_I32` relocation represents an offset
between its relocating address and the symbol address. It's very similar
to `R_X86_64_PC32` but restricted to be used for only data segments.

```
S + A - P
```

A: Represents the addend used to compute the value of the relocatable
field.
P: Represents the place of the storage unit being relocated.
S: Represents the value of the symbol whose index resides in the
relocation entry.

Proposal: https://github.com/WebAssembly/tool-conventions/issues/162

Differential Revision: https://reviews.llvm.org/D96659
2021-03-08 11:34:10 -08:00

49 lines
1.3 KiB
LLVM

; RUN: llc -O0 -filetype=obj %s -o - | llvm-readobj -r --expand-relocs - | FileCheck %s
; CHECK: Format: WASM
; CHECK: Relocations [
; CHECK-NEXT: Section (3) DATA {
; CHECK-NEXT: Relocation {
; CHECK-NEXT: Type: R_WASM_MEMORY_ADDR_LOCREL_I32 (23)
; CHECK-NEXT: Offset: 0x6
; CHECK-NEXT: Symbol: foo
; CHECK-NEXT: Addend: 0
; CHECK-NEXT: }
; CHECK-NEXT: Relocation {
; CHECK-NEXT: Type: R_WASM_MEMORY_ADDR_LOCREL_I32 (23)
; CHECK-NEXT: Offset: 0xA
; CHECK-NEXT: Symbol: fizz
; CHECK-NEXT: Addend: 0
; CHECK-NEXT: }
; CHECK-NEXT: Relocation {
; CHECK-NEXT: Type: R_WASM_MEMORY_ADDR_LOCREL_I32 (23)
; CHECK-NEXT: Offset: 0x17
; CHECK-NEXT: Symbol: foo
; CHECK-NEXT: Addend: 4
; CHECK-NEXT: }
; CHECK-NEXT: }
; CHECK-NEXT: ]
target triple = "wasm32-unknown-unknown"
; @foo - @bar
@foo = external global i32, align 4
@bar = constant i32 sub (
i32 ptrtoint (i32* @foo to i32),
i32 ptrtoint (i32* @bar to i32)
), section ".sec1"
; @foo - @addend + 4
@fizz = constant i32 42, align 4, section ".sec2"
@addend = constant i32 sub (
i32 ptrtoint (i32* @foo to i32),
i32 ptrtoint (i32* @fizz to i32)
), section ".sec2"
@x_sec = constant i32 sub (
i32 ptrtoint (i32* @fizz to i32),
i32 ptrtoint (i32* @x_sec to i32)
), section ".sec1"