Skip to content

Commit be0a20c

Browse files
authored
Ignore --initial-stack-pointer arg to wasm-emscripten-finalize (#2201)
We were passing bad value in --initial-stack-pointer which did not include the STATIC_BUMP (since STATIC_BUMP is determinted by the output of finalize). If emscripten wants to set the stack pointer position it can do so by calling the stackRestore() function at startup. This argument will be removed completely once we stop passing it on the emscripten side. See emscripten-core/emscripten#8905
1 parent f7ebd21 commit be0a20c

16 files changed

+22
-31
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ full changeset diff at the end of each section.
1515
Current Trunk
1616
-------------
1717

18+
v85
19+
---
20+
21+
- The --initial-stack-pointer argument to wasm-emscripten-finalize no longer
22+
has any effect. It will be removed completely in future release.
23+
1824
- Wast file parsing rules now don't allow a few invalid formats for typeuses
1925
that were previously allowed. Typeuse entries should follow this format,
2026
meaning they should have (type) -> (param) -> (result) order if more than one

scripts/test/lld.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def args_for_finalize(filename):
2525
if 'shared' in filename:
2626
return ['--side-module']
2727
else:
28-
return ['--global-base=568', '--initial-stack-pointer=16384']
28+
return ['--global-base=568']
2929

3030

3131
def test_wasm_emscripten_finalize():

src/tools/wasm-emscripten-finalize.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ int main(int argc, const char* argv[]) {
4949
bool isSideModule = false;
5050
bool legalizeJavaScriptFFI = true;
5151
uint64_t globalBase = INVALID_BASE;
52-
uint64_t initialStackPointer = INVALID_BASE;
5352
ToolOptions options("wasm-emscripten-finalize",
5453
"Performs Emscripten-specific transforms on .wasm files");
5554
options
@@ -78,13 +77,13 @@ int main(int argc, const char* argv[]) {
7877
[&globalBase](Options*, const std::string& argument) {
7978
globalBase = std::stoull(argument);
8079
})
80+
// TODO(sbc): Remove this one this argument is no longer passed by
81+
// emscripten. See https://github.com/emscripten-core/emscripten/issues/8905
8182
.add("--initial-stack-pointer",
8283
"",
83-
"The initial location of the stack pointer",
84+
"ignored - will be removed in a future release",
8485
Options::Arguments::One,
85-
[&initialStackPointer](Options*, const std::string& argument) {
86-
initialStackPointer = std::stoull(argument);
87-
})
86+
[](Options*, const std::string& argument) {})
8887
.add("--side-module",
8988
"",
9089
"Input is an emscripten side module",
@@ -169,9 +168,6 @@ int main(int argc, const char* argv[]) {
169168
if (globalBase == INVALID_BASE) {
170169
Fatal() << "globalBase must be set";
171170
}
172-
if (initialStackPointer == INVALID_BASE) {
173-
Fatal() << "initialStackPointer must be set";
174-
}
175171
Export* dataEndExport = wasm.getExport("__data_end");
176172
if (dataEndExport == nullptr) {
177173
Fatal() << "__data_end export not found";
@@ -210,7 +206,6 @@ int main(int argc, const char* argv[]) {
210206
} else {
211207
generator.generateRuntimeFunctions();
212208
generator.generateMemoryGrowthFunction();
213-
generator.generateStackInitialization(initialStackPointer);
214209
// For side modules these gets called via __post_instantiate
215210
if (Function* F = generator.generateAssignGOTEntriesFunction()) {
216211
auto* ex = new Export();

src/wasm-emscripten.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class EmscriptenGlueGenerator {
3434
void generateRuntimeFunctions();
3535
Function* generateMemoryGrowthFunction();
3636
Function* generateAssignGOTEntriesFunction();
37-
void generateStackInitialization(Address addr);
3837
void generatePostInstantiateFunction();
3938

4039
// Create thunks for use with emscripten Runtime.dynCall. Creates one for each

src/wasm/wasm-emscripten.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,6 @@ Function* EmscriptenGlueGenerator::generateMemoryGrowthFunction() {
311311
return growFunction;
312312
}
313313

314-
void EmscriptenGlueGenerator::generateStackInitialization(Address addr) {
315-
auto* stackPointer = getStackPointerGlobal();
316-
assert(!stackPointer->imported());
317-
if (!stackPointer->init || !stackPointer->init->is<Const>()) {
318-
Fatal() << "stack pointer global is not assignable";
319-
}
320-
stackPointer->init->cast<Const>()->value = Literal(int32_t(addr));
321-
}
322-
323314
inline void exportFunction(Module& wasm, Name name, bool must_export) {
324315
if (!wasm.getFunctionOrNull(name)) {
325316
assert(!must_export);

test/lld/duplicate_imports.wast.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
(memory $0 2)
1414
(data (i32.const 568) "Hello, world\00")
1515
(table $0 1 1 funcref)
16-
(global $global$0 (mut i32) (i32.const 16384))
16+
(global $global$0 (mut i32) (i32.const 66128))
1717
(global $global$1 i32 (i32.const 66128))
1818
(global $global$2 i32 (i32.const 581))
1919
(export "memory" (memory $0))

test/lld/em_asm.wast.mem.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
(import "env" "emscripten_asm_const_iii" (func $emscripten_asm_const_iii (param i32 i32 i32) (result i32)))
1111
(memory $0 2)
1212
(table $0 1 1 funcref)
13-
(global $global$0 (mut i32) (i32.const 16384))
13+
(global $global$0 (mut i32) (i32.const 66192))
1414
(global $global$1 i32 (i32.const 66192))
1515
(global $global$2 i32 (i32.const 652))
1616
(export "memory" (memory $0))

test/lld/em_asm.wast.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
(memory $0 2)
1212
(data (i32.const 568) "{ Module.print(\"Hello world\"); }\00{ return $0 + $1; }\00{ Module.print(\"Got \" + $0); }\00")
1313
(table $0 1 1 funcref)
14-
(global $global$0 (mut i32) (i32.const 16384))
14+
(global $global$0 (mut i32) (i32.const 66192))
1515
(global $global$1 i32 (i32.const 66192))
1616
(global $global$2 i32 (i32.const 652))
1717
(export "memory" (memory $0))

test/lld/em_asm_O0.wast.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
(memory $0 2)
1414
(data (i32.const 568) "{ Module.print(\"Hello world\"); }\00{ return $0 + $1; }\00{ Module.print(\"Got \" + $0); }\00")
1515
(table $0 1 1 funcref)
16-
(global $global$0 (mut i32) (i32.const 16384))
16+
(global $global$0 (mut i32) (i32.const 66192))
1717
(global $global$1 i32 (i32.const 66192))
1818
(global $global$2 i32 (i32.const 652))
1919
(export "memory" (memory $0))

test/lld/em_asm_table.wast.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
(import "env" "emscripten_asm_const_iii" (func $emscripten_asm_const_iii (param i32 i32 i32) (result i32)))
99
(table $0 159609 funcref)
1010
(elem (i32.const 1) $fimport$0 $emscripten_asm_const_iii)
11-
(global $global$0 (mut i32) (i32.const 16384))
11+
(global $global$0 (mut i32) (i32.const 1024))
1212
(global $global$1 i32 (i32.const 1048))
1313
(export "__data_end" (global $global$1))
1414
(export "stackSave" (func $stackSave))

0 commit comments

Comments
 (0)