From 4caea4872aed6d1cb7ef42c9a2364870eb574e41 Mon Sep 17 00:00:00 2001 From: jgravelle-google Date: Wed, 30 Nov 2016 15:34:39 -0800 Subject: Handle importing globals in s2wasm (#843) * Handle importing globals in s2wasm * Make importedGlobals a set of Names, make Names hashable * Revert "Make importedGlobals a set of Names, make Names hashable" This reverts commit 1d0ca7a5e3839b15ca60593330979864c9c3ed60. * Refactor relocation parsing to handle expressions directly * PR Feedback - Move comment where it belongs - Add comment about ownership to addRelocation - Remove do-nothing parseImportGlobal * Reword "imported globals" to "imported objects" - Flip isObjectImported to isObjectImplemented, for consistency * Add tests for s2wasm globals. Also implement import relocation expression handling * Simplify globals.s test * Fix memory leak of relocation * Use unique_ptr instead of delete in getRelocatableExpression --- src/wasm-linker.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/wasm-linker.cpp') diff --git a/src/wasm-linker.cpp b/src/wasm-linker.cpp index 56ec03851..76bf8942d 100644 --- a/src/wasm-linker.cpp +++ b/src/wasm-linker.cpp @@ -40,7 +40,9 @@ void Linker::placeStackPointer(Address stackAllocation) { // stack pointer to point to one past-the-end of the stack allocation. std::vector raw; raw.resize(pointerSize); - out.addRelocation(LinkerObject::Relocation::kData, (uint32_t*)&raw[0], ".stack", stackAllocation); + auto relocation = new LinkerObject::Relocation( + LinkerObject::Relocation::kData, (uint32_t*)&raw[0], ".stack", stackAllocation); + out.addRelocation(relocation); assert(out.wasm.memory.segments.empty()); out.addSegment("__stack_pointer", raw); } @@ -327,6 +329,8 @@ void Linker::emscriptenGlue(std::ostream& o) { exportFunction(f->name, true); } + emscripten::addObjectImports(out.wasm, out.symbolInfo.importedObjects); + auto staticBump = nextStatic - globalBase; emscripten::generateEmscriptenMetadata(o, out.wasm, segmentsByAddress, staticBump, out.initializerFunctions); } -- cgit v1.2.3