Results 1 to 9 of 9

Thread: the smallest fpc program

  1. #1

    the smallest fpc program

    i've tried to make the smallest fpc program without compression , this is what i did


    program test;
    begin
    end.

    //---compilation ---
    fpc test.pas -O3 -XsX -CX -Sd

    i got 30kb

    so any one else have got less than 30kb ?

    (with delphi i got 3.5 kb , with mini system and sysinit units)
    i don't know if fpc has system units like in delphi !!
    Last edited by AirPas; 09-11-2011 at 09:27 AM.

  2. #2
    For FPC the smallest RTL you can get(without ugly hacks or using Crinkler) is this:

    system.pas
    Code:
    unit system;
    
    interface
    
    type
     HResult = longint;
    
    implementation
    
    procedure FPC_INITIALIZEUNITS; nostackframe; [public, alias: 'FPC_INITIALIZEUNITS'];
    begin
    end;
    
    procedure FPC_DO_EXIT; nostackframe; [public, alias: 'FPC_DO_EXIT'];
    begin
    end;
    
    end.
    sysinitpas.pas
    Code:
    unit sysinitpas;
    
    interface
    
    implementation
    
    procedure PASCALMAIN; external name 'PASCALMAIN';
    
    procedure ExitProcess(ExitCode: longint); stdcall; external 'kernel32.dll' name 'ExitProcess';
    
    procedure Entry; [public, alias: '_mainCRTStartup'];
    begin
       PASCALMAIN;
       ExitProcess(0);
    end;
    
    end.
    fpintres.pas
    Code:
    unit fpintres;
    
    interface
    
    implementation
    
    end.
    With Crinkler you can easily get below 1kb if you craft some proper RTL units
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  3. #3
    hi jsoftware
    thanks , but how could you get this compiled together !
    i mean the commandline

    i used -O3 -XsX -CX -Sd but i only got system.o

  4. #4
    does FPC not remove unused code, variable and consts?

    in my assembler/compiler, i have include 10,000 lines of code, and if my main file does nothing it will be the minimum exe size, why does FPC use 30kb that is ridiculous....

    in ziron, even a messagebox app is 2kb

    Code:
    program WIN32GUI 'Test';
    
    #include 'kernel32.zir';
    #include 'user32.zir';
    
    MessageBox(0, 'Hello World!', 'Hello', MB_OK);
    
    ExitProcess(0);
    I'd be interested in what FPU adds so much to the exe to be 30kb!!!!!!!! :O

    the minimum size note on windows (PE) is 1kb, since you need 512 bytes for headers and 512 for your code.

    Code:
    program WIN32GUI 'Test';
    
    #include 'kernel32.zir';
    #include 'user32.zir';
    #include 'strings.zir';
    #include 'gdi32.zir';
    
    function Unused1() {
    	#repeat 100000:
    		eax = eax;		//useless code to make the exe huge :) (not really since it will be discarded)
    	#end
    }
    
    MessageBox(0, 'Hello World!', 'Hello', MB_OK);
    
    ExitProcess(0);
    this compiles with an equiv of 101873 lines of code and is still only 2kb, i can add error checking too which takes it to 3.5kb......
    Last edited by Colin; 09-11-2011 at 03:35 PM.
    Download the Ziron Assembler
    Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.

  5. #5
    You have to compile the units first.

    fpc -O3 -Us system
    fpc -O3 fpintres
    fpc -O3 sysinitpas
    fpc -O3 -XsX -CX yourcode
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  6. #6
    Quote Originally Posted by Colin View Post
    does FPC not remove unused code, variable and consts?

    in my assembler/compiler, i have include 10,000 lines of code, and if my main file does nothing it will be the minimum exe size, why does FPC use 30kb that is ridiculous....
    You forget that FPC has a lot of internals that needs initialization in a stock RTL. Multithreaded heap management, code page conversion tables for strings, wide string managers, thread managers, stack checking, command line parsing, virtual methods for TObject, etc
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  7. #7
    thanks for your help ,looks interesting now , MessageBox becomes 542b !! after compressing with upx and com
    Last edited by AirPas; 10-11-2011 at 07:46 AM.

  8. #8
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Aside from a 30kb executeable being limited in functionality - UPX is a very good bet IMO. Although I admit I find 700kb ok and 70kb to be very small for me. You could always do some ASM8086 on linux - virtually no size at all.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  9. #9
    Also read the FPC wiki page about EXE sizes: http://wiki.freepascal.org/Size_Matters

    Most importantly the "why bother?" bit.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •