Re: Getting the lr register in a C subroutine
- From: joseluismarchetti@xxxxxxxxxxxx
- Date: 30 Jun 2005 08:46:43 -0700
Wilco Dijkstra wrote:
> <joseluismarchetti@xxxxxxxxxxxx> wrote in message
> news:1120106856.718408.36300@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> > Hello,
> >
> > I am trying to create a C function that will get the lr ( return
> > address ), but I am having a undesired warning from the ads compiler
> > saying that I am corrupting r14 ( lr ).
> > I saw the assembler code that was generated and did not see any
> > corruption.
> > In short what I am trying to do is:
> >
> > int GetCallerAddress( void )
> > {
> > int caller_address;
> >
> > __asm( mov caller_address, lr );
> >
> > return(caller_address);
> > }
> >
> > Does anybody knows a good C way ( not assembler ) to do that and
> > not receiving warnings ?
>
> No, you can't do this in ADS without assembler.
That is the answer I was looking for.
>
> What exactly makes you think the return address is always stored in LR?
> The compiler can place the return address whereever it wants, including
> in a different register than LR or anywhere on the stack. It may corrupt
> LR by making a function call (to push registers, do a stackcheck or similar),
> or use it to store a argument. It may change its mind and move the return
> address from one place to another (this typically happens with shrinkwrapping).
> Since LR may be corrupted or reused on function entry, it is wrong to think
> that LR still contains the return address on the first statement of a function.
>
I will tell you what makes me think this:
The routine I would create is a controled one and all it will do is get
the lr,
so the things you are talking should not happens there, actually I put
an example
of that routine:
int GetCallerAddress( void )
{
int caller_address;
__asm( mov caller_address, lr );
return(caller_address);
}
The assembler code that was generated was perfect and none of the cases
you talk
about happens here, the only problem is the warning message, that to me
does
not make sense because lr is not corrupted in this routine as the
warning message
indicates. The compiler is not smart enough to realize that and just
send out
the warning message as soon lr is in the inline assembler. Another
thing, if I
change lr to r0, the compiler send not warning message out ...
>
> In ADS you simply can't do it - the warning is telling you that you're reading
> a register that the compiler believes isn't valid - you may be lucky sometimes,
> but given the above, do you feel lucky in all cases?
As stated before, it will be a controlled routine.
> It's best to use a small
> assembler function for this - since you don't need to do this often, the overhead
> is minimal.
I thought about that and that is probably what I will do.
> In RVCT there is an intrinsic __return_address() which will go off
> and fetch the return address for you, no matter where it lives.
>
What is RVCT ? __return_address() sounds great, I hope we could have it
here.
> Wilco
Thanks!
.
- Follow-Ups:
- Re: Getting the lr register in a C subroutine
- From: Wilco Dijkstra
- Re: Getting the lr register in a C subroutine
- References:
- Getting the lr register in a C subroutine
- From: joseluismarchetti
- Re: Getting the lr register in a C subroutine
- From: Wilco Dijkstra
- Getting the lr register in a C subroutine
- Prev by Date: Re: help regarding uclinux
- Next by Date: assembly optimization on ARM /(armv5tde xscale).
- Previous by thread: Re: Getting the lr register in a C subroutine
- Next by thread: Re: Getting the lr register in a C subroutine
- Index(es):
Relevant Pages
|