GCC access memory above the top of the stack

I have a C function that does some SSE calculations. When I compile it with GCC, I get the following code

/* Start of function */
mov    (%rdi),%rax
movslq %ecx,%rcx
...
mov    0x8(%rdi),%rax
pxor   %xmm12,%xmm3
movaps %xmm0,-0x28(%rsp)
movaps %xmm6,%xmm1
...
movaps 0x50(%rax,%rcx,1),%xmm2
movaps 0x60(%rax,%rcx,1),%xmm15
pxor   %xmm2,%xmm0
pxor   %xmm2,%xmm6
movaps -0x28(%rsp),%xmm2
pxor   %xmm15,%xmm5
pxor   %xmm15,%xmm2
movaps 0x70(%rax,%rcx,1),%xmm15
movaps (%rax,%rcx,1),%xmm11
mov    0x10(%rdi),%rax
movaps %xmm15,-0x18(%rsp)
pxor   %xmm11,%xmm4
pxor   %xmm12,%xmm11
pxor   %xmm15,%xmm12

Look at the instructions movaps- this is accessing memory on top of the top stack:

movaps %xmm15,-0x18(%rsp)

Isn't that access to undefined memory? And why did GCC create such wrong code?

+4
source share
1 answer

At the assembly level, there is no such thing as "undefined memory". gcc freely emits code that accesses the stack in any way that it sees fit, as long as the behavior is as expected.

, , , , . , call. ( C, .)

ABI , x86-64. AMD64 ABI:

128- , % rsp . . , , . .

.

+5

All Articles