From bfff0c33e42ab4a51e34f3eed0def60b18afe277 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 2 Sep 2018 18:10:01 +0200 Subject: [PATCH] Fix external globals This broke the allocator on ARM, and with that the blinky example. --- arm.ld | 1 - compiler.go | 5 ++++- ir.go | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/arm.ld b/arm.ld index ad3ab1ad..76a64f1f 100644 --- a/arm.ld +++ b/arm.ld @@ -80,4 +80,3 @@ __bss_end__ = _ebss; /* For the memory allocator. */ _heap_start = _ebss; _heap_end = ORIGIN(RAM) + LENGTH(RAM); -runtime.heapptr = _heap_start; /* necessary? */ diff --git a/compiler.go b/compiler.go index dd73dfe4..b6999f74 100644 --- a/compiler.go +++ b/compiler.go @@ -252,7 +252,7 @@ func (c *Compiler) Parse(mainPath string, buildTags []string) error { } global := llvm.AddGlobal(c.mod, llvmType, g.LinkName()) g.llvmGlobal = global - if !strings.HasPrefix(g.LinkName(), "_extern_") { + if !g.IsExtern() { global.SetLinkage(llvm.InternalLinkage) initializer, err := getZeroValue(llvmType) if err != nil { @@ -745,6 +745,9 @@ func (c *Compiler) initMapNewBucket(mapType *types.Map) (llvm.Value, uint64, uin } func (c *Compiler) parseGlobalInitializer(g *Global) error { + if g.IsExtern() { + return nil + } llvmValue, err := c.getInterpretedValue(g.initializer) if err != nil { return err diff --git a/ir.go b/ir.go index 7f5212bf..7a405247 100644 --- a/ir.go +++ b/ir.go @@ -220,3 +220,7 @@ func (g *Global) LinkName() string { return g.g.RelString(nil) } } + +func (g *Global) IsExtern() bool { + return strings.HasPrefix(g.g.Name(), "_extern_") +}