Understanding GCC Behaviour

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi everyone,
I'm a computer engineering student and recently I got interested in
understanding how compilers work, especially gcc.
I have a rather noobish question which made me busy during last week.
I basically want to understand what gcc is actually doing.
To be more precise, I want to know: when we do a function call,

   1. What happens to $esp, $ebp, etc.  and what are the things that are
   pushed to the stack?
   2. Where in the stack the function arguments are being pushed?
   3. How storing the local variables in the stack is being handled?

To be more specific, i wrote a code as an example, i would be very thankful
if you can tell me what will happen in the stack after running each line of
the code down bellow:

void func(int a, int b, int c){

        int x[4] = {5,5,5,5,5};

}

int main(){

        int a = 1;

        int b = 2;

        int c = 3;

        func(10,9,8);

        return 0;

}


I'm using gcc version 9.2.1 20191008 (Ubuntu 9.2.1-9ubuntu2) on a
x86_64-linux-gnu machine.
I would appreciate it if anyone can also point me in the right direction to
find out what happens when using other gcc versions or other architectures.
I'm lost around using gdb and other tools, but haven't got an answer yet.


Thanks, Pouria.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux