Yes, as Keith said, the 16-byte alignment requirement of sp is for the size 
of the entire stack, and there is no such requirement for a single variable 
on the stack. We can access a single variable through sp+/-offset.
The code has already dealt with the overall alignment of sp. I tried to 
remove the alignment requirement for a single variable on linux/arm64, and 
all the tests in all.bash passed. So I think this alignment requirement for 
a single variable is unnecessary on linux/arm64. In addition, I also 
checked the result generated by gcc. In the case of -O0, the alignment of a 
single variable on the stack is consistent with its own size.

在2020年11月5日星期四 UTC+8 上午8:21:34<Keith Randall> 写道:

> 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/6a52dee6-bf89-4365-ad95-96af119fc261n%40googlegroups.com.

Reply via email to