This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: develop a 'customized ld'





From: Daniel Jacobowitz <drow@false.org>
To: seanatpurdue@hotmail.com, binutils@sourceware.org,Simon.Richter@hogyros.de
Subject: Re: develop a 'customized ld'
Date: Sat, 10 Sep 2005 13:43:02 -0400


On Sat, Sep 10, 2005 at 10:19:47AM -0700, Ian Lance Taylor wrote:
> Simon Richter <Simon.Richter@hogyros.de> writes:
>
> > sean yang wrote:
> >
> > > For example, I want to find the program counter(i.e., the address of the
> > > instruction) of "call '@foo'" instruction at link time.
> >
> > This can be done for assembler code, but obvoisly not for C code as
> > there is no way to make sure the C compiler will always use the same
> > instructions. Just declare an assembler label in front of the
> > instruction of which you want to take the address.
>
> You can use a gcc extension creatively to approximate this:
>
> void foo ()
> {
> lab:
> printf ("%p\n", &&lab);
> }


But be careful with it - recent versions of GCC are pretty bad about
preserving the addresses of labels not used for control flow.  I assume
Ian's example will be OK, but if you don't have a computed goto which
might target the label, GCC may just put it somewhere else...
Thanks to both of you. This is one conern, the other is I really don't want to have extra intruction--if the programming load for modification the binutils is not too heavy. Perticularly, I don't want to have printf() in the final code. Could u give some more suggestion on this?

Thanks again,
Sean


-- Daniel Jacobowitz CodeSourcery, LLC

_________________________________________________________________
Don?t just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]