Yasm working with Win32

Peter Tanski p.tanski at gmail.com
Wed Dec 13 16:10:08 EST 2006


On Dec 12, 2006, at 4:15 AM, Simon Marlow wrote:

> You haven't allayed my fears.  If a Yasm-generated object file has  
> a special .reloc/.stab section to handle complex relocations, and  
> the GNU linker understands this special section, won't the MS  
> linker choke on it?  Or are complex relocations done in the same  
> way by the MS tools too?

I tracked down the cause of the problem with the .comment section.   
It was not caused by Yasm and will not cause a problem with the MS  
tools.  That said, Peter Johnson will patch Yasm for use under Mingw,  
for compatibility.

You know that GHC appends an .ident pseudo-op (directive) at the end  
of assembler output:

.ident "GHC 6.6"

This .ident is turned into a .comment, following the COFF  
specification--the MS PE-COFF spec. says nothing about this, but  
contains the same information in the define IMAGE_SCN_LNK_INFO, value  
0x00000200, which is the same value as the STYP_INFO define in the  
COFF spec.

According to the GAS source (in binutils/gas/config/obj-coff.c: 
476-502, at http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gas/ 
config/obj-coff.c?cvsroot=src), GAS normally does the same thing  
for .ident pseudo-ops as Yasm: turn them into .comment sections.   
Under Mingw, however, the binutils/LD does loads the .comment section  
into memory (invalid for windows executable images).  Rather than fix  
this problem with LD, GAS outputs the .ident content as a new  
subsection, ".rdata$zzz" with the proper section flags.

I also tested a Yasm-assembled file containing a complex relocation  
and an .ident directive:

--- tst_reloc.s ---

.section .rodata
	.align	4
.globl	_tst_main_srt
_tst_main_srt:
	.long	0

.text
	.align	4
_tst_main_info:
	.long	_tst_main_srt-(_tst_main)+0
	.long	0
	
.globl	_tst_main
_tst_main:
	enter	$0, $0
	pusha	
	
	mov		(_tst_main_info+0), %eax
	
	movl	%ebp, %esp
	popl	%ebp
	ret
	
.ident	"tst_reloc ident"

-----------------------

and used a C wrapper for the rest:

--- print_reloc.c ---

#include <stdio.h>

unsigned int __cdecl tst_main( void );

int main(int argc, const char* argv[])
{
	unsigned int addr;
	
	addr = tst_main();
	
	printf("Relocation address: %x\n", addr);
	
	return 0;
}

-----------------------

The Yasm-assembled output, tst_reloc.obj did contain a .comment  
section and a simple MS CL command:

cl tst_reloc.obj print_reloc.c

resulted in a good executable.  Output when run:
Relocation address: dff8

Cheers,
Pete
  



More information about the Cvs-ghc mailing list