Changeset 85
- Timestamp:
- 12/17/05 17:08:57 (3 years ago)
- Files:
-
- trunk/buildutils.bat (modified) (2 diffs)
- trunk/clean.bat (modified) (1 diff)
- trunk/ddl/DynamicLibrary.d (modified) (1 diff)
- trunk/ddl/DynamicLibraryLoader.d (modified) (1 diff)
- trunk/ddl/Linker.d (modified) (5 diffs)
- trunk/ddl/all.d (modified) (1 diff)
- trunk/ddl/coff/COFFImage.d (modified) (2 diffs)
- trunk/ddl/coff/COFFLibrary.d (modified) (15 diffs)
- trunk/ddl/coff/COFFLoader.d (modified) (1 diff)
- trunk/ddl/coff/COFFModule.d (modified) (1 diff)
- trunk/ddl/coff/COFFObject.d (modified) (10 diffs)
- trunk/ddl/coff/COFFWrite.d (modified) (1 diff)
- trunk/ddl/ddl/DDLBinary.d (modified) (3 diffs)
- trunk/ddl/ddl/DDLLibrary.d (modified) (2 diffs)
- trunk/ddl/ddl/DDLLoader.d (modified) (1 diff)
- trunk/ddl/elf/ELFLoader.d (modified) (1 diff)
- trunk/ddl/insitu/InSituBinary.d (modified) (1 diff)
- trunk/ddl/insitu/InSituLibBinary.d (modified) (2 diffs)
- trunk/ddl/insitu/InSituLibrary.d (modified) (2 diffs)
- trunk/ddl/insitu/InSituLoader.d (modified) (2 diffs)
- trunk/ddl/insitu/InSituMapBinary.d (modified) (3 diffs)
- trunk/ddl/insitu/InSituModule.d (modified) (1 diff)
- trunk/ddl/omf/OMFBinary.d (modified) (18 diffs)
- trunk/ddl/omf/OMFLibrary.d (modified) (5 diffs)
- trunk/ddl/omf/OMFLoader.d (modified) (1 diff)
- trunk/ddl/omf/OMFModule.d (modified) (3 diffs)
- trunk/ddl/omf/all.d (modified) (1 diff)
- trunk/ddoc/install/static/ddl.spec.xml (modified) (1 diff)
- trunk/doc/html/classes.html (modified) (2 diffs)
- trunk/doc/html/methods.html (modified) (1 diff)
- trunk/doc/html/module-tree.html (modified) (3 diffs)
- trunk/doc/html/module.ddl.Demangle.html (modified) (1 diff)
- trunk/doc/html/module.ddl.DynamicLibrary.html (modified) (1 diff)
- trunk/doc/html/module.ddl.DynamicLibraryLoader.html (modified) (2 diffs)
- trunk/doc/html/module.ddl.DynamicModule.html (modified) (1 diff)
- trunk/doc/html/module.ddl.ExportSymbol.html (modified) (1 diff)
- trunk/doc/html/module.ddl.Linker.html (modified) (3 diffs)
- trunk/doc/html/module.ddl.Mangle.html (modified) (1 diff)
- trunk/doc/html/module.ddl.all.html (modified) (1 diff)
- trunk/doc/html/module.ddl.bootstrap.html (modified) (1 diff)
- trunk/doc/html/module.ddl.coff.COFF.html (modified) (1 diff)
- trunk/doc/html/module.ddl.coff.COFFBinary.html (modified) (1 diff)
- trunk/doc/html/module.ddl.coff.COFFImage.html (modified) (1 diff)
- trunk/doc/html/module.ddl.coff.COFFLibrary.html (modified) (1 diff)
- trunk/doc/html/module.ddl.coff.COFFLoader.html (modified) (1 diff)
- trunk/doc/html/module.ddl.coff.COFFModule.html (modified) (1 diff)
- trunk/doc/html/module.ddl.coff.COFFObject.html (modified) (1 diff)
- trunk/doc/html/module.ddl.coff.COFFWrite.html (modified) (1 diff)
- trunk/doc/html/module.ddl.coff.cursor.html (modified) (1 diff)
- trunk/doc/html/module.ddl.ddl.DDLBinary.html (modified) (3 diffs)
- trunk/doc/html/module.ddl.ddl.DDLLibrary.html (modified) (1 diff)
- trunk/doc/html/module.ddl.ddl.DDLLoader.html (modified) (1 diff)
- trunk/doc/html/module.ddl.dll.DLLLoader.html (modified) (1 diff)
- trunk/doc/html/module.ddl.elf.ELFLoader.html (modified) (1 diff)
- trunk/doc/html/module.ddl.insitu.InSituBinary.html (modified) (1 diff)
- trunk/doc/html/module.ddl.insitu.InSituLibBinary.html (modified) (1 diff)
- trunk/doc/html/module.ddl.insitu.InSituLibrary.html (modified) (1 diff)
- trunk/doc/html/module.ddl.insitu.InSituLoader.html (modified) (1 diff)
- trunk/doc/html/module.ddl.insitu.InSituMapBinary.html (modified) (1 diff)
- trunk/doc/html/module.ddl.insitu.InSituModule.html (modified) (1 diff)
- trunk/doc/html/module.ddl.omf.OMFBinary.html (modified) (1 diff)
- trunk/doc/html/module.ddl.omf.OMFException.html (modified) (1 diff)
- trunk/doc/html/module.ddl.omf.OMFLibrary.html (modified) (1 diff)
- trunk/doc/html/module.ddl.omf.OMFLoader.html (modified) (1 diff)
- trunk/doc/html/module.ddl.omf.OMFModule.html (modified) (1 diff)
- trunk/doc/html/module.ddl.omf.RecordCursor.html (modified) (1 diff)
- trunk/doc/html/modules.html (modified) (3 diffs)
- trunk/utils/bless.d (modified) (6 diffs)
- trunk/utils/ddlinfo.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/buildutils.bat
r66 r85 1 1 @echo off 2 2 3 echo UTILS:Building 3 4 build -full utils\ddlinfo.d 4 5 build -full utils\bless.d … … 9 10 copy insitu.map utils 10 11 11 zip ../downloads/ddl.utils.1.0.bin.zip utils/*.exe 12 echo UTILS:Packaging Win32 Binaries 13 rm ../downloads/ddl.beta.utils.1.0.win32.bin.zip 14 zip ../downloads/ddl.beta.utils.1.0.win32.bin.zip utils/*.exe 15 16 echo UTILS:Packaging Source 17 rm ../downloads/ddl.beta.utils.1.0.src.zip 18 zip ../downloads/ddl.beta.utils.1.0.src.zip utils/*.d trunk/clean.bat
r66 r85 1 @echo off 2 3 echo CLEAN:cleaning files 1 4 del /s ddl\*.obj 2 5 del /s ddl\*.html trunk/ddl/DynamicLibrary.d
r66 r85 41 41 public ExportSymbol getExport(char[] name); 42 42 public DynamicModule[] getModules(); 43 public char[] getType(); 44 public char[][char[]] getAttributes(); 43 45 44 46 public void* getExportAddress(char[] name){ trunk/ddl/DynamicLibraryLoader.d
r66 r85 33 33 34 34 private import ddl.DynamicLibrary; 35 private import std.stream; 36 private import std.string; 37 38 interface DynamicLibraryLoader{ 39 public DynamicLibrary loadFromFile(char[] filename); 40 public DynamicLibrary loadFromStream(Stream stream); 41 } 42 43 package static DynamicLibraryLoader[char[]] loaders; 35 private import ddl.LoaderRegistry; 36 private import ddl.Utils; 44 37 45 38 /** 46 Loads a DDL supported binary from a file. 39 Base class for all dynamic library loaders. 40 */ 41 abstract class DynamicLibraryLoader{ 42 /** 43 Returns: the type for this library. 44 */ 45 public char[] getLibraryType(); 47 46 48 Params: 49 filename = The filename of the binary file to load. 50 */ 51 DynamicLibrary loadDDL(char[] filename){ 52 uint split = filename.irfind("."); 53 if(split == -1) return null; 47 /** 48 Returns: the preferred file extension for this library. 49 */ 50 public char[] getFileExtension(); 54 51 55 char[] extension = filename[split+1..$]; 52 /** 53 Returns: true if the file can be loaded by this loader, false if it cannot. 54 */ 55 public bit canLoadLibrary(DDLFile file); 56 56 57 return loadDDL(filename,extension); 57 /** 58 Loads a binary file. 59 60 Returns: the library stored in the provided file. 61 Params: 62 file = the file that contains the binary library data. 63 */ 64 public DynamicLibrary load(LoaderRegistry registry,DDLFile file); 58 65 } 59 60 /**61 Loads a DDL supported binary from a file.62 63 Params:64 filename = The filename of the binary file to load.65 extension = The true extension/type of the binary file.66 */67 DynamicLibrary loadDDL(char[] filename,char[] extension){68 if(!(extension in loaders)) return null;69 70 DynamicLibraryLoader loader = loaders[extension];71 72 return loader.loadFromFile(filename);73 }74 75 /**76 Returns a list of extensions currently supported.77 */78 char[][] getDDLSupportedExtensions(){79 return loaders.keys;80 }trunk/ddl/Linker.d
r66 r85 30 30 module ddl.Linker; 31 31 32 //private import ddl.CachedLoader;32 private import ddl.Utils; 33 33 private import ddl.ExportSymbol; 34 34 private import ddl.DynamicLibrary; 35 35 private import ddl.DynamicModule; 36 36 private import ddl.Demangle; 37 38 debug private import std.stdio; 39 40 private import std.moduleinit; // used for ModuleInfo 37 private import ddl.LoaderRegistry; 38 39 private import std.moduleinit; // used for ModuleInfo type 41 40 42 41 /** … … 71 70 General-Purpose runtime linker for DDL. 72 71 */ 73 class Linker{ 72 class Linker{ 73 protected LoaderRegistry registry; 74 74 /** 75 75 Library list for libraries used for linking. … … 92 92 93 93 /** 94 Default constructor. 95 */ 96 public this(){ 97 // do nothing 98 } 99 100 /** 101 Adds a library to the linker to be used during link operations. 102 */ 103 void add(DynamicLibrary lib){ 104 debug foreach(DynamicModule mod; lib.getModules){ 105 writefln("add: %s",mod.getName); 106 } 107 libraries ~= lib; 94 The linker uses an LoaderRegistry to handle internal library dependencies 95 automatically, such that the developer can more easily automate linking behavior. 96 97 Params: 98 registry = the LoaderRegistry to use when loading binaries. 99 */ 100 public this(LoaderRegistry registry){ 101 this.registry = registry; 102 } 103 104 /** 105 Returns: the current registry 106 */ 107 public LoaderRegistry getRegistry(){ 108 return this.registry; 108 109 } 109 110 … … 174 175 nextDep: 175 176 debug if(sym == ExportSymbol.init){ 176 writefln("cannot find %s",dep);177 debugLog("[Linker.link]: cannot find %s",dep); 177 178 } 178 179 } … … 217 218 } 218 219 } 220 221 222 /** 223 Registers a library with the linker to be used during link operations. 224 */ 225 void register(DynamicLibrary lib){ 226 debug foreach(DynamicModule mod; lib.getModules){ 227 debugLog("[Linker.register]: %s",mod.getName); 228 } 229 libraries ~= lib; 230 } 231 232 /** 233 Loads a DDL library and registers it with this linker. 234 235 Returns: the DynamicLibrary that corresponds to filename 236 Params: 237 filename = the file name of the library to load 238 */ 239 public DynamicLibrary loadAndRegister(char[] filename){ 240 DynamicLibrary result = registry.load(filename); 241 register(result); 242 return result; 243 } 244 245 /** 246 Loads a DDL library and links it against all registered libraries. 247 248 Returns: the DynamicLibrary that corresponds to filename 249 Params: 250 filename = the file name of the library to load 251 */ 252 public DynamicLibrary loadAndLink(char[] filename){ 253 DynamicLibrary result = registry.load(filename); 254 link(result); 255 return result; 256 } 257 258 /** 259 Loads a DDL library, links it against all registered libraries, and registers it. 260 261 Returns: the DynamicLibrary that corresponds to filename 262 Params: 263 filename = the file name of the library to load 264 */ 265 public DynamicLibrary loadLinkAndRegister(char[] filename){ 266 DynamicLibrary result = registry.load(filename); 267 link(result); 268 register(result); 269 return result; 270 } 219 271 } trunk/ddl/all.d
r66 r85 25 25 module ddl.all; 26 26 27 // low level support 27 import ddl.DynamicLibrary; 28 import ddl.DefaultRegistry; 29 import ddl.DynamicLibraryLoader; 30 import ddl.DynamicModule; 28 31 import ddl.ExportSymbol; 29 import ddl.DynamicModule;30 import ddl.DynamicLibrary;31 import ddl.DynamicLibraryLoader;32 32 import ddl.Demangle; 33 import ddl.bootstrap;34 33 import ddl.Linker; 34 import ddl.LoaderRegistry; 35 import ddl.Mangle; 36 import ddl.Utils; 37 trunk/ddl/coff/COFFImage.d
r55 r85 4 4 //////////////////////////////////////////////////////////////////////////////////////////////////////////////// 5 5 6 private import ddl.all; 6 private import ddl.ExportSymbol; 7 private import ddl.Utils; 8 7 9 private import ddl.coff.COFF; 8 10 private import ddl.coff.COFFBinary; 9 11 private import ddl.coff.COFFObject; 10 //private import ddl.coff.codeview; 11 //private import ddl.coff.petools; 12 //private import ddl.coff.symbols; 13 14 15 //private import windows.win32; 16 //private import windows.winnt; 12 17 13 private import std.string; 18 14 private import std.stdio; … … 141 137 uint debug_dir = RVA2Offset( datadir.Debug.RVA ); 142 138 uint dircnt = datadir.Debug.Size / COFFImageDebugDirectory.sizeof; 143 // debug writefln( "Found %d debug director%s at file position 0x%X\n",dircnt,dircnt==1?"y":"ies",debug_dir);139 // debugLog( "Found %d debug director%s at file position 0x%X\n",dircnt,dircnt==1?"y":"ies",debug_dir); 144 140 145 141 // read debug directory trunk/ddl/coff/COFFLibrary.d
r56 r85 4 4 5 5 //import ddl.coff.coff; 6 import ddl.coff.COFFBinary; 7 import ddl.coff.COFFModule; 8 import ddl.coff.COFFWrite; 9 10 private import ddl.all; 6 private import ddl.coff.cursor; 7 private import ddl.coff.COFFBinary; 8 private import ddl.coff.COFFModule; 9 private import ddl.coff.COFFWrite; 10 11 private import ddl.ExportSymbol; 12 private import ddl.DynamicLibrary; 13 private import ddl.DynamicModule; 14 private import ddl.Utils; 11 15 12 16 private import std.string; … … 45 49 loadFromStream(stream); 46 50 } 47 51 52 public this(DataCursor cur){ 53 loadFromCursor(cur); 54 } 55 56 public char[] getType(){ 57 return("COFF"); 58 } 59 60 public char[][char[]] getAttributes(){ 61 return (char[][char[]]).init; //TODO: support this 62 } 63 48 64 public ExportSymbol[] getExports() 49 65 { … … 80 96 81 97 // print debug output 82 debug writefln( "File: ", filename );83 debug writefln( "File type: COFF LIBRARY\n" );98 debug debugLog( "File: ", filename ); 99 debug debugLog( "File type: COFF LIBRARY\n" ); 84 100 85 101 // open & parse the file … … 87 103 loadFromStream( libFile ); 88 104 libFile.close(); 105 } 106 107 void loadFromCursor(DataCursor cur){ 108 //TODO: 89 109 } 90 110 … … 112 132 while( !file.eof() ) 113 133 { 114 // debug writefln( "reading library member header %d - %d bytes left", i, file.available );134 // debug debugLog( "reading library member header %d - %d bytes left", i, file.available ); 115 135 116 136 // each member header starts on the first even address after the end of the previous archive member 117 137 if( ( nAddress & 1 ) == 1 ) 118 138 { 119 // debug writefln( "* padding data address" );139 // debug debugLog( "* padding data address" ); 120 140 byte bTemp; 121 141 file.read( bTemp ); … … 168 188 // link member #1 - skip 169 189 assert( itemName == "/" ); 170 debug writefln( "\nLIB MEMBER #1 - 1st Linker Member - obsolete" );190 debug debugLog( "\nLIB MEMBER #1 - 1st Linker Member - obsolete" ); 171 191 // next member 172 192 i++; … … 179 199 assert( itemName == "/" ); 180 200 181 debug writefln( "\nLIB MEMBER #2 - 2nd Linker Member - symbols table" );201 debug debugLog( "\nLIB MEMBER #2 - 2nd Linker Member - symbols table" ); 182 202 183 203 // load linker symbol … … 187 207 uint numModules = (*cast(uint*)dataPtr); 188 208 uint[] moduleOffsets; 189 debug writefln( "\t\tNumber of members: ", numModules );209 debug debugLog( "\t\tNumber of members: ", numModules ); 190 210 191 211 // increment data … … 198 218 foreach( int index, uint offset; moduleOffsets ) 199 219 { 200 // writefln( "\t\t\t%d - 0x%08x", index, offset );220 // debugLog( "\t\t\t%d - 0x%08x", index, offset ); 201 221 } 202 222 } … … 208 228 // get number of symbols 209 229 numSymbols = (*cast(uint*)dataPtr); 210 debug writefln( "\t\tNumber of symbols: ", numSymbols );230 debug debugLog( "\t\tNumber of symbols: ", numSymbols ); 211 231 212 232 // increment data … … 220 240 { 221 241 assert( offset <= numModules ); 222 // writefln( "\t\t\t%d - archive %d", index, offset );242 // debugLog( "\t\t\t%d - archive %d", index, offset ); 223 243 } 224 244 } … … 232 252 char[] symbolName = std.string.toString( dataPtr ); 233 253 dataPtr += symbolName.length + 1; 234 // writefln( "\t\t\t%d - ", symbolIndex, symbolName );254 // debugLog( "\t\t\t%d - ", symbolIndex, symbolName ); 235 255 236 256 // place symbol into table … … 246 266 if( (i == 2) && (itemName == "//") ) 247 267 { 248 debug writefln( "\nLIB MEMBER #3 - 3rd Linker Member - longnames table" );268 debug debugLog( "\nLIB MEMBER #3 - 3rd Linker Member - longnames table" ); 249 269 250 270 // longnames list … … 278 298 writef( "\nLIB MEMBER #", std.conv.toString(i+1) ); 279 299 if( importObj ) 280 writefln( " - COFF IMPORT OBJECT\n" );300 debugLog( " - COFF IMPORT OBJECT\n" ); 281 301 else 282 writefln( " - COFF OBJECT\n" );283 writefln( "\tname ", itemName );284 writefln( "\tdate ", strDate );285 writefln( "\tuser ", itemUser );286 writefln( "\tgroup ", itemGroup );287 writefln( "\tmode ", itemMode );288 writefln( "\tsize ", itemSize );302 debugLog( " - COFF OBJECT\n" ); 303 debugLog( "\tname ", itemName ); 304 debugLog( "\tdate ", strDate ); 305 debugLog( "\tuser ", itemUser ); 306 debugLog( "\tgroup ", itemGroup ); 307 debugLog( "\tmode ", itemMode ); 308 debugLog( "\tsize ", itemSize ); 289 309 } 290 310 … … 375 395 } 376 396 377 debug writefln( "COFF library parsing complete" );397 debug debugLog( "COFF library parsing complete" ); 378 398 379 399 //skip the dictionary (redundant) trunk/ddl/coff/COFFLoader.d
r58 r85 4 4 import ddl.coff.COFFModule; 5 5 import ddl.coff.COFFLibrary; 6 import ddl.coff.cursor; 6 7 7 private import ddl.all; 8 private import std.stream; 8 private import ddl.ExportSymbol; 9 private import ddl.DynamicLibrary; 10 private import ddl.DynamicLibraryLoader; 11 private import ddl.LoaderRegistry; 12 private import ddl.Utils; 9 13 10 class COFFLoader : DynamicLibraryLoader 11 { 12 public DynamicLibrary loadFromFile(char[] filename) 13 { 14 return new COFFLibrary(filename); 14 class COFFLibLoader : DynamicLibraryLoader{ 15 public static char[] typeName = "COFFLIB"; 16 public static char[] fileExtension = "lib"; 17 18 public char[] getLibraryType(){ 19 return(typeName); 15 20 } 16 17 public DynamicLibrary loadFromStream(Stream stream) 18 { 19 return new COFFLibrary(stream); 21 22 public char[] getFileExtension(){ 23 return(fileExtension); 24 } 25 26 public bit canLoadLibrary(DDLFile file){ 27 return file.buffer[0..8] == cast(ubyte[])"!<arch>\n"; 28 } 29 30 public DynamicLibrary load(LoaderRegistry registry,DDLFile file){ 31 DataCursor cur; 32 cur.data = cast(char[])file.buffer; 33 cur.position = 0; 34 35 return new COFFLibrary(cur); 20 36 } 21 37 } 22 38 23 24 class COFFObjLoader : DynamicLibraryLoader 25 { 26 public bit canLoad(char[] filename)27 {28 return (filename.length >= 4) && (filename[$-4..$] == ".obj");39 class COFFObjLoader : DynamicLibraryLoader{ 40 public static char[] typeName = "COFFOBJ"; 41 public static char[] fileExtension = "obj"; 42 43 public char[] getLibraryType(){ 44 return(typeName); 29 45 } 30 31 public DynamicLibrary loadFromStream(Stream stream) 32 { 46 47 public char[] getFileExtension(){ 48 return(fileExtension); 49 } 50 51 public bit canLoadLibrary(DDLFile file){ 52 return file.buffer[0] == 0x4c && file.buffer[1] == 0x01; 53 } 54 55 public DynamicLibrary load(LoaderRegistry registry,DDLFile file){ 33 56 COFFLibrary lib = new COFFLibrary(); 34 57 35 58 // load object format 36 COFFModule mod = new COFFModule(stream); 59 DataCursor cur; 60 cur.data = cast(char[])file.buffer; 61 cur.position = 0; 62 63 COFFModule mod = new COFFModule(cur,file.filename); 37 64 lib.addModule(mod); 38 39 return lib;40 }41 42 public DynamicLibrary loadFromFile(char[] filename)43 {44 assert(filename.length >= 4);45 46 COFFLibrary lib = new COFFLibrary();47 48 // load object format49 COFFModule mod = new COFFModule(filename);50 lib.addModule(mod);51 52 65 return lib; 53 66 } 54 67 } 68 69 class COFFPELoader : DynamicLibraryLoader{ 70 public static char[] typeName = "COFFDLL"; 71 public static char[] fileExtension = "dll"; //TODO: what about .exe? 72 73 public char[] getLibraryType(){ 74 return(typeName); 75 } 76 77 public char[] getFileExtension(){ 78 return(fileExtension); 79 } 80 81 public bit canLoadLibrary(DDLFile file){ 82 return file.buffer[0] == 'M' && file.buffer[1] == 'Z'; 83 } 84 85 public DynamicLibrary load(LoaderRegistry registry,DDLFile file){ 86 throw new Exception("COFF/PE files are not supported"); 87 return null; 88 } 89 } trunk/ddl/coff/COFFModule.d
r57 r85 3 3 module ddl.coff.COFFModule; 4 4 5 import ddl.all; 6 import ddl.coff.COFF; 7 import ddl.coff.COFFBinary; 8 import ddl.coff.COFFObject; 9 import ddl.coff.cursor; 5 private import ddl.ExportSymbol; 6 private import ddl.DynamicModule; 7 private import ddl.Utils; 8 9 private import ddl.coff.COFF; 10 private import ddl.coff.COFFBinary; 11 private import ddl.coff.COFFObject; 12 private import ddl.coff.cursor; 13 10 14 11 15 private import std.string; trunk/ddl/coff/COFFObject.d
r58 r85 3 3 // COFF Object class (.obj file) 4 4 5 import ddl.all;6 7 import ddl.coff.COFF; 8 import ddl.coff.COFFBinary;9 //import ddl.coff.coffwrite;5 private import ddl.ExportSymbol; 6 private import ddl.Utils; 7 8 private import ddl.coff.COFF; 9 private import ddl.coff.COFFBinary; 10 10 11 11 private import std.string; … … 115 115 this.name = getBaseName( filename ).dup; 116 116 117 debugwritefln( "COFFObject - load from file: %s (%s)", this.filename, this.name );117 writefln( "COFFObject - load from file: %s (%s)", this.filename, this.name ); 118 118 119 119 loadFromStream( new File(filename, FileMode.In) ); … … 239 239 case IMAGE_REL_I386_DIR32: // The targets 32-bit virtual address. 240 240 fix.isSegmentRelative = false; // is this a segment relative fixup (true=add address of segment, false=use actual address) 241 debugwritefln( "fixup type: target" );241 writefln( "fixup type: target" ); 242 242 break; 243 243 case IMAGE_REL_I386_REL32: // The 32-bit relative displacement to the target. This supports the x86 relative branch and call instructions. 244 244 fix.isSegmentRelative = true; // is this a segment relative fixup (true=add address of segment, false=use actual address) 245 debugwritefln( "fixup type: 32-bit relative" );245 writefln( "fixup type: 32-bit relative" ); 246 246 break; 247 247 // case IMAGE_REL_I386_DIR32NB: // The targets 32-bit relative virtual address. 248 // debugwritefln( "fixup type: relative target" );248 // writefln( "fixup type: relative target" ); 249 249 // break; 250 250 // case IMAGE_REL_I386_SECTION: // The 16-bit-section index of the section containing the target. This is used to support debugging information. 251 // debugwritefln( "fixup type: section index" );251 // writefln( "fixup type: section index" ); 252 252 // break; 253 253 // case IMAGE_REL_I386_SECREL: // The 32-bit offset of the target from the beginning of its section. This is used to support debugging information as well as static thread local storage. 254 // debugwritefln( "fixup type: 32-bit offset" );254 // writefln( "fixup type: 32-bit offset" ); 255 255 // break; 256 256 default: … … 336 336 protected void resolveFixups(Fixup[] fixupSet) 337 337 { 338 debugwritefln("resolve fixups (%d)", fixupSet.length );338 writefln("resolve fixups (%d)", fixupSet.length ); 339 339 for(uint fixIdx=0; fixIdx<fixupSet.length; fixIdx++) 340 340 { … … 350 350 if( !target.isResolved ) 351 351 { 352 debugwritefln(" - symbol unresolved" );352 writefln(" - symbol unresolved" ); 353 353 // cannot fix this up yet, so save it for later 354 354 unresolvedFixups ~= *fix; … … 358 358 // set address value 359 359 fixupValue = cast(uint)target.address; 360 debugwritefln( "fixup: %s @ 0x08%x",target.name, fixupValue );360 writefln( "fixup: %s @ 0x08%x",target.name, fixupValue ); 361 361 } 362 362 else … … 368 368 if( !sym.isResolved ) 369 369 { 370 debugwritefln(" - symbol unresolved" );370 writefln(" - symbol unresolved" ); 371 371 // cannot fix this up yet, so save it for later 372 372 unresolvedFixups ~= *fix; … … 377 377 // fixupValue = cast(uint)(seg.data.ptr); 378 378 fixupValue = cast(uint)sym.address; 379 debugwritefln("fixup: %s @ 0x08%x", sym.name, fixupValue);379 writefln("fixup: %s @ 0x08%x", sym.name, fixupValue); 380 380 } 381 381 … … 387 387 // self relative fixup 388 388 uint value = fixupValue - cast(uint)dest - 4; // relative fixup, offset by width of field 389 debugwritefln("[self relative] %d dest %0.8X (at %0.8X) to %0.8X",fix.destSectionIndex,*dest,dest,value^0xffffffff);389 writefln("[self relative] %d dest %0.8X (at %0.8X) to %0.8X",fix.destSectionIndex,*dest,dest,value^0xffffffff); 390 390 *dest = value; 391 391 } 392 392 else 393 393 { 394 debugwritefln("[segment] %d dest %0.8X to %0.8X",fix.destSectionIndex,*dest,fixupValue);394 writefln("[segment] %d dest %0.8X to %0.8X",fix.destSectionIndex,*dest,fixupValue); 395 395 *dest += fixupValue; 396 396 } … … 969 969 if( (linkerDirectives.length = cast(ubyte) sect.data[0]) != 0 ) 970 970 memcpy( linkerDirectives.ptr, §.data[1], linkerDirectives.length ); 971 debugwritefln( "\t\tlinker directives: %s", linkerDirectives );971 writefln( "\t\tlinker directives: %s", linkerDirectives ); 972 972 } 973 973 trunk/ddl/coff/COFFWrite.d
r55 r85 2 2 // utils for writing out PE-COFF data structures 3 3 4 private import ddl.Utils; 5 6 private import ddl.coff.COFF; 7 private import ddl.coff.COFFBinary; 4 8 private import ddl.coff.COFFObject; // .obj 5 9 private import ddl.coff.COFFLibrary; // .lib trunk/ddl/ddl/DDLBinary.d
r68 r85 28 28 module ddl.ddl.DDLBinary; 29 29 30 private import std.stream; 31 private import std.string; 32 33 debug private import std.stdio; 30 private import ddl.Utils; 34 31 35 32 /** 36 Exibits two different behaviors depending on which constructor is used. 37 38 - this(char[] binaryFilename) 39 Reads in the header only and skips the binary loading. 40 Call getBinaryStream to explicitly load the binary data from the file 41 42 - this(Stream) 43 Reads in the entire file from the stream, including the contained binary 33 Provides support for loading and saving DDL files. 44 34 */ 45 35 class DDLBinary{ 46 protected static const uint DDLVersion = 0x00010000; 36 protected static const uint MagicBytes = ('D'<<24)|('D'<<16)|('L'<<8)|('!'); 37 protected static const uint DDLVersion = 0x00010001; 47 38 protected static const uint BufferSize = 4096; 48 39 49 public char[] filename;50 public char[] binaryExtension;40 public char[] binaryType; 41 public char[] processorArch; 51 42 public char[][] definedNamespaces; 52 43 public char[][] importedModules; 44 public char[][char[]] attributes; 53 45 public ubyte[] binaryData; 46 54 47 55 48 public this(){ … … 58 51 59 52 /** 60 Loads just the file header, a call to getBinaryStream() does the rest. 61 */ 62 public this(char[] binaryFilename){ 63 this.filename = binaryFilename; 64 File binaryFile = new File(filename); 65 loadHeader(binaryFile); 66 binaryFile.close(); 53 Loads the entire file, and buffers the attached binary file 54 */ 55 public this(ubyte[] data){ 56 ReadCursor cursor = new ReadCursor(data); 57 loadHeader(cursor); 58 binaryData ~= cursor.getCurrentData(); 67 59 } 68 60 69 /** 70 Loads the entire file 71 */ 72 public this(Stream binaryFile){ 73 loadHeader(binaryFile); 74 75 // get the entire trailing binary file 76 ubyte[] buffer = new ubyte[BufferSize]; 77 78 while(!binaryFile.eof()){ 79 uint amount = binaryFile.read(buffer); 80 binaryData ~= buffer[0..amount]; 81 } 82 } 83 84 protected uint readVersion(Stream binaryFile){ 85 uint ver; 86 binaryFile.read(ver); 87 if(ver != DDLVersion){ 88 throw new Exception(std.string.format("DDL library is the wrong version: %d.%d",(ver>>16),(ver&0x000F))); 61 protected void loadHeader(ReadCursor cursor){ 62 uint magic = cursor.getDWord(); 63 if(magic != MagicBytes){ 64 throw new Exception("File is not a DDL library"); 89 65 } 90 66 91 return ver; 92 } 93 94 protected void loadHeader(Stream binaryFile){ 95 readVersion(binaryFile); 96 97 uint binaryStart; 98 binaryFile.read(binaryStart); // dummy read, never used 99 100 binaryFile.read(binaryExtension); 67 uint ver = cursor.getDWord(); 68 if(ver != DDLVersion){ 69 throw new Exception("DDL library is the wrong version"); 70 } 71 72 uint binaryStart = cursor.getDWord(); 73 binaryType = cursor.getString(); 74 processorArch = cursor.getString(); 101 75 102 76 uint count; 103 char[] str;104 77 105 binaryFile.read(count); <78 count = cursor.getDWord();
