aboutsummaryrefslogtreecommitdiffstats
path: root/prog/target.go
diff options
context:
space:
mode:
authorAlbert van der Linde <alinde@google.com>2020-07-14 07:47:26 +0000
committerDmitry Vyukov <dvyukov@google.com>2020-07-14 12:20:37 +0200
commit6f4580264a29fa73097e96b436141a8594b97610 (patch)
tree3e184241f624d90f04cffc9d546eee4e03099216 /prog/target.go
parent230553f68fcaa90508b724edd0dfc806669c1f22 (diff)
prog/alloc: align address allocation for aligned[addr]
Calls to alloc didn't respect the alignment attribute. Now Type.Alignment() is used to ensure each type is correctly aligned. Existing descriptions with [align[X]] don't have an issue as they align to small blocks and default align is to 64 bytes. This commits adds support for [align[X]] for an X larger than 64.
Diffstat (limited to 'prog/target.go')
-rw-r--r--prog/target.go8
1 files changed, 3 insertions, 5 deletions
diff --git a/prog/target.go b/prog/target.go
index 3dbad8a67..b090613be 100644
--- a/prog/target.go
+++ b/prog/target.go
@@ -305,14 +305,12 @@ func (pg *Builder) Append(c *Call) error {
return nil
}
-func (pg *Builder) Allocate(size uint64) uint64 {
- return pg.ma.alloc(nil, size)
+func (pg *Builder) Allocate(size, alignment uint64) uint64 {
+ return pg.ma.alloc(nil, size, alignment)
}
func (pg *Builder) AllocateVMA(npages uint64) uint64 {
- psize := pg.target.PageSize
- addr := pg.ma.alloc(nil, (npages+1)*psize)
- return (addr + psize - 1) & ^(psize - 1)
+ return pg.ma.alloc(nil, npages*pg.target.PageSize, pg.target.PageSize)
}
func (pg *Builder) Finalize() (*Prog, error) {