News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Golink and DLL Functions

Started by bartc, May 17, 2016, 10:12:31 AM

Previous topic - Next topic

bartc

I'm currently using Nasm and LD (part of gcc) as linker, and am interested in switching to Golink.

But I want to clarify how Golink deals with imported function names from DLLs. Take this code (in Nasm syntax):

segment   .text
global main
main:
sub rsp,32
mov rcx,KK14
extern puts
call puts
add rsp,32
mov rax,0
ret       

segment   .data
align     8
KK14:
db 'Hi There!',0


This works with both LD and Golink. But now take that 'call puts' and make it indirect:


       mov rax, puts
       call rax


In this form, it works as expected with LD, but not Golink. With Golink, I have to write it like this:


       mov rax, puts
       call [rax]


with an extra level of indirection. Can someone please confirm that this is the case? There was mention of something along these lines in the docs, but that doesn't explain why a normal 'call puts' works without the extra indirection.

Thanks. (BTW do I have to answer all those questions about Franco and Mussolini every time I make a post?  And, apparently, edit one.)

Note, the test.obj file from Nasm was linked as follows:

golink /console /entry main /fo test.exe test.obj \windows\system32\msvcrt.dll

wjr

Although the symbol 'puts' is extern, the address that goes into the instruction points into the imports, which the OS loader fills in with the actual function address. I confirm that you need to use either:


mov rax, puts
call [rax]


or


mov rax,[puts]
call rax


There is also a difference between call puts and call [puts]. The first one with a call encoded as E8 will use a jump table in the import section. Some more details here http://masm32.com/board/index.php?topic=3117.0