%pc relative addressing of string literals/const data

Alan Modra amodra@gmail.com
Tue Oct 5 22:19:00 GMT 2010


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.

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Gcc mailing list