I compiled the following C code with GCC for windows 10 (mingw-64) :
#include <stdio.h>
int main(){
printf("Hello World!");
return 0;
}
with the command
gcc.exe -o test test.c
It works because when I execute the resulting file I do get a Hello World! in the console, however I am surprised because when I open test.exe in notepad++ it is 220 lines long with some readable text in it such as
Address %p has no image-section VirtualQuery failed for %d bytes at address %p
and also
Unknown pseudo relocation protocol version %d. Unknown pseudo relocation bit size %d.
However when I open the same file in Sublime Text 3, I get over 3300 lines of just some seemingly random numbers and letters such as :
4d5a 9000 0300 0000 0400 0000 ffff 0000
b800 0000 0000 0000 4000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 8000 0000
0e1f ba0e 00b4 09cd 21b8 014c cd21 5468
6973 2070 726f 6772 616d 2063 616e 6e6f
7420 6265 2072 756e 2069 6e20 444f 5320
6d6f 6465 2e0d 0d0a 2400 0000 0000 0000
5045 0000 6486 0f00 5aca 455d 0068 0000
9304 0000 f000 2700 0b02 021e 001e 0000
0038 0000 000a 0000 e014 0000 0010 0000
0000 4000 0000 0000 0010 0000 0002 0000
0400 0000 0000 0000 0500 0200 0000 0000
0020 0100 0004 0000 0e3e 0100 0300 0000
0000 2000 0000 0000 0010 0000 0000 0000
0000 1000 0000 0000 0010 0000 0000 0000
0000 0000 1000 0000 0000 0000 0000 0000
0080 0000 6c07 0000 0000 0000 0000 0000
0050 0000 7002 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
I also tried to get the assembly version and this one is the same in notepad and sublime :
.file "test.c"
.text
.def __main; .scl 2; .type 32; .endef
.section .rdata,"dr"
.LC0:
.ascii "Hello World!\0"
.section .text.startup,"x"
.p2align 4,,15
.globl main
.def main; .scl 2; .type 32; .endef
.seh_proc main
main:
subq $40, %rsp #,
.seh_stackalloc 40
.seh_endprologue
# test.c:2: int main(){
call __main #
# test.c:3: printf("Hello World!");
leaq .LC0(%rip), %rcx #,
call printf #
# test.c:5: }
xorl %eax, %eax #
addq $40, %rsp #,
ret
.seh_endproc
.ident "GCC: (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0"
.def printf; .scl 2; .type 32; .endef
First question :
why is the output different in sublime text and notepad ?
Second question :
where are the 0s and 1s , I thought machine code was only 0s and 1s ?
Third question :
how come it's 3300 lines for just a simple hello world, doesnt that sound grossly inefficient?
Thanks for any insight!