WebAssembly: do not link with --allow-undefined unconditionally - #14069
Closed
jedisct1 wants to merge 1 commit into
Closed
WebAssembly: do not link with --allow-undefined unconditionally#14069jedisct1 wants to merge 1 commit into
jedisct1 wants to merge 1 commit into
Conversation
In ziglang#1622, when targeting WebAsembly, the --allow-undefined flag became unconditionally added to the linker. This is not always desirable. First, this is error prone. Code with references to unkown symbols will link just fine, but then fail at run-time. This behavior is inconsistent with all other targets. For freestanding wasm applications, and applications that only use WASI, undefined references are better reported at compile-time. This behavior is also inconsistent with clang itself. Autoconf and cmake scripts checking for function presence think that all tested functions exist, but then resulting application cannot run. For example, this is one of the reasons compilation of Ruby 3.2.0 to WASI fails with zig cc, while it works out of the box with clang. But all applications checking for symbol existence before compilation are affected. This reverts the behavior to the one Zig had before ziglang#1622, and introduces an `import_symbols` flag to ignore undefined symbols, assuming that the webassembly runtime will define them.
Contributor
|
As you may have noticed this change actually requires quite some big changes in the linker, but also in some other areas such as the way we export compiler-rt symbols for the Wasm target (as we need to get rid of the |
Contributor
Author
|
Hi @Luukdegram ! Yes, unfortunately these changes are not enough. I got stuck trying to get rid of the |
Contributor
|
Got it, I'll try to have something ready by tomorrow :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In #2193, when targeting WebAsembly, the --allow-undefined flag became unconditionally added to the linker.
This is not always desirable.
First, this is error prone. Code with references to unkown symbols will link just fine, but then fail at run-time.
This behavior is inconsistent with all other targets.
For freestanding wasm applications, and applications that only use WASI, undefined references are better reported at compile-time.
This behavior is also inconsistent with clang itself. Autoconf and cmake scripts checking for function presence think that all tested functions exist, but then resulting application cannot run.
For example, this is one of the reasons compilation of Ruby 3.2.0 to WASI fails with zig cc, while it works out of the box with clang. But all applications checking for symbol existence before compilation are affected.
This reverts the behavior to the one Zig had before #2193, and introduces an
import_symbolsflag to ignore undefined symbols, assuming that the webassembly runtime will define them.