1
0
mirror of https://github.com/golang/go synced 2024-09-29 18:24:29 -06:00

runtime/internal/atomic: align 64-bit types to 8 bytes everywhere

This change extends https://go.dev/cl/381317 to the
runtime/internal/atomic package in terms of aligning 64-bit types to 8
bytes, even on 32-bit platforms.

Change-Id: Id8c45577d07b256e3144d88b31f201264295cfcd
Reviewed-on: https://go-review.googlesource.com/c/go/+/404096
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
Michael Anthony Knyszek 2022-05-04 19:48:29 +00:00 committed by Michael Knyszek
parent 2eb8b6eec6
commit 0f715f1ac9
2 changed files with 18 additions and 4 deletions

View File

@ -169,7 +169,7 @@ func calcStructOffset(errtype *Type, t *Type, o int64, flag int) int64 {
}
// Special case: sync/atomic.align64 is an empty struct we recognize
// as a signal that the struct it contains must be 64-bit-aligned.
if isStruct && t.NumFields() == 0 && t.Sym() != nil && t.Sym().Name == "align64" && isSyncAtomic(t.Sym().Pkg) {
if isStruct && t.NumFields() == 0 && t.Sym() != nil && t.Sym().Name == "align64" && isAtomicStdPkg(t.Sym().Pkg) {
maxalign = 8
}
lastzero := int64(0)
@ -231,8 +231,9 @@ func calcStructOffset(errtype *Type, t *Type, o int64, flag int) int64 {
return o
}
func isSyncAtomic(p *Pkg) bool {
return p.Prefix == "sync/atomic" || p.Prefix == `""` && base.Ctxt.Pkgpath == "sync/atomic"
func isAtomicStdPkg(p *Pkg) bool {
return (p.Prefix == "sync/atomic" || p.Prefix == `""` && base.Ctxt.Pkgpath == "sync/atomic") ||
(p.Prefix == "runtime/internal/atomic" || p.Prefix == `""` && base.Ctxt.Pkgpath == "runtime/internal/atomic")
}
// CalcSize calculates and stores the size and alignment for t.

View File

@ -49,9 +49,12 @@ func (i *Int32) Add(delta int32) int32 {
// Int64 is an atomically accessed int64 value.
//
// 8-byte aligned on all platforms, unlike a regular int64.
//
// An Int64 must not be copied.
type Int64 struct {
noCopy noCopy
_ align64
value int64
}
@ -242,9 +245,12 @@ func (u *Uint32) Add(delta int32) uint32 {
// Uint64 is an atomically accessed uint64 value.
//
// 8-byte aligned on all platforms, unlike a regular uint64.
//
// A Uint64 must not be copied.
type Uint64 struct {
noCopy noCopy
_ align64
value uint64
}
@ -346,9 +352,11 @@ func (u *Uintptr) Add(delta uintptr) uintptr {
// Float64 is an atomically accessed float64 value.
//
// 8-byte aligned on all platforms, unlike a regular float64.
//
// A Float64 must not be copied.
type Float64 struct {
// Inherits noCopy from Uint64.
// Inherits noCopy and align64 from Uint64.
u Uint64
}
@ -416,3 +424,8 @@ type noCopy struct{}
// Lock is a no-op used by -copylocks checker from `go vet`.
func (*noCopy) Lock() {}
func (*noCopy) Unlock() {}
// align64 may be added to structs that must be 64-bit aligned.
// This struct is recognized by a special case in the compiler
// and will not work if copied to any other package.
type align64 struct{}