aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-07-15 12:21:42 +0100
committergingerBill <bill@gingerbill.org>2024-07-15 12:21:42 +0100
commit549311fac98ce447e8ab18d365841dc4f0671abf (patch)
tree5419414785383d324d3b19219a7a7cc0f6480d82 /src/llvm_backend.cpp
parentc5decd3eaecf393e1bf216b4d864fc9cfc5db0c2 (diff)
Fix global variables being "missing" with `-use-separate-modules`
Diffstat (limited to 'src/llvm_backend.cpp')
-rw-r--r--src/llvm_backend.cpp37
1 files changed, 16 insertions, 21 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp
index d975ac600..4f3186dba 100644
--- a/src/llvm_backend.cpp
+++ b/src/llvm_backend.cpp
@@ -137,18 +137,23 @@ gb_internal void lb_set_entity_from_other_modules_linkage_correctly(lbModule *ot
}
char const *cname = alloc_cstring(permanent_allocator(), name);
mpsc_enqueue(&other_module->gen->entities_to_correct_linkage, lbEntityCorrection{other_module, e, cname});
+}
- // 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);
- // }
+gb_internal void lb_correct_entity_linkage(lbGenerator *gen) {
+ for (lbEntityCorrection ec = {}; mpsc_dequeue(&gen->entities_to_correct_linkage, &ec); /**/) {
+ LLVMValueRef other_global = nullptr;
+ if (ec.e->kind == Entity_Variable) {
+ other_global = LLVMGetNamedGlobal(ec.other_module->mod, ec.cname);
+ } else if (ec.e->kind == Entity_Procedure) {
+ other_global = LLVMGetNamedFunction(ec.other_module->mod, ec.cname);
+ }
+ if (other_global) {
+ LLVMSetLinkage(other_global, LLVMExternalLinkage);
+ }
+ }
}
+
gb_internal void lb_emit_init_context(lbProcedure *p, lbAddr addr) {
TEMPORARY_ALLOCATOR_GUARD();
@@ -1386,6 +1391,7 @@ gb_internal void lb_create_global_procedures_and_types(lbGenerator *gen, Checker
if (USE_SEPARATE_MODULES) {
m = lb_module_of_entity(gen, e);
}
+ GB_ASSERT(m != nullptr);
if (e->kind == Entity_Procedure) {
array_add(&m->global_procedures_to_create, e);
@@ -3431,18 +3437,7 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
lb_add_foreign_library_paths(gen);
TIME_SECTION("LLVM Correct Entity Linkage");
- for (lbEntityCorrection ec = {}; mpsc_dequeue(&gen->entities_to_correct_linkage, &ec); /**/) {
- LLVMValueRef other_global = nullptr;
- if (ec.e->kind == Entity_Variable) {
- other_global = LLVMGetNamedGlobal(ec.other_module->mod, ec.cname);
- } else if (ec.e->kind == Entity_Procedure) {
- other_global = LLVMGetNamedFunction(ec.other_module->mod, ec.cname);
- }
- if (other_global) {
- LLVMSetLinkage(other_global, LLVMExternalLinkage);
- }
- }
-
+ lb_correct_entity_linkage(gen);
////////////////////////////////////////////
for (auto const &entry: gen->modules) {