Changeset 220
- Timestamp:
- 07/29/06 23:47:32 (2 years ago)
- Files:
-
- trunk/ddl/DefaultRegistry.d (modified) (1 diff)
- trunk/ddl/ar/ArchiveLibrary.d (modified) (4 diffs)
- trunk/ddl/ar/ArchiveLoader.d (modified) (1 diff)
- trunk/ddl/elf/ELFBinary.d (modified) (5 diffs)
- trunk/ddl/elf/ELFModule.d (modified) (1 diff)
- trunk/ddl/elf/ELFPrinter.d (modified) (3 diffs)
- trunk/ddl/omf/OMFBinary.d (modified) (11 diffs)
- trunk/ddl/omf/OMFModule.d (modified) (8 diffs)
- trunk/utils/Script.d (modified) (1 diff)
- trunk/utils/bless_bn.d (modified) (1 diff)
- trunk/utils/ddlinfo_bn.d (modified) (1 diff)
- trunk/utils/insitu_bn.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ddl/DefaultRegistry.d
r218 r220 34 34 35 35 private import ddl.LoaderRegistry; 36 //private import ddl.ar.ArchiveLoader;36 private import ddl.ar.ArchiveLoader; 37 37 private import ddl.omf.OMFLoader; 38 38 private import ddl.ddl.DDLLoader; 39 //private import ddl.elf.ELFObjLoader;39 private import ddl.elf.ELFObjLoader; 40 40 private import ddl.insitu.InSituLoader; 41 41 //private import ddl.coff.COFFLoader; trunk/ddl/ar/ArchiveLibrary.d
r195 r220 1 1 /+ 2 Copyright (c) 2005 Lars Ivar Igesund, J Duncan, Eric Anderton2 Copyright (c) 2005,2006 Lars Ivar Igesund, J Duncan, Eric Anderton 3 3 4 4 Permission is hereby granted, free of charge, to any person … … 42 42 43 43 class ArchiveLibrary : DynamicLibrary{ 44 const char[] ARCHID = "!<arch>\n"; 45 46 struct Symbol{ 47 uint offset; 48 ubyte[] name; 49 } 50 51 private int exportsready = 0; 52 private LoaderRegistry registry = null; 53 private char[] stringtable; 54 private DynamicModule [] modules; 55 private ExportSymbol [char[]] exports; 56 private Attributes attributes; 57 private ArchiveReader reader; 58 private uint [char[]] symbolOffsets; 59 60 public this(LoaderRegistry registry, FileBuffer file, 61 bool loadall = true){ 62 this.registry = registry; 63 attributes["archive.filename"] = file.getPath.toString(); 64 debug debugLog("* Loading the archive"); 65 load(file, loadall); 66 } 67 68 public this(FileBuffer file, bool loadall = true){ 69 this(new DefaultRegistry, file, loadall); 70 } 71 72 73 public void loadSymbolTable(char [] symtable) 44 const char[] ARCHID = "!<arch>\n"; 45 46 private ArchiveReader reader; 47 private char[] stringtable; 48 private uint [char[]] symbolOffsets; 49 50 private LoaderRegistry registry = null; 51 private DynamicModule[] modules; 52 private DynamicModule[char[]] crossReference; // modules by symbol name 53 private ExportSymbolPtr[char[]] dictionary; // symbols by symbol name 54 private Attributes attributes; 55 56 57 public this(LoaderRegistry registry, FileBuffer file, bool loadall = true){ 58 this.registry = registry; 59 attributes["archive.filename"] = file.getPath.toString(); 60 debug debugLog("* Loading the archive"); 61 load(file, loadall); 62 } 63 64 public this(FileBuffer file, bool loadall = true){ 65 this(new DefaultRegistry, file, loadall); 66 } 67 68 protected void loadSymbolTable(char [] symtable) 74 69 in { 75 70 assert (symtable.length >= 4); … … 101 96 } 102 97 } 103 104 public DynamicModule[] getModules(){ 105 return this.modules; 106 } 107 108 private char[] getModuleName(char[] filename){ 109 if(filename[0] == '/'){ 110 uint offset = Atoi.parse(Text.trim(filename[1..$])); 111 debug debugLog("* Finding filename in stringtable, length %s, starting at offset %s", stringtable.length, offset); 112 return stringtable[offset..Text.indexOf(stringtable[offset..$], "/")+offset]; 113 } 114 else{ 115 return filename[0..Text.indexOf(filename, r"/")]; 116 } 117 } 118 119 private void load(IBuffer data, bool loadall) { 120 121 //int nAddress; 122 char[] signature; 123 signature.length = ARCHID.length; 98 // returns the name of a module - for reporting/debugging purposes 99 protected char[] getModuleName(char[] filename){ 100 if(filename[0] == '/'){ 101 uint offset = Atoi.parse(Text.trim(filename[1..$])); 102 debug debugLog("* Finding filename in stringtable, length %s, starting at offset %s", stringtable.length, offset); 103 return stringtable[offset..Text.indexOf(stringtable[offset..$], "/")+offset]; 104 } 105 else{ 106 return filename[0..Text.indexOf(filename, r"/")]; 107 } 108 } 109 110 private void load(IBuffer data, bool loadall) { 111 //int nAddress; 112 char[] signature; 113 signature.length = ARCHID.length; 114 115 reader = new ArchiveReader(data); 116 debug debugLog("* Created an archive reader instance"); 117 118 // read the library signature 119 reader.get(signature, signature.length); 120 debug debugLog("* Read archive signature %s", signature); 121 122 if(signature != ARCHID){ 123 throw new DDLException("Archive " ~ attributes["archive.filename"] ~ " has invalid library signature."); 124 } 125 126 ArchiveHeader hdr; 127 char[] memberData; 128 char[] fName; 129 130 while(reader.hasMore()) 131 { 132 if (reader.getFile(hdr, memberData, fName) is null) { 133 debug debugLog("* ArchiveReader.getFile() returned null"); 134 break; 135 } 136 137 debug debugLog("* Iterating over files, current is %s", fName); 138 switch(fName){ 139 case "/": 140 // Need to check the next header 141 // If it has the same name, it is a 142 // PECOFF lib, otherwise it's an Ar-lib 143 ArchiveHeader tmphdr; 144 ubyte[] tmphdrarr; 145 reader.peek(tmphdrarr, ArchiveHeader.sizeof); 146 if (Text.trim(tmphdr.ar_name) == "/") { 147 // PECOFF archive 148 debug debugLog("* Found PECOFF archive"); 149 reader.getFile(hdr, memberData, fName); 150 loadSymbolTable(memberData.dup); 151 } 152 else { // Ar 153 loadSymbolTable(memberData.dup); 154 } 155 break; 156 case "//": 157 debug debugLog("* Extracting stringtable"); 158 stringtable = memberData.dup; 159 break; 160 default: 161 if (loadall) 162 loadModule(fName, memberData); 163 else return; 164 } 165 } 166 } 167 168 private void loadModule(char[] fName, char[] memberData, uint idx = -1) { 169 if (idx > 0) { 170 //TODO: allow for dynamic positioning into the input stream for lazy loading 171 //reader.setPosition(idx); 172 } 173 174 debug debugLog("* Loading module %s from archive", getModuleName(fName)); 175 debug debugLog("* file starts with: ", memberData[0..4]); 176 FileBuffer embeddedFile = new FileBuffer(getModuleName(fName),memberData); 177 DynamicLibrary dl = this.registry.load(embeddedFile); 178 179 foreach(mod; dl.getModules()){ 180 addModule(mod); 181 } 182 } 183 184 public DynamicModule[] getModules(){ 185 return this.modules; 186 } 187 188 public ExportSymbolPtr getSymbol(char[] name){ 189 ExportSymbolPtr* sym = name in dictionary; 190 if(sym) return *sym; 191 else return &ExportSymbol.NONE; 192 } 124 193 125 reader = new ArchiveReader(data); 126 debug debugLog("* Created an archive reader instance"); 127 128 // read the library signature 129 reader.get(signature, signature.length); 130 debug debugLog("* Read archive signature %s", signature); 131 132 if(signature != ARCHID){ 133 throw new DDLException("Archive " ~ attributes["archive.filename"] ~ " has invalid library signature."); 134 } 135 136 ArchiveHeader hdr; 137 char[] memberData; 138 char[] fName; 139 140 while(reader.hasMore()) 141 { 142 if (reader.getFile(hdr, memberData, fName) is null) { 143 debug debugLog("* ArchiveReader.getFile() returned null"); 144 break; 145 } 146 147 debug debugLog("* Iterating over files, current is %s", fName); 148 switch(fName){ 149 case "/": 150 // Need to check the next header 151 // If it has the same name, it is a 152 // PECOFF lib, otherwise it's an Ar-lib 153 ArchiveHeader tmphdr; 154 ubyte[] tmphdrarr; 155 reader.peek(tmphdrarr, ArchiveHeader.sizeof); 156 if (Text.trim(tmphdr.ar_name) == "/") { 157 // PECOFF archive 158 debug debugLog("* Found PECOFF archive"); 159 reader.getFile(hdr, memberData, fName); 160 loadSymbolTable(memberData.dup); 161 } 162 else { // Ar 163 loadSymbolTable(memberData.dup); 164 } 165 break; 166 case "//": 167 debug debugLog("* Extracting stringtable"); 168 stringtable = memberData.dup; 169 break; 170 default: 171 if (loadall) 172 loadModule(fName, memberData); 173 else return; 174 } 175 176 } 177 } 194 public char[] getType(){ 195 return "Archive"; 196 } 197 198 public Attributes getAttributes(){ 199 if(this.attributes != Attributes.init){ 200 return this.attributes; 201 } 202 } 203 178 204 179 private DynamicModule loadModule(char[] fName, char[] memberData, uint idx = -1) { 180 181 if (idx > 0) { 182 //TODO: Fix this 183 //reader.setPosition(idx); 184 } 185 186 debug debugLog("* Loading module %s from archive", getModuleName(fName)); 187 debug debugLog("* file starts with: ", memberData[0..4]); 188 FileBuffer embeddedFile = new FileBuffer(getModuleName(fName),memberData); 189 DynamicLibrary dl = this.registry.load(embeddedFile); 190 addModules(dl.getModules()); 191 return dl.getModules()[0]; 192 } 193 194 public ExportSymbol[] getExports(){ 195 return exports.values; 196 } 197 198 public ExportSymbol getExport(char[] name){ 199 debug debugLog("* Available exports: %s", exports.length); 200 if (name in exports){ 201 return exports[name]; 202 } 203 else if (name in symbolOffsets) { 204 //TODO : Fix this 205 //loadModule(symbolOffsets[mangleNamespace(name)]); 206 assert (name in exports); 207 return exports[name]; 208 } 209 else { 210 return ExportSymbol.NONE; 211 } 212 } 213 214 public char[] getType(){ 215 return "Archive"; 216 } 217 218 public Attributes getAttributes(){ 219 if(this.attributes != Attributes.init){ 220 return this.attributes; 221 } 222 } 223 224 //TODO: implement me 225 public DynamicModule getModuleForExport(char[] name){ 226 debug debugLog("* Getting module for export: %s", name); 227 debug debugLog("* Mangled input is %s", mangleNamespace(name)); 228 if (mangleNamespace(name) in symbolOffsets) { 229 debug debugLog("* Found symbol %s in offsetlist", name); 230 231 // TODO: Fix this 232 // return loadModule(symbolOffsets[mangleNamespace(name)]); 233 return null; 234 } 235 return null; 236 } 237 238 //TODO: implement me 239 public ubyte[] getResource(char[] name){ 240 return (ubyte[]).init; 241 } 242 243 private void addModule(DynamicModule mod){ 244 if (!exportsready){ 245 foreach(ExportSymbol es; mod.getExports()){ 246 exports[es.name] = es; 247 } 248 } 249 this.modules ~= mod; 250 } 251 252 private void addModules(DynamicModule[] modules){ 253 if (!exportsready){ 254 foreach(DynamicModule dm; modules){ 255 debug debugLog("* Adding %s exports", dm.getExports().length); 256 foreach(ExportSymbol es; dm.getExports()){ 257 exports[es.name] = es; 258 } 259 } 260 } 261 this.modules ~= modules; 262 } 263 205 //TODO: implement lazy loading of modules via the symbolOffsets table 206 public DynamicModule getModuleForSymbol(char[] name){ 207 debug debugLog("[AR] looking for " ~ name); 208 DynamicModule* mod = name in crossReference; 209 debug debugLog("[AR] Result: %0.8X",mod); 210 if(mod) return *mod; 211 } 212 213 // AR files have no resources 214 public ubyte[] getResource(char[] name){ 215 return (ubyte[]).init; 216 } 217 218 protected void addModule(DynamicModule mod){ 219 this.modules ~= mod; 220 auto symbols = mod.getSymbols(); 221 for(uint i=0; i<symbols.length; i++){ 222 ExportSymbolPtr exp = &(symbols[i]); 223 if(exp.name in crossReference){ 224 switch(exp.type){ 225 case SymbolType.Weak: // replace extern only 226 if(dictionary[exp.name].type == SymbolType.Extern){ 227 crossReference[exp.name] = mod; 228 dictionary[exp.name] = exp; 229 } 230 break; 231 case SymbolType.Strong: // always overwrite 232 crossReference[exp.name] = mod; 233 dictionary[exp.name] = exp; 234 break; 235 default: 236 // do nothing 237 } 238 } 239 else{ 240 crossReference[exp.name] = mod; 241 dictionary[exp.name] = exp; 242 } 243 } 244 } 245 246 /** 247 Helper function shift around the values present in the symbol table. 248 Will be used when the loadSymbolTable member is implemented. 249 */ 250 private uint sgetl(ubyte[] val) 251 in { 252 assert(val.length == 4); 253 } 254 body{ 255 return (val[0] << 24) | (val[1] << 16) | (val[2] << 8) | val[3]; 256 } 264 257 } 265 258 266 /** 267 Helper function shift around the values present in the symbol table. 268 Will be used when the loadSymbolTable member is implemented. 269 */ 270 private uint sgetl(ubyte[] val) 271 in { 272 assert(val.length == 4); 273 } 274 body{ 275 return (val[0] << 24) | (val[1] << 16) | (val[2] << 8) | val[3]; 276 } 277 259 ///////////////////////////////// 278 260 debug (UNITTEST) { 279 261 private import ddl.DefaultRegistry; … … 308 290 } 309 291 310 assert( sgetl(sputl(114)) == 114);292 assert(3(sputl(114)) == 114); 311 293 312 294 //TODO: unittest loadSymbolTable trunk/ddl/ar/ArchiveLoader.d
r195 r220 37 37 private import ddl.ar.ArchiveLibrary; 38 38 39 debug private import mango.io.Stdout;40 41 39 /** 42 40 An implementation of the abstract class DynamicLibraryLoader for trunk/ddl/elf/ELFBinary.d
r195 r220 49 49 50 50 class ELFBinary{ 51 52 private:53 Elf32_Ehdr elfhdr;54 Elf32_Shdr[] sechdrs;55 Elf32_Phdr[] proghdrs;56 Elf32_Sym[] globalSymbols;57 Elf32_Sym[] localSymbols;58 Elf32_Sym[] weakSymbols;59 60 Elf32_Sym[] symbols;61 62 ExportSymbol[char[]] exports;63 ExportSymbol[] unresolvedSymbols;64 65 char[] shnames;66 char[] dynsymnames;67 char[] symtabnames;68 69 bit dynamic;70 71 Attributes attributes;72 51 public: 52 Elf32_Ehdr elfhdr; 53 Elf32_Shdr[] sechdrs; 54 Elf32_Phdr[] proghdrs; 55 Elf32_Sym[] globalSymbols; 56 Elf32_Sym[] localSymbols; 57 Elf32_Sym[] weakSymbols; 58 59 Elf32_Sym[] symbols; 60 61 ExportSymbol[char[]] exports; 62 ExportSymbol[] unresolvedSymbols; 63 64 char[] shnames; 65 char[] dynsymnames; 66 char[] symtabnames; 67 68 bit dynamic; 69 70 Attributes attributes; 71 73 72 /** 74 73 Constructor. … … 78 77 79 78 /** 80 Loads an ELF object file from the provided data.81 82 Params: data = the ELF object file data83 */84 void load(IBuffer buffer){85 load(new ELFReader(buffer));86 }87 88 /**89 79 Loads an ELF object file from the provided reader. 90 80 … … 92 82 be read 93 83 */ 94 void load(ELFReader reader){ 95 parseObjectFile(reader); 96 resolveInternals(); 97 // TODO: Finish up, resolve and stuff 98 } 99 100 101 void parseObjectFile(ELFReader reader){ 84 void parse(ELFReader reader){ 102 85 // Read ELF Header 103 86 reader.get(elfhdr); … … 184 167 debugLog("section header size: %d",elfhdr.e_shentsize); 185 168 } 186 187 parseSections(reader); 188 189 } 190 191 protected void parseSections(ELFReader reader){ 169 192 170 // section header index for symbol table 193 171 uint symtableidx = -1; … … 280 258 } 281 259 282 protected void loadSymTable(uint idx, ELFReader reader) { 283 284 } 285 286 protected void parseSYMTAB(uint symbols, char[][uint] symbolNames, 287 ELFReader reader){ 288 for(int i=0; i<symbols; i++){ 289 Elf32_Sym sym; 290 reader.get(sym); 260 protected void loadSymTable(uint idx, ELFReader reader) { 261 262 } 263 264 protected void parseSYMTAB(uint symbols, char[][uint] symbolNames,ELFReader reader){ 265 for(int i=0; i<symbols; i++){ 266 Elf32_Sym sym; 267 reader.get(sym); 291 268 292 //TODO: refer to STB_LOCAL to ensure that symbols don't overlap269 //TODO: refer to STB_LOCAL to ensure that symbols don't overlap 293 270 294 ExportSymbol exportSym;295 debug debugLog("* Symbol name: %s", sym.st_name);296 exportSym.name = symbolNames[sym.st_name];297 debug debugLog("* Extracted symbol %s", exportSym.name);271 ExportSymbol exportSym; 272 debug debugLog("* Symbol name: %s", sym.st_name); 273 exportSym.name = symbolNames[sym.st_name]; 274 debug debugLog("* Extracted symbol %s", exportSym.name); 298 275 299 //TODO: resolve symbol data address by cracking the sym fields per the specification 300 } 301 } 302 303 protected void resolveInternals(){ 304 305 /* All of these aren't exportable symbols, methinks 306 foreach(Elf32_Sym symbol; symbols){ 307 ExportSymbol es; 308 es.address = cast(void*)symbol.st_value; 309 es.name = getNameString(dynamic ? dynsymnames : symtabnames, 310 symbol.st_name); 311 exports[es.name] = es; 312 } 313 */ 314 } 315 316 public bit isResolved(){ 317 return this.unresolvedSymbols.length == 0; 318 } 319 320 public ExportSymbol[] getExports(){ 321 return exports.values; 322 } 323 324 public ExportSymbol getExport(char[] name){ 325 debug debugLog("* Available exports: %s", exports.length); 326 if (!(name in exports)){ 327 return ExportSymbol.NONE; 328 } 329 return exports[name]; 330 } 331 332 public Attributes getAttributes(){ 333 if(this.attributes != Attributes.init){ 334 return this.attributes; 335 } 336 337 ELFPrinter printer = new ELFPrinter(); 338 char[] buf = new char[10]; 339 340 attributes["elf.header"] = printer.printElfHeader(elfhdr); 341 342 foreach(n,hdr; proghdrs){ 343 attributes["elf.proghdr" ~ Integer.format(buf,n)] = printer.printProgramHeader(n,hdr); 344 } 345 346 foreach(n,hdr; sechdrs){ 347 char[] name;// TODO: = shnames[hdr.sh_name]; 348 attributes["elf.sechdr" ~ Integer.format(buf,n)] = printer.printSectionHeader(n,name,hdr); 276 //TODO: resolve symbol data address by cracking the sym fields per the specification 349 277 } 350 351 foreach(n,sym; symbols){ 352 char[] name;// TODO: = symtabnames[sym.st_name]; 353 attributes["elf.symbol" ~ Integer.format(buf,n)] = printer.printSymbol(n,name,sym); 278 } 279 280 public Attributes getAttributes(){ 281 if(this.attributes != Attributes.init){ 282 return this.attributes; 354 283 } 355 284 356 285 return attributes; 357 } 358 286 } 287 288 char[] toString(){ 289 char[] result = ""; 290 ELFPrinter printer = new ELFPrinter(); 291 292 result ~= "Header:\n" ~ printer.printElfHeader(elfhdr); 293 result ~= "\n" ~ printer.printProgramHeaders(proghdrs); 294 result ~= "\n" ~ printer.printSectionHeaders(sechdrs); 295 result ~= "\n" ~ printer.printSymbols(symbols); 296 297 return result; 298 } 359 299 } 360 300 trunk/ddl/elf/ELFModule.d
r176 r220 44 44 */ 45 45 class ELFModule : DynamicModule{ 46 struct SegmentImage{ 47 void[] data; 48 } 49 50 struct Fixup{ 51 uint targetIndex; 52 bool isExternStyleFixup; 53 bool isSegmentRelative; 54 void* destAddress; 55 } 56 57 alias ExportSymbol* ExportSymbolPtr; 58 alias SegmentImage* SegmentImagePtr; 46 59 47 // ELFModule properties 48 ELFBinary binary; 49 char[] filename; 50 char[][char[]] dependencies; 60 Fixup[] fixups; 61 SegmentImage[] segmentImages; 62 ExportSymbol[] symbols; 63 ExportSymbolPtr[char[]] symbolXref; 64 char[] moduleName; 65 bool resolved; 66 67 debug ELFBinary binary; 51 68 52 /** 53 Constructor 54 55 Params: 56 file = DDLFile holding the data of the ELF object file. 57 */ 58 this(FileBuffer file){ 59 binary = new ELFBinary(); 60 binary.load(file); 61 this.filename = file.getPath.toString(); 62 // TODO: Add this later larsivi 20060109 63 // syncronizeSymbols(); 64 } 65 66 /** 67 Returns the module name. 68 */ 69 public char[] getName(){ 70 return filename; 71 } 72 /** 73 Returns the list of dependencies for this module. 74 */ 75 public char[][] getDependencies(){ 76 return dependencies.values; 77 } 78 79 /** 80 Resolves a dependency, given a name and an address. 81 82 Params: 83 name = the name of the symbol to resolve 84 address = the address of the symbol to resolve 85 */ 86 public void resolveDependency(char[] name,void* address){ 87 // TODO: Implement 88 assert(0); 89 } 90 91 /** 92 Resolves the given dependencies. 93 94 Params: 95 exports = a list of ExportSymbols to resolve 96 */ 97 public void resolveDependencies(ExportSymbol[] exports){ 98 // TODO: Implement 99 assert(0); 100 } 101 102 /** 103 Returns a list of the module's export symbols. 104 105 Returns: An ExportSymbol[], holding the symbols of the module. 106 */ 107 public ExportSymbol[] getExports(){ 108 return binary.getExports(); 109 } 110 111 /** 112 Returns the ExportSymbol for the given name. 113 114 Returns: An ExportSymbol for the provided name. 115 Params: 116 name = the name of the wanted export symbol 117 */ 118 public ExportSymbol getExport(char[] name){ 119 return binary.getExport(name); 120 } 121 122 /** 123 Returns true if all symbols are resolved. 124 */ 125 public bit isResolved(){ 126 return binary.isResolved(); 127 } 128 129 public Attributes getAttributes(){ 130 Attributes temp = binary.getAttributes; 131 super.getAttributes().copyInto(temp); 132 return temp; 133 } 69 this(FileBuffer buffer){ 70 resolved = false; 71 loadBinary(new DDLReader(buffer)); 72 } 73 74 this(DDLReader reader){ 75 resolved = false; 76 loadBinary(reader); 77 } 78 79 public char[] getName(){ 80 return moduleName; 81 } 82 83 public ExportSymbol[] getSymbols(){ 84 return symbols; 85 } 86 87 public ExportSymbol* getSymbol(char[] name){ 88 if(name in symbolXref) return symbolXref[name]; 89 else return &ExportSymbol.NONE; 90 } 91 92 public void resolveFixups(){ 93 Fixup[] remainingFixups; 94 95 foreach(idx,fix; fixups) with(fix){ 96 uint fixupValue; 97 } 98 99 this.fixups = remainingFixups; 100 } 101 102 public bool isResolved(){ 103 if(resolved) return true; 104 105 if(fixups.length > 0) return false; 106 foreach(sym; symbols){ 107 if(sym.type != SymbolType.Strong) return false; 108 } 109 resolved = true; 110 return true; 111 } 112 113 protected void loadBinary(DDLReader reader){ 114 if(debug) else{ 115 ELFBinary binary; 116 } 117 118 //TODO: analyze 119 } 120 121 char[] toString(){ 122 char[] result = ""; 123 ExtSprintClass sprint = new ExtSprintClass(1024); 124 125 if(debug){ 126 result = "ELF Binary Data: \n" ~ binary.toString(); 127 } 128 129 return result; 130 } 134 131 } trunk/ddl/elf/ELFPrinter.d
r180 r220 103 103 char[] result; 104 104 105 result ~= sprint(" Magic:\t%02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X ", m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9], m[10], m[11], m[12], m[13], m[14], m[15]);106 result ~= sprint(" Class:\t\t\t\t%s ", classStrings[m[EI_CLASS]]);107 result ~= sprint(" Data:\t\t\t\t\t%s ", dataStrings[m[EI_DATA]]);108 result ~= sprint(" Version:\t\t\t\t%s ", versionStrings[m[EI_VERSION]]);109 result ~= sprint(" Type:\t\t\t\t\t%s ", objectTypeStr(hdr.e_type));110 result ~= sprint(" Machine:\t\t\t\t%s ", machineStrings[hdr.e_machine]);111 result ~= sprint(" Version:\t\t\t\t0x%x ", hdr.e_version);112 result ~= sprint(" Entry point address:\t\t\t0x%x ", hdr.e_entry);113 result ~= sprint(" Start of program headers:\t\t%s (bytes into the file) ", hdr.e_phoff);114 result ~= sprint(" Start of section headers:\t\t%s (bytes into the file) ", hdr.e_shoff);115 result ~= sprint(" Flags:\t\t\t\t0x%x ", hdr.e_flags);116 result ~= sprint(" Size of this header:\t\t\t%s (bytes) ", hdr.e_ehsize);117 result ~= sprint(" Size of program headers:\t\t%s (bytes) ", hdr.e_phentsize);118 result ~= sprint(" Number of program headers:\t\t%s ", hdr.e_phnum);119 result ~= sprint(" Size of section headers:\t\t%s (bytes) ",hdr.e_shentsize);120 result ~= sprint(" Number of section headers:\t\t%s ",hdr.e_shnum);121 result ~= sprint(" Section header string table index:\t%s\n ", hdr.e_shstrndx);105 result ~= sprint(" Magic:\t%02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9], m[10], m[11], m[12], m[13], m[14], m[15]); 106 result ~= sprint(" Class:\t\t\t\t%s\n", classStrings[m[EI_CLASS]]); 107 result ~= sprint(" Data:\t\t\t\t\t%s\n", dataStrings[m[EI_DATA]]); 108 result ~= sprint(" Version:\t\t\t\t%s\n", versionStrings[m[EI_VERSION]]); 109 result ~= sprint(" Type:\t\t\t\t\t%s\n", objectTypeStr(hdr.e_type)); 110 result ~= sprint(" Machine:\t\t\t\t%s\n", machineStrings[hdr.e_machine]); 111 result ~= sprint(" Version:\t\t\t\t0x%x\n", hdr.e_version); 112 result ~= sprint(" Entry point address:\t\t\t0x%x\n", hdr.e_entry); 113 result ~= sprint(" Start of program headers:\t\t%s (bytes into the file)\n", hdr.e_phoff); 114 result ~= sprint(" Start of section headers:\t\t%s (bytes into the file)\n", hdr.e_shoff); 115 result ~= sprint(" Flags:\t\t\t\t0x%x\n", hdr.e_flags); 116 result ~= sprint(" Size of this header:\t\t\t%s (bytes)\n", hdr.e_ehsize); 117 result ~= sprint(" Size of program headers:\t\t%s (bytes)\n", hdr.e_phentsize); 118 result ~= sprint(" Number of program headers:\t\t%s\n", hdr.e_phnum); 119 result ~= sprint(" Size of section headers:\t\t%s (bytes)\n",hdr.e_shentsize); 120 result ~= sprint(" Number of section headers:\t\t%s\n",hdr.e_shnum); 121 result ~= sprint(" Section header string table index:\t%s\n\n", hdr.e_shstrndx); 122 122 123 123 return(result); 124 124 } 125 125 126 126 public char[] printProgramHeader(uint n, Elf32_Phdr hdr){ 127 127 char[] result; 128 128 129 result ~= sprint("Program header %d .", n);130 result ~= sprint(" Type:\t\t\t\t%s ", segmentTypeStr(hdr.p_type));131 result ~= sprint(" Offset:\t\t\t0x%x ", hdr.p_offset);132 result ~= sprint(" Virtual address:\t\t0x%x ", hdr.p_vaddr);133 result ~= sprint(" Physical address:\t\t0x%x ", hdr.p_paddr);134 result ~= sprint(" Size in file:\t\t\t%d (in bytes) ", hdr.p_filesz);135 result ~= sprint(" Size in memory:\t\t%d (in bytes) ", hdr.p_offset);136 result ~= sprint(" Flags:\t\t\t0x%x ", hdr.p_flags);129 result ~= sprint("Program header %d\n", n); 130 result ~= sprint(" Type:\t\t\t\t%s\n", segmentTypeStr(hdr.p_type)); 131 result ~= sprint(" Offset:\t\t\t0x%x\n", hdr.p_offset); 132 result ~= sprint(" Virtual address:\t\t0x%x\n", hdr.p_vaddr); 133 result ~= sprint(" Physical address:\t\t0x%x\n", hdr.p_paddr); 134 result ~= sprint(" Size in file:\t\t\t%d (in bytes)\n", hdr.p_filesz); 135 result ~= sprint(" Size in memory:\t\t%d (in bytes)\n", hdr.p_offset); 136 result ~= sprint(" Flags:\t\t\t0x%x\n", hdr.p_flags); 137 137 result ~= sprint(" Alignment:\t\t\t%d\n", hdr.p_align); 138 138 … … 140 140 } 141 141 142 public char[] printProgramHeaders(Elf32_Phdr[] headers){ 143 char[] result = sprint("Program Headers: %d\n",headers.length); 144 foreach(idx,hdr; headers) result ~= printProgramHeader(idx,hdr); 145 return result; 146 } 147 142 148 public char[] printSectionHeader(uint n, char[] name, Elf32_Shdr hdr){ 143 149 char[] result; 144 150 145 result ~= sprint("Section header %d: %s ", n, name);146 result ~= sprint(" Type:\t\t\t\t%s ", sectionTypeStr(hdr.sh_type));147 result ~= sprint(" Flags:\t\t\t0x%x ", hdr.sh_flags);148 result ~= sprint(" Memory address:\t\t0x%x ", hdr.sh_addr);149 result ~= sprint(" File offset:\t\t\t%d ", hdr.sh_offset);150 result ~= sprint(" Size:\t\t\t\t%d (in bytes) ", hdr.sh_size);151 result ~= sprint(" Linked section:\t\t%d ", hdr.sh_link);152 result ~= sprint(" Info:\t\t\t\t%d ", hdr.sh_info);153 result ~= sprint(" Alignment:\t\t\t%d ", hdr.sh_addralign);151 result ~= sprint("Section header %d: %s\n", n, name); 152 result ~= sprint(" Type:\t\t\t\t%s\n", sectionTypeStr(hdr.sh_type)); 153 result ~= sprint(" Flags:\t\t\t0x%x\n", hdr.sh_flags); 154 result ~= sprint(" Memory address:\t\t0x%x\n", hdr.sh_addr); 155 result ~= sprint(" File offset:\t\t\t%d\n", hdr.sh_offset); 156 result ~= sprint(" Size:\t\t\t\t%d (in bytes)\n", hdr.sh_size); 157 result ~= sprint(" Linked section:\t\t%d\n", hdr.sh_link); 158 result ~= sprint(" Info:\t\t\t\t%d\n", hdr.sh_info); 159 result ~= sprint(" Alignment:\t\t\t%d\n", hdr.sh_addralign); 154 160 result ~= sprint(" Entry size:\t\t\t%d (in bytes)\n", hdr.sh_entsize); 155 161 … … 157 163 } 158 164 165 public char[] printSectionHeaders(Elf32_Shdr[] headers){ 166 char[] result = sprint("Headers: %d\n",headers.length); 167 char[] name = ""; //TODO 168 foreach(idx,hdr; headers) result ~= printSectionHeader(idx,name,hdr); 169 return result; 170 } 171 159 172 public char[] printSymbol(uint n, char[] name, Elf32_Sym sym){ 160 173 char[] result; 161 174 162 result ~= sprint("Symbol %d: %s ", n, name);163 result ~= sprint(" Value:\t\t\t0x%x ", sym.st_value);164 result ~= sprint(" Size:\t\t\t%d ", sym.st_size);165 result ~= sprint(" Info:\t\t\t%d ", sym.st_info);166 result ~= sprint(" Other:\t\t\t%d ", sym.st_other);175 result ~= sprint("Symbol %d: %s\n", n, name); 176 result ~= sprint(" Value:\t\t\t0x%x\n", sym.st_value); 177 result ~= sprint(" Size:\t\t\t%d\n", sym.st_size); 178 result ~= sprint(" Info:\t\t\t%d\n", sym.st_info); 179 result ~= sprint(" Other:\t\t\t%d\n", sym.st_other); 167 180 result ~= sprint(" Section index:\t\t%d\n", sym.st_shndx); 168 181 169 182 return(result); 170 183 } 184 185 public char[] printSymbols(Elf32_Sym[] symbols){ 186 char[] result = sprint("Symbols: %d\n",symbols.length); 187 char[] name = ""; //TODO 188 foreach(idx,sym; symbols) result ~= printSymbol(idx,name,sym); 189 return result; 190 } 171 191 } trunk/ddl/omf/OMFBinary.d
r219 r220 359 359 uint destSegmentIndex; 360 360 uint destOffset; 361 uint destNameIndex; // symbol name of referenced COMDAT 361 362 uint targetIndex; // external reference 362 363 bool isExternStyleFixup; // true if this uses an external index as a target, false if it is a segment index … … 393 394 Temporary record usd to store LIDATA, LEDATA and COMDAT address information for 394 395 subsequent use by FIXUPP records 396 397 TODO: fashion a "Fixup Source" that optionally references COMDAT symbol by name 398 so 399 395 400 **/ 396 401 struct FixupData{ … … 398 403 uint segmentIndex; 399 404 uint offset; 405 OMFIndex destNameIndex; 400 406 FixupThread[4] frameThreads; 401 407 FixupThread[4] targetThreads; … … 451 457 //bit isSegmentRelativeFixup = (type & 0b01000000) != 0; 452 458 location = (type & 0b00111100) >> 2; 453 uint offset2 = offset | ((type & 0b00000011) << 8); // get the high-order bits from the 'locat'459 uint offset2 = cast(uint)offset | ((type & 0b00000011) << 8); // get the high-order bits from the 'locat' 454 460 455 461 // get the 'fix data' byte … … 500 506 fix.destSegmentIndex = fixupData.segmentIndex; 501 507 fix.destOffset = fixupData.offset + offset2; 508 fix.destNameIndex = fixupData.destNameIndex; 502 509 fix.targetIndex = targetDatum; 503 510 //NOTE: assumes that non extern fixups are segment fixups … … 545 552 fixupData.segmentIndex = data.segmentIndex; 546 553 fixupData.offset = data.offset; 554 fixupData.destNameIndex = 0; 547 555 } 548 556 … … 610 618 fixupData.segmentIndex = data.segmentIndex; 611 619 fixupData.offset = data.offset; 620 fixupData.destNameIndex = 0; 612 621 } 613 622 … … 773 782 fixupData.groupIndex = data.groupIndex; 774 783 fixupData.segmentIndex = data.segmentIndex; 775 fixupData.offset = data.enumDataOffset; 784 fixupData.offset = data.enumDataOffset; 785 fixupData.destNameIndex = data.nameIndex; 776 786 777 787 if(!data.isContinuation){ &nb
