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: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2012-11-06 4:50

>>52
I was evaluating MingW to see if it might be better than MSVC due to all the new features gcc has. I'm not convinced it's better.

Here's the results of something less trivial (internal network testing app):

Total size(MingW): 38.0KB
Total size(MSVC): 23.5KB

Size of sections:
MSVC:
 Header 0.5KB
 .text 19KB
 .rsrc 4KB

MingW:
 Header 1KB
 .text 27.5KB (!!!)
 .data 0.5KB
 .idata 1KB
 .CRT 0.5KB (WTF?)
 .tls 0.5KB (WTF?)
 .rsrc 1KB

A closer look shows that GCC/GAS is horrible at code generation. Here is a fragment of code pulled at random from the MingW executable:


004066E8 C70424407C4000   mov       d[esp], 00407C40
004066EF E838FFFFFF       call      0040662C
004066F4 51               push      ecx
004066F5 C744241001000000 mov       d,[esp+0010],00000001
004066FD C744240C0A194000 mov       d,[esp+000C],0040190A
00406705 C744240800000000 mov       d,[esp+0008],00000000
0040670D C7442404C8000000 mov       d,[esp+0004],000000C8
00406715 A120C84000       mov       eax,[0040C820]
0040671A 890424           mov       [esp],eax
0040671D E88AFEFFFF       call      004065AC
00406722 83EC14           sub       esp,14
00406725 A360934000       mov       [00409360],eax
0040672A 8D5DDC           lea       ebx,[ebp-0024]
0040672D E9DF000000       jmp       00406811
(It takes a detour here, for no good reason.)
00406811 C744241001000000 mov       d,[esp+0010],00000001
00406819 C744240C271B4000 mov       d,[esp+000C],00401B27
00406821 C744240800000000 mov       d,[esp+0008],00000000
00406829 C744240465000000 mov       d,[esp+0004],00000065
00406831 A120C84000       mov       eax,[0040C820]
00406836 890424           mov       [esp],eax
00406839 E8CEFCFFFF       call      0040650C
0040683E 83EC14           sub       esp,14
00406841 85C0             test      eax,eax

124 bytes.

This is the same portion of source code, compiled by MSVC:

004051BF 68481C4000      push      00401C48
004051C4 FF1528104000    call      LoadLibraryA
004051CA 8B1DB4104000    mov       ebx,[004010B4]
004051D0 6A01            push      01
004051D2 68111D4000      push      00401D11
004051D7 56              push      esi
004051D8 68C8000000      push      000000C8
004051DD FF3580974000    push      d,[00409780]
004051E3 FFD3            call      ebx
004051E5 6A01            push      01
004051E7 68E3204000      push      004020E3
004051EC 56              push      esi
004051ED 6A65            push      65
004051EF FF3580974000    push      d,[00409780]
004051F5 A3F8904000      mov       [004090F8],eax
004051FA FF1550114000    call      DialogBoxParamA
00405200 85C0            test      eax,eax

68 bytes.

Remember, this is -Os so I am not interested in stupid move-to-stack tricks. GCC/GAS seems completely oblivious to push imm8 and doesn't store frequently used constants (like 0 or the address of a function) in a register. The double-indirect import call is also bloaty, being 25% nops.

Conclusion:
MSVC 8/10
GCC 2/10

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