From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id D15543858402 for ; Fri, 1 Mar 2024 09:29:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D15543858402 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D15543858402 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::633 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709285388; cv=none; b=gd+bhzQtffZnyyspvKYSQgSBpvV46nqhZXTEM0H+uziVy48BtZOTu7ZOg6dSj+U9w0rxm0NMFeIZew2FiRhRCPjtORWIzFSrUvFKme/6Aw2agVv3zVgyKcG4idlauUMJzmIuuHQzi7ObX/r1VsRmK1xxC2cAEoao+lzvw7pWftk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709285388; c=relaxed/simple; bh=EGl9AJ1TOOATvaCgOnKFd/rozNxY6hsmm6ijbtLMABI=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=XJSg08ClLzLuuarVlM4w+A3vwkO0mObfhk78FoDO+qXSKOwqS7gE+q9RfirvyrobjpzmyW2gsXN2rSQOR+QWVL6iC9W1v3Ym9Jz+/b71+ld9YTh9w6iGz9X7VWqiN/BqmC1K3EbQUhm1KyyoufMsYQgq/YB1sdQrKekhlidBvn8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a44665605f3so159657266b.2 for ; Fri, 01 Mar 2024 01:29:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709285382; x=1709890182; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=f401zihUhRpWUM6qm5u2lxSspg5Ohahvqzk2j9LIkRw=; b=gqX2/DWy5Wr+IRbE3EFL6YxUS02I6UuekdJU8cytcOtosPp/l56aN7akSMh7MRY+jB ca/XK5/xK0Gj63Hfzv19G/Uh/wD7NjZh184QnFGlSyrdq2r5eRVmOFJIB0EAvPTSjEY3 3Sd2wZN/+5GkOyZoSOqgCzaNidNSEwtIUiS0s9XXKesz+mbbT+kYxrhyTBaBnX17AWv+ XI6M/Ks5HdZ/ZICoChF6cuaZg2BSkWIa5/GCI78QoFx8OTjncRn2d4yxKly6EmgptppF 222/BVxtjUZf4E5Mmltak++HfScKOrkQVV2frtqrUCJEKgIoHW4DL6tOf6RwhD/T7z+8 FruA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709285382; x=1709890182; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=f401zihUhRpWUM6qm5u2lxSspg5Ohahvqzk2j9LIkRw=; b=TgLwne2yw2T8AjrebdUYIcFduCHctJktcNIVMFtbGSeY6+iunrRLExbjo89WU9b9eY MlGb4npmMmkCDtUrkiz/YCblFzD9NUsAhRpmFBkuXEn+w+lMHyg2M8opWLcpWn7U/f0K IHyIk62/+eB8ZiF6kzgzfBLFo9rec9X8gbAsfGs4PLvEiE9Esn7lMTJqqy5wpzE9o7j9 i8S/y3iQ7A48GSs+K00HIAiljmSA0Z0TnzmPCq6qTqb4cVXsW1rXkSWTQ/CK5Bug6HrN k5roNWZog/BEVOP8m6ljuDvTYdZwTF6EK4lA5xQ4O3YvuPalyjT+nHC5dItuwDYlVkVL iKWw== X-Gm-Message-State: AOJu0YzxAsXRJn+SOQJMJQPw1iaJcwKv2AblKoJiKCXkomCE9sqPXFMP wHsiiYrc0fajIw8NO0bXqN9FF/bo190I+mWTDztKOjyxUzCBtla01M0G2azeHIspjQTsn0tWAwM lm2DKtvOMN39OYiALZIJpbCOHq9I= X-Google-Smtp-Source: AGHT+IHske7Yr32qw+kw/imHXqSN2lnRQ7MXmKHXcGMmuIMdGsmTv9NtxAU8LrIq09IZJk+dIHK1V+0pUHcbJ7tfpwc= X-Received: by 2002:a17:906:5a97:b0:a3e:e3a9:57e5 with SMTP id l23-20020a1709065a9700b00a3ee3a957e5mr794554ejq.58.1709285382421; Fri, 01 Mar 2024 01:29:42 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Fri, 1 Mar 2024 09:29:31 +0000 Message-ID: Subject: Re: Understanding GCC Behaviour To: Pouria Khajepour Cc: gcc-help@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, 1 Mar 2024 at 08:41, Pouria Khajepour via Gcc-help 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.