Compiling: where is function "_start"?

by Martin Monperrus

When linking programs, by convention, function "_start" is the entry point. Hence, the linked has to find it somewhere in the object files or libraries that are linked. Otherwise, the linker would say something like:

  tcc: error: _start not defined

or

  undefined reference to `_start'

Function _start is provided by the implementation of the libc. However, there is no convention on the file name where the _start function should be put.

Once you know this, it makes things easier :)

Troubleshooting trace on a Debian system (“T” means the symbol is in the code (text) section, i.e. it is defined):

  $ nm /usr/lib/i386-linux-gnu/crt1.o | grep start
  00000000 D __data_start
  00000000 W data_start
          U __libc_start_main
  00000000 T _start
  
  $ nm /usr/lib/newlib/i486-linux-gnu/lib/crt0.o | grep start
  00000000 T _start
  
  $ nm /usr/lib/diet/lib/start.o | grep start
  00000000 T _start

See also:

Tagged as: