Changeset 274

Show
Ignore:
Timestamp:
11/15/06 21:15:07 (2 years ago)
Author:
pragma
Message:

Yep, just one file fix those nasty COMDEF issues.

Files:

Legend:

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

    r273 r274  
    9292    } 
    9393     
     94    protected bool containsAddress(void* addr){ 
     95        foreach(seg; this.segmentImages){ 
     96            debug debugLog("checking addr: [%0.8X] [%0.8X] [%0.8X]",seg.data.ptr,addr,(seg.data.ptr + seg.data.length)); 
     97            if(addr >= seg.data.ptr && addr <= (seg.data.ptr + seg.data.length)){ 
     98                return true; 
     99            } 
     100        } 
     101        return false; 
     102    } 
     103     
    94104    public void resolveFixups(){ 
    95105        Fixup[] remainingFixups; 
     
    108118                } 
    109119                else{ 
     120                    debug debugLog("Fixup dest symbol: %s [%0.8X] %d",destSymbol.name,destSymbol.address,destSymbolOffset); 
    110121                    destAddress = cast(uint)destSymbol.address + destSymbolOffset; 
    111122                } 
     
    114125                destAddress = cast(uint)destSegmentAddress; 
    115126            } 
     127             
     128            if(!containsAddress(cast(void*)destAddress)){ 
     129                debug debugLog("Module does not contain the destination address for fixup. [%0.8X]",destAddress); 
     130                debug debugLog("dump: %s",this.toString()); 
     131                assert(false); 
     132            } 
     133            //assert(containsAddress(cast(void*)destAddress),"Module does not contain the destination address for fixup."); 
    116134             
    117135            // get the fixup value 
     
    127145                fixupValue = cast(uint)(segmentImages[targetSegmentIndex].data.ptr); 
    128146            } 
     147             
    129148            debug if(destSymbol){ 
    130149                debugLog("fixup dest %s:%s [%0.8X] (%0.8X) = fixupValue [%0.8X] rel:%d",destSymbol.name,destSymbol.getTypeName(),destAddress,*cast(uint*)destAddress,fixupValue,cast(uint)isSegmentRelative); 
     
    185204            } 
    186205        } 
    187          
     206                
    188207        //build up symbol table 
    189208        //NOTE: extern indicies match their OMF counterparts 
     
    278297            image.data[offset..offset+dataLength] = ledata.data; 
    279298        } 
    280      
    281                  
    282         //1st pass for COMDAT records 
    283         //build up the memory image of the referenced segments 
     299                                 
     300        // establish COMDAT temporary address information and segment data 
    284301        foreach(idx,comdat; binary.communalData){ 
    285             SegmentImagePtr image = &(segmentImages[comdat.segmentIndex]);       
     302            // data to the segment 
     303            SegmentImagePtr image = &(segmentImages[comdat.segmentIndex]); 
     304                         
     305            // set temporary address (offset into the segment image) 
     306            if(!comdat.isContinuation){ 
     307                symbolXref[binary.names[comdat.nameIndex]].type = SymbolType.Weak; 
     308                symbolXref[binary.names[comdat.nameIndex]].address = cast(void*)image.data.length; 
     309            } 
     310             
    286311            image.data ~= comdat.data; 
    287         } 
    288  
    289         //2nd pass for COMDAT records 
    290         // establish extern addresses 
    291         void*[] currentAddress; 
    292         currentAddress.length = segmentImages.length; 
    293  
    294         //2nd pass for COMDAT records        
     312        }            
     313 
     314        // fix COMDAT addresses by adding the starting segment address 
    295315        foreach(idx,comdat; binary.communalData){ 
    296316            SegmentImagePtr image = &(segmentImages[comdat.segmentIndex]); 
    297             void** addr = &(currentAddress[comdat.segmentIndex]); 
    298             if(*addr == null){ 
    299                 //TODO: change to orignal segment size 
    300                 *addr = image.data.ptr + binary.segments[comdat.segmentIndex].dataLength; 
    301             } 
    302              
    303             // set temporary address 
    304             //NOTE: this is done to calculate the offset on this pass 
     317            ExportSymbolPtr symbol = symbolXref[binary.names[comdat.nameIndex]]; 
     318             
    305319            if(!comdat.isContinuation){ 
    306                 symbolXref[binary.names[comdat.nameIndex]].type = SymbolType.Strong; 
    307                 symbolXref[binary.names[comdat.nameIndex]].address = *addr; 
    308             } 
    309              
    310             *addr += comdat.data.length; 
    311         } 
     320                symbol.address = cast(void*)(cast(uint)symbol.address + cast(uint)image.data.ptr); 
     321            } 
     322        }        
    312323                         
    313324        // public symbols (done here so address offsets are valid)