#7207: linker fails to load package with binding to foreign library (win64)
-------------------------------+--------------------------------------------
 Reporter:  nus                |          Owner:                
     Type:  bug                |         Status:  new           
 Priority:  normal             |      Component:  GHCi          
  Version:  7.6.1-rc1          |       Keywords:                
       Os:  Windows            |   Architecture:  x86_64 (amd64)
  Failure:  GHCi crash         |       Testcase:                
Blockedby:                     |       Blocking:                
  Related:  #7097 #7134 #7040  |  
-------------------------------+--------------------------------------------
Changes (by nus):

  * related:  #7097 #7134 => #7097 #7134 #7040


Comment:

 Backtracing the first failure:
 {{{
 Breakpoint 16, barf (
     s=0x24d54a0 "R_X86_64_PC32: High bits are set in %zx for %s")
     at rts\RtsMessages.c:41
 41        va_start(ap,s);
 (gdb) bt
 #0  barf (s=0x24d54a0 "R_X86_64_PC32: High bits are set in %zx for %s")
     at rts\RtsMessages.c:41
 #1  0x0000000002103ced in ocResolve_PEi386 (oc=0x6abb270) at
 rts\Linker.c:3938
 #2  0x000000000210201d in resolveObjs () at rts\Linker.c:2608
 [...snip...]
 (gdb) up
 #1  0x0000000002103ced in ocResolve_PEi386 (oc=0x6abb270) at
 rts\Linker.c:3938
 3938                           barf("R_X86_64_PC32: High bits are set in
 %zx for
  %s",
 (gdb) info locals
 v = 8791724452850
 sym = 0x286ffba
 reltab_j = 0x2861f40
 sectab_i = 0x2840018
 reltab = 0x285fe20
 secname = 0x6ac8160 ""
 hdr = 0x2840004
 sectab = 0x2840018
 symtab = 0x286bb62
 strtab = 0x2871868 "=£\001"
 A = 0
 S = 8791766694568
 pP = 0x2848eb2
 i = 0
 j = 848
 noRelocs = 3313
 symbol = "_get_osfhandle", '\000' <repeats 985 times>


 }}}

 rts/Linker.c:
 {{{
 ocResolve_PEi386 ( ObjectCode* oc )
 [...snip...]
          if (sym->StorageClass == MYIMAGE_SYM_CLASS_STATIC) {
 [...snip...]
          } else {
             copyName ( sym->Name, strtab, symbol, 1000-1 );
             S = (size_t) lookupSymbol( (char*)symbol );
 [...snip...]
             case 4: /* R_X86_64_PC32 */
                {
                    intptr_t v;
                    v = ((intptr_t)S) + ((intptr_t)(Int32)A) -
 ((intptr_t)pP) - 4;
                    if ((v >> 32) && ((-v) >> 32)) {
                        copyName ( sym->Name, strtab, symbol, 1000-1 );
                        barf("R_X86_64_PC32: High bits are set in %zx for
 %s",
                             v, (char *)symbol);
                    }
 }}}
 {{{
 void *
 lookupSymbol( char *lbl )
 [...snip...]
 #       elif defined(OBJFORMAT_PEi386)
         void* sym;

         sym = lookupSymbolInDLLs((unsigned char*)lbl);
         if (sym != NULL) { return sym; };
 }}}
 {{{
 static void *
 lookupSymbolInDLLs ( UChar *lbl )
 [...snip...]
         sym = GetProcAddress(o_dll->instance, (char*)lbl);
 }}}
 Back to the trace:
 {{{
 Breakpoint 8, lookupSymbolInDLLs (lbl=0x22d700 "_get_osfhandle")
     at rts\Linker.c:3292
 [...snip...]
 3307            sym = GetProcAddress(o_dll->instance, (char*)lbl);
 (gdb) n
 3308            if (sym != NULL) {
 (gdb) n
 3310                return sym;
 (gdb) info locals
 o_dll = 0x3f5e650
 sym = 0x7fefe217aa8
 (gdb) print o_dll->name
 $78 = (
     pathchar *) 0x3f5e6a0 L"\155\163\166\143\162", <incomplete sequence
 \164>
 (gdb) p/c (wchar_t [7])*(o_dll->name)
 $79 = {109 'm', 115 's', 118 'v', 99 'c', 114 'r', 116 't', 0 '\000'}
 }}}
 `GetProcAddress` is returning `0x7fefe217aa8` -- the address of
 `_open_osfhandle` in `msvcrt.dll` which has already been loaded by the
 time `ansi-terminal` is loading. There are `0x9f000` bytes of
 `C:\Windows\System32\msvcrt.dll` mapped into the `ghc` process at the load
 address `0x7fefe210000`.
 The situation with the `network` package is similar.
 So far this stems from the same problem as in #7040 -- operations with
 pointers to the memory regions beyond the limits of the small C code
 model.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7207#comment:1>
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