%pc relative addressing of string literals/const data

Joakim Tjernlund joakim.tjernlund@transmode.se
Thu Oct 7 14:53:00 GMT 2010


Michael Meissner <meissner@linux.vnet.ibm.com> wrote on 2010/10/07 15:00:25:
>
> On Tue, Oct 05, 2010 at 11:56:55AM -0700, Richard Henderson wrote:
> > On 10/05/2010 06:54 AM, Joakim Tjernlund wrote:
> > > Ian Lance Taylor <iant@google.com> wrote on 2010/10/05 15:47:38:
> > >> Joakim Tjernlund <joakim.tjernlund@transmode.se> writes:
> > >>> While doing relocation work on u-boot I often whish for strings/const data
> > >>> to be accessible through %pc relative address rather than and ABS address
> > >>> or through GOT. Has this feature ever been considered by gcc?
> > >>
> > >> The feature can only be supported on processors which are reasonably
> > >> able to support it.  So, what target are you asking about?
> > >
> > > In my case PowerPC but I think most arch's would want this feature.
> > > Is there arch's where this cannot be support at all or just within
> > > some limits? I think within limits could work for small apps
> > > like u-boot.
> >
> > PowerPC doesn't really have the relocations for pc-relative offsets
> > within code -- primarily because it doesn't have pc-relative insns
> > to match.  Nor, unfortunately, does it have got-relative relocations,
> > like some other targets.  These are normally how we get around not
> > having pc-relative relocations and avoiding tables in memory.  C.f.
>
> The new PowerPC medium code model for 64-bit now uses GOT-relative relocations
> for local data: The compiler issues (r2 has the TOC/GOT pointer):
>
>    addis <reg>,r2,label@toc@ha
>    addi <reg2>,<reg>,label@toc@l
>
> to load the address in <reg2>.  If the data happens to be within 32K of the TOC
> pointer, the linker will transform this to:
>
>    nop
>    addi <reg2>,r2,label@toc@l
>
> For non-local loads or the large code model, the compiler issues:
>
>    addis <reg>,r2,label@got@ha
>    ld <reg2>,label@got@l(<reg>)
>
> If the address happens to be defined in the current program unit (main program
> or shared librar), the linker can transform this to:
>
>    addis <reg>,r2,label@toc@ha
>    addi <reg2>,<reg>,labal@toc@l
>
> or:
>
>    nop
>    addi <reg2>,r2,labal@toc@l
>
> or:
>
>    nop
>    ld <reg2>,labal@got@l(r2)

Why not offer some of this on PowerPC32? mcmodel=small would probably be enough.

     Jocke



More information about the Gcc mailing list