Live data from Hacker News

I want to compile a C program so simple I can explain all of the assembly

blog.ksplice.com

1–10 of 39 posts

Re: I want to compile a C program so simple I can explain all of the assembly

#2
reminds me of a really old article (before the term 'blog' even existed) about a person exploring why the heck a 'hello world' Linux ELF binary was so darn big. i think it's an interesting exercise to figure out why 'hello world' in your favorite language/runtime environment is the size that it is (e.g., what initialization code is being called, are any VMs or intepreters being setup, etc.)

Re: I want to compile a C program so simple I can explain all of the assembly

#3
post #2

reminds me of a really old article (before the term 'blog' even existed) about a person exploring why the heck a 'hello world' Linux ELF binary was so darn big. i think it's an interesting exercise to figure out why 'hello world' in your favorite language/runtime environment is the size that it is (e.g., what initialization code is being called, are any VMs or intepreters being setup, etc.)

That was my first thought as well. That article is found at http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm... (if that's the one you were thinking of)

Re: I want to compile a C program so simple I can explain all of the assembly

#4
post #2

reminds me of a really old article (before the term 'blog' even existed) about a person exploring why the heck a 'hello world' Linux ELF binary was so darn big. i think it's an interesting exercise to figure out why 'hello world' in your favorite language/runtime environment is the size that it is (e.g., what initialization code is being called, are any VMs or intepreters being setup, etc.)

That was my first thought as well. That article is found at http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm... (if that's the one you were thinking of)

Yup, it was the same article that I was thinking about. Although architecture has changed from x86 to amd64.

Re: I want to compile a C program so simple I can explain all of the assembly

#6
post #5

That was a really cool article, anyone with more knowledge on the subject want to comment on how sound the author's thought process is? Thanks.

It all looks correct to me. Some of it is a little "needlessly-surprised", honestly, like the bit about having to make a syscall trap to exit the program. Programs don't exit on their own: something needs to tell the kernel that the process is done.

Re: I want to compile a C program so simple I can explain all of the assembly

#7
post #2

reminds me of a really old article (before the term 'blog' even existed) about a person exploring why the heck a 'hello world' Linux ELF binary was so darn big. i think it's an interesting exercise to figure out why 'hello world' in your favorite language/runtime environment is the size that it is (e.g., what initialization code is being called, are any VMs or intepreters being setup, etc.)

That was my first thought as well. That article is found at http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm... (if that's the one you were thinking of)

yup exactly! HN makes for a great crowdsourced expert search engine ;)

Re: I want to compile a C program so simple I can explain all of the assembly

#8
post #6
post #5

That was a really cool article, anyone with more knowledge on the subject want to comment on how sound the author's thought process is? Thanks.

It all looks correct to me. Some of it is a little "needlessly-surprised", honestly, like the bit about having to make a syscall trap to exit the program. Programs don't exit on their own: something needs to tell the kernel that the process is done.

This point isn't actually blindingly obvious. Those of us raised on Pascal might have assumed (or, in my case, actually did assume, without thinking hard about it) that the program ended when the execution point reached "the end," where the main method was probably located in the binary.

It's disturbing how many Pascal-isms still pervade my thinking, even 20 years since I last (willingly) touched the language.

Re: I want to compile a C program so simple I can explain all of the assembly

#9
post #5

That was a really cool article, anyone with more knowledge on the subject want to comment on how sound the author's thought process is? Thanks.

The article is quite sound and doing all this is standard practice in the embedded world where you can't afford the size of glibc. The article is a bit incomplete, but presumably he'll address the rest in his next installment.

As a preview, to provide the correct C ABI to main() you need to zero the BSS (this is how your static variables get initialized), maybe copy the initalized data, call the constructors and destructors for C++ / C (gcc extension), provide memcpy() and others stdlib functions (which gcc will use even if you don't), etc. You can do all of this without assembly in C, but it does take some effort.

Post reply on HN