public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Pouria Khajepour <poria.gm@gmail.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Understanding GCC Behaviour
Date: Fri, 1 Mar 2024 09:29:31 +0000	[thread overview]
Message-ID: <CAH6eHdTZO7TLWgSoqHzMZMsv+TqREAD60qBq8m4Y4-+AVa5h5g@mail.gmail.com> (raw)
In-Reply-To: <CA+NLcdQfg9dTDM0Wio9B=qDzyMsZufY2ZVnQiT+HZfGtcJLozQ@mail.gmail.com>

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

      reply	other threads:[~2024-03-01  9:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-01  8:39 Pouria Khajepour
2024-03-01  9:29 ` Jonathan Wakely [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAH6eHdTZO7TLWgSoqHzMZMsv+TqREAD60qBq8m4Y4-+AVa5h5g@mail.gmail.com \
    --to=jwakely.gcc@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=poria.gm@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).