Skip to content

Commit 778208a

Browse files
authored
Wasm: bump default stack size to 128K (#2026)
The default of 64K is too low, especially as tail calls are not available by default on Wasm. It also means Swift Testing is unusable in `main` development snapshots due to stack overflows. rdar://160218251
1 parent 7833ebe commit 778208a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Sources/SwiftDriver/Jobs/WebAssemblyToolchain+LinkerSupport.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ extension WebAssemblyToolchain {
166166
commandLine.appendFlag(.Xlinker)
167167
commandLine.appendFlag("--table-base=\(SWIFT_ABI_WASM32_LEAST_VALID_POINTER)")
168168

169+
// Set slightly higher than the default (64K) stack size so that basic
170+
// workflows like Swift Testing can run within this limited stack space.
171+
let SWIFT_WASM_DEFAULT_STACK_SIZE = 1024 * 128
172+
commandLine.appendFlag(.Xlinker)
173+
commandLine.appendFlag("--stack-size=\(SWIFT_WASM_DEFAULT_STACK_SIZE)")
174+
169175
// Delegate to Clang for sanitizers. It will figure out the correct linker
170176
// options.
171177
if linkerOutputType == .executable && !sanitizers.isEmpty {

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,6 +2766,7 @@ final class SwiftDriverTests: XCTestCase {
27662766
XCTAssertTrue(cmd.contains(.responseFilePath(.absolute(path.appending(components: "wasi", "static-executable-args.lnk")))))
27672767
XCTAssertTrue(cmd.contains(subsequence: [.flag("-Xlinker"), .flag("--global-base=4096")]))
27682768
XCTAssertTrue(cmd.contains(subsequence: [.flag("-Xlinker"), .flag("--table-base=4096")]))
2769+
XCTAssertTrue(cmd.contains(subsequence: [.flag("-Xlinker"), .flag("--stack-size=\(128 * 1024)")]))
27692770
XCTAssertTrue(cmd.contains(.flag("-O3")))
27702771
XCTAssertEqual(linkJob.outputs[0].file, try toPath("Test"))
27712772

0 commit comments

Comments
 (0)