Yasm and bad Windows executables using Mingw/ld

Peter Tanski p.tanski at gmail.com
Tue Dec 12 19:51:06 PST 2006


On Dec 12, 2006, at 2:30 AM, Peter Johnson wrote:
> On Tue, 12 Dec 2006, Peter Tanski wrote:
>> 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?.
>
> Interesting.  No, Yasm only outputs a .comment section for PE/COFF  
> if one is specified in the input file.  It doesn't add one  
> otherwise. Apparently the GAS or binutils folks have run into this  
> and ignore/drop the section for PE output?  I can certainly have  
> yasm do the same thing. Alternatively, there's probably a way you  
> can throw it away in the ld script (if you can modify it for your  
> application).

The .comment section in the output is created from the GHC-default  
directive:

.ident "GHC 6.6"

at the end of the assembler file.  (You already know this has the  
value IMAGE_SCN_LNK_INFO (or STYP_INFO), value 0x00000200.)

For compatibility with binutils/ld, which loads .comment sections  
into memory (invalid in PE-COFF files), and since the section must be  
read only, GAS outputs the .comment section to a specially named  
".rdata" section: ".rdata$zzz".

binutils/gas/config/obj-coff.c:476-502
(also at http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/config/ 
obj-coff.c?cvsroot=src)

/* Handle the .ident pseudo-op.  */

static void
obj_coff_ident (int ignore ATTRIBUTE_UNUSED)
{
   segT current_seg = now_seg;
   subsegT current_subseg = now_subseg;

#ifdef TE_PE
   {
     segT sec;

     /* We could put it in .comment, but that creates an extra section
        that shouldn't be loaded into memory, which requires linker
        changes...  For now, until proven otherwise, use .rdata.  */
     sec = subseg_new (".rdata$zzz", 0);
     bfd_set_section_flags (stdoutput, sec,
			   ((SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA)
			    & bfd_applicable_section_flags (stdoutput)));
   }
#else
   subseg_new (".comment", 0);
#endif

   stringer (1);
   subseg_set (current_seg, current_subseg);
}

So modification would only be necessary for compatibility with  
binutils/ld.  I can look into modifications to Yasm to save you some  
time; I am not sure whether you would *want* to modify Yasm's output  
just for compatibility with binutils/ld, unless that was specified by  
a different output format than win32.

Cheers,
Pete


More information about the yasm-devel mailing list