aboutsummaryrefslogtreecommitdiffhomepage
path: root/compiler/interface.go
diff options
context:
space:
mode:
authorDamian Gryski <[email protected]>2023-03-09 07:49:57 -0800
committerRon Evans <[email protected]>2023-03-19 17:45:43 +0100
commit0d65b4dd26a3ac31c443e48d93f21145708c9a5e (patch)
tree6dba4d4a25321897063b8bd1ba289fc8fe93dca8 /compiler/interface.go
parent6a685b2a8d7e5c0432c9445196bee11caa01f160 (diff)
downloadtinygo-0d65b4dd26a3ac31c443e48d93f21145708c9a5e.tar.gz
tinygo-0d65b4dd26a3ac31c443e48d93f21145708c9a5e.zip
compiler: only define the package path once
Adding https://github.com/tinygo-org/tinygo/pull/3534 by hand to avoid conflicts when I rebase.
Diffstat (limited to 'compiler/interface.go')
-rw-r--r--compiler/interface.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/compiler/interface.go b/compiler/interface.go
index cbebec824..128844c00 100644
--- a/compiler/interface.go
+++ b/compiler/interface.go
@@ -90,13 +90,16 @@ func (c *compilerContext) pkgPathPtr(pkgpath string) llvm.Value {
pkgpathName = "reflect/types.type.pkgpath:" + pkgpath
}
- pkgpathInitializer := c.ctx.ConstString(pkgpath+"\x00", false)
- pkgpathGlobal := llvm.AddGlobal(c.mod, pkgpathInitializer.Type(), pkgpathName)
- pkgpathGlobal.SetInitializer(pkgpathInitializer)
- pkgpathGlobal.SetAlignment(1)
- pkgpathGlobal.SetUnnamedAddr(true)
- pkgpathGlobal.SetLinkage(llvm.LinkOnceODRLinkage)
- pkgpathGlobal.SetGlobalConstant(true)
+ pkgpathGlobal := c.mod.NamedGlobal(pkgpathName)
+ if pkgpathGlobal.IsNil() {
+ pkgpathInitializer := c.ctx.ConstString(pkgpath+"\x00", false)
+ pkgpathGlobal = llvm.AddGlobal(c.mod, pkgpathInitializer.Type(), pkgpathName)
+ pkgpathGlobal.SetInitializer(pkgpathInitializer)
+ pkgpathGlobal.SetAlignment(1)
+ pkgpathGlobal.SetUnnamedAddr(true)
+ pkgpathGlobal.SetLinkage(llvm.LinkOnceODRLinkage)
+ pkgpathGlobal.SetGlobalConstant(true)
+ }
pkgPathPtr := llvm.ConstGEP(pkgpathGlobal.GlobalValueType(), pkgpathGlobal, []llvm.Value{
llvm.ConstInt(c.ctx.Int32Type(), 0, false),
llvm.ConstInt(c.ctx.Int32Type(), 0, false),