Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lld][WebAssembly] Initialize bss segments using memory.fill
Previously we were relying on the dynamic loader to take care of this but it simple and correct for us to do it here instead. Now we initialize bss segments as part of `__wasm_init_memory` at the same time we initialize passive segments. In addition we extent the us of `__wasm_init_memory` outside of shared memory situations. Specifically it is now used to initialize bss segments when the memory is imported. Differential Revision: https://reviews.llvm.org/D112667
- Loading branch information
Showing
9 changed files
with
257 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s | ||
# RUN: wasm-ld --experimental-pic -shared --shared-memory -o %t.so %t.o | ||
# RUN: llvm-objdump -d --no-show-raw-insn --no-leading-addr %t.so | FileCheck %s | ||
# RUN: obj2yaml %t.so | FileCheck %s --check-prefix=YAML | ||
|
||
.section .bss.foo,"",@ | ||
.globl foo | ||
.p2align 2 | ||
foo: | ||
.int32 0 | ||
.size foo, 4 | ||
|
||
.section .data.bar,"",@ | ||
.globl bar | ||
.p2align 2 | ||
bar: | ||
.int32 42 | ||
.size bar, 4 | ||
|
||
.section .custom_section.target_features,"",@ | ||
.int8 2 | ||
.int8 43 | ||
.int8 7 | ||
.ascii "atomics" | ||
.int8 43 | ||
.int8 11 | ||
.ascii "bulk-memory" | ||
|
||
# Verify that there is only a single data segment and no bss | ||
# in the binary: | ||
|
||
# YAML: - Type: DATA{{$}} | ||
# YAML-NEXT: Segments: | ||
# YAML-NEXT: - SectionOffset: 3 | ||
# YAML-NEXT: InitFlags: 1 | ||
# YAML-NEXT: Content: 2A000000 | ||
# YAML-NEXT: - Type: CUSTOM | ||
|
||
# CHECK: <__wasm_init_memory>: | ||
# CHECK-NEXT: .local i32 | ||
# CHECK-NEXT: global.get 0 | ||
# CHECK-NEXT: i32.const 8 | ||
# CHECK-NEXT: i32.add | ||
# CHECK-NEXT: local.set 0 | ||
# CHECK-NEXT: block | ||
# CHECK-NEXT: block | ||
# CHECK-NEXT: block | ||
# CHECK-NEXT: local.get 0 | ||
# CHECK-NEXT: i32.const 0 | ||
# CHECK-NEXT: i32.const 1 | ||
# CHECK-NEXT: i32.atomic.rmw.cmpxchg 0 | ||
# CHECK-NEXT: br_table {0, 1, 2} # 1: down to label1 | ||
# CHECK-NEXT: # 2: down to label0 | ||
# CHECK-NEXT: end | ||
|
||
# Regular data gets initialized with memory.init | ||
|
||
# CHECK-NEXT: i32.const 0 | ||
# CHECK-NEXT: global.get 0 | ||
# CHECK-NEXT: i32.add | ||
# CHECK-NEXT: i32.const 0 | ||
# CHECK-NEXT: i32.const 4 | ||
# CHECK-NEXT: memory.init 0, 0 | ||
|
||
# BSS gets initialized with memory.fill | ||
|
||
# CHECK-NEXT: i32.const 4 | ||
# CHECK-NEXT: global.get 0 | ||
# CHECK-NEXT: i32.add | ||
# CHECK-NEXT: i32.const 0 | ||
# CHECK-NEXT: i32.const 4 | ||
# CHECK-NEXT: memory.fill 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.