[PATCH] D96659: [WebAssembly] Add new relocation for location relative data
Yuta Saito via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 1 16:28:02 PST 2021
kateinoigakukun added inline comments.
================
Comment at: lld/test/wasm/reloc-relative.s:3
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o
+# RUN: wasm-ld --no-entry --no-gc-sections --allow-undefined -fatal-warnings -o %t.wasm %t.o %t.hello32.o
+# RUN: obj2yaml %t.wasm | FileCheck %s
----------------
sbc100 wrote:
> Do you need `--allow-undefined` here?
Yes, hello.s requires `puts` symbol but this test doesn't use printing function, so I put `--allow-undefined` to ignore such unrelated symbols.
```
## hello.s
.globl hello
hello:
.functype hello () -> ()
i32.const hello_str
call puts
end_function
.section .rodata.hello_str,"",@
.globl hello_str
hello_str:
.asciz "hello\n"
.size hello_str, 7
.functype puts (i32) -> ()
```
================
Comment at: lld/test/wasm/reloc-relative.s:29
+bar:
+ .int32 hello_str - bar
+ .size bar, 4
----------------
sbc100 wrote:
> How does this not trigger the `can not be placed in a different section` error in the object writer?
```
S + A - P
```
`R_WASM_MEMORY_ADDR_LOCREL_I32` allows `S` to be a symbol in a different section, but doesn't allow `P` to be in a different section. This limitation is because a relocation entry can have only one symbol, so the base address (`P`) needs to be relative to the writing location.
In this case, `hello_str` is an external section symbol, but `S` can be a symbol in a different section and `bar` is placed in the same section with writing location, so does not trigger `can not be placed in a different section`.
This expression emits the below relocation entry.
```
Relocation {
Type: R_WASM_MEMORY_ADDR_LOCREL_I32 (23)
Offset: 0x0
Symbol: hello_str
Addend: 0
}
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D96659/new/
https://reviews.llvm.org/D96659
More information about the llvm-commits
mailing list