[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
This commit is contained in:
Derek Schuff 2018-11-06 17:27:25 +00:00
parent 724014adde
commit 6881806241
4 changed files with 39 additions and 1 deletions

View File

@ -214,6 +214,7 @@ enum : unsigned {
enum : unsigned {
WASM_LIMITS_FLAG_HAS_MAX = 0x1,
WASM_LIMITS_FLAG_IS_SHARED = 0x2,
};
// Kind codes used in the custom "name" section

View File

@ -193,7 +193,7 @@ static Error readInitExpr(wasm::WasmInitExpr &Expr,
static wasm::WasmLimits readLimits(WasmObjectFile::ReadContext &Ctx) {
wasm::WasmLimits Result;
Result.Flags = readVaruint1(Ctx);
Result.Flags = readVaruint32(Ctx);
Result.Initial = readVaruint32(Ctx);
if (Result.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX)
Result.Maximum = readVaruint32(Ctx);

View File

@ -416,6 +416,7 @@ void ScalarBitSetTraits<WasmYAML::LimitFlags>::bitset(
IO &IO, WasmYAML::LimitFlags &Value) {
#define BCase(X) IO.bitSetCase(Value, #X, wasm::WASM_LIMITS_FLAG_##X)
BCase(HAS_MAX);
BCase(IS_SHARED);
#undef BCase
}

View File

@ -0,0 +1,36 @@
# RUN: yaml2obj %s | obj2yaml | FileCheck %s
--- !WASM
FileHeader:
Version: 0x00000001
Sections:
- Type: TYPE
Signatures:
- Index: 0
ReturnType: I32
ParamTypes:
- I32
- Type: IMPORT
Imports:
- Module: foo
Field: imported_memory
Kind: MEMORY
Memory:
Flags: [ HAS_MAX, IS_SHARED ]
Initial: 0x00000010
Maximum: 0x00000011
...
# CHECK: --- !WASM
# CHECK: FileHeader:
# CHECK: Version: 0x00000001
# CHECK: Sections:
# CHECK: - Type: IMPORT
# CHECK: Imports:
# CHECK: - Module: foo
# CHECK: Field: imported_memory
# CHECK: Kind: MEMORY
# CHECK: Memory:
# CHECK: Flags: [ HAS_MAX, IS_SHARED ]
# CHECK: Initial: 0x00000010
# CHECK: Maximum: 0x00000011
# CHECK: ...