[PATCH] Fix broken -fPIC on Darwin/PPC
PIC.initializePicBase_ppc
was wrongly assuming that only the first block was an entry point, which resulted in the following panic when we were compiling libraries/ghc-prim/dist-install/build/GHC/Classes.dyn_o
:
ghc-stage1: panic! (the 'impossible' happened)
(GHC version 7.7.20121119 for powerpc-apple-darwin):
allocateRegsAndSpill: Cannot read from uninitialized register
%vI_nawI
Here is the result of -ddump-opt-cmm
for the code block in question:
==================== Optimised Cmm ====================
section "data" {
ghc-prim:GHC.Classes.$dm<={v rbx}_closure:
const ghc-prim:GHC.Classes.$dm<={v rbx}_info;
}
==================== Optimised Cmm ====================
ghc-prim:GHC.Classes.$dm<={v rbx}_entry() // [R4, R3, R2]
{ [(cawk,
ghc-prim:GHC.Classes.$dm<={v rbx}_info:
const 1310723;
const 0;
const 983040;),
(cawl,
block{v cawl}_info:
const 0;
const 2097152;)]
}
{offset
cawk:
/***** FETCHPC is rightly inserted here. *****/
_s7Ce::P32 = R4;
_s7Cd::P32 = R3;
_s7Cc::P32 = R2;
if ((Sp + -16) < SpLim) goto cawA; else goto cawz;
cawA:
R4 = _s7Ce::P32;
R3 = _s7Cd::P32;
R2 = _s7Cc::P32;
R1 = I32[PicBaseReg + Lghc-prim:GHC.Classes.$dm<={v rbx}_closure$non_lazy_ptr-1b];
call (I32[BaseReg - 4])(R4, R3, R2, R1) args: 4, res: 0, upd: 4;
cawz:
I32[Sp - 4] = PicBaseReg + block{v cawl}_info-1b;
R2 = _s7Cc::P32;
I32[Sp - 16] = I32[PicBaseReg + Lstg_ap_pp_info$non_lazy_ptr-1b];
P32[Sp - 12] = _s7Cd::P32;
P32[Sp - 8] = _s7Ce::P32;
Sp = Sp - 16;
call ghc-prim:GHC.Classes.compare{v r5v}_info(R2) returns to cawl, args: 16, res: 4, upd: 4;
cawl:
/***** But not here! This is the cause of panic! *****/
if (R1 & 3 != 3) goto cawt; else goto cawn;
cawt:
R1 = I32[PicBaseReg + Lghc-prim:GHC.Types.True{(w) d 6u}_closure$non_lazy_ptr-1b] + 2;
Sp = Sp + 4;
call (P32[Sp])(R1) args: 4, res: 0, upd: 4;
cawn:
R1 = I32[PicBaseReg + Lghc-prim:GHC.Types.False{(w) d 68}_closure$non_lazy_ptr-1b] + 1;
Sp = Sp + 4;
call (P32[Sp])(R1) args: 4, res: 0, upd: 4;
}
}
To pull my patch:
% git fetch git://github.com/phonohawk/ghc.git darwin-ppc-pic-fix
I'm pretty sure that Linux/ppc32 suffers from the same bug too, but I have no idea how to fix its awfully complicated logic so I have no choice but to leave it untouched.
Trac metadata
Trac field | Value |
---|---|
Version | 7.7 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |