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

Conversation

MaxDesiatov
Copy link
Contributor

@MaxDesiatov MaxDesiatov commented Jan 29, 2024

Depends on #1533.

Embedded Wasm binaries don't have compatible compiler-rt or C stdlib available, turn it off by default. Otherwise this makes trivial Embedded Wasm projects fail at link time.

Currently when linking with `swiftc` for `-unknown-none-` triples, it attempts to link `swiftrt.o` runtime file, which is currently not needed and is not present for these triples. We should avoid linking it in these cases.
Embedded Wasm binaries don't have compatible compiler-rt or C stdlib available, turn it off by default.
@MaxDesiatov MaxDesiatov added bug Something isn't working embedded Changes related to Embedded Swift labels Jan 29, 2024
@MaxDesiatov
Copy link
Contributor Author

@kubamracek @rauhul it's unclear to me if we want to pass -nostdlib for all bare metal embedded triples. I find that I have to always pass it in practice, since compiler-rt and C stdlib are not available for armv7-unknown-none-eabi either.

Copy link
Member

@kateinoigakukun kateinoigakukun left a comment

Choose a reason for hiding this comment

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

It makes some sense to make -nostdlib as default for Embedded + WebAssembly targets.
But the problems here are:

  1. Embedded feature and -nostdlib are orthogonal concepts and Embedded application are not prohibited from linking libc and compiler-rt.
  2. There is no way to tell clang linker driver to re-enable stdlib link.

So at least, we should have an option not to add -nostdlib even with Embedded + WebAssemby targets. Or given that Embedded is for expert feature, we can ask developers to add -Xclang-linker -nostdlib for their driver invocations.

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)

Base automatically changed from maxd/embedded-no-swiftrt to main January 29, 2024 17:59
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

MaxDesiatov added a commit that referenced this pull request Feb 20, 2024
Embedded targets may need `-nostdlib` passed to `clang` linker driver in certain situations, see #1534 for more details.

Currently, `swiftc` doesn't recognize `-nostdlib` at all, while `-Xlinker -nostdlib` passed to a `swiftc` link job from the build system will be passed verbatim to the linker and not recognized by the linker driver. We should support this flag in `swiftc` to fix this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working embedded Changes related to Embedded Swift
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants