flat assembler
Message board for the users of flat assembler.

Index > Windows > Size of DLL files

Author
Thread Post new topic Reply to topic
Icefex



Joined: 11 Feb 2009
Posts: 17
Icefex 01 Jul 2009, 15:41
While coding a simple DLL i came across a bug/feature/annoyance. I first wrote the DLL in C, (simply as a helper for doing it in asm) compiled it and it had a size of 2kb. Then I translated it to asm and it was 3.5kb. Well, I never thought that a C compiler (tcc in my case) would produce a smaller file than hand written assembly...
I looked at the sections of the dlls and surprise, those from the assembly dll where smaller (ASM: 246bytes, C: 416bytes). So my question is why is the ASM dll larger?

Attached are the source files I used


Description:
Download
Filename: dll_test.zip
Filesize: 2.85 KB
Downloaded: 256 Time(s)

Post 01 Jul 2009, 15:41
View user's profile Send private message Reply with quote
arigity



Joined: 22 Dec 2008
Posts: 45
arigity 01 Jul 2009, 15:55
the C dll mashed imports exports and data into 1 section while the asm dll has separate sections for all 3.
Post 01 Jul 2009, 15:55
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder 01 Jul 2009, 15:58
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:49; edited 2 times in total
Post 01 Jul 2009, 15:58
View user's profile Send private message Reply with quote
Icefex



Joined: 11 Feb 2009
Posts: 17
Icefex 01 Jul 2009, 15:59
Well, is then there a way to get the sections smaller? Because they are padded to 512bytes afaik.
Post 01 Jul 2009, 15:59
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 01 Jul 2009, 16:02
Code:
; DLL creation example

format PE GUI 4.0 DLL
entry DllEntryPoint

include 'win32a.inc'

section '.text' code readable executable

proc DllEntryPoint hinstDLL,fdwReason,lpvReserved
        mov     eax,TRUE
        ret
endp

proc TestFunction
        invoke  MessageBox,0,_message,_caption,MB_OK
        ret
endp

section '.data' data readable writeable

  _caption db 'Win32 assembly',0
  _message db 'Some text no one cares about!',0

;section '.idata' import data readable writeable
data import
  library user,'USER32.DLL'

  import user,\
         MessageBox,'MessageBoxA'
end data

;section '.edata' export data readable
data export

  export 'TEST.DLL',\
         TestFunction,'TestFunction'

end data

section '.reloc' fixups data discardable
; data fixups ; using this instead of a separate section would shave 512 bytes
; end data      

2 KB and replicates the sections of the C version.
Post 01 Jul 2009, 16:02
View user's profile Send private message Reply with quote
arigity



Joined: 22 Dec 2008
Posts: 45
arigity 01 Jul 2009, 16:03
here, i modified your example to fit imports and exports and data in 1 section

Code:
; DLL creation example

format PE GUI 4.0 DLL
entry DllEntryPoint

include 'win32a.inc'

section '.text' code readable executable

proc DllEntryPoint hinstDLL,fdwReason,lpvReserved
        mov     eax,TRUE
        ret
endp

proc TestFunction
        invoke  MessageBox,0,_message,_caption,MB_OK
        ret
endp

section '.data' data readable writeable

  _caption db 'Win32 assembly',0
  _message db 'Some text no one cares about!',0

data import

  library user,'USER32.DLL'

  import user,\
         MessageBox,'MessageBoxA'

end data

data export
  export 'TEST.DLL',\
         TestFunction,'TestFunction'
end data

section '.reloc' fixups data discardable
    


edit >_> woops loco beat me :/
Post 01 Jul 2009, 16:03
View user's profile Send private message Reply with quote
Icefex



Joined: 11 Feb 2009
Posts: 17
Icefex 01 Jul 2009, 16:12
w00t! Thank you guys!
Post 01 Jul 2009, 16:12
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 01 Jul 2009, 16:21
BTW, actually to replicate the C version even further you should add "align 16" before "data import" and "data export".
Post 01 Jul 2009, 16:21
View user's profile Send private message Reply with quote
Icefex



Joined: 11 Feb 2009
Posts: 17
Icefex 01 Jul 2009, 16:27
Actually my intention was not replicating the C version, but making it as small. But you guys helped my a lot with this.
Post 01 Jul 2009, 16:27
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder 01 Jul 2009, 16:33
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:49; edited 1 time in total
Post 01 Jul 2009, 16:33
View user's profile Send private message Reply with quote
Icefex



Joined: 11 Feb 2009
Posts: 17
Icefex 01 Jul 2009, 16:53
I think there is no such import/export in coff, but functions can be declared as extern. And when a coff is linked the linker tries to resolve those. Also there are afaik no exports, because they would be kinda useless in a coff file...

P.S.: I give no guarantee for accuracy
Post 01 Jul 2009, 16:53
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder 01 Jul 2009, 17:12
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:49; edited 1 time in total
Post 01 Jul 2009, 17:12
View user's profile Send private message Reply with quote
Icefex



Joined: 11 Feb 2009
Posts: 17
Icefex 01 Jul 2009, 17:16
No, not coff itself but the linker tries to resolve not known functions. Coff itself only contains code and data.
Post 01 Jul 2009, 17:16
View user's profile Send private message Reply with quote
manfred



Joined: 28 Feb 2009
Posts: 43
Location: Racibórz, Poland
manfred 01 Jul 2009, 17:29
Read The Friendly PE Manual.
These informations is stored in (AFAIK) symbol table.

_________________
Sorry for my English...
Post 01 Jul 2009, 17:29
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.