Ah, arm64. That code jesper points to looks like the culprit. The whole stack frame alignment should be handled separately from the alignment of individual variables, so the total alignment needed shouldn't matter.
Not sure why we do that. A small archaeology dive indicates this code dates from when the compiler was written in C. No indication of why it was added. I've opened an issue to look at this. https://github.com/golang/go/issues/42386 On Wednesday, November 4, 2020 at 5:51:03 AM UTC-8 jesper.lou...@gmail.com wrote: > On Wed, Nov 4, 2020 at 9:36 AM eric...@arm.com <eric...@arm.com> wrote: > >> I got it, the code is here >> https://github.com/golang/go/blob/633f9e206045176a12c301eb2c249c1c1d9a5d2e/src/cmd/compile/internal/gc/pgen.go#L186 >> , >> I don't know why the slot is required to be aligned at least 8 bytes on >> these architectures. I will try to see if this requirement can be removed >> on linux/arm64, >> and to determine the slot size based on the actual size of the variable, >> just like linux/amd64 does. >> >> > If my memory serves (and it is spotty, you should definitely look it up) > arm64 requires sp to be 16-byte aligned (or two times the word size to be > precise), and this is a hardware requirement if accessing memory. > > There might be other reasons to want aligned access pertaining to > atomicity guarantees and memory models. If the garbage collector assumes > certain things about memory access when it is doing its unspeakable things > to the stack, you may want it to have alignment to ensure certain > operations behave nicely. Tread carefully, my friend. > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/862cf03d-6d7e-47e5-b0c6-7eff89eba5cdn%40googlegroups.com.