← Back to Notebook

How compilers work


Compiler Toolchain

What this program does?

0000000   317 372 355 376 014 000 000 001 000 000 000 000 001 000 000 000
0000020   004 000 000 000 270 001 000 000 000 040 000 000 000 000 000 000
0000040   031 000 000 000 070 001 000 000 000 000 000 000 000 000 000 000
0000060   000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
0000100   150 000 000 000 000 000 000 000 330 001 000 000 000 000 000 000
0000120   150 000 000 000 000 000 000 000 007 000 000 000 007 000 000 000
0000140   003 000 000 000 000 000 000 000 137 137 164 145 170 164 000 000
0000160   000 000 000 000 000 000 000 000 137 137 124 105 130 124 000 000
0000200   000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
0000220   064 000 000 000 000 000 000 000 330 001 000 000 002 000 000 000
0000240   100 002 000 000 003 000 000 000 000 004 000 200 000 000 000 000
0000260   000 000 000 000 000 000 000 000 137 137 143 163 164 162 151 156
0000300   147 000 000 000 000 000 000 000 137 137 124 105 130 124 000 000
0000320   000 000 000 000 000 000 000 000 064 000 000 000 000 000 000 000
0000340   017 000 000 000 000 000 000 000 014 002 000 000 000 000 000 000
0000360   000 000 000 000 000 000 000 000 002 000 000 000 000 000 000 000
0000400   000 000 000 000 000 000 000 000 137 137 143 157 155 160 141 143
0000420   164 137 165 156 167 151 156 144 137 137 114 104 000 000 000 000
0000440   000 000 000 000 000 000 000 000 110 000 000 000 000 000 000 000
0000460   040 000 000 000 000 000 000 000 040 002 000 000 003 000 000 000
0000500   130 002 000 000 001 000 000 000 000 000 000 002 000 000 000 000
0000520   000 000 000 000 000 000 000 000 062 000 000 000 030 000 000 000
0000540   001 000 000 000 000 000 017 000 000 005 017 000 000 000 000 000
0000560   002 000 000 000 030 000 000 000 140 002 000 000 006 000 000 000
0000600   300 002 000 000 050 000 000 000 013 000 000 000 120 000 000 000
0000620   000 000 000 000 004 000 000 000 004 000 000 000 001 000 000 000
0000640   005 000 000 000 001 000 000 000 000 000 000 000 000 000 000 000
0000660   000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
*
0000720   000 000 000 000 000 000 000 000 377 203 000 321 375 173 001 251
0000740   375 103 000 221 010 000 200 122 350 013 000 271 277 303 037 270
0000760   000 000 000 220 000 000 000 221 000 000 000 224 340 013 100 271
0001000   375 173 101 251 377 203 000 221 300 003 137 326 110 145 154 154
0001020   157 054 040 127 157 162 154 144 041 012 000 000 000 000 000 000
0001040   000 000 000 000 000 000 000 000 064 000 000 000 000 000 000 004
0001060   000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
0001100   040 000 000 000 005 000 000 055 034 000 000 000 001 000 000 114
0001120   030 000 000 000 001 000 000 075 000 000 000 000 001 000 000 006
0001140   042 000 000 000 016 001 000 000 000 000 000 000 000 000 000 000
0001160   001 000 000 000 016 002 000 000 064 000 000 000 000 000 000 000
0001200   034 000 000 000 016 002 000 000 064 000 000 000 000 000 000 000
0001220   026 000 000 000 016 003 000 000 110 000 000 000 000 000 000 000
0001240   010 000 000 000 017 001 000 000 000 000 000 000 000 000 000 000
0001260   016 000 000 000 001 000 000 000 000 000 000 000 000 000 000 000
0001300   000 154 137 056 163 164 162 000 137 155 141 151 156 000 137 160
0001320   162 151 156 164 146 000 154 164 155 160 062 000 154 164 155 160
0001340   061 000 154 164 155 160 060 000                                
0001350

Complex, right? Let me help you a bit

main.o:	file format mach-o arm64

Disassembly of section __TEXT,__text:

0000000000000000 <ltmp0>:
       0: d10083ff     	sub	sp, sp, #0x20
       4: a9017bfd     	stp	x29, x30, [sp, #0x10]
       8: 910043fd     	add	x29, sp, #0x10
       c: 52800008     	mov	w8, #0x0                ; =0
      10: b9000be8     	str	w8, [sp, #0x8]
      14: b81fc3bf     	stur	wzr, [x29, #-0x4]
      18: 90000000     	adrp	x0, 0x0 <ltmp0>
      1c: 91000000     	add	x0, x0, #0x0
      20: 94000000     	bl	0x20 <ltmp0+0x20>
      24: b9400be0     	ldr	w0, [sp, #0x8]
      28: a9417bfd     	ldp	x29, x30, [sp, #0x10]
      2c: 910083ff     	add	sp, sp, #0x20
      30: d65f03c0     	ret

Now if you have some notions about ARM64 you could have guessed, but in case you don’t know assembly, I’m gonna help you even more:

#include <stdio.h>

int main(void)
{
    printf("Hello, World!\n");
    return 0;
}

Now is pretty clear, even a person not familiar with C programming language could have guessed what the program does.

This is what a compiler does, takes human-readable code (source code) and converts it into a target language, a language that the computer can understand (machine code).

Well, to be more precise this is what a compiler toolchain does, a compiler is just one component of the whole toolchain.

A compiler toolchain includes multiple stages:

canvas explaining compiler toolchain process

Compiler