Skip to content

Commit 1388d74

Browse files
authored
[6.3] Wasm: bump default stack size to 128K (#2030)
Cherry-pick of #2026. **Explanation**: The default of 64K for stack size 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. **Scope**: Limited to Wasm support. **Risk**: Low due to isolated scope. **Testing**: Added automated end-to-end test in swiftlang/swift-integration-tests#167. **Issue**: rdar://160218251 **Reviewer**: @kateinoigakukun
1 parent 483e6d6 commit 1388d74

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Sources/SwiftDriver/Jobs/WebAssemblyToolchain+LinkerSupport.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ 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 running Swift Testing can proceed within this limited stack space.
171+
let SWIFT_WASM_DEFAULT_STACK_SIZE = 1024 * 128
172+
commandLine.appendFlag(.Xlinker)
173+
commandLine.appendFlag("-z")
174+
commandLine.appendFlag(.Xlinker)
175+
commandLine.appendFlag("stack-size=\(SWIFT_WASM_DEFAULT_STACK_SIZE)")
176+
169177
// Delegate to Clang for sanitizers. It will figure out the correct linker
170178
// options.
171179
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("-z"), .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)