Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why "Procedure Call Standard for the ARM Architecture" (AAPCS) requires SP to be 8-byte aligned?

Since this is a recurring topic, I'm putting up a question about it.

According to AAPCS:

5.2.1.1 Universal stack constraints

  • SP mod 4 = 0. The stack must at all times be aligned to a word boundary

5.2.1.2 Stack constraints at a public interface

  • SP mod 8 = 0. The stack must be double-word aligned.

What is the rational behind 8-byte alignment?

like image 847
auselen Avatar asked Feb 12 '23 06:02

auselen


2 Answers

The main reason is that that STRD and LDRD can only work on 8byte aligned addresses. So, to use them on stack variables the stackpointer needs to be 8-byte aligned to all the time.

To quote the ARM Website:

Eight-byte stack alignment is of particular benefit to processors supporting LDRD and STRD instructions, for example, processors based on ARM architecture v5TE and later. If the stack is not eight-byte aligned the use of LDRD and STRD might cause an alignment fault, depending on the target and configuration used.

ARM also explains it in detail in this ABI Advisory Note.

like image 160
Nico Erfurth Avatar answered Mar 05 '23 17:03

Nico Erfurth


It's due to ldrd and strd.

They require double word alignments.

like image 33
Jake 'Alquimista' LEE Avatar answered Mar 05 '23 15:03

Jake 'Alquimista' LEE