Skip to content

Conversation

@jedisct1
Copy link
Contributor

@jedisct1 jedisct1 commented Dec 25, 2022

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_symbols flag to ignore undefined symbols, assuming that the webassembly runtime will define them.

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.
@jedisct1 jedisct1 added breaking Implementing this issue could cause existing code to no longer compile or have different behavior. arch-wasm 32-bit and 64-bit WebAssembly os-wasi WebAssembly System Interface labels Dec 25, 2022
@jedisct1 jedisct1 closed this Dec 25, 2022
@Luukdegram
Copy link
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 --export flag altogether. Let me know if you need some guidance on this, or if you'd prefer for me to take it over from here as you already closed the PR. I don't mind putting this on the top of my list and getting this in for you.

@jedisct1
Copy link
Contributor Author

Hi @Luukdegram !

Yes, unfortunately these changes are not enough. I got stuck trying to get rid of the --export flag.
Feel free to take over it, as you're the wasm linker expert :)

@Luukdegram
Copy link
Contributor

Got it, I'll try to have something ready by tomorrow :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm 32-bit and 64-bit WebAssembly breaking Implementing this issue could cause existing code to no longer compile or have different behavior. os-wasi WebAssembly System Interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants