From 0463d348875f6ca4588115baabdc020ebbc3e775 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Mon, 6 Mar 2023 01:41:52 +0100 Subject: [PATCH] compiler: emit correct alignment in debug info for global variables Previously we were using a really weird calculation to determine the alignment in bits - written by me (no idea what I was thinking at the time, it's obviously incorrect). Just replace it with the much more obviously correct multiplication by 8 to get bits from bytes. Found while working on properly dealing with alignment in `-size=full`. --- compiler/symbol.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/symbol.go b/compiler/symbol.go index 87e7b1ed..67012b14 100644 --- a/compiler/symbol.go +++ b/compiler/symbol.go @@ -433,7 +433,6 @@ func (c *compilerContext) getGlobal(g *ssa.Global) llvm.Value { llvmGlobal = llvm.AddGlobal(c.mod, llvmType, info.linkName) // Set alignment from the //go:align comment. - var alignInBits uint32 alignment := c.targetData.ABITypeAlignment(llvmType) if info.align > alignment { alignment = info.align @@ -444,7 +443,6 @@ func (c *compilerContext) getGlobal(g *ssa.Global) llvm.Value { c.addError(g.Pos(), "global variable alignment must be a positive power of two") } else { // Set the alignment only when it is a power of two. - alignInBits = uint32(alignment) ^ uint32(alignment-1) llvmGlobal.SetAlignment(alignment) } @@ -459,7 +457,7 @@ func (c *compilerContext) getGlobal(g *ssa.Global) llvm.Value { Type: c.getDIType(typ), LocalToUnit: false, Expr: c.dibuilder.CreateExpression(nil), - AlignInBits: alignInBits, + AlignInBits: uint32(alignment) * 8, }) llvmGlobal.AddMetadata(0, diglobal) }