[PATCH] powerpc: Work around gcc miscompilation of __pa() on 64-bit

Alan Modra amodra at gmail.com
Tue Aug 27 17:12:35 EST 2013


On Tue, Aug 27, 2013 at 04:07:49PM +1000, Paul Mackerras wrote:
> On 64-bit, __pa(&static_var) gets miscompiled by recent versions of
> gcc as something like:
> 
>         addis 3,2,.LANCHOR1+4611686018427387904 at toc@ha
>         addi 3,3,.LANCHOR1+4611686018427387904 at toc@l

I might argue that this isn't a miscompilation, since -mcmodel=medium
assumes everything can be accessed within +/-2G of the toc pointer,
but it's definitely a problem since gas and/or ld don't give an
overflow error.  They would except for the fact that our ABI has a
hole in it.

We have relocs that error on 16-bit overflow, eg.
  addi 3,2,x at toc
will give an error if x is more than +/-32k from the toc pointer, but
@ha and _HA/_HI relocs don't error on 32-bit overflow.  (They can't,
because they were really designed to be used in HIHGESTA, HIGHERA, HA,
LO sequences to build up 64-bit values.)

The proper fix is to define a whole slew of new relocations and reloc
specifiers, and modify everything to use them, but that seems like too
much bother.  I had ideas once upon a time to implement gas and ld
options that makes @ha and _HA report overflows, but haven't found one
of those round tuits.

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Linuxppc-dev mailing list