Tamar Christina pushed to branch wip/bump-win32-tarballs at Glasgow Haskell Compiler / GHC

Commits:

1 changed file:

Changes:

  • rts/linker/PEi386.c
    ... ... @@ -1168,7 +1168,11 @@ bool checkAndLoadImportLibrary( pathchar* arch_name, char* member_name, FILE* f
    1168 1168
         // way is to load the symbol immediately. We already have all the
    
    1169 1169
         // information so might as well
    
    1170 1170
         SymbolAddr* sym = lookupSymbolInDLL_PEi386 (symbol, instance, dll, NULL);
    
    1171
    -    ASSERT(sym);
    
    1171
    +
    
    1172
    +    // Could be an import descriptor etc, skip if no symbol.
    
    1173
    +    if (!sym)
    
    1174
    +      return true;
    
    1175
    +
    
    1172 1176
         // The symbol must have been found, and we can add it to the RTS symbol table
    
    1173 1177
         IF_DEBUG(linker, debugBelch("checkAndLoadImportLibrary: resolved symbol %s to %p\n", symbol, sym));
    
    1174 1178
         // Because the symbol has been loaded before we actually need it, if a
    
    ... ... @@ -1932,6 +1936,27 @@ ocGetNames_PEi386 ( ObjectCode* oc )
    1932 1936
               }
    
    1933 1937
               if(NULL != targetSection)
    
    1934 1938
                   addr = (SymbolAddr*) ((size_t) targetSection->start + getSymValue(info, targetSym));
    
    1939
    +          else
    
    1940
    +            {
    
    1941
    +                // Do the symbol lookup based on name, this follows Microsoft's weak external's
    
    1942
    +                // format 3 specifications.  Example header generated:
    
    1943
    +                // api-ms-win-crt-stdio-l1-1-0.dll:     file format pe-x86-64
    
    1944
    +                //
    
    1945
    +                // SYMBOL TABLE:
    
    1946
    +                // [  0](sec -1)(fl 0x00)(ty    0)(scl   3) (nx 0) 0x0000000000000000 @comp.id
    
    1947
    +                // [  1](sec -1)(fl 0x00)(ty    0)(scl   3) (nx 0) 0x0000000000000000 @feat.00
    
    1948
    +                // [  2](sec  0)(fl 0x00)(ty    0)(scl   2) (nx 0) 0x0000000000000000 _write
    
    1949
    +                // [  3](sec  0)(fl 0x00)(ty    0)(scl 105) (nx 1) 0x0000000000000000 write
    
    1950
    +                // AUX lnno 3 size 0x0 tagndx 2
    
    1951
    +                //
    
    1952
    +                // https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#auxiliary-format-3-weak-externals
    
    1953
    +                SymbolName *target_sname = get_sym_name (getSymShortName (info, targetSym), oc);
    
    1954
    +                if (target_sname)
    
    1955
    +                  addr = lookupSymbol_PEi386 (target_sname, oc, &type);
    
    1956
    +
    
    1957
    +                IF_DEBUG(linker, debugBelch("weak external symbol @ %s => %s resolved to %p\n", \
    
    1958
    +                                            sname, target_sname, addr));
    
    1959
    +            }
    
    1935 1960
           }
    
    1936 1961
           else if (  secNumber == IMAGE_SYM_UNDEFINED && symValue > 0) {
    
    1937 1962
              /* This symbol isn't in any section at all, ie, global bss.