Re: Understanding GCC Behaviour

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

 



On Fri, 1 Mar 2024 at 08:41, Pouria Khajepour via Gcc-help
<gcc-help@xxxxxxxxxxx> wrote:
>
> 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?

GCC doesn't get to choose this, it has to follow the target platform's
ABI so that code compiled by GCC can interoperate with code compiled
by other compilers on the same platform.

See https://wiki.osdev.org/System_V_ABI for an intro to the topic, and
links to the psABI for x86.


>    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