At some places, I have read that stacks grow from a higher address to a lower address, but when I checked it out myself, I noticed that it grows from a lower to a higher address. For example, I allocated stack for a thread at address 2aba5ab06010 and at some point found out its value to be 2aba5b7050f0, which is clearly greater than the top of the stack.
But when I check the disassembly, I can see that function prologues subtract %rsp and epilogues add it, so in that sense, shouldn’t be the value of %rsp less than the top of the stack. Why these contradictory results?
Note that I am using Linux on an x86 64 bit machine and the gcc compiler.
The thread stack can grow upwards or downwards depending on the platform. A typically way to check this is let A call B function and with
now compare the address of localStackVariableB and FromFunctionA and determine the direction. Make sure the optimization is turned off completely.