public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Amittai Aviram <amittai.aviram@yale.edu>
To: gcc-help@gcc.gnu.org
Subject: x86_64 calling conventions and stack frames
Date: Sat, 24 Dec 2011 11:02:00 -0000	[thread overview]
Message-ID: <BDAB5D55-0242-4044-8589-72BE25E2E7B7@yale.edu> (raw)

I am trying to make sense out of the executable code that GCC (4.4.3) is generating for an x86_64 machine running under Ubuntu Linux.  In particular, I don't understand how the code keeps track of stack frames.  In the old days, in 32-bit code, I am accustomed to seeing this as a "prologue" in just about every function:

push %ebp
movl %esp, %ebp

Then, at the end of the function, there would either be 

sub $xx, %esp   # Where xx is a number based on GCC's accounting.
pop %ebp
ret

or simply

leave
ret

which accomplishes the same thing:
- Set the Stack Pointer to the top of the current frame, just below the return address
- Restore the old Frame Pointer value.

In 64-bit code, as I see it through an objdump disassembly, many functions do not follow this convention--they do not push %rbp and then save %rsp to %rbp, How does a debugger like GDB build a backtrace?

My real goal here to is to try to figure out a reasonable address to consider as the top (highest address) of the user stack when execution reaches the start of a function further into the program, where perhaps the Stack Pointer has moved down.  I had at first thought that I could use the old backtrace method: chasing saved Frame Pointer values until the value saved is 0--then, the next one after that can count as the highest practical value.  Now, I don't know how to get the equivalent address in 64-bit code.

Thanks.


Amittai Aviram
PhD Student in Computer Science
Yale University
646 483 2639
amittai.aviram@yale.edu
http://www.amittai.com

             reply	other threads:[~2011-12-24  7:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-24 11:02 Amittai Aviram [this message]
2011-12-24 19:10 ` Bob Plantz
2011-12-25  0:50   ` Amittai Aviram
2011-12-25 21:31     ` Amittai Aviram
2011-12-27 15:16 ` Ian Lance Taylor

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=BDAB5D55-0242-4044-8589-72BE25E2E7B7@yale.edu \
    --to=amittai.aviram@yale.edu \
    --cc=gcc-help@gcc.gnu.org \
    /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).