Changeset 116

Show
Ignore:
Timestamp:
01/16/06 17:03:08 (3 years ago)
Author:
pragma
Message:

Fix for OMF implibs - for #23.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ddl/omf/OMFBinary.d

    r114 r116  
    2929private import ddl.omf.OMFException; 
    3030 
     31version(Windows){ 
     32    extern (Windows) 
     33    { 
     34        alias uint HANDLE; 
     35        alias HANDLE HMODULE; 
     36        alias int BOOL; 
     37        alias int (*FARPROC)(); 
     38        alias void* LPCSTR; 
     39        FARPROC GetProcAddress(HMODULE hModule, LPCSTR lpProcName); 
     40        HMODULE LoadLibraryA(LPCSTR lpLibFileName); 
     41        BOOL FreeLibrary(HMODULE hLibModule); 
     42    }    
     43} 
     44 
    3145struct Group{ 
    3246    char[] name; 
     
    113127    Fixup[] unresolvedFixups; 
    114128     
     129    //OS specific bits 
     130    version(Windows){ 
     131        HANDLE[char[]] dllHandles; 
     132    } 
     133     
    115134    public this(){ 
    116135        groups.length = 1; 
     
    118137        names.length = 1; 
    119138        segments.length = 1; 
     139    } 
     140     
     141    public ~this(){ 
     142        version(Windows){ 
     143            foreach(HANDLE handle; dllHandles){ 
     144                FreeLibrary(handle); 
     145            } 
     146        } 
    120147    } 
    121148     
     
    192219            //TODO: store someplace else 
    193220            //this.libraryName = comment; 
    194             break;       
     221            break; 
     222             
     223        case 0xA0: // OMF extensions 
     224            ubyte extensionType = comment[0]; 
     225            WordOMFRecordCursor cursor = new WordOMFRecordCursor(cast(ubyte[])comment[1..$],0); 
     226                                             
     227            switch(extensionType){ 
     228            case 0x01: // import definition record 
     229                version(Windows){ 
     230                    ubyte ordinalFlag = cursor.getByte(); 
     231                    char[] internalName = cursor.getLString(); 
     232                    char[] moduleName = cursor.getLString(); 
     233                    HANDLE* pHandle = moduleName in dllHandles; 
     234                    HANDLE thisHandle; 
     235                     
     236                    if(!pHandle){ 
     237                        thisHandle = LoadLibraryA((moduleName~"\0").ptr); 
     238                        dllHandles[moduleName] = thisHandle; 
     239                    } 
     240                    else{ 
     241                        thisHandle = *pHandle; 
     242                    } 
     243                             
     244                    if(ordinalFlag == 0){ 
     245                        char[] entryName; 
     246                        if(cursor.peekByte() == 0){ 
     247                            entryName = internalName; 
     248                        } 
     249                        else{ 
     250                            entryName = cursor.getLString(); 
     251                        } 
     252                        debugLog("impdef: [%s] [%s] %s",internalName,moduleName,entryName); 
     253                         
     254                        // store the extern as both its entry name and the internal name 
     255                        PublicSymbol pub; 
     256                        pub.name = internalName; 
     257                        pub.segmentIndex = 0; 
     258                        pub.offset = cast(uint)GetProcAddress(thisHandle,(entryName~"\0").ptr); 
     259                        publics[pub.name] = pub;                                 
     260                         
     261                        pub.name = entryName; 
     262                        publics[pub.name] = pub;                         
     263                    } 
     264                    else{ 
     265                        uint entryOrdinal = cursor.getWord();                    
     266                        debugLog("impdef: [%s] [%s] %d",internalName,moduleName,entryOrdinal); 
     267                         
     268                        // store the extern via its ordinal in the dll 
     269                        PublicSymbol pub; 
     270                        pub.name = internalName; 
     271                        pub.segmentIndex = 0; 
     272                        pub.offset = cast(uint)GetProcAddress(thisHandle,cast(void*)entryOrdinal); 
     273                        publics[pub.name] = pub;                     
     274                    } 
     275                } 
     276                else{ 
     277                    throw new Exception("Non-Windows operating systems cannot support implib style OMF binaries."); 
     278                } 
     279                 
     280            } 
     281            break; 
    195282             
    196283        case 0xA8: // Weak extern (dependency) 
     
    200287            // default extern index is thrown out 
    201288             
    202             debug writefln("dependency: symbol %d",externIndex); 
     289            debug debugLog("dependency: symbol %d",externIndex); 
    203290 
    204291            this.dependencies[this.externs[externIndex].name] ~= externIndex; 
  • trunk/ddl/omf/OMFLibrary.d

    r101 r116  
    149149        //skip the dictionary (redundant) 
    150150    } 
     151     
     152    public char[] toString(){ 
     153        char[] result = ""; 
     154        foreach(DynamicModule mod; modules){ 
     155            result ~= mod.toString(); 
     156        } 
     157        return result; 
     158    } 
    151159} 
    152160 
  • trunk/utils/bless_bn.d

    r101 r116  
    22// This file is automatically maintained by the BUILD utility, 
    33// Please refrain from manually editing it. 
    4 long auto_build_number = 151
     4long auto_build_number = 193
  • trunk/utils/ddlinfo.d

    r92 r116  
    147147        }    
    148148    } 
     149    //Stdout.println("%s",lib.toString()); 
    149150 
    150151    return 0; 
  • trunk/utils/ddlinfo_bn.d

    r101 r116  
    22// This file is automatically maintained by the BUILD utility, 
    33// Please refrain from manually editing it. 
    4 long auto_build_number = 151
     4long auto_build_number = 193
  • trunk/utils/insitu_bn.d

    r101 r116  
    22// This file is automatically maintained by the BUILD utility, 
    33// Please refrain from manually editing it. 
    4 long auto_build_number = 151
     4long auto_build_number = 193