From 50201e1c30e0d71bafd643e9804d55eceb7b3542 Mon Sep 17 00:00:00 2001 From: Luuk de Gram Date: Sun, 12 Dec 2021 16:21:25 +0100 Subject: wasm-linker: Allow specifying symbols to be exported Notating a symbol to be exported in code will only tell the linker where to find this symbol, so other object files can find it. However, this does not mean said symbol will also be exported to the host environment. Currently, we 'fix' this by force exporting every single symbol that is visible. This creates bigger binaries and means host environments have access to symbols that they perhaps shouldn't have. Now, users can tell Zig which symbols are to be exported, meaning all other symbols that are not specified will not be exported. Another change is we now support `-rdynamic` in the wasm linker as well, meaning all symbols will be put in the dynamic symbol table. This is the same behavior as with ELF. This means there's a 3rd strategy users will have to build their wasm binary. --- src/Compilation.zig | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/Compilation.zig') diff --git a/src/Compilation.zig b/src/Compilation.zig index 81c3d0132f..d58394de65 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -727,6 +727,7 @@ pub const InitOptions = struct { linker_initial_memory: ?u64 = null, linker_max_memory: ?u64 = null, linker_global_base: ?u64 = null, + linker_export_symbol_names: []const []const u8 = &.{}, each_lib_rpath: ?bool = null, disable_c_depfile: bool = false, linker_z_nodelete: bool = false, @@ -1457,6 +1458,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { .initial_memory = options.linker_initial_memory, .max_memory = options.linker_max_memory, .global_base = options.linker_global_base, + .export_symbol_names = options.linker_export_symbol_names, .z_nodelete = options.linker_z_nodelete, .z_notext = options.linker_z_notext, .z_defs = options.linker_z_defs, -- cgit v1.2.3