diff --git a/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift b/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift index 05f53a52f..502fbc563 100644 --- a/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift +++ b/Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift @@ -195,6 +195,11 @@ extension GenericUnixToolchain { commandLine.appendPath(swiftrtPath) } + // Embedded Wasm binaries don't have compatible compiler-rt or C stdlib available, turn it off by default. + if isEmbeddedEnabled && (targetTriple.arch == .wasm32 || targetTriple.arch == .wasm64) { + commandLine.appendFlag("-nostdlib") + } + // If we are linking statically, we need to add all // dependencies to a library search group to resolve // potential circular dependencies diff --git a/Tests/SwiftDriverTests/SwiftDriverTests.swift b/Tests/SwiftDriverTests/SwiftDriverTests.swift index 28c5b2f17..4cd75349d 100644 --- a/Tests/SwiftDriverTests/SwiftDriverTests.swift +++ b/Tests/SwiftDriverTests/SwiftDriverTests.swift @@ -6564,6 +6564,7 @@ final class SwiftDriverTests: XCTestCase { XCTAssertFalse(linkJob.commandLine.contains(.flag("-force_load"))) XCTAssertFalse(linkJob.commandLine.contains(.flag("-rpath"))) XCTAssertFalse(linkJob.commandLine.contains(.flag("-lswiftCore"))) + XCTAssertTrue(linkJob.commandLine.contains(.flag("-nostdlib"))) } // Embedded Wasm link job @@ -6576,6 +6577,7 @@ final class SwiftDriverTests: XCTestCase { XCTAssertFalse(linkJob.commandLine.contains(.flag("-force_load"))) XCTAssertFalse(linkJob.commandLine.contains(.flag("-rpath"))) XCTAssertFalse(linkJob.commandLine.contains(.flag("-lswiftCore"))) + XCTAssertTrue(linkJob.commandLine.contains(.flag("-nostdlib"))) XCTAssertFalse(linkJob.commandLine.joinedUnresolvedArguments.contains("swiftrt.o")) }