Open johabu opened 5 years ago
No, it’s correct as-is. If it were “maximum” we would have to use 16-byte stack slots for every 1-byte char passed on the stack.
On Fri, Oct 25, 2019 at 2:09 AM Johannes Bucher notifications@github.com wrote:
In the integer calling convention the stack alignment is specified as follows:
Aggregates or scalars passed on the stack are aligned to the minimum of the object alignment and the stack alignment.
I suppose that arguments should be aligned to the maximum of the object alignment and the stack alignment.
Am I wrong or is this an error in the calling convention specification?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/riscv/riscv-elf-psabi-doc/issues/120?email_source=notifications&email_token=AAH3XQSEUVEJKAA6HWBH4W3QQKZUFA5CNFSM4JFAVE52YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HUKR2ZQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH3XQTPETF5DRYGZN55DS3QQKZUFANCNFSM4JFAVE5Q .
I falsely assumed that "stack alignment" in this case refers to parameter stack slots of size XLEN, not the 16-byte stack alignment.
However, using "minimum" implies that the alignment for 1-byte char arguments passed on the stack is 1 byte. Multiple arguments of type char would then be placed at 0(sp)
, 1(sp)
, 2(sp)
, etc. Is this the intended behavior? A quick look at assembly code emitted by gcc shows that at least gcc puts them at 0(sp)
, 4(sp)
, 8(sp)
, etc., indicating a 4-byte alignment.
I forgot that the stack slots are rounded up to the word size. What I meant to say is that they aren't rounded up to the 16-byte stack alignment. So it's probably more accurate to say min(stack alignment, max(type alignment, XLEN)) or something like that.
Ok, thanks for the clarification. This is how I initially understood the calling convention, but after reading the specification again I wasn't really sure anymore because the stack slots being rounded up to the word size is not explicitly mentioned. Maybe that paragraph should be reworded to be clear.
In the integer calling convention the stack alignment is specified as follows:
I suppose that arguments should be aligned to the maximum of the object alignment and the stack alignment.
Am I wrong or is this an error in the calling convention specification?