Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Fucking MingW

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2012-11-04 9:11

#include <stdio.h>

int main() {
 printf("Hello world!\n");
 return 0;
}


Default MingW compilation+link size: 47KB
Best MingW compilation+link size: 8KB

Default MSVC compilation+link size: 40KB
Best MSVC compilation+link size: 1KB

After postprocessing:
MingW (using MS's linker and libs): 1594 bytes
MSVC: 624 bytes

What the fuck? Am I missing something here?

MingW optimised command line (compile only):
gcc -nostdlib -Os -c -s -o hello.obj hello.c -Wl,--gc-sections,--section-alignment,4096,--file-alignment,512

MingW link command line:
link hello.obj msvcrtlib mainstub.obj /align:4096 /filealign:512 /entry:main /merge:.rdata=.text /merge:.eh_fram=.text /merge:.text.st=.text /section:.text,EWR /stub:mzstub64.exe

mainstub.obj is a dummy __main because libming32.a which is supposed to contain it also contains __CTOR_LIST_ and some other C++ shit. I'm compiling a C program, with gcc, and they force you to link with a bunch of C++ shit? Are you kidding me?

(Why won't it merge the bloody .eh_fram and .text.st sections?!?! Maybe this is a bug of MS's linker since it merges fine with its own compiler output, but the compiler shouldn't be generating .eh_fram and .text.st anyway!)

Executables for your inspecting:
MingW: http://pastebin.com/vZn5WtMz
MSVC: http://pastebin.com/AV63Hr5x

Therefore, I challenge anyone to come up with a smaller Hello World using MingW, and post the commands you used to do it.

Name: Anonymous 2012-11-04 22:38

mingw gcc + msvc link:

$ gcc -nostdlib -Os -s -c small.c -ffunction-sections -fdata-sections -Wl,--gc-sections,--section-alignment,4096,--file-alignment,512

$ link small.o msvcrt.lib __main.o /entry:_start /subsystem:console /merge:.rdata=.text /merge:.eh_frame=.text /merge:.bss=.text /fixed

$ du -b small.exe
1024

Best I could get with just mingw gcc and mingw ld:

$ gcc -Os -s -o smallmingw.exe small.c -mconsole -nostartfiles -ffunction-sections -fdata-sections -Wl,--gc-sections,--section-alignment,4096,--file-alignment,512,-e,__start,merge_sections.ld

$ du -b smallmingw.exe
1536

merge_sections.ld script:

SECTIONS {
    .text : {
        *(.text)
        *(.eh_frame)
        *(.idata)
        *(.rdata)
        *(SORT(.rdata$*))
    }
}


(I still can't get rid of the .idata section for some reason, if I could the size would be 1K just like msvc linker)

small.c:

#include <stdio.h>

void _start(void)
{
    puts("Hello World");
}


And this is not using any packer or PE stub tricks, just the basic compiler output.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List