Understanding Stack Alignment

I am reading an Intel manual about Stack Frames. It was noted that

The end of the input argument area should be aligned at 16 (32 if __m256passed along the stack).

I do not quite understand what this means. Does this mean that it rspshould point to an address that is always aligned at 16?

I tried to experiment with it and wrote a very simple program:

section .text
    global _start

_start:
    push byte 0xFF

    ;SYS_exit syscall

I ran it with help gdband noted that before executing the command push rsp = 0x7fffffffdcf0. And he was really aligned at 16. x/1xg $rspback 0x0000000000000001.

Now after clicking the content has rspbecome 0x7fffffffdce8. Is this a violation of alignment requirements?

x/1xg $rsp 0xffffffffffffffff. , 1 8 , , push. ? x/1xg $rsp 0x00000000000000FF ( ).

+4
1

rsp at _start - , ABI, call, call 8B , , rsp -8 .

, , ABI ( C runtime lib, main, crtlib, _start).


rsp 0x7fffffffdce8. ?

, call , , , printf ( SSE ), , , segfault.


push byte 0xFF:

64b ( 16 32- ) ( byte , byte , , 16, 32 64 ), NASM ( , qword 64b ) imm8 .

BTW -w+all, NASM ( , , , ) :

warning: signed byte value exceeds bounds

, push word 0xFF , 0x00FF.


: , , , ABI ( 64b, , , push, push rbp).

, rsp ( rbp, ), and rsp,-16, .

, , ABI, call, -8B. push rbp , , rbp ( mov rbp, rsp "" ) .


: , ...

, 100% , NASM, , push , NASM ( , , , ).

push byte 0xFF, NASM byte " ", . byte push, NASM qword 64b. byte , - 0xFF qword. undefined. NASM, , , , NASM , , push word -1, "push word operand imm8". , , imm16 push strict word -1.

. , ( 64b) ( , , , " qword", imm32, imm64 ( op64 , )... , dword qword, 32b 64b):

 6 00000000 6AFF                            push    -1
 7 00000002 6AFF                            push    strict byte 0xFF
 8          ******************       warning: signed byte value exceeds bounds
 9 00000004 6AFF                            push    byte 0xFF
10          ******************       warning: signed byte value exceeds bounds
11 00000006 6AFF                            push    strict byte -1
12 00000008 6AFF                            push    byte -1
13 0000000A 6668FF00                        push    strict word 0xFF
14 0000000E 6668FF00                        push    word 0xFF
15 00000012 6668FFFF                        push    strict word -1
16 00000016 666AFF                          push    word -1
17 00000019 68FF000000                      push    strict dword 0xFF
18 0000001E 68FF000000                      push    dword 0xFF
19 00000023 68FFFFFFFF                      push    strict dword -1
20 00000028 6AFF                            push    dword -1
21 0000002A 68FF000000                      push    strict qword 0xFF
22 0000002F 68FF000000                      push    qword 0xFF
23 00000034 68FFFFFFFF                      push    strict qword -1
24 00000039 6AFF                            push    qword -1

, , , 64b, , qword push (rsp -= 8) , push -1 NASM imm8, , rsp -8, . , , , , byte .

, , NASM/bugzilla/-, . , " " ( , , , , ). , , . NASM imm16 imm8, .

+4

Source: https://habr.com/ru/post/1693359/


All Articles