This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: %pc relative addressing of string literals/const data
Alan Modra <amodra@gmail.com> wrote on 2010/10/06 00:19:26:
>
> On Tue, Oct 05, 2010 at 11:40:11PM +0200, Joakim Tjernlund wrote:
> > yes, but this could be a new PIC mode that uses a new better
> > PIC mode for everything. Especially one that doesn't require each function
> > to calculate the GOT address in the function prologue(why is that so?)
>
> The ppc32 ABI is old, much like x86. cf. x86 -O2 -fPIC (without
> hidden pragma).
>
> foo:
> call __i686.get_pc_thunk.cx
> addl $_GLOBAL_OFFSET_TABLE_, %ecx
> pushl %ebp
> movl %esp, %ebp
> popl %ebp
> movl y@GOT(%ecx), %eax
> movl x@GOT(%ecx), %edx
> movl (%eax), %eax
> addl (%edx), %eax
> ret
> [snip]
> __i686.get_pc_thunk.cx:
> movl (%esp), %ecx
> ret
>
> The new ppc64 -mcmodel=medium support does give you pic access to
> locals.
>
> -fPIC -O2 without hidden
> .LC0:
> .tc x[TC],x <-- compiler managed GOT entries
> .LC1:
> .tc y[TC],y
> [snip]
> .L.foo:
> addis 11,2,.LC0@toc@ha
> addis 9,2,.LC1@toc@ha
> ld 11,.LC0@toc@l(11)
> ld 9,.LC1@toc@l(9)
> lwz 3,0(11)
> lwz 0,0(9)
> add 3,3,0
> extsw 3,3
> blr
>
> -fPIC -O2 with hidden pragma
> .L.foo:
> addis 11,2,x@toc@ha
> addis 9,2,y@toc@ha
> lwz 3,x@toc@l(11) <-- TOC/GOT pointer relative
> lwz 0,y@toc@l(9)
> add 3,3,0
> extsw 3,3
> blr
>
> x@toc is equivalent to @GOTOFF on other processors.
Now I have had a closer look at this and it looks much like -fpic
on ppc32, you still use the GOT/TOC to load the address where the data is.
I was looking for true %pc relative addressing of data. I guess this is really
hard on PowerPC?
I have hacked -fpic support for -mrelocatable too:
>From d8ff0b3f0b44480542eab04d1659f4368b6b09cf Mon Sep 17 00:00:00 2001
From: Joakim Tjernlund <Joakim.Tjernlund@transmode.se>
Date: Sun, 10 Oct 2010 10:34:50 +0200
Subject: [PATCH] powerpc: Support -fpic too with mrelocatable
Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se>
---
sysv4.h | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h
index 8da8410..e4b8280 100644
--- a/gcc/config/rs6000/sysv4.h
+++ b/gcc/config/rs6000/sysv4.h
@@ -227,7 +227,8 @@ do { \
} \
\
else if (TARGET_RELOCATABLE) \
- flag_pic = 2; \
+ if (!flag_pic) \
+ flag_pic = 2; \
} while (0)
#ifndef RS6000_BI_ARCH
--
1.7.2.2
I am not sure this is all it takes to make -fpic to work with -mrelocatable,
any ideas?
Jocke