Correct missing procedures in other build modules which cause a linkage problem

This commit is contained in:
gingerBill
2023-01-12 16:59:16 +00:00
parent 34f9170189
commit 402a165b60
4 changed files with 21 additions and 16 deletions

View File

@@ -5092,7 +5092,7 @@ gb_internal bool check_proc_info(Checker *c, ProcInfo *pi, UntypedExprInfoMap *u
if ((e->flags & EntityFlag_Used) == 0) {
// NOTE(bill, 2019-08-31): It was never used, don't check
// NOTE(bill, 2023-01-02): This may need to be checked again if it is used elsewhere?
pi->decl->proc_checked_state.store(ProcCheckedState_Unchecked);
pi->decl->proc_checked_state.store(ProcCheckedState_Unchecked);
return false;
}
}

View File

@@ -1852,6 +1852,7 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
isize worker_count = thread_count-1;
bool do_threading = !!(LLVMIsMultithreaded() && USE_SEPARATE_MODULES && MULTITHREAD_OBJECT_GENERATION && worker_count > 0);
do_threading = false;
lbModule *default_module = &gen->default_module;
CheckerInfo *info = gen->info;
@@ -2067,9 +2068,7 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
Type *t = alloc_type_array(t_type_info, max_type_info_count);
LLVMValueRef g = LLVMAddGlobal(m->mod, lb_type(m, t), LB_TYPE_INFO_DATA_NAME);
LLVMSetInitializer(g, LLVMConstNull(lb_type(m, t)));
if (!USE_SEPARATE_MODULES) {
LLVMSetLinkage(g, LLVMInternalLinkage);
}
LLVMSetLinkage(g, USE_SEPARATE_MODULES ? LLVMExternalLinkage : LLVMInternalLinkage);
lbValue value = {};
value.value = g;
@@ -2241,11 +2240,7 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
LLVMSetLinkage(g.value, LLVMDLLExportLinkage);
LLVMSetDLLStorageClass(g.value, LLVMDLLExportStorageClass);
} else if (!is_foreign) {
if (USE_SEPARATE_MODULES) {
LLVMSetLinkage(g.value, LLVMExternalLinkage);
} else {
LLVMSetLinkage(g.value, LLVMInternalLinkage);
}
LLVMSetLinkage(g.value, USE_SEPARATE_MODULES ? LLVMExternalLinkage : LLVMInternalLinkage);
}
lb_set_linkage_from_entity_flags(m, g.value, e->flags);

View File

@@ -2598,7 +2598,15 @@ gb_internal lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e)
ignore_body = other_module != m;
lbProcedure *missing_proc = lb_create_procedure(m, e, ignore_body);
if (!ignore_body) {
if (ignore_body) {
mutex_lock(&other_module->values_mutex);
auto *found = map_get(&other_module->values, e);
if (found == nullptr) {
lbProcedure *missing_proc_in_other_module = lb_create_procedure(other_module, e, false);
array_add(&other_module->missing_procedures_to_check, missing_proc_in_other_module);
}
mutex_unlock(&other_module->values_mutex);
} else {
array_add(&m->missing_procedures_to_check, missing_proc);
}
found = map_get(&m->values, e);

View File

@@ -190,11 +190,6 @@ gb_internal lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool i
lb_add_attribute_to_proc(m, p->value, "cold");
}
lbValue proc_value = {p->value, p->type};
lb_add_entity(m, entity, proc_value);
lb_add_member(m, p->name, proc_value);
lb_add_procedure_value(m, p);
if (p->is_export) {
LLVMSetLinkage(p->value, LLVMDLLExportLinkage);
LLVMSetDLLStorageClass(p->value, LLVMDLLExportStorageClass);
@@ -202,7 +197,9 @@ gb_internal lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool i
lb_set_wasm_export_attributes(p->value, p->name);
} else if (!p->is_foreign) {
if (!USE_SEPARATE_MODULES) {
if (USE_SEPARATE_MODULES) {
LLVMSetLinkage(p->value, LLVMExternalLinkage);
} else {
LLVMSetLinkage(p->value, LLVMInternalLinkage);
// NOTE(bill): if a procedure is defined in package runtime and uses a custom link name,
@@ -316,6 +313,11 @@ gb_internal lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool i
}
}
lbValue proc_value = {p->value, p->type};
lb_add_entity(m, entity, proc_value);
lb_add_member(m, p->name, proc_value);
lb_add_procedure_value(m, p);
return p;
}