Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

crt0.o and crt1.o -- What's the difference?

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?

like image 796
Earlz Avatar asked Apr 25 '10 21:04

Earlz


People also ask

What is CRT1 O file?

crti.o is the bootstrap library, generally quite small. It's usually statically linked into your binary. It should be found in /usr/lib . If you're running a binary distribution they tend to put all the developer stuff into -dev packages (e.g. libc6-dev) as it's not needed to run compiled programs, just to build them.

What is crt0 used for?

crt0 (also known as c0) is a set of execution startup routines linked into a C program that performs any initialization work required before calling the program's main function.


1 Answers

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 systems 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 do not support constructors/destructors.
like image 138
kriss Avatar answered Sep 22 '22 03:09

kriss