Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Sources/SwiftDriver/Jobs/WebAssemblyToolchain+LinkerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ extension WebAssemblyToolchain {
// Explicitly pass the target to the linker
commandLine.appendFlag("--target=\(targetTriple.triple)")

// WebAssembly doesn't reserve low addresses as its ABI. But without
// "extra inhabitants" of the pointer representation, runtime performance
// and memory footprint are significantly degraded. So we reserve the
// low addresses to use them as extra inhabitants by telling the lowest
// valid address to the linker.
// The value of lowest valid address, called "global base", must be always
// synchronized with `SWIFT_ABI_WASM32_LEAST_VALID_POINTER` defined in
// apple/swift's runtime library.
commandLine.appendFlag(.Xlinker)
commandLine.appendFlag("--global-base=4096")

// Delegate to Clang for sanitizers. It will figure out the correct linker
// options.
guard sanitizers.isEmpty else {
Expand Down
1 change: 1 addition & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2315,6 +2315,7 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertTrue(commandContainsTemporaryPath(cmd, "bar.o"))
XCTAssertTrue(commandContainsTemporaryResponsePath(cmd, "Test.autolink"))
XCTAssertTrue(cmd.contains(.responseFilePath(.absolute(path.appending(components: "wasi", "static-executable-args.lnk")))))
XCTAssertTrue(cmd.contains(subsequence: [.flag("-Xlinker"), .flag("--global-base=4096")]))
XCTAssertTrue(cmd.contains(.flag("-O3")))
XCTAssertEqual(linkJob.outputs[0].file, try VirtualPath(path: "Test"))

Expand Down