Skip to content

Commit 75fe22a

Browse files
committed
update executable-by-hand post with hexdump
1 parent f12d93f commit 75fe22a

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

embed/content/posts/executable-by-hand.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,30 @@ If you've been following along:
532532
533533
True, it's the world's most pointless compiler, and if we're being pedantic it's technically just a code generator, since we're not translating a source language. But hey, now you have something you can build upon. Here's an exercise for you: swap out the hard-coded hello world string with a string that you read from a text file. That's sort of a language, right?
534534
535+
By the way, if you want to admire your handiwork, run `hexdump -C my_elf`.
536+
537+
```
538+
$ hexdump -C my_elf
539+
00000000 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 |.ELF............|
540+
00000010 02 00 3e 00 01 00 00 00 bf 10 40 00 00 00 00 00 |..>.......@.....|
541+
00000020 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |@...............|
542+
00000030 00 00 00 00 40 00 38 00 02 00 40 00 00 00 00 00 |....@.8...@.....|
543+
00000040 01 00 00 00 04 00 00 00 b0 00 00 00 00 00 00 00 |................|
544+
00000050 b0 10 40 00 00 00 00 00 b0 10 40 00 00 00 00 00 |..@.......@.....|
545+
00000060 0f 00 00 00 00 00 00 00 0f 00 00 00 00 00 00 00 |................|
546+
00000070 00 10 00 00 00 00 00 00 01 00 00 00 05 00 00 00 |................|
547+
00000080 bf 00 00 00 00 00 00 00 bf 10 40 00 00 00 00 00 |..........@.....|
548+
00000090 bf 10 40 00 00 00 00 00 27 00 00 00 00 00 00 00 |..@.....'.......|
549+
000000a0 27 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 |'...............|
550+
000000b0 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21 0a 00 b8 |Hello, world!...|
551+
000000c0 01 00 00 00 bf 01 00 00 00 48 be b0 10 40 00 00 |.........H...@..|
552+
000000d0 00 00 00 ba 0f 00 00 00 0f 05 b8 3c 00 00 00 bf |...........<....|
553+
000000e0 45 00 00 00 0f 05 |E.....|
554+
000000e6
555+
```
556+
557+
That, is a 230-byte hand-rolled Linux x86_64 executable. Everything the kernel needs to spawn a process. And it's beautiful.
558+
535559
## Gotta Go
536560
537561
When I had finished the first working version of this program, it took me a few hours of playing around with it to realize that, in my pursuit of learning more about compilers, I ended up building one.

0 commit comments

Comments
 (0)