# WebAssembly: do not link with \-\-allow-undefined unconditionally · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/7802c26449657b205dcaa47bb6575bb26171c024)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 7802c26449657b205dcaa47bb6575bb26171c024

Requested commit: 7802c26449657b205dcaa47bb6575bb26171c024

Commit: 7802c26449657b205dcaa47bb6575bb26171c024

Tree: 1f4ca594d37bf4d9c51d85ed63164b86c5771029

Author: Frank Denis

Committer: Frank Denis

## Message

```
WebAssembly: do not link with --allow-undefined unconditionally

In #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 #1622, and
introduces an `import_symbols` flag to ignore undefined symbols,
assuming that the webassembly runtime will define them.

```

## Parents

- [0c30e006c90db4e6ca77d9054d391340282b96f6](https://git.cafe/gitcafe/zig/commit/0c30e006c90db4e6ca77d9054d391340282b96f6?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/7802c26449657b205dcaa47bb6575bb26171c024?format=markdown)
