From b0aeaed635a01b041dbc4cb0707545a6e18dbdce Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Mon, 17 Sep 2018 15:13:11 +0200 Subject: [PATCH] compiler: allow a global to be defined multiple times This is only possible when using compiler directives like the magic _extern_ prefix on global variables. --- compiler.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler.go b/compiler.go index 5f7cae86..12a35237 100644 --- a/compiler.go +++ b/compiler.go @@ -270,7 +270,10 @@ func (c *Compiler) Parse(mainPath string, buildTags []string) error { if err != nil { return err } - global := llvm.AddGlobal(c.mod, llvmType, g.LinkName()) + global := c.mod.NamedGlobal(g.LinkName()) + if global.IsNil() { + global = llvm.AddGlobal(c.mod, llvmType, g.LinkName()) + } g.llvmGlobal = global if !g.IsExtern() { global.SetLinkage(llvm.InternalLinkage)