Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded: pass -nostdlib for Embedded Wasm #1534

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the correct file you intended to modify is Sources/SwiftDriver/Jobs/WebAssemblyToolchain+LinkerSupport.swift. GenericUnixToolchain is not used for wasm targets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebAssemblyToolchain is not used for Embedded Swift targets either, it's currently only picked up for WASI. I'm inclined to rename that one to WASIToolchain maybe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I was wrong. A bit off-topic, but I think we might need to use WebAssemblyToolchain for all platforms using wasm-ld including Embedded WebAssembly targets because wasm-ld has quite different options set than other unix linkers. (e.g. wasm-ld doesn't have --start-group, all wasm targets needs --global-base, etc)

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"))
}

Expand Down