Skip to content

Commit 6881806

Browse files
committed
[WebAssembly] Add shared memory support to limits field
Support the IS_SHARED bit in the memory limits flag word. The compiler does not create object files with memory definitions, but the field is used by the linker. Differential Revision: https://reviews.llvm.org/D54131 llvm-svn: 346246
1 parent 724014a commit 6881806

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

llvm/include/llvm/BinaryFormat/Wasm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ enum : unsigned {
214214

215215
enum : unsigned {
216216
WASM_LIMITS_FLAG_HAS_MAX = 0x1,
217+
WASM_LIMITS_FLAG_IS_SHARED = 0x2,
217218
};
218219

219220
// Kind codes used in the custom "name" section

llvm/lib/Object/WasmObjectFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static Error readInitExpr(wasm::WasmInitExpr &Expr,
193193

194194
static wasm::WasmLimits readLimits(WasmObjectFile::ReadContext &Ctx) {
195195
wasm::WasmLimits Result;
196-
Result.Flags = readVaruint1(Ctx);
196+
Result.Flags = readVaruint32(Ctx);
197197
Result.Initial = readVaruint32(Ctx);
198198
if (Result.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX)
199199
Result.Maximum = readVaruint32(Ctx);

llvm/lib/ObjectYAML/WasmYAML.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ void ScalarBitSetTraits<WasmYAML::LimitFlags>::bitset(
416416
IO &IO, WasmYAML::LimitFlags &Value) {
417417
#define BCase(X) IO.bitSetCase(Value, #X, wasm::WASM_LIMITS_FLAG_##X)
418418
BCase(HAS_MAX);
419+
BCase(IS_SHARED);
419420
#undef BCase
420421
}
421422

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# RUN: yaml2obj %s | obj2yaml | FileCheck %s
2+
--- !WASM
3+
FileHeader:
4+
Version: 0x00000001
5+
Sections:
6+
- Type: TYPE
7+
Signatures:
8+
- Index: 0
9+
ReturnType: I32
10+
ParamTypes:
11+
- I32
12+
- Type: IMPORT
13+
Imports:
14+
- Module: foo
15+
Field: imported_memory
16+
Kind: MEMORY
17+
Memory:
18+
Flags: [ HAS_MAX, IS_SHARED ]
19+
Initial: 0x00000010
20+
Maximum: 0x00000011
21+
22+
...
23+
# CHECK: --- !WASM
24+
# CHECK: FileHeader:
25+
# CHECK: Version: 0x00000001
26+
# CHECK: Sections:
27+
# CHECK: - Type: IMPORT
28+
# CHECK: Imports:
29+
# CHECK: - Module: foo
30+
# CHECK: Field: imported_memory
31+
# CHECK: Kind: MEMORY
32+
# CHECK: Memory:
33+
# CHECK: Flags: [ HAS_MAX, IS_SHARED ]
34+
# CHECK: Initial: 0x00000010
35+
# CHECK: Maximum: 0x00000011
36+
# CHECK: ...

0 commit comments

Comments
 (0)