From: Josef D. <jo...@ge...> - 2005-11-07 16:49:13
|
Frank Kotler wrote: > Josef Drexler wrote: > >> > nasm -f coff -o cofftest.o cofftest.asm >> > objdump -h cofftest.o >> >> cofftest.o: file format pe-i386 > > > Whoa! "-f coff" shouldn't be creating "pe" files, should it? Well, PE and COFF are two variations on a theme. The structure is very similar, anyway. > ... > >> (made by GNU ld) > > Which GNU ld, exactly? i686-pc-mingw-ld version 2.15.94 20041229 (running on Linux). > If it's Mingw/Cygwin, try "-f win32" and see if > that solves the problem. If it's djgpp's ld, "-f coff" should be right, > but I'm not sure where the "pe" is coming from... That part of outcoff.c is the same for win32/coff. I did find out eventually that I needed to use "-f win32" to get the relocations right, though, but for the section metadata it makes no difference other than the section flags. > You may have discovered something, and we certainly appreciate the > proposed fix(!!!), but I'm confused about "which COFF" you're using. > There's another potential issue... earlier versions of Mingw's ld did it > like MS documented it, which is not the way they *did* it! This was > blamed on a Nasm bug, but ld changed its handling of the "virtual size", > and now Nasm's okay :) (I forget version numbers - November of 2003, I > think???) If you've got an older version of (Mingw/Cygwin) ld, a newer > version might make a difference. I'll try that. > If either of these things turned out to be the problem, it would be even > easier than applying your fix! :) After some experimenting with GNU as, I found that it always sets vsize=0: gcc/as: NAME VSIZE VADDR DSIZE OFS RELOFS LINEOFS NREL NLINE FLAGS .text 0 0 20h 8Ch 1ECh 0 2 0 60000020 .data 0 0 140h ACh 0 0 0 0 C0000040 .bss 0 0 30h 0 0 0 0 0 C0000080 nasm/coff: NAME VSIZE VADDR DSIZE OFS RELOFS LINEOFS NREL NLINE FLAGS .text 0 0 12h 8Ch 9Eh 0 2 0 00000020 .data 12h 0 140h B2h 1F2h 0 0 0 00000040 .bss 152h 0 28h 0 0 0 0 0 00000080 nasm/win32: NAME VSIZE VADDR DSIZE OFS RELOFS LINEOFS NREL NLINE FLAGS .text 0 0 12h 8Ch 9Eh 0 2 0 60500020 .data 12h 0 140h B2h 1F2h 0 0 0 C0300040 .bss 152h 0 28h 0 0 0 0 0 C0300080 So as far as section headers are concerned, coff and win32 differ only in the flags, which seem to be correct for both. According to http://www.xaff.org/GI/COFF/coff.html, the vsize should be zero for all object files, and is only set for actual linked executables. When I change outcoff.c to always set vsize=0, the linked exectuables are fine too. I'm not sure however whether there are people who need the old vsize behaviour. The text at the beginning of outcoff.c makes it clear that it was intentional, so it might not be the best idea to just change it like that without better understanding of the reasoning behind it. Perhaps this calls for a third coff output type? -- Josef Drexler |