wasm-linker: Only export symbols notated as such

This exposes a function from stage2 to stage1 to append symbols to automatically export them.

This happends under the following conditions:
- Target is wasm
- User has not provided --export/--rdynamic flags themselves.
This commit is contained in:
Luuk de Gram
2022-01-05 20:47:04 +01:00
parent 0772fb0518
commit 6d951aff7e
6 changed files with 65 additions and 13 deletions

View File

@@ -9905,6 +9905,18 @@ void codegen_build_object(CodeGen *g) {
codegen_add_time_event(g, "Done");
codegen_switch_sub_prog_node(g, nullptr);
// append all export symbols to stage2 so we can provide them to the linker
if (target_is_wasm(g->zig_target)){
Error err;
auto export_it = g->exported_symbol_names.entry_iterator();
decltype(g->exported_symbol_names)::Entry *curr_entry = nullptr;
while ((curr_entry = export_it.next()) != nullptr) {
if ((err = stage2_append_symbol(&g->stage1, buf_ptr(curr_entry->key)))) {
fprintf(stderr, "Unable to export symbol '%s': %s\n", buf_ptr(curr_entry->key), err_str(err));
}
}
}
}
ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path,