Why move rcx to the shadow store

  64-bit, assembly, c++

Viewing the disassembly of C++ code running on a 64 bit windows PC, I see what appears to be the compiler moving the first argument to the shadow store.

void someMethod(uint32_t* someInt)
mov qword ptr [rsp+8], rcx

From what I understand, 4 register’s worth of space is stored before the stack root, and this space is called the shadow store. The documentation from Microsoft says the first 4 argument registers can be dumped there if need be, however, I can’t find any explanation on why it’d ever be necessary.
As far as I can tell, you can access the data via rcx just fine, and moving its value to the shadow store just takes up a register’s worth of space that could be used for something else.

If I had to guess, I’d say that maybe this has something to do with cache lines, and that maybe if the method were very long, the compiler wouldn’t make this mov.

Hopefully someone out there has a definitive answer.

Source: Windows Questions C++

LEAVE A COMMENT