public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: John Fine <johnsfine@verizon.net>
To: gcc-help@gcc.gnu.org
Subject: Re: how --builtin--return--address() works??
Date: Mon, 15 Sep 2008 12:09:00 -0000	[thread overview]
Message-ID: <48CE5048.5060406@verizon.net> (raw)
In-Reply-To: <48CE2CE9.9040005@redhat.com>

I agree with Andrew's answer.  I just want to add a few details where I 
think it might have been misleading.

Andrew Haley wrote:
> RANJITH KUMAR KASUKURTHI wrote:
>
>   
>> 3) The location where that return address is stored on stack may vary 
>> depending upon  number  of arguments  passed to the function, or number of
>> local variables inside the function, or whether the function is returning
>> a value or not........
>>     
>
> Not usually, no.  On those machines that pass the return address on the stack,
> that address is on the top.
>   
 From the point of view of code running inside a function, the location 
of the return address typically does vary with the number of local 
variables.  It does not vary with the number of arguments.
>> How __builtin_return_address() function knows where exactly the return
>> address is stored on stack????
>>     
>
> The compiler knows where everything is: the return address is nothing
> special.
>
>   
Often the compiler can't know where "everything" (relevant to the 
current stack frame) is, because it often can't know how many arguments 
were passed.

But (as you indicated) it always knows where the return address is.  If 
it didn't, then it couldn't even generate correct code for the function 
to return.

Because of the flexibility the compiler has with register use, it 
typically would be impossible for a something like 
__builtin_return_address() to be fully defined by a header file.  The 
compiler can know all about the stack usage for saved registers and 
local variables, etc. so at any point in a function it knows where the 
return address is.  But code in a header file can't know that much.


      reply	other threads:[~2008-09-15 12:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-15  7:25 RANJITH KUMAR KASUKURTHI
2008-09-15  9:49 ` Andrew Haley
2008-09-15 12:09   ` John Fine [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=48CE5048.5060406@verizon.net \
    --to=johnsfine@verizon.net \
    --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).