powerpc: Work around gcc miscompilation of __pa() on 64-bit
authorPaul Mackerras <paulus@samba.org>
Tue, 27 Aug 2013 06:07:49 +0000 (16:07 +1000)
committerBen Hutchings <ben@decadent.org.uk>
Tue, 10 Sep 2013 00:57:34 +0000 (01:57 +0100)
commit3bf7055b3d4062d835d15d734ca5a9baa9403e1e
treebea4d5a96322c2e898679a8b37f237b47875c723
parentc349bf07d6c05e89c967327af0f334604826d0e4
powerpc: Work around gcc miscompilation of __pa() on 64-bit

commit bdbc29c19b2633b1d9c52638fb732bcde7a2031a upstream.

On 64-bit, __pa(&static_var) gets miscompiled by recent versions of
gcc as something like:

        addis 3,2,.LANCHOR1+4611686018427387904@toc@ha
        addi 3,3,.LANCHOR1+4611686018427387904@toc@l

This ends up effectively ignoring the offset, since its bottom 32 bits
are zero, and means that the result of __pa() still has 0xC in the top
nibble.  This happens with gcc 4.8.1, at least.

To work around this, for 64-bit we make __pa() use an AND operator,
and for symmetry, we make __va() use an OR operator.  Using an AND
operator rather than a subtraction ends up with slightly shorter code
since it can be done with a single clrldi instruction, whereas it
takes three instructions to form the constant (-PAGE_OFFSET) and add
it on.  (Note that MEMORY_START is always 0 on 64-bit.)

Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
arch/powerpc/Kconfig
arch/powerpc/include/asm/page.h