[GHC] #8024: Dynamic linking not working on PowerPC Linux.

GHC ghc-devs at haskell.org
Fri Dec 12 22:56:12 UTC 2014


#8024: Dynamic linking not working on PowerPC Linux.
----------------------------------------------+---------------------------
              Reporter:  erikd                |            Owner:
                  Type:  bug                  |           Status:  patch
              Priority:  normal               |        Milestone:
             Component:  Compiler             |          Version:  7.7
            Resolution:                       |         Keywords:
      Operating System:  Linux                |     Architecture:  powerpc
       Type of failure:  Building GHC failed  |       Difficulty:  Unknown
             Test Case:                       |       Blocked By:
              Blocking:                       |  Related Tickets:
Differential Revisions:  D560                 |
----------------------------------------------+---------------------------
Changes (by slyfox):

 * status:  infoneeded => patch
 * differential:   => D560


Comment:

 The problem happened to be in code emitting prologs
 for basic block entries (also got fixed by
 https://phabricator.haskell.org/D560).

 Typically haskell function has single entry point (-fPIC -ddump-asm-
 native):
 {{{
 M.f_info:
 _ci4:
 ; PIC prolog
         bcl     20,31,1f
 1:      mflr    %vI_nic
         lwz     %vI_nij, _nii-(1b)(%vI_nic)
         add     %vI_nic, %vI_nic, %vI_nij
 ... <HERE GOES ACTUAL CODE> ...
 ; offset to LCTOC from nearest '1:'
 .text
 .align 2
 _nii:
         .long   .LCTOC1-(1b)+0
 }}}

 But sometimes runtime needs to return back
 into a middle of haskell function (try/catch primitives?)
 and prolog gets emitted at each such point using the same LCTOC offset:
 {{{
 M.f_info:
 _ci4:
 ; PIC prolog
         bcl     20,31,1f
 1:      mflr    %vI_nic ; REF 1
         lwz     %vI_nij, _nii-(1b)(%vI_nic)
         add     %vI_nic, %vI_nic, %vI_nij
 ... <HERE GOES ACTUAL CODE> ...
 returns_here_later:
 ; PIC prolog
         bcl     20,31,1f
 1:      mflr    %vI_nic ; REF 2
         lwz     %vI_nij, _nii-(1b)(%vI_nic)
         add     %vI_nic, %vI_nic, %vI_nij
 ...
 ; offset to LCTOC from nearest '1:'
 .text
 .align 2
 _nii:
         .long   .LCTOC1-(1b)+0
 }}}
 Here '_nii' contains offset to nearest '1:' label, not first one (as
 intended).
 It leads to miscomputation of LCTOC1 in function entry (around first '1:'
 which usually manifests in call to random location.

 It is fixed by using simpler prolog (similar to what modern gcc emits
 nowadays):
 {{{
         bcl     20,31,1f
 1:      mflr    %vI_ny4
         addis   %vI_ny4, %vI_ny4, .LCTOC1-(1b)@ha
         addi    %vI_ny4, %vI_ny4, .LCTOC1-(1b)@l
         mr      30, %vI_ny4
 }}}
 And it is safe to duplicate.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8024#comment:10>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list