views:

490

answers:

2

Hello, recently I've been trying to debug some low level work and I could not find the crt0.S for the compiler(avr-gcc) but I did find a crt1.S (and the same with the corresponding .o files)

What is the difference between these two files? Is crt1 something completely different or what? They both seem to have to do with something for bootstrapping(setting up stack frame and such), but why the distinction?

A: 

I believe the short answer is that crt0 contains the common startup code for statically-linked binaries, whereas crt1 is used in dynamically-linked binaries that make use of shared libraries.

Arto Bendiken
This doesn't make sense though. avr-gcc produces statically linked executables and uses crt1.
Earlz
Also, when I created my own OS for the x86, my executables were static linked and used crt0
Earlz
+1  A: 

Both crt0/crt1 do the same thing, basically do what is needed before calling main() (like initializing stack, setting irqs, etc.). You should link with one or the other but not both. They are not really libraries but really inline assembly code.

As far as I understand, crt comes in two "flavors"

  • crt1 is used on system that support constructors and destructors (functions called before and after main and exit). In this case main is treated like a normal function call.
  • crt0 is used on systems that does not support constructors/destructors.
kriss
+1 http://lists.uclibc.org/pipermail/uclibc/2002-December/025943.html
stacker