diff options
| author | Frank Denis <github@pureftpd.org> | 2022-12-25 22:04:01 +0100 |
|---|---|---|
| committer | Frank Denis <github@pureftpd.org> | 2022-12-25 22:32:21 +0100 |
| commit | 7802c26449657b205dcaa47bb6575bb26171c024 (patch) | |
| tree | 1f4ca594d37bf4d9c51d85ed63164b86c5771029 /src/Compilation.zig | |
| parent | 0c30e006c90db4e6ca77d9054d391340282b96f6 (diff) | |
| download | zig-7802c26449657b205dcaa47bb6575bb26171c024.tar.gz zig-7802c26449657b205dcaa47bb6575bb26171c024.zip | |
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.
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index b385fa5f72..ab91e3cbb3 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -954,6 +954,7 @@ pub const InitOptions = struct { linker_allow_shlib_undefined: ?bool = null, linker_bind_global_refs_locally: ?bool = null, linker_import_memory: ?bool = null, + linker_import_symbols: bool = false, linker_import_table: bool = false, linker_export_table: bool = false, linker_initial_memory: ?u64 = null, @@ -1811,6 +1812,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { .bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false, .compress_debug_sections = options.linker_compress_debug_sections orelse .none, .import_memory = options.linker_import_memory orelse false, + .import_symbols = options.linker_import_symbols, .import_table = options.linker_import_table, .export_table = options.linker_export_table, .initial_memory = options.linker_initial_memory, |
