Changeset 193

Show
Ignore:
Timestamp:
05/27/06 05:35:40 (2 years ago)
Author:
larsivi
Message:

Compile fixes and Erics additions, get an ArrayBoundsError? in ELBinary(292) though.

Files:

Legend:

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

    r167 r193  
    160160     
    161161    // override to provide debug support 
    162     debug protected IReader decodeArray (void[]* x, uint bytes, uint width, uint type){ 
     162    debug (REMOVE) protected IReader decodeArray (void[]* x, uint bytes, uint width, uint type){ 
    163163        try{ 
    164164            return super.decodeArray(x,bytes,width,type); 
  • trunk/ddl/ar/ArchiveLibrary.d

    r186 r193  
    155155                // PECOFF lib, otherwise it's an Ar-lib 
    156156                ArchiveHeader tmphdr; 
    157                 reader.get(tmphdr); 
     157                ubyte[] tmphdrarr; 
     158                reader.peek(tmphdrarr, ArchiveHeader.sizeof); 
     159                //tmphdr 
    158160                                     
    159161                if (Text.trim(tmphdr.ar_name) == "/") { 
     
    172174                    // instead. larsivi 20060101 
    173175                    int len = ArchiveHeader.sizeof; 
    174                     reader.seek(reader.getPosition() - len); 
     176                    //reader.seek(reader.getPosition() - len); 
    175177                    loadSymbolTable(memberData,fSize); 
    176178                } 
     
    180182                stringtable.length = fSize; 
    181183                assert (stringtable.length == memberData.length); 
    182                 stringtable = memberData
     184                stringtable = memberData.dup
    183185                break; 
    184186            default: // The rest 
     
    244246    return (val[0] << 24) | (val[1] << 16) | (val[2] << 8) | val[3]; 
    245247}  
     248 
     249debug (UNITTEST) { 
     250    private import ddl.DefaultRegistry; 
     251    private import mango.io.Stdout; 
     252} 
     253 
     254unittest { 
     255    ArchiveLibrary archlib = new ArchiveLibrary(new DefaultRegistry,  
     256                                         new FileBuffer("libunittest.a")); 
     257    assert (archlib.getModules().length == 8); 
     258    Stdout.println("Correct number of files found"); 
     259    DynamicModule [] mods = archlib.getModules(); 
     260    Stdout.println(mods[0].getName()); 
     261    Stdout.println(mods[1].getName()); 
     262    Stdout.println(mods[2].getName()); 
     263 
     264    char[] testtable = "thisisaverylongfilename.o/\nyetanotherlongfilename.o/\n"; 
     265    archlib.stringtable = testtable; 
     266    assert("thisisaverylongfilename.o" == archlib.getModuleName("/0")); 
     267    assert("yetanotherlongfilename.o" == archlib.getModuleName("/27")); 
     268    assert("shortername.o" == archlib.getModuleName("shortername.o/foobar")); 
     269    Stdout.println("getModuleName works"); 
     270 
     271} 
     272 
     273debug (UNITTEST) { 
     274    void main(){} 
     275} 
  • trunk/ddl/ar/ArchiveLoader.d

    r175 r193  
    3737private import ddl.ar.ArchiveLibrary; 
    3838 
     39debug private import mango.io.Stdout; 
     40 
    3941/** 
    4042    An implementation of the abstract class DynamicLibraryLoader for 
     
    5456        false if it cannot. 
    5557    */ 
    56     public bit canLoadLibrary(FileBuffer file){ 
     58    public bool canLoadLibrary(FileBuffer file){ 
    5759        return (cast(ubyte[])file.get(8,false)) == cast(ubyte[])"!<arch>\n"; 
    5860    } 
     
    6668    */ 
    6769    public DynamicLibrary load(LoaderRegistry registry,FileBuffer file){ 
     70        debug Stdout.println("Loading the lib");    
    6871        return new ArchiveLibrary(registry, file); 
    6972    } 
  • trunk/ddl/elf/ELFBinary.d

    r189 r193  
    4444private import mango.convert.Integer; 
    4545 
     46//TODO: the efficency of this parser/class can be *greatly* enhanced by the use of some C programming idioms 
     47//TODO: read in the entire file into a flat memory buffer, and cast offset fields to pointers to move around 
     48//TODO: avoid copying the data - just point and use look-aside hashtables for D compatibility 
     49 
    4650class ELFBinary{ 
    4751 
     
    6266    char[] dynsymnames; 
    6367    char[] symtabnames; 
    64  
    65     Elf32_Shdr[char[]] sectionLookup; 
    6668     
    6769    bit dynamic; 
     
    195197        reader.get(shnames,sechdrs[elfhdr.e_shstrndx].sh_size); 
    196198         
     199        // parse sections 
    197200        for(int i = 0; i < sechdrs.length; i++) { 
    198201            Elf32_Shdr thisSection = sechdrs[i]; 
    199             char[] sectionName = getNameString(shnames, thisSection.sh_name); 
    200              
    201             sectionLookup[sectionName] = thisSection; 
    202              
    203             //NOTE: section names and types expanded for debugging and development purposes 
    204             //NOTE: these can probably be reduced down to a minimal set once the data in each section 
    205             //NOTE: can be handled and accounted for either in the symbol table and/or relocations data. 
    206             //TODO: reduce this monster switch 
    207             switch(sectionName){ 
    208             case ".bss": 
    209                 /* This section holds uninitialized data that contribute to the program's memory image. By 
    210                 definition, the system initializes the data with zeros when the program begins to run. The 
    211                 section occupies no file space, as indicated by the section type, SHT_NOBITS.*/ 
    212                 break; 
    213             case ".comment": 
    214                 /* This section holds version control information. */ 
    215                 break; 
    216             case ".data": 
    217             case ".data1": 
    218                 /* These sections hold initialized data that contribute to the program's memory image. */ 
    219                 break; 
    220             case ".debug": 
    221                 /* This section holds information for symbolic debugging. The contents are unspecified. */ 
    222                 break; 
    223             case ".dynamic": 
    224                 /* This section holds dynamic linking information. The section's attributes will include the 
    225                 SHF_ALLOC bit. Whether the SHF_WRITE bit is set is processor specific. */ 
    226                 break; 
    227                  
    228             case ".dynstr": 
    229                 /* This section holds strings needed for dynamic linking, most commonly the strings that 
    230                 represent the names associated with symbol table entries. */ 
    231                 reader.setPosition(thisSection.sh_offset); 
    232                 reader.get(dynsymnames,thisSection.sh_size); 
    233                 break;               
    234                  
    235             case ".dynsym": 
    236                 /* This section holds the dynamic linking symbol table, as "Symbol Table" describes. */ 
    237                 dynamic = true; 
    238                 symtableidx = i; 
    239                 break; 
    240                  
    241             case ".fini": 
    242                 /* This section holds executable instructions that contribute to the process termination code. 
    243                 That is, when a program exits normally, the system arranges to execute the code in this 
    244                 section. */ 
    245                 break; 
    246             case ".got": 
    247                 /* This section holds the global offset table. */ 
    248                 break; 
    249             case ".hash": 
    250                 /* This section holds a symbol hash table. */ 
    251                 break; 
    252             case ".init": 
    253                 /* This section holds executable instructions that contribute to the process initialization code. 
    254                 That is, when a program starts to run, the system arranges to execute the code in this section 
    255                 before calling the main program entry point (called main for C programs). */ 
    256                 break; 
    257             case ".interp": 
    258                 /* This section holds the path name of a program interpreter. If the file has a loadable segment 
    259                 that includes the section, the section's attributes will include the SHF_ALLOC bit; otherwise, 
    260                 that bit will be off. */ 
    261                 break; 
    262             case ".line": 
    263                 /* This section holds line number information for symbolic debugging, which describes the 
    264                 correspondence between the source program and the machine code. The contents are 
    265                 unspecified. */ 
    266                 break; 
    267             case ".note": 
    268                 /* This section holds information in the format for the "Note Section" */ 
    269                 break; 
    270             case ".plt": 
    271                 /* This section holds the procedure linkage table. */ 
    272                 break; 
    273             case ".rodata": 
    274             case ".rodata1": 
    275                 /* These sections hold read-only data that typically contribute to a non-writable segment in 
    276                 the process image. */ 
    277                 break; 
    278             case ".shstrtab": 
    279                 /* This section holds section names. */ 
    280                 break; 
    281                  
    282             case ".strtab": 
    283                 /* This section holds strings, most commonly the strings that represent the names associated 
    284                 with symbol table entries. If the file has a loadable segment that includes the symbol string 
    285                 table, the section's attributes will include the SHF_ALLOC bit; otherwise, that bit will be off. */ 
    286                 reader.setPosition(thisSection.sh_offset); 
    287                 reader.get(symtabnames,thisSection.sh_size); 
    288                 break;        
    289                           
    290             case ".symtab": 
    291                 /* This section holds a symbol table, as "Symbol Table" in this section describes. If the file 
    292                 has a loadable segment that includes the symbol table, the section's attributes will include 
    293                 the SHF_ALLOC bit; otherwise, that bit will be off. */ 
    294                  
    295                 //loadStaticSymbols(thisSection.sh_offset,thisSection.sh_size); 
    296                  
    297                 dynamic = false; 
    298                 symtableidx = i; 
    299                 break; 
    300                  
    301             case ".text": 
    302                 /* This section holds the "text," or executable instructions, of a program. */ 
    303                 break;                                 
    304             default: 
    305                 /* .relname and .relaname 
    306                 These sections hold relocation information, as "Relocation" below describes. If the file has 
    307                 a loadable segment that includes relocation, the sections' attributes will include the 
    308                 SHF_ALLOC bit; otherwise, that bit will be off. Conventionally, name is supplied by the 
    309                 section to which the relocations apply. Thus a relocation section for .text normally 
    310                 would have the name .rel.text or .rela.text. */ 
    311                      
    312                 if(sectionName.length >= 6 && sectionName[0..6] == ".rela."){    
    313                     char[] relocatedName = sectionName[6..$]; 
    314                     Elf32_Rela rel; 
    315                 } 
    316                 else if(sectionName.length >= 5 && sectionName[0..5] == ".rel."){    
    317                     char[] relocatedName = sectionName[5..$]; 
    318                     Elf32_Rel rel; 
    319                 } 
    320                 else{ 
    321                     //TODO: treat the section as it's own symbol perhaps? (e.g. gnu.linkonce.t) 
    322                 } 
    323                 break; 
    324             } 
     202                         
     203            switch(thisSection.sh_type){ 
     204            case SHT_NULL:  
     205            /*This value marks the section header as inactive; it does not have an associated section. 
     206            Other members of the section header have undefined values */ 
     207                break; 
     208                 
     209            case SHT_PROGBITS:  
     210            /*The section holds information defined by the program, whose format and meaning are 
     211            determined solely by the program.*/ 
     212                break; 
     213                 
     214            case SHT_SYMTAB: 
     215            /* symbol table */ 
     216                // get associated string table 
     217                Elf32_Shdr stringSection = sechdrs[thisSection.sh_link]; 
     218                char[] stringTable; 
     219                 
     220                reader.setPosition(stringSection.sh_offset); 
     221                reader.get(stringTable,stringSection.sh_size); 
     222                 
     223                char[][] symbolNames = crackStringTable(stringTable); 
     224 
     225                // read in the symbols 
     226                reader.setPosition(thisSection.sh_offset); 
     227                parseSYMTAB(thisSection.sh_info, symbolNames, reader); 
     228                break; 
     229                 
     230            case SHT_STRTAB:  
     231            /*The section holds a string table. An object file may have multiple string table sections. */ 
     232                break; 
     233                 
     234            case SHT_RELA:  
     235            /*The section holds relocation entries with explicit addends, such as type Elf32_Rela 
     236            for the 32-bit class of object files. An object file may have multiple relocation sections.*/ 
     237                break; 
     238                 
     239            case SHT_HASH: break; 
     240            case SHT_DYNAMIC: break; 
     241             
     242            case SHT_NOTE:  
     243            /*The section holds information that marks the file in some way.  
     244            See "Note Section" in Part 2 for details.*/ 
     245                 
     246                break; 
     247                 
     248            case SHT_NOBITS: break; 
     249            case SHT_REL:  
     250            /* The section holds relocation entries without explicit addends, such as type 
     251            Elf32_Rel for the 32-bit class of object files. An object file may have multiple relocation 
     252            sections. */ 
     253                break; 
     254                 
     255            case SHT_SHLIB: break; 
     256            case SHT_DYNSYM: break; 
     257            case SHT_LOPROC: break; 
     258            case SHT_HIPROC: break; 
     259            case SHT_LOUSER: break; 
     260            case SHT_HIUSER: break; 
     261            default: 
     262            } 
    325263        } 
    326264        loadSymTable(symtableidx, reader); 
    327265    } 
    328  
    329     protected char[] getNameString(char [] tab, uint pos){ 
    330         assert(pos < tab.length); 
    331         int i = pos; 
    332         while(tab[i] != '\0'){ 
    333             i++; 
    334         } 
    335         debug debugLog("\tgetNameString: %s",tab[pos..i]); 
    336         return tab[pos..i]; 
    337     } 
    338  
    339     protected void loadSymTable(uint secnum, ELFReader reader){ 
    340         assert(sechdrs[secnum].sh_entsize > 0); 
    341         reader.setPosition(sechdrs[secnum].sh_offset); 
    342          
    343         // TODO: Probably NOT put all symbols at the same place 
    344         symbols.length = sechdrs[secnum].sh_size / sechdrs[secnum].sh_entsize; 
    345         for(int i = 0; i < symbols.length; i++){ 
    346             Elf32_Sym symbol; 
    347             reader.get(symbol); 
    348             symbols[i] = symbol; 
    349            // debug debugLog("symbol: %s",symbol.st.name 
    350         } 
     266     
     267    protected char[][] crackStringTable(char[] data){ 
     268        char[][] table; 
     269        for(uint i = 0, last = 0; i<data.length; i++){ 
     270            if(data[i] == '\0'){ 
     271                table ~= data[last..i]; 
     272                i++; 
     273                last = i; 
     274            } 
     275        } 
     276        return table; 
     277    } 
     278 
     279    protected void loadSymTable(uint idx, ELFReader reader) { 
     280 
     281    } 
     282     
     283    protected void parseSYMTAB(uint symbols, char[][] symbolNames, 
     284                               ELFReader reader){ 
     285        for(int i=0; i<symbols; i++){ 
     286            Elf32_Sym sym; 
     287            reader.get(sym); 
     288             
     289            //TODO: refer to STB_LOCAL to ensure that symbols don't overlap 
     290             
     291            ExportSymbol exportSym; 
     292            exportSym.name = symbolNames[sym.st_name]; 
     293             
     294            //TODO: resolve symbol data address by cracking the sym fields per the specification 
     295        } 
    351296    } 
    352297 
  • trunk/ddl/elf/ELFObjLoader.d

    r189 r193  
    3535private import ddl.Utils; 
    3636private import ddl.FileBuffer; 
     37private import ddl.Utils; 
    3738 
    3839private import ddl.elf.ELFLibrary; 
     
    5960        magic string, "\x7fELF". 
    6061    */ 
    61     public bit canLoadLibrary(FileBuffer file){ 
     62    public bool canLoadLibrary(FileBuffer file){ 
     63        debug debugLog("Testing for ELF compliance"); 
     64        debug debugLog("from file: ", cast(char[])file.get(4,false)); 
     65        debug debugLog("magic header: \0x7ELF"); 
    6266        if((cast(ubyte[])file.get(4,false)) == cast(ubyte[])"\x7fELF"){ 
     67            debug debugLog("ELF header verified"); 
    6368            return true; 
    6469        } 
  • trunk/utils/ArgParser.d

    r191 r193  
    248248    } 
    249249} 
     250 
     251unittest { 
     252 
     253    //import mango.text.String; 
     254 
     255    ArgParser parser = new ArgParser(); 
     256    bool h = h2 = b = bb = false; 
     257    bool boolean = false; 
     258    int n; 
     259 
     260    parser.bind("--", "h2", delegate void(){ 
     261        h2 = true; 
     262    }); 
     263 
     264    parser.bind("-", "h", delegate void(){ 
     265        h = true; 
     266    }); 
     267 
     268    parser.bind("-", "bb", delegate void(){ 
     269        bb = true; 
     270    }); 
     271 
     272    parser.bind("-", "b", delegate void(){ 
     273        b = true; 
     274    }); 
     275 
     276    parser.bind("-", "n", delegate uint(char[] value){ 
     277        assert(value.length > 2); 
     278        assert(value[1] == '='); 
     279        n = toInt(value[2..5]); 
     280        return 5; 
     281    }); 
     282 
     283    parser.bind("-", "bool", delegate uint(char[] value){ 
     284        assert(value.length == 9); 
     285        assert(value[4] == '='); 
     286        if (value[5..9] == "true") { 
     287            boolean = true; 
     288        } 
     289        else { 
     290            assert(false); 
     291        } 
     292        return 9; 
     293    }); 
     294 
     295    parser.bindDefault(delegate uint(char[] value, uint ordinal){ 
     296        assert (ordinal < 2); 
     297        ordinalCount = ordinal; 
     298        if (ordinal == 0) { 
     299            assert(value == "ordinalTest1"); 
     300        } 
     301        else if (ordinal == 1) { 
     302            assert(value == "ordinalTest2"); 
     303        } 
     304        return value.length; 
     305    }); 
     306 
     307    parser.bindDefault("-", delegate uint(char[] value, uint ordinal){ 
     308        assert(ordinal < 2); 
     309        dashOrdinalCount = ordinal; 
     310        if (ordinal == 0) { 
     311            assert(value == "dashTest1"); 
     312        } 
     313        else if (ordinal == 1) { 
     314            assert(value == "dashTest1"); 
     315        } 
     316        return value.length; 
     317    }); 
     318 
     319    parser.bindDefault("@", delegate uint(char[] value, uint ordinal){ 
     320        assert (value == "atTest"); 
     321        return value.length; 
     322    }); 
     323 
     324     
     325 
     326} 
  • trunk/utils/bless_bn.d

    r191 r193  
    22// This file is automatically maintained by the BUILD utility, 
    33// Please refrain from manually editing it. 
    4 long auto_build_number = 573
     4long auto_build_number = 591
  • trunk/utils/ddlinfo_bn.d

    r191 r193  
    22// This file is automatically maintained by the BUILD utility, 
    33// Please refrain from manually editing it. 
    4 long auto_build_number = 614
     4long auto_build_number = 632
  • trunk/utils/insitu_bn.d

    r191 r193  
    22// This file is automatically maintained by the BUILD utility, 
    33// Please refrain from manually editing it. 
    4 long auto_build_number = 570
     4long auto_build_number = 588