From 3eb42ecb550acc2d4df7372ad1319aca7af645d0 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 8 Jun 2021 13:00:20 +0100 Subject: Minor improvements to `-use-separate-modules` --- src/llvm_backend.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'src/llvm_backend.cpp') diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 22fb3c498..73b420adf 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -2819,7 +2819,12 @@ lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool ignore_body) char const *export_name = alloc_cstring(permanent_allocator(), p->name); LLVMAddTargetDependentFunctionAttr(p->value, "wasm-export-name", export_name); } + } else if (!p->is_foreign) { + if (!USE_SEPARTE_MODULES) { + LLVMSetLinkage(p->value, LLVMInternalLinkage); + } } + if (p->is_foreign) { if (is_arch_wasm()) { char const *import_name = alloc_cstring(permanent_allocator(), p->name); @@ -6066,6 +6071,23 @@ lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e) { return {}; } +void lb_set_entity_from_other_modules_linkage_correctly(lbModule *other_module, Entity *e, String const &name) { + if (other_module == nullptr) { + return; + } + char const *cname = alloc_cstring(temporary_allocator(), name); + + LLVMValueRef other_global = nullptr; + if (e->kind == Entity_Variable) { + other_global = LLVMGetNamedGlobal(other_module->mod, cname); + } else if (e->kind == Entity_Procedure) { + other_global = LLVMGetNamedFunction(other_module->mod, cname); + } + if (other_global) { + LLVMSetLinkage(other_global, LLVMExternalLinkage); + } +} + lbValue lb_find_value_from_entity(lbModule *m, Entity *e) { e = strip_entity_wrapping(e); GB_ASSERT(e != nullptr); @@ -6106,12 +6128,7 @@ lbValue lb_find_value_from_entity(lbModule *m, Entity *e) { LLVMSetLinkage(g.value, LLVMExternalLinkage); - // if (other_module != nullptr) { - // lbValue *other_found = string_map_get(&other_module->members, name); - // if (other_found) { - // lbValue other_g = *other_found; - // } - // } + lb_set_entity_from_other_modules_linkage_correctly(other_module, e, name); // LLVMSetLinkage(other_g.value, LLVMExternalLinkage); @@ -11820,6 +11837,8 @@ lbValue lb_find_ident(lbProcedure *p, lbModule *m, Entity *e, Ast *expr) { String name = lb_get_entity_name(other_module, e); + lb_set_entity_from_other_modules_linkage_correctly(other_module, e, name); + lbValue g = {}; g.value = LLVMAddGlobal(m->mod, lb_type(m, e->type), alloc_cstring(permanent_allocator(), name)); g.type = alloc_type_pointer(e->type); -- cgit v1.2.3