diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/support/archive.cpp | 10 | ||||
-rw-r--r-- | src/tools/s2wasm.cpp | 3 | ||||
-rw-r--r-- | src/wasm-linker.cpp | 21 | ||||
-rw-r--r-- | src/wasm-linker.h | 27 |
4 files changed, 36 insertions, 25 deletions
diff --git a/src/support/archive.cpp b/src/support/archive.cpp index b394294c6..b9ca827e4 100644 --- a/src/support/archive.cpp +++ b/src/support/archive.cpp @@ -129,15 +129,11 @@ std::string Archive::Child::getRawName() const { } Archive::Child Archive::Child::getNext(bool& error) const { - size_t toSkip = len; - // Members are aligned to even byte boundaries. - if (toSkip & 1) ++toSkip; - const uint8_t* nextLoc = data + toSkip; - if (nextLoc >= (uint8_t*)&*parent->data.end()) { // End of the archive. + uint32_t nextOffset = len + (len & 1); // Members are aligned to even byte boundaries. + if ((size_t)(data - (const uint8_t*)parent->data.data() + nextOffset) >= parent->data.size()) { // End of the archive. return Child(); } - - return Child(parent, nextLoc, &error); + return Child(parent, data + nextOffset, &error); } std::string Archive::Child::getName() const { diff --git a/src/tools/s2wasm.cpp b/src/tools/s2wasm.cpp index 8c36a0d58..ef5d276d3 100644 --- a/src/tools/s2wasm.cpp +++ b/src/tools/s2wasm.cpp @@ -132,7 +132,8 @@ int main(int argc, const char *argv[]) { if (options.debug) std::cerr << "Global base " << globalBase << '\n'; Linker linker(globalBase, stackAllocation, initialMem, maxMem, - ignoreUnknownSymbols, startFunction, options.debug); + generateEmscriptenGlue, ignoreUnknownSymbols, startFunction, + options.debug); S2WasmBuilder mainbuilder(input.c_str(), options.debug); linker.linkObject(mainbuilder); diff --git a/src/wasm-linker.cpp b/src/wasm-linker.cpp index 014dfe6a9..56ec03851 100644 --- a/src/wasm-linker.cpp +++ b/src/wasm-linker.cpp @@ -107,14 +107,25 @@ void Linker::layout() { } else { out.wasm.memory.initial = initialMem / Memory::kPageSize; } + out.wasm.memory.exists = true; if (userMaxMemory) out.wasm.memory.max = userMaxMemory / Memory::kPageSize; - auto memoryExport = make_unique<Export>(); - memoryExport->name = MEMORY; - memoryExport->value = Name::fromInt(0); - memoryExport->kind = ExternalKind::Memory; - out.wasm.addExport(memoryExport.release()); + if (importMemory) { + auto memoryImport = make_unique<Import>(); + memoryImport->name = MEMORY; + memoryImport->module = ENV; + memoryImport->base = MEMORY; + memoryImport->kind = ExternalKind::Memory; + out.wasm.memory.imported = true; + out.wasm.addImport(memoryImport.release()); + } else { + auto memoryExport = make_unique<Export>(); + memoryExport->name = MEMORY; + memoryExport->value = Name::fromInt(0); + memoryExport->kind = ExternalKind::Memory; + out.wasm.addExport(memoryExport.release()); + } // XXX For now, export all functions marked .globl. for (Name name : out.globls) exportFunction(name, false); diff --git a/src/wasm-linker.h b/src/wasm-linker.h index 4a0e1e0b9..3660b3038 100644 --- a/src/wasm-linker.h +++ b/src/wasm-linker.h @@ -193,18 +193,18 @@ class LinkerObject { // applying the relocations, resulting in an executable wasm module. class Linker { public: - Linker(Address globalBase, Address stackAllocation, - Address userInitialMemory, Address userMaxMemory, - bool ignoreUnknownSymbols, Name startFunction, - bool debug) : - ignoreUnknownSymbols(ignoreUnknownSymbols), - startFunction(startFunction), - globalBase(globalBase), - nextStatic(globalBase), - userInitialMemory(userInitialMemory), - userMaxMemory(userMaxMemory), - stackAllocation(stackAllocation), - debug(debug) { + Linker(Address globalBase, Address stackAllocation, Address userInitialMemory, + Address userMaxMemory, bool importMemory, bool ignoreUnknownSymbols, + Name startFunction, bool debug) + : ignoreUnknownSymbols(ignoreUnknownSymbols), + startFunction(startFunction), + globalBase(globalBase), + nextStatic(globalBase), + userInitialMemory(userInitialMemory), + userMaxMemory(userMaxMemory), + importMemory(importMemory), + stackAllocation(stackAllocation), + debug(debug) { if (userMaxMemory && userMaxMemory < userInitialMemory) { Fatal() << "Specified max memory " << userMaxMemory << " is < specified initial memory " << userInitialMemory; @@ -217,6 +217,7 @@ class Linker { Fatal() << "Specified initial memory " << userInitialMemory << " is not a multiple of 64k"; } + // Don't allow anything to be allocated at address 0 if (globalBase == 0) nextStatic = 1; @@ -312,6 +313,8 @@ class Linker { Address userInitialMemory; // Initial memory size (in bytes) specified by the user. Address userMaxMemory; // Max memory size (in bytes) specified by the user. //(after linking, this is rounded and set on the wasm object in pages) + bool importMemory; // Whether the memory should be imported instead of + // defined. Address stackAllocation; bool debug; |