Hi friends,

Is it possible to use ld.exe - the GNU linker from MinGW package with MASM? Anyone who tried?
Posted on 2004-09-23 14:45:42 by Vortex
masm uses ms-coff object format, while gnu typicall uses gnu-coff (I think mingw does that too). This means the format of some relocations is different, and you will thus have FUBAR exe files. Why do you want to use gnu ld anyway?
Posted on 2004-09-23 15:55:17 by f0dder
Hi f0dder,

Yes, I knew that GNU uses a variant of COFF. I wished to do some simple experiments with my import library maker inc2lib, that's why I asked about GNU ld.
Posted on 2004-09-23 16:01:24 by Vortex
Hi Vortex,

Please ask to Greenant, he know about that because he is using make from MinGW package.
http://greenant.cjb.net/
regards
ipadilla
Posted on 2004-09-23 23:38:06 by ipadilla
I only use make and no other software from mingw. So I don't know nothing about different variant of coff.

Does ml.exe output only ms-coff?
Posted on 2004-09-24 02:46:21 by greenant
Hi greenant,

Ml.exe outputs also OMF code which cannot be processed by MinGW. These GNU tools accepts only COFF code.

Thanks for your help.
Posted on 2004-09-24 05:21:57 by Vortex
I also would like - just for fun - to know how one may use ld with MASM
or, the other way, use a GCC object module with MS link.

The first way I tried with DJGPP ld.exe (which surely isn't the "standard" ld.exe binary), but soon gave up. ld seems to ignore - or most likely not to understand - the linker commands placed by MASM in the ".drectve" section.
Posted on 2004-09-25 16:28:11 by japheth
To use ms/gnu coff files in "non-native" platform, you'd need a object-file-fixer that changes the relocations. Haven't seen one of those yet, and I'm not interested enough in GNU tools to write one. There's usually better solutions than making workaround for GNU stuff ;)

Hm, does anything but microsoft software parse the .drectve section?
Posted on 2004-09-25 16:45:00 by f0dder
MASM puts the entry point in this section. So if the linker complains about not finding a program entry, it most likely doesn't understand it.

ALINK.EXE complains.

The other linkers I know (TLINK/ILINK, WLINK, QLINK, LINK from Digital Mars) are OMF linkers.
Posted on 2004-09-25 17:01:36 by japheth
COFF means Common Object File Format. Is it corret?
And what does OMF mean?
Posted on 2004-09-26 02:42:50 by greenant
I think OMF is for "Object Module Format/File", but it's mostly a guess. Wotsit.org prolly knows.
Posted on 2004-09-26 02:46:08 by f0dder
OMF=Object module file format
Posted on 2004-09-26 03:06:54 by Vortex
Very interesting, today I tried to link a GCC object module (hello world) with MS link (using a simple, self-written C runtime lib). the linker doesn't report problems, but the executable crashes. As f0dder already mentioned, the relocations are different, and the "printf" call is wrongly resolved. But may be there exist an option (among approximately 2000 others) in GCC (or AS) to adjust this?
Posted on 2004-09-26 12:28:38 by japheth
Greetings all!

It's a novelty to use ld with masm, but since it's not clear how to optimize output using ld (unless someone can give an example) it's actually preferable to use MSLINK or some other linker which supports optimization more transparently. ld's (I'm using the MinGW version) commandline syntax is similar to MSLINK's, say MAIN is your program's entry point and imports from user32 and kernel32 are required, then the syntax is:


ld -e_MAIN -subsystem console -Lc:\MASM\LIB -o yourprog.exe yourprog.obj -luser32 -lkernel32  



The chm file for ld is available from the MinGW website and describes the commandline syntax fully. Here's a NMAKE makefile example which demonstrates how to employ ld in this context:


NAME=myprog

BIN=\masm32\bin
BIN2=c:\MinGW\bin

SUBSYSTEM=console
LIBPATH=\masm32\lib
AFLAGS=/c /coff /Cp /Fl /Sn

.asm.obj:
$(BIN)\ml $(AFLAGS) $<
.rc.obj:
$(BIN)\rc /v RSRC.RC
$(BIN)\cvtres /machine:ix86 RSRC.RES
.obj.exe:
$(BIN2)\ld -e_MAIN -subsystem $(SUBSYSTEM) -L $(LIBPATH) -o $(NAME).exe $< RSRC.OBJ -lgetclargs -lmsvcrt -luser32 -lkernel32 -lversion -lshlwapi
del $<
del RSRC.OBJ
del RSRC.RES

all: $(NAME).exe

$(NAME).exe: $(NAME).obj RSRC.obj
$(NAME).obj: $(NAME).asm RSRC.RC
Posted on 2004-10-02 13:34:36 by Poimander
Poimander (or anyone who knows),

do you know how to tell LD to include relocation info in the PE binary? All my binaries are "fixed" and I'm unable to find the command line switch to enable this feature.

Regards

Japheth
Posted on 2004-10-09 11:17:21 by japheth
The linker written by Pelle Orinius works fine with ML coff output and it generally produces a slightly smaller executable file as well.
Posted on 2004-10-09 18:04:19 by hutch--

do you know how to tell LD to include relocation info in the PE binary?


You have to employ the -r (i.e. -relocatable) command line switch. I recommend you download the .chm file (http://htmlhelp.berlios.de/books/chm.php).
Posted on 2004-10-09 18:34:46 by Poimander
Thanks Poimander,

but I wouln't ask if I hadn't read the docs first. And I had tried the -r switch, but this switch seems to cause ld to produce another coff file (beginning with word 014Ch), which, as it is documented, can serve as input for ld (partiall linking). Very nice, but not the simple feature I was looking for.

Regards

Japheth



Hutch, in case your post was refering to my post: I am currently checking some win32 development environments to be suitable for a certain task. For this they must be able produce relocatable PE binaries. And LD belongs to the MinGW package (C++), among others.
Posted on 2004-10-10 01:05:00 by japheth
ld seems to ignore - or most likely not to understand - the linker commands placed by MASM in the ".drectve" section
---------------------------
Hm, does anything but microsoft software parse the .drectve section?
---------------------------
MASM puts the entry point in this section. So if the linker complains about not finding a program entry, it most likely doesn't understand it.
ALINK.EXE complains.
The other linkers I know (TLINK/ILINK, WLINK, QLINK, LINK from Digital Mars) are OMF linkers.

Just for the record, my Golink which is a COFF linker looks for the specified starting address and exported names in the .drectve section (as one way to find this information).
Posted on 2004-10-10 08:19:47 by jorgon

but I wouln't ask if I hadn't read the docs first. And I had tried the -r switch, but this switch seems to cause ld to produce another coff file ...


My apologies, I thought the situation was more complicated only after
issuing my post. :roll: However, I found a post on Google/Groups which
suggests using CygWin ld (the alternative -q option isn't implemented in the MinGW version).

Subject: Re: loading COFF
Posted on 2004-10-10 16:20:39 by Poimander