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

[wasm] Enable --gc-sections for WebAssembly by default #71768

Conversation

kateinoigakukun
Copy link
Member

This change enables the --gc-sections linker flag for WebAssembly targets by default. This flag has been disabled because it did not respect llvm.used and it caused stripping swift5 metadata sections even though they were used through encapsulation symbols (a.k.a __start/__stop).

The issue has been fixed in the LLVM side (llvm/llvm-project@ba3c1f9) by adding new segment flags to the WebAssembly object file format, which is represented by "R" flag in assembly or llvm.used in LLVM IR.

This change enables the `--gc-sections` linker flag for WebAssembly
targets by default. This flag has been disabled because it did not
respect `llvm.used` and it caused stripping `swift5` metadata sections
even though they were used through encapsulation symbols (a.k.a `__start`/`__stop`).

The issue has been fixed in the LLVM side (llvm/llvm-project@ba3c1f9)
by adding new segment flags to the WebAssembly object file format.
@kateinoigakukun
Copy link
Member Author

preset=buildbot_linux_crosscompile_wasm
@swift-ci Please test with preset Linux Platform

@kateinoigakukun kateinoigakukun marked this pull request as ready for review February 21, 2024 10:50
@kateinoigakukun kateinoigakukun requested review from mikeash, al45tair and a team as code owners February 21, 2024 10:50
@kateinoigakukun
Copy link
Member Author

@swift-ci Please smoke test

kateinoigakukun added a commit to kateinoigakukun/swift-package-manager that referenced this pull request Feb 21, 2024
This effectively reverts 3a366cc.
After swiftlang/swift#71768, we don't have any
reason to disable `--gc-sections` for WebAssembly targets.
Note that the new wasm segment flags are only supported by the latest
LLVM and wasm-ld, but we can assume that toolchains or Swift SDKs for
WebAssembly have wasm-ld built from the latest LLVM.
@kateinoigakukun
Copy link
Member Author

@swift-ci Please smoke test

kateinoigakukun added a commit to kateinoigakukun/swift-package-manager that referenced this pull request Feb 21, 2024
This effectively reverts 3a366cc.
After swiftlang/swift#71768, we don't have any
reason to disable `--gc-sections` for WebAssembly targets.
Note that the new wasm segment flags are only supported by the latest
LLVM and wasm-ld, but we can assume that toolchains or Swift SDKs for
WebAssembly have wasm-ld built from the latest LLVM.
@kateinoigakukun
Copy link
Member Author

@swift-ci Please smoke test Windows platform

MaxDesiatov pushed a commit to swiftlang/swift-package-manager that referenced this pull request Feb 21, 2024
Enable `--gc-sections` back for WebAssembly targets

### Motivation:

We disabled `--gc-sections` for Wasm targets due to a lack of features
in the object file format. However, we recently added the missing piece
in wasm object file format, so we no longer have any reason to disable
it.

### Modifications:

This effectively reverts 3a366cc. After
swiftlang/swift#71768, we don't have any reason to
disable `--gc-sections` for WebAssembly targets. Note that the new wasm
segment flags are only supported by the latest LLVM and wasm-ld, but we
can assume that toolchains or Swift SDKs for WebAssembly have wasm-ld
built from the latest LLVM.


### Result:

Allow dead code stripping at link time for WebAssembly targets.
@kateinoigakukun kateinoigakukun merged commit d3d4bd2 into swiftlang:main Feb 21, 2024
4 checks passed
@kateinoigakukun kateinoigakukun deleted the pr-5b0947b86ee45b937e9b6fedd0963644227b754d branch February 22, 2024 04:38
furby-tm pushed a commit to wabiverse/swift-package-manager that referenced this pull request May 15, 2024
Enable `--gc-sections` back for WebAssembly targets

### Motivation:

We disabled `--gc-sections` for Wasm targets due to a lack of features
in the object file format. However, we recently added the missing piece
in wasm object file format, so we no longer have any reason to disable
it.

### Modifications:

This effectively reverts 3a366cc. After
swiftlang/swift#71768, we don't have any reason to
disable `--gc-sections` for WebAssembly targets. Note that the new wasm
segment flags are only supported by the latest LLVM and wasm-ld, but we
can assume that toolchains or Swift SDKs for WebAssembly have wasm-ld
built from the latest LLVM.


### Result:

Allow dead code stripping at link time for WebAssembly targets.
furby-tm pushed a commit to wabiverse/swift-package-manager that referenced this pull request May 15, 2024
Enable `--gc-sections` back for WebAssembly targets

### Motivation:

We disabled `--gc-sections` for Wasm targets due to a lack of features
in the object file format. However, we recently added the missing piece
in wasm object file format, so we no longer have any reason to disable
it.

### Modifications:

This effectively reverts 3a366cc. After
swiftlang/swift#71768, we don't have any reason to
disable `--gc-sections` for WebAssembly targets. Note that the new wasm
segment flags are only supported by the latest LLVM and wasm-ld, but we
can assume that toolchains or Swift SDKs for WebAssembly have wasm-ld
built from the latest LLVM.


### Result:

Allow dead code stripping at link time for WebAssembly targets.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants