Yasm and bad Windows executables using Mingw/ld
Peter Tanski
p.tanski at gmail.com
Mon Dec 11 21:20:22 PST 2006
Hello Peter,
Maybe I was wrong about the original problem--it may not be due to
the presence or absence of the .stab and .stabstr sections. Instead,
the .comment section seems to be the real difference:
output from objdump -h [file]:
--output from yasm-r1705
hello.obj: file format pe-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0000013a 00000000 00000000 000000b4 2**4
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .rodata 00000020 00000000 00000000 000002de 2**3
CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
2 .data 00000030 00000000 00000000 00000330 2**2
CONTENTS, ALLOC, LOAD, RELOC, DATA
3 .comment 00000009 00000000 00000000 0000037e 2**2
CONTENTS, READONLY, DEBUGGING
--output from mingw/as
hello.o: file format pe-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000140 00000000 00000000 000000dc 2**4
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 00000030 00000000 00000000 0000021c 2**4
CONTENTS, ALLOC, LOAD, RELOC, DATA
2 .bss 00000000 00000000 00000000 00000000 2**4
ALLOC
3 .rodata 00000020 00000000 00000000 0000024c 2**2
CONTENTS, ALLOC, LOAD, RELOC, DATA
4 .rdata$zzz 00000008 00000000 00000000 0000026c 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
The big difference between these two is the .comment and the PE-COFF
read-only data section, .rdata$zzz. Yasm seems to follow the Nasm
model for putting the section header table into the .comment section
(at the top, following the ELF format), correct?.
The objdump of the bad executable, the good executable and another
good executable from mingw/as shows that the .stab and .stabstr
sections do not hurt:
--ghc executable using 'ld' without stripping symbols:
hello_badexec.exe: file format pei-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .comment 00000009 00000000 00000000 00000358 2**2
CONTENTS, READONLY, DEBUGGING
1 .text 00032f34 00401000 00401000 00000600 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE, DATA
2 .data 00002980 00434000 00434000 00033600 2**4
CONTENTS, ALLOC, LOAD, DATA
3 .rdata 00007120 00437000 00437000 00036000 2**4
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .rodata 00000020 0043f000 0043f000 0003d200 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
5 .bss 00002460 00440000 00440000 00000000 2**4
ALLOC
6 .idata 00000fd0 00443000 00443000 0003d400 2**2
CONTENTS, ALLOC, LOAD, DATA
7 .stab 00016308 00444000 00444000 0003e400 2**2
CONTENTS, READONLY, DEBUGGING, NEVER_LOAD, EXCLUDE
8 .stabstr 00002959 0045b000 0045b000 00054800 2**0
CONTENTS, READONLY, DEBUGGING, NEVER_LOAD, EXCLUDE
--ghc executable using 'ld' and stripping all symbols:
hello_good.exe: file format pei-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00032f34 00401000 00401000 00000400 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE, DATA
1 .data 00002980 00434000 00434000 00033400 2**4
CONTENTS, ALLOC, LOAD, DATA
2 .rdata 00007120 00437000 00437000 00035e00 2**4
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .rodata 00000020 0043f000 0043f000 0003d000 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .bss 00002460 00440000 00440000 00000000 2**4
ALLOC
5 .idata 00000fd0 00443000 00443000 0003d200 2**2
CONTENTS, ALLOC, LOAD, DATA
--ghc executable using mingw/as, no symbols stripped:
hello_tst.exe: file format pei-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00032f34 00401000 00401000 00000400 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE, DATA
1 .data 00002980 00434000 00434000 00033400 2**4
CONTENTS, ALLOC, LOAD, DATA
2 .rodata 00000020 00437000 00437000 00035e00 2**2
CONTENTS, ALLOC, LOAD, DATA
3 .rdata 00007128 00438000 00438000 00036000 2**4
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .bss 00002460 00440000 00440000 00000000 2**4
ALLOC
5 .idata 00000fd0 00443000 00443000 0003d200 2**2
CONTENTS, ALLOC, LOAD, DATA
6 .stab 00016308 00444000 00444000 0003e200 2**2
CONTENTS, READONLY, DEBUGGING, NEVER_LOAD, EXCLUDE
7 .stabstr 00002959 0045b000 0045b000 00054600 2**0
CONTENTS, READONLY, DEBUGGING, NEVER_LOAD, EXCLUDE
The only difference between the bad executable and the mingw/as
executable (aside from section ordering) is the .comment section at
the top.
I am also looking at the GNU-binutils (gas) source code, particularly
the Binary File Descriptor files (bfd/peXXigen.c, etc.) to see their
solution to the problem. (I am a bit curious about the .rdata$zzz
section.)
Cheers,
Pete
More information about the yasm-devel
mailing list