#5230: Segfault in cgrun064
----------------------------------+-----------------------------------------
    Reporter:  daniel.is.fischer  |       Owner:  tibbe       
        Type:  bug                |      Status:  new         
    Priority:  normal             |   Component:  Compiler    
     Version:  7.1                |    Keywords:              
    Testcase:                     |   Blockedby:              
          Os:  Unknown/Multiple   |    Blocking:              
Architecture:  x86                |     Failure:  None/Unknown
----------------------------------+-----------------------------------------
Changes (by tibbe):

  * os:  Linux => Unknown/Multiple


Comment:

 I've stared at the assembly for `GHC.PrimopWrappers.copyArray#` (as
 reported by GDB's disassemble command) but I can't figure out what's going
 on. Here's the (partially annotated) assembly:

 {{{

 ghczmprim_GHCziPrimopWrappers_copyArrayzh_info:
 mov    0x0(%ebp),%eax           ; eax = src
 mov    0x4(%ebp),%ecx           ; ecx = src_off
 mov    0x8(%ebp),%edx           ; edx = dst
 mov    %eax,0x40(%esp)          ; save src on the stack
 mov    0xc(%ebp),%eax           ; eax = dst_off
 mov    %eax,0x4c(%esp)          ; save dst_off on the stack
 mov    0x10(%ebp),%eax          ; eax = n
 mov    %eax,0x58(%esp)          ; save n on the stack
 mov    0x2430e0,%eax            ; set header
 mov    %eax,(%edx)              ; set header cont.
 sub    $0x4,%esp
 mov    0x5c(%esp),%eax          ; eax = n
 shl    $0x2,%eax                ; eax = BYTES(n)
 push   %eax                     ; 3rd memcpy arg = BYTES(n)
 shl    $0x2,%ecx                ; ecx = BYTES(src_off)
 mov    0x48(%esp),%eax          ; eax = src
 add    $0xc,%eax                ; eax = src + 12
 add    %ecx,%eax                ; eax = src + 12 + BYTES(src_off)
 push   %eax                     ; 2nd memcpy arg = src + 12 +
 BYTES(src_off)
 mov    0x58(%esp),%eax          ; eax = dst_off
 mov    %eax,%ecx                ; ecx = dst_off
 shl    $0x2,%ecx                ; ecx = BYTES(dst_off)
 lea    0xc(%edx),%eax           ; eax = dst + 12
 add    %ecx,%eax                ; eax = dst + 12 + BYTES(dst_off)
 push   %eax                     ; 1st memcpy arg = dst + 12 +
 BYTES(dst_off)
 mov    %edx,0x74(%esp)          ; save edx
 call   0x2426da <dyld_stub_memcpy> ; caller-saves: eax, ecx, edx
 add    $0x10,%esp               ; stack clean-up
 mov    0x4c(%esp),%eax          ; eax = n
 mov    %eax,%ecx                ; ecx = n
 shr    $0x7,%ecx                ; ecx = n >> 7
 sub    $0x7,%esp                ; ??? Why subtract 7?
 mov    $0x1,%edx                ; edx = 1
 sub    %ecx,%edx                ; edx = 1 - (n >> 7)
 mov    %ecx,0x74(%esp)          ; save edx
 mov    0x5c(%esp),%ecx
 add    %ecx,%eax
 shr    $0x7,%eax
 add    %edx,%eax
 push   %eax
 push   $0x1
 mov    0x70(%esp),%eax
 mov    0x4(%eax),%ecx           ; crash here
 shl    $0x2,%ecx
 mov    0x7c(%esp),%edx
 add    %edx,%ecx
 add    $0xc,%eax
 add    %ecx,%eax
 push   %eax
 call   0x2426e6 <dyld_stub_memset>
 add    $0x10,%esp
 add    $0x14,%ebp
 jmp    *0x0(%ebp)
 sbb    %al,(%eax)
 add    %al,(%eax)
 xchg   %ax,%ax
 }}}

 I recommend reading it side-by-side with `emitCopyArray` from
 `compiler/codeGen/CgPrimOp.hs`.

 The assembly makes sense to me up to the point where 7 is subtracted from
 the stack pointer.

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

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to