Live data from Hacker News

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

blog.ksplice.com

31–39 of 39 posts

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

#31
post #24

I'm not sure I understand the revelation here. GCC is often used to target single boards with little resources. You can build gcc for the environment you want to target. Sounds like attempting to use a compiler flag in a way it wasn't intended. If you wanted to reduce the binary size wouldn't you look at the linker?

Did you actually read the article? You don't sound like you did.

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

#32
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)

The same project with Win32 PEs: http://www.phreedom.org/solar/code/tinype/

I've used that page as a reference several times over the years.

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

#33

I wish someone would dissect JVM in exactly the same way: i.e. clearly explained what needs to be stripped off to have a quickly loading "hello world" implementation eating less than 1MB of RAM and starting in a few microseconds, like a normal, sane process should. All these wonderful things are being built (Clojure, JRuby) on top of JVM that are of no use outside of web/EE because default JVM is so heavy. Yes, a VM…

This reminds me of a blog post from one of the Unity developers: We joke that doing anything in C# will result in an XML parser being included somewhere. This is not that far from the truth; e.g. calling float.ToString() will pull in whole internationalization system, which probably somewhere needs to read some global XML configuration file to figure out whether daylight savings time is active when Eastern European B…

I heard a joke once that anytime you run Javascript in a browser an XML parser is being included somewhere.

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

#36

If you really want to write code that you can understand all the way down I suggest starting from as close to bare metal as your level of masochism allows. For me, that's GRUB. This tutorial walks you through making a kernel image that GRUB can load, and shows how to poke bytes into video memory to print characters to the screen: http://wiki.osdev.org/Bare_bones

And then buy an FPGA and bust out some Verilog and write the metal yourself.

which kind of reminds of alan-kay's musing "Hardware is really just software crystallized early"

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

#37

I wish someone would dissect JVM in exactly the same way: i.e. clearly explained what needs to be stripped off to have a quickly loading "hello world" implementation eating less than 1MB of RAM and starting in a few microseconds, like a normal, sane process should. All these wonderful things are being built (Clojure, JRuby) on top of JVM that are of no use outside of web/EE because default JVM is so heavy. Yes, a VM…

> Just look at Microsoft CLR: same feature set, yet none of that sluggish starting, RAM-wasting JVM nonsense.

If anything, CLR is more bloated than the JVM, not less. The libraries it uses just are used at startup, so when you start an app they are already in memory.

Note that I don't think that the bloatedness of JVM or CLR is a bad thing -- as long as you properly dynamically link, the cost of having them is quite minimal on modern hardware.

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

#38

I wish someone would dissect JVM in exactly the same way: i.e. clearly explained what needs to be stripped off to have a quickly loading "hello world" implementation eating less than 1MB of RAM and starting in a few microseconds, like a normal, sane process should. All these wonderful things are being built (Clojure, JRuby) on top of JVM that are of no use outside of web/EE because default JVM is so heavy. Yes, a VM…

There are folks within Sun/Oracle doing exactly that. One effort, Project Jigsaw, is aimed at splitting the large rt.jar into smaller modules to reduce the number of classes loaded on startup. Here is an update from last December:

http://blogs.sun.com/alanb/entry/is_the_jdk_losing_its

Somewhere in there is a comment that says the JVM loads around 300 classes to run an empty main class.

I'm curious to see what the merged HotSpot+JRockit JVM will look like in a few years.

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

#39
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)

I'm not surprised you thought of that; Jessica McKellar's article almost sounds as if it was modeled after mine in places. I'm wondering now if that's due to actual imitation, or a subconscious influence, or if it's just a natural approach for someone to take to the subject. Which naturally leads to the question: was I unconsciously imitating someone else when I wrote my article?

(Come to think of it, I vaguely remember having in mind some of Isaac Asmiov's science essays when I wrote that -- one of the type in which he would trace the discovery of some principle through several refinements over the centuries. Those essays gave me an appreciation for the value of studying science in its historical context. But that's a much more general influence than what I'm referring to.)

Post reply on HN