aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-08-25 04:50:51 -0400
committerGitHub <noreply@github.com>2018-08-25 04:50:51 -0400
commit4003cd4747019d79ff50aaa22415d2d3dfc15cf4 (patch)
tree1f77690a5fb7ccbef75bcab9c8c1e008ef3c5068 /src/codegen.cpp
parentbf1f91595d4d3b5911632c671ef16e44d70dc9a6 (diff)
parent815950996dcc92ac6ac285f2005dbac51b9cb6f8 (diff)
downloadzig-4003cd4747019d79ff50aaa22415d2d3dfc15cf4.tar.gz
zig-4003cd4747019d79ff50aaa22415d2d3dfc15cf4.zip
Merge pull request #1406 from ziglang/macos-stack-traces
MacOS stack traces closes #1365
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index e926d14a7e..7ea322c1c3 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -5812,12 +5812,16 @@ static void do_code_gen(CodeGen *g) {
LLVMValueRef global_value;
if (var->linkage == VarLinkageExternal) {
- global_value = LLVMAddGlobal(g->module, var->value->type->type_ref, buf_ptr(&var->name));
-
- // TODO debug info for the extern variable
+ LLVMValueRef existing_llvm_var = LLVMGetNamedGlobal(g->module, buf_ptr(&var->name));
+ if (existing_llvm_var) {
+ global_value = LLVMConstBitCast(existing_llvm_var, LLVMPointerType(var->value->type->type_ref, 0));
+ } else {
+ global_value = LLVMAddGlobal(g->module, var->value->type->type_ref, buf_ptr(&var->name));
+ // TODO debug info for the extern variable
- LLVMSetLinkage(global_value, LLVMExternalLinkage);
- LLVMSetAlignment(global_value, var->align_bytes);
+ LLVMSetLinkage(global_value, LLVMExternalLinkage);
+ LLVMSetAlignment(global_value, var->align_bytes);
+ }
} else {
bool exported = (var->linkage == VarLinkageExport);
const char *mangled_name = buf_ptr(get_mangled_name(g, &var->name, exported));