This is the mail archive of the crossgcc@sourceware.cygnus.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more infromation.


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

Re: register-relative data section accesses?


Mark:

Indeed they do, at least for the m68k target (which I just built gcc for a few
moments ago):

*****
extern int foo_data;
extern void foo_function( void );

int foo( void )
{
        foo_function();
        return foo_data;
}

*****

        .file   "test.c"
gcc2_compiled.:
__gnu_compiled_c:
.text
        .even
.globl foo
foo:
        link.w %a6,#0
        move.l %a5,-(%sp)
        lea (%pc, _GLOBAL_OFFSET_TABLE_@GOTPC), %a5
        bsr foo_function@PLTPC
        move.l foo_data@GOT.w(%a5),%d0
        move.l %d0,%a0
        move.l (%a0),%d1
        move.l %d1,%d0
        jbra .L2
        .even
.L2:
        move.l -4(%a6),%a5
        unlk %a6
        rts

*****

You get something very similar for the x86 targets.

This is kind of the do-it-yourself approach, as it appears that you have to supply
the GLOBAL_OFFSET_TABLE, foo_function@PLTPC, and foo_data@GOT symbols yourself.
Maybe the linker helps out here-- I don't know yet.

Can anyone comment on this, or point me to a FAQ?

Curiously, the assembly code for the SH-2 target (my current platform) is unaffected
by the -fpic and -fPIC flags.  I don't know whether it's  because I don't understand
all the opcode subtleties, or because this flag isn't supported (I suspect the
latter, unfortunately).

I looked at the SH-2 code before I made my original posting on this subject.  If
I had looked at m68k code first, I would have asked a slightly different question...
:^)

b.g.


Mark Phillips wrote:

> Did you try -fpic or -fPIC?
>
> They normally enable Position Independent Code, which may work out to be
> roughly what you want?
>
> Cheers
> Mark
>
> On Thu, 9 Sep 1999, William Gatliff wrote:
>
> > Oops!
> >
> > Note that foo_data is a global variable...
> >
> > b.g.
> >
> > William Gatliff wrote:
> >
> > > Guys:
> > >
> > > I have a need for register-relative data access, i.e. the data
> > > equivalent to PC-relative code addressing.
> > >
> > > I don't see right offhand the gcc switches to do this, although it seems
> > > like something that GNU would support...
> > >
> > > For example, when I do this:
> > >
> > >         return foo_data;
> > >
> > > then, rather than this:
> > >
> > >         mov.l  _foo_data, d0
> > >
> > > I need this:
> > >
> > >         mov.l  12(a4), d0
> > >
> > > [Note that I'm a bit rusty on my 68k asm.  I hope my intent is at least
> > > clear, tho'.]
> > >
> > > Any ideas?  I know the MRI 68k compiler can do this...
> > >
> > > Thanks!
> > >
> > > b.g.
> > >
> > > --
> > > William A. Gatliff
> > > Senior Design Engineer
> > > Komatsu Mining Systems
> > > To teach is to learn.
> > >
> > > ------
> > > Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
> > > Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com
> >
> > --
> > William A. Gatliff
> > Senior Design Engineer
> > Komatsu Mining Systems
> > To teach is to learn.
> >
> >
> >
> >
> > ------
> > Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
> > Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com
> >
>
> --
> Mark S. Phillips                ESN 742 2461
> msp@nortelnetwork.co.uk         Tel. +44 1279 402461

--
William A. Gatliff
Senior Design Engineer
Komatsu Mining Systems
To teach is to learn.




------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com


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