Author Topic: Using "#DYNAMICLINKFILE" in golink  (Read 4128 times)

Offline wyvern666

  • Jr. Member
  • *
  • Posts: 32
Using "#DYNAMICLINKFILE" in golink
« on: June 22, 2011, 03:48:03 AM »
Hi people.

Im trying to use the "#DYNAMICLINKFILE lib1.dll, lib2.dll" sintax to avoid adding the libs in the command line when calling golink. But nasm give me this:

Quote
error: label or instruction expected at start of line

The #DYNAMICLINKFILE is unknown to NASM. There is anyway to fix that?, or it will only work with the goasm assembler?. Also i want to know what is the diference between "static link" and "dynamic link".

thanks!


Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: Using "#DYNAMICLINKFILE" in golink
« Reply #1 on: June 22, 2011, 05:07:40 AM »
The directive #DYNAMICLINKFILE makes use of the .drectve section of the object file. This is an informative section which doesn't make it to the final executable (MASM also uses this section for handling includelib). NASM doesn't have a directive which makes use of this, but it doesn't mean you can't do it manually or use a macro.

Code: [Select]
BITS 32

[SECTION .drectve info align=8]
DB "kernel32.dll", 0x20 ; Space Terminated Strings
DB "user32.dll", 0x20

EXTERN MessageBoxA ; GoLink will handle decoration for us.
EXTERN ExitProcess

SECTION .data

strCaption: DB "Hi!", 0
strMessage: DB "Win32 NASM - Dynamic Linking Sample", 0

SECTION .text
start: push DWORD 0 ; MB_OK
push DWORD strCaption
push DWORD strMessage
push DWORD 0
call MessageBoxA

push DWORD 0
call ExitProcess

And if you want a macro you can try this one:

Code: [Select]
%imacro @DYNAMICLINKFILE 1-*
%push
[SECTION .drectve info align=8]
%rep %0
%ifstr %1
%define %$baka %1
%else
%defstr %$baka %1
%endif
DB %$baka, 0x20
%rotate 1
%endrep
__SECT__
%pop
%endmacro

If I was going to be using GoLink exclusively, I would probably add this macro to my standard.mac and rebuild my copy of NASM so I'd never have to worry about it. Usage of @DYNAMICLINKFILE macro is exactly the same as the #DYNAMICLINKFILE where the filenames can be quoted or not.

Here is a cute little GoASM-ish version of the sample above.

Code: [Select]
BITS 32

;; --- GOASM COMPATABILITY MACROS ---

%imacro @DYNAMICLINKFILE 1-*
%push
[SECTION .drectve info align=8]
%rep %0
%ifstr %1
%define %$baka %1
%else
%defstr %$baka %1
%endif
DB %$baka, 0x20
%rotate 1
%endrep
__SECT__
%pop
%endmacro

%define T(x) TWORD x
%define Q(x) QWORD x
%define D(x) DWORD x
%define W(x) WORD x
%define B(x) BYTE x

; ---- END OF GOASM COMPATABILITY MACROS ---

@DYNAMICLINKFILE kernel32.dll, user32.dll
EXTERN MessageBoxA
EXTERN ExitProcess

SECTION .data

strCaption: DB "Hi!", 0
strMessage: DB "Win32 NASM - Dynamic Linking Sample", 0

SECTION .text
start: push D( 0 ) ; MB_OK
push D( strCaption )
push D( strMessage )
push D( 0 )
call MessageBoxA

push D( 0 )
call ExitProcess

HtH,
~Bryant

About Bryant Keller
bkeller@about.me

Offline wyvern666

  • Jr. Member
  • *
  • Posts: 32
Re: Using "#DYNAMICLINKFILE" in golink
« Reply #2 on: June 22, 2011, 08:19:38 PM »
oh man, that was really good! ;D thank you very much.