From 7802c26449657b205dcaa47bb6575bb26171c024 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 25 Dec 2022 22:04:01 +0100 Subject: 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. --- src/link.zig | 1 + 1 file changed, 1 insertion(+) (limited to 'src/link.zig') diff --git a/src/link.zig b/src/link.zig index 450763ac18..1dadacc2fe 100644 --- a/src/link.zig +++ b/src/link.zig @@ -128,6 +128,7 @@ pub const Options = struct { compress_debug_sections: CompressDebugSections, bind_global_refs_locally: bool, import_memory: bool, + import_symbols: bool, import_table: bool, export_table: bool, initial_memory: ?u64, -- cgit v1.2.3