MASM2DJG 1.02 ------------- MASM2DJG is a command line utility that patches Microsoft COFF format object files, enabling them to be linked with the DJGPP linker 'ld'. MASM2DJG enables assembler routines built with Microsoft MASM version 6 or later to be linked with C sources built using DJGPP. Syntax: masm2djg [options] -h : Help -u : Convert gnu objects to Microsoft format -m : Convert Microsoft objects to gnu format (default) -v : Increase verbosity of output -t : Decrease verbosity of output -r : Report patches but don't change the file -p : Apply all changes (default) so to fixup a.obj type: masm2djg -t a.obj Why is MASM2DJG necessary? -------------------------- MASM produces a COFF output file that contains relocation fixups that are incompatible with DJGPP's ld. 1. A call to an external subroutine is assembled as an 0E8h opcode followed by a relative offset (initially 0). A REL32 relocation record is created pointing to the offset. 'ld' incorrectly calculates the displacement to the target because it ignores the offset of the fixup within the section. This patch subtracts the offset within the section of all REL32 fixups. 2. References to local static data are assembled with a section relative address and a DIR32 relocation record. 'ld' incorrectly calculates the virtual address because it subtracts the relative section offset from it. This patch adds the section offset of the fixup to all 'static' type DIR32 fixups. 3. References to externally visible but locally defined functions are assembled with a 0 relative address and a DIR32 relocation record with an IMAGE_SYM_CLASS_EXTERNAL storage class. 'ld' incorrectly calculates the virtual address because it subtracts the relative section offset from it. This patch adds the section offset of the fixup to all 'extern' type DIR32 fixups. Notes on using MASM with DJGPP ------------------------------ MASM 6 and later will produce a COFF format object file if supplied the /coff switch on the comand line. The only source code change required is to add the following directives: .386 .MODEL FLAT ; Start the data segment .DATA ; Start the code segment .CODE ; If the source uses DGROUP then define it: DGROUP EQU flat Building the source ------------------- There's a makefile for gcc (DJGPP, cygwin etc), a project file (masm2djg.dsp) for Visual C 6 and a project for Visual C 1.51 (masm2djg.mak) which built the 16 bit executable provided. Last revised 2001-04-30 lvr Lawrence Rust lvr@softsystem.co.uk Software Systems Tel: +33 5 49 72 79 63 www.softsystem.co.uk