diff --git a/ast.go b/ast.go index 99aeaee..d194c9b 100644 --- a/ast.go +++ b/ast.go @@ -223,8 +223,7 @@ type Global struct { func NewGlobal(sym operand.Symbol) *Global { return &Global{ - Symbol: sym, - Attributes: RODATA, + Symbol: sym, } } diff --git a/build/context.go b/build/context.go index 75a11b7..50aa33a 100644 --- a/build/context.go +++ b/build/context.go @@ -107,6 +107,10 @@ func (c *Context) StaticGlobal(name string) operand.Mem { return c.global.Base() } +func (c *Context) DataAttributes(a avo.Attribute) { + c.activeglobal().Attributes = a +} + func (c *Context) AddDatum(offset int, v operand.Constant) { if err := c.activeglobal().AddDatum(avo.NewDatum(offset, v)); err != nil { c.AddError(err) diff --git a/build/global.go b/build/global.go index 03e8847..b0491fe 100644 --- a/build/global.go +++ b/build/global.go @@ -24,8 +24,10 @@ func TEXT(name, signature string) { func LABEL(name string) { ctx.Label(avo.Label(name)) } -func GLOBL(name string) operand.Mem { - return ctx.StaticGlobal(name) +func GLOBL(name string, a avo.Attribute) operand.Mem { + g := ctx.StaticGlobal(name) + ctx.DataAttributes(a) + return g } func DATA(offset int, v operand.Constant) { diff --git a/build/pseudo.go b/build/pseudo.go index f394c40..0e1252f 100644 --- a/build/pseudo.go +++ b/build/pseudo.go @@ -1,6 +1,7 @@ package build import ( + "github.com/mmcloughlin/avo" "github.com/mmcloughlin/avo/operand" "github.com/mmcloughlin/avo/reg" @@ -46,6 +47,7 @@ func (c *Context) Store(src reg.Register, dst gotypes.Component) { func (c *Context) ConstData(name string, v operand.Constant) operand.Mem { g := c.StaticGlobal(name) + c.DataAttributes(avo.RODATA | avo.NOPTR) c.AppendDatum(v) return g } diff --git a/examples/data/asm.go b/examples/data/asm.go index 91ff81a..58e4ebe 100644 --- a/examples/data/asm.go +++ b/examples/data/asm.go @@ -5,12 +5,13 @@ package main import ( "math" + "github.com/mmcloughlin/avo" . "github.com/mmcloughlin/avo/build" . "github.com/mmcloughlin/avo/operand" ) func main() { - bytes := GLOBL("bytes") + bytes := GLOBL("bytes", avo.RODATA|avo.NOPTR) DATA(0, U64(0x0011223344556677)) DATA(8, String("strconst")) DATA(16, F32(math.Pi)) diff --git a/examples/data/data.s b/examples/data/data.s index 8962ddb..fb528c1 100644 --- a/examples/data/data.s +++ b/examples/data/data.s @@ -10,7 +10,7 @@ DATA bytes<>+32(SB)/4, $0x00112233 DATA bytes<>+36(SB)/2, $0x4455 DATA bytes<>+38(SB)/1, $0x66 DATA bytes<>+39(SB)/1, $0x77 -GLOBL bytes<>(SB), RODATA, $40 +GLOBL bytes<>(SB), RODATA|NOPTR, $40 // func DataAt(i int) byte TEXT ·DataAt(SB), $0-9 diff --git a/examples/geohash/geohash.s b/examples/geohash/geohash.s index dc62e25..494192e 100644 --- a/examples/geohash/geohash.s +++ b/examples/geohash/geohash.s @@ -22,13 +22,13 @@ TEXT ·EncodeInt(SB), $0-24 RET DATA reciprocal180<>(SB)/8, $(0.005555555555555556) -GLOBL reciprocal180<>(SB), RODATA, $8 +GLOBL reciprocal180<>(SB), RODATA|NOPTR, $8 DATA onepointfive<>(SB)/8, $(1.5) -GLOBL onepointfive<>(SB), RODATA, $8 +GLOBL onepointfive<>(SB), RODATA|NOPTR, $8 DATA reciprocal360<>(SB)/8, $(0.002777777777777778) -GLOBL reciprocal360<>(SB), RODATA, $8 +GLOBL reciprocal360<>(SB), RODATA|NOPTR, $8 DATA mask<>(SB)/8, $0x5555555555555555 -GLOBL mask<>(SB), RODATA, $8 +GLOBL mask<>(SB), RODATA|NOPTR, $8 diff --git a/examples/returns/returns.s b/examples/returns/returns.s index 515e013..fe48055 100644 --- a/examples/returns/returns.s +++ b/examples/returns/returns.s @@ -44,7 +44,7 @@ TEXT ·CriticalLine(SB), $0-24 RET DATA half<>(SB)/8, $(0.5) -GLOBL half<>(SB), RODATA, $8 +GLOBL half<>(SB), RODATA|NOPTR, $8 // func NewStruct(w uint16, p [2]float64, q uint64) Struct TEXT ·NewStruct(SB), $0-64