1

I've assembled a simple code with nasm and linked output obj file with both ld and golink The issue is golink output executable is 2kb of size but ld output executable is 85kb of size

I'm using mingw32 and both are using the library kernel32.dll.

linking commands are:

golink /entry _start /console test.obj kernel32.dll

&

gcc test.obj-L kernel32.dll

So why is this huge difference in sizes?

Am I doing something wrong? Could you enlighten me please.

Dan Jay
  • 816
  • 10
  • 25
  • 1
    You are probably linking with the C librrary, try `gcc -nostdlib`. – Jester Feb 06 '14 at 12:45
  • with -nostdlib option the file size became down to 5.02kb... But with -nostdlib option will I be able to use functions like _printf ? – Dan Jay Feb 06 '14 at 13:02
  • 1
    Functions like _printf are part of the C standard library and it is not possible to use them without linking against C standard library. – golem Oct 31 '15 at 20:54

1 Answers1

1

To hit 2KB executable size with GCC, run this:

gcc test.obj -nostartfiles -s

GCC contains more data within the executable by default, compared to GoLink linker. A simple gcc command contains a symbol table, relocation information and some other references. We use the -s flag to remove the symbol table and relocation information, and -nostartfiles flag to stop using the standard system startup files (which reference other stuff).

TechWisdom
  • 2,750
  • 3
  • 27
  • 35