Re: Problem Linking (win32)



07/24/2008 03:58 PM 521 bwaichu2.asm
07/24/2008 03:58 PM 1,536 bwaichu2.exe
07/24/2008 03:58 PM 1,669 bwaichu2.lst
07/24/2008 03:58 PM 448 bwaichu2.obj

Q:\bwaichu2>bwaichu2.exe
Test
Q:\bwaichu2>

The files are available here as zip'd files.
http://www.microcosmotalk.com/tech/asm/bwaichu/

And the second file that you posted, I modified it a little, but here
it is. It compiled fine and worked fine and presented the message test
as seen above.

I used PoLink to link.

<file name="bwaichu2.asm">
;nasm.exe -f win32 -l bwaichu2.lst bwaichu2.asm
;golink /console bwaichu2.obj kernel32.dll user32.dll msvcrt.dll
;polink /ENTRY:start /SUBSYSTEM:CONSOLE bwaichu2.obj kernel32.lib user32.lib msvcrt.lib
;

%define GetLastError _GetLastError@0
%define ExitProcess _ExitProcess@4
%define printf _printf

extern printf
extern ExitProcess
extern GetLastError

section .text

global start
start:
call GetLastError

push dword sText
call printf
add esp, 4

push dword 0
call ExitProcess

section .data
sText dd "Test", 0
<bwaichu2>

I didn't have any problems running it. I will mention, in case I have
not mentioned this in the past, that NASM does NOT make a valid PE
object file. Meaning specifically, meaning that dumpbin.exe and link.exe
can not extract the /IMPORTS and /EXPORTS. This is more for those that
develop the compiler than for us lay people. But perhaps someone else
other than I would be interested in seeing this?

<dump file="bwaichu2.obj">
Microsoft (R) COFF Binary File Dumper Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.


Dump of file bwaichu2.obj

File Type: COFF OBJECT

Summary

8 .data
1F .text

</dump>

<dump file="bwaichu2.exe">
Microsoft (R) COFF Binary File Dumper Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.


Dump of file bwaichu2.exe

File Type: EXECUTABLE IMAGE

Section contains the following imports:

KERNEL32.dll
402058 Import Address Table
402044 Import Name Table
0 time date stamp
0 Index of first forwarder reference

0 GetLastError
0 ExitProcess

MSVCRT.dll
402064 Import Address Table
402050 Import Name Table
0 time date stamp
0 Index of first forwarder reference

29E printf

Summary

1000 .data
1000 .text

</dump>

I'm not sure what it will take to get that in place, but the .exe
seems to dump properly.

And back to Brian, I'm linking against LIB files, i.e. files with
..lib extensions. If you want those files I got the msvcrt.lib from
the PO C compiler, and for the Windows files, I use either the MS
DDK, the MS PSDK, or one of the many other sources, which I think
even nasm provides.

http://www.microsoft.com/whdc/DevTools/ddk/
http://www.smorgasbordet.com/pellesc/ (polink/c compiler/make/etc)

Forgive me for not trying to link against dll's.

: Is the setting of the error value a bug with the linker, a
: bug with the creation of the obj file, a bug with the ms
: loader, or something else? Should I clear the error value
: whenever I assemble a file that links back to msvcrt.dll after
: a prologue?

I'm not sure. Someone else needs to jump in and see if they can
think of something. I know the API functions all have an underscore
prefixed. I've been using the %define statements to make sure the
underscore goes into place, even on the printf and sprintf functions.
Since you're pushing the parameters yourself, I don't think we need
to worry about left to right or right to left order. See if you can
link against the .lib files and see if that changes anything for you?

--
JC
Natural Cure For Pink-Eye (Conjunctivitis)
http://www.associatedcontent.com/article/381336/saliva_a_natural_cure_for_conjunctivitis.html

.



Relevant Pages

  • Re: VBA : shrinking a multidimensional array to nothing and restarting again...
    ... >> Gerry Quinn wrote: ... > have been documented (or how would Nash have known of it?). ... We're talking about what Microsoft does, ... >>> certain function not operating as he expected in one compiler. ...
    (comp.programming)
  • Re: To Richard Heathfield: enoughs enough
    ... Abandoning Hungarian notation because it is ... So write you're own compiler for a new language, ... >> I don't own any such books. ... Not even Microsoft claims that anymore. ...
    (comp.programming)
  • Re: [announcement] SYSAPI and SYSSVC for Windows
    ... are 3D GUI objects a Microsoft invention? ... copies to circumvent payment is a nice thing to do, but I think "secure" ... :> "trusted" applications like media player, real player, and its ilk or not ... I don't think small compiler companies will always use dongles. ...
    (comp.lang.ada)
  • Re: Visual C++ 6 support issue
    ... Of course, Eclipse has the ... Apparently there is a discussion group going on in Microsoft which is discussing the tool ... >the same parsing job that the first couple of passes of the compiler ... And the compiler and the IDE are completely orthogonal. ...
    (microsoft.public.vc.mfc)
  • Re: How to Duplicate CStrings Default Data Type
    ... The parameter is copied by value because the parameter is a pointer and the pointer is ... This is why a CString is really just a wrapper for a pointer to a heap object. ... didn't the compiler copy the CString in Test2?". ... argument to printf, the compiler made a copy of the entire object, passed it ...
    (microsoft.public.vc.mfc)