From 0d65b4dd26a3ac31c443e48d93f21145708c9a5e Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Thu, 9 Mar 2023 07:49:57 -0800 Subject: [PATCH] compiler: only define the package path once Adding https://github.com/tinygo-org/tinygo/pull/3534 by hand to avoid conflicts when I rebase. --- compiler/interface.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/compiler/interface.go b/compiler/interface.go index cbebec82..128844c0 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),