Programming Tools Guide
Chapter 4, COFF link editor

Changing the entry point

Changing the entry point

The UNIX system a.out optional header contains a field for the (primary) entry point of the file. This field is set using one of the following rules: the rule used is the first one (from the order given) that applies:

  1. The value of the symbol specified with the -e option to ld is used if present

  2. The value of the symbol _start is used if present

  3. The value of the symbol main (defined somewhere in the user program) is used if present

  4. The value zero is used
The start symbol (the C language startup routine) is usually defined in the crt file found in /lib. It may be defined in an ifile using an assignment statement of the form:
   _start   =   expression;
If ld is called through cc, a startup routine is automatically linked in. When the program is executed, this startup routine causes exit() to be called after main() finishes to close file descriptors and do other cleanup. When calling ld directly or when changing the entry point, the user must supply the start-up routine or make sure that the program always calls exit rather than falling through the end. Otherwise, the program will dump core.