Got an interesting problem. I have a function void F() , that is, it does not accept any parameters. But in its assembly code this is the beginning:

 1: mov rax, rsp 2: mov qword ptr [rax+8], rbx 3: push rdi ... 

I am surprised at the second line. If we do not pass parameters, why does the function allow itself to overwrite the value of [rsp+8] . The address of [rsp] contains the return address, but then, after all, someone else’s stack frame, and this function overwrites the value. Further, because of this, I get an error. Why is there such a team and what can be done?

I will add that this is an educational task and within its framework I form a stack manually (I write down return addresses, function parameters, etc.). In the Debug version, everything is fine, in Release, here in this place the value I need is overwritten.

  • You would have given the C-code of this function a full asm start. maybe this is your own operation, you are doing something with a stack - Mike
  • @Mike this function is written entirely in C ++, I don’t directly work with the stack in it, that is, I couldn’t spoil anything. - Alexey Sarovsky Nov.
  • I did not quite understand something. This first line of code you cited is the very beginning of the function. There were no more instructions, some enter, for example. It's just that this is absolutely not similar to the standard start that generates compilers for functions - Mike
  • @Mike this is really done by the compiler - Alexey Sarovsky
  • one
    The assembly source code is better to squeeze out from the compiler. For gcc this is the -S switch. - PinkTux

0