cassembly

Creating and running executable by hand


Just for interest sake, I want to compile and run the simplest C program by hand;

//t.c

int main() {
       return 0;
}

So I want to do:

The problem I'm having is with as, since running the final command yields:

ld: warning: cannot find entry symbol _start; defaulting to 00000000000400b0

What's going on? I purposly left out libc to keep this as simple as possible, but I don't understand what's happening. What flags am I missing?


Solution

  • There's a bit more to loading and executing a program. As you can guess from the linker output, execution starts not at main, but at _start, which is provided by the CRT (C runtime) library that is bundled with the compiler and gets linked with your code behind the scene.

    Here and here are some overviews of what's going on at program startup on Linux.

    Do cc -v -Wall on your dummy source to see all the required steps in detail.