0

I have created a DLL file (library) with one assembler function. This file is 75kB size. How to make this file smaller? Like I suspect, there is an automatically included System unit. Can I exclude this unit from my dll file?

apocalypse
  • 5,764
  • 9
  • 47
  • 95
  • 1
    If we've understood what you're doing correctly, your best option may be to use a free assembler such as FASM rather than FPC. – Harry Johnston Apr 29 '13 at 02:26
  • Yes I tried to do something with it, but FPC+Lazarus is very simple to use. Anyway I will take a look at this assembler. – apocalypse Apr 29 '13 at 02:36

3 Answers3

3

I googled your Issue, as it came to my mind in Visual C++ there are Debug&Release Modes. So maybe you can try creating a smaller Dll using the Release Mode. I found some settings for this: http://bugs.freepascal.org/bug_view_advanced_page.php?bug_id=18632
Maybe this helps you, but I'm not sure it will work because I didn't work with Pascal for like 2 years :)

yrk
  • 155
  • 1
  • 3
  • 17
  • 1
    It helped, from 75kB to 35kB. Thanks. – apocalypse Apr 23 '13 at 16:35
  • You may be able to further reduce this by eliminating any unnecessary DLL imports, and removing the C runtime library if it is present. – Harry Johnston Apr 26 '13 at 00:13
  • FPC, like Delphi doesn't use MSVC runtimes. winapi dlls only. – Marco van de Voort Apr 27 '13 at 12:44
  • @MarcovandeVoort: I'm confused now. Why is the OP using a Pascal compiler if he's writing assembly code? Or does the word "assembler" have a special meaning in this context? – Harry Johnston Apr 28 '13 at 05:55
  • Free Pascal/Delphi have an internal assembler. So he is probably writing his assembler inside a pascal source file. The system unit is the core unit that is always included (comparable with libgcc and the basic file I/O and string parts of libc) – Marco van de Voort Apr 28 '13 at 14:53
1
  1. Why? are you concerned about binary sizes on one hand, and have a 64-bit tag on the other?

  2. Debug info, pass -Xs to strip debuginfo

  3. Smartlinking, pass -XX (dead code elimination) 1+2 combines to -XXs

  4. Avoid advanced functionality. Do NOT set any $Mode, the delphi compatible additions to system will bulk it up.

If you want to further reduce you will have to edit the RTL source and recompile it.

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89
1

You can also try UPX to pack your DLL-s. I recently made a simple DLL in Delphi and here are some observations I made:

1) Delphi 7 made almost 2 times smaller file than Delphi XE3 (32bit, Release mode). Lazarus made the biggest file. So maybe older FPC can make smaller file?

2) I stripped all non-mine units from the library. I even replaced Math and Windows with my own, super-short versions. This reduced the file size about twice.

3) System unit is something you can't just remove, but there are ways to create your own, recompile and replace. I guess this is also possible with Lazarus/FPC.

Tom
  • 2,962
  • 3
  • 39
  • 69