Minimalist executable - Programmer

This is a discussion on Minimalist executable - Programmer ; Hello, I am programming for Windows, using MinGW (GCC 3.2.3) and I have just read "Techniques for reducing Executable size" ( http://www.catch22.org.uk/tuts/minexe.asp ). I want to write the smallest program with gcc, and I will use neither command line arguments ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Minimalist executable

  1. Minimalist executable

    Hello,

    I am programming for Windows, using MinGW (GCC 3.2.3) and I have just read
    "Techniques for reducing Executable size"
    (http://www.catch22.org.uk/tuts/minexe.asp). I want to write the smallest
    program with gcc, and I will use neither command line arguments (argc and
    argv) nor memory functions (malloc, ...) (I will take advantage of
    HeapAlloc) nor exception handling so that I do need the functions that are
    called before main(). As a consequence I just wote

    int mainCRTStartup()
    {
    return 0;
    }

    which is exactly 2 048 bytes, telling the linker I did not want any standard
    or startup library.

    I would like to get even smaller executables, by changing the FILEALIGN and
    ALIGN of the executable, as explained in catch22's article. They use, for
    Visual C++ 6.0 :

    //---------------
    // Make section alignment really small
    #pragma comment(linker, "/FILEALIGN:16")
    #pragma comment(linker, "/ALIGN:16")

    // Merge sections
    #pragma comment(linker, "/MERGE:.rdata=.text")
    #pragma comment(linker, "/MERGE:.text=.text")
    #pragma comment(linker, "/MERGE:.reloc=.text")
    //---------------

    How could I "translate" this for the MinGW linker ?

    Thanks,
    Sam.




  2. Re: Minimalist executable

    On Fri, 15 Aug 2003 14:34:56 +0200,
    Sam <_antispam_sam.g@myrealbox.com> wrote
    in Msg. <3f3cd373$0$26422$626a54ce@news.free.fr>

    > I want to write the smallest program with gcc,


    That's off-topic in comp.lang.c. Please try to limit this thread to
    comp.os.ms-windows.programmer.misc where it belongs (f'up set)

    --Daniel

    --
    "With me is nothing wrong! And with you?" (from r.a.m.p)

  3. Re: Minimalist executable

    Sam wrote:

    > int mainCRTStartup()

    ^

    In C you need to write "(void)".

    > #pragma comment(linker, "/MERGE:.rdata=.text")
    > #pragma comment(linker, "/MERGE:.text=.text")
    > #pragma comment(linker, "/MERGE:.reloc=.text")
    > //---------------
    >
    > How could I "translate" this for the MinGW linker ?


    Search a group or mailing list for that compiler, since this is about the
    linker not the C language.

    /Sven

    --
    Sven Semmler http://www.semmlerconsulting.com/
    GPG Fingerprint: 72CA E26D C2A3 1FEB 7AFC 10EA F769 A9A4 937F 5E67

  4. Re: Minimalist executable

    "Sam" <_antispam_sam.g@myrealbox.com> wrote in message
    news:3f3cd373$0$26422$626a54ce@news.free.fr...
    > //---------------
    > // Make section alignment really small
    > #pragma comment(linker, "/FILEALIGN:16")
    > #pragma comment(linker, "/ALIGN:16")
    >
    > // Merge sections
    > #pragma comment(linker, "/MERGE:.rdata=.text")
    > #pragma comment(linker, "/MERGE:.text=.text")
    > #pragma comment(linker, "/MERGE:.reloc=.text")
    > //---------------
    >
    > How could I "translate" this for the MinGW linker ?


    ld --help is useful . I've got Cygwin here, not MinGW, but hopefully they
    use the same version of ld.

    Relevant alignment options:
    --file-alignment Set file alignment
    --section-alignment Set section alignment

    I don't think there's an option for merging read-only sections like the
    second set of pragmas. I don't know off-hand what sections ld wants to emit
    (maybe it puts everything in .text anyway), but you could check the linker
    script. On Cygwin, they're stored in /lib/ldscripts. I'd recommend making a
    copy of one of these, modifying it so that sections are merged as
    appropriate, and passing its name to ld via the -T option. Editing the
    linker script manually can also give you more control over alignment; in
    fact, it gives you full control over where each section goes.

    --
    Tim Robinson (MVP, Windows SDK)
    http://www.themobius.co.uk/



  5. Re: Minimalist executable

    On Fri, 15 Aug 2003 14:34:56 +0200, in comp.lang.c , "Sam"
    <_antispam_sam.g@myrealbox.com> wrote:

    >Hello,
    >
    >I am programming for Windows, using MinGW (GCC 3.2.3) and I have just read
    >"Techniques for reducing Executable size"

    .....
    >I would like to get even smaller executables, by changing the FILEALIGN and
    >ALIGN of the executable, as explained in catch22's article.

    .....
    >How could I "translate" this for the MinGW linker ?


    This has /ABSOLUTELY/ nothing to do with C, you need to ask in a group
    specialising in MinGW, whatever that is. Be prepared for
    disappointment.
    --
    Mark McIntyre
    CLC FAQ
    CLC readme:


    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---

+ Reply to Thread