crt.txt 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. Mini FAQ about the misc libc/gcc crt files.
  2. Some definitions:
  3. PIC - position independent code (-fPIC)
  4. PIE - position independent executable (-fPIE -pie)
  5. crt - C runtime
  6. crt0.o crt1.o etc...
  7. Some systems use crt0.o, while some use crt1.o (and a few even use crt2.o
  8. or higher). Most likely due to a transitionary phase that some targets
  9. went through. The specific number is otherwise entirely arbitrary -- look
  10. at the internal gcc port code to figure out what your target expects. All
  11. that matters is that whatever gcc has encoded, your C library better use
  12. the same name.
  13. This object is expected to contain the _start symbol which takes care of
  14. bootstrapping the initial execution of the program. What exactly that
  15. entails is highly libc dependent and as such, the object is provided by
  16. the C library and cannot be mixed with other ones.
  17. On uClibc/glibc systems, this object initializes very early ABI requirements
  18. (like the stack or frame pointer), setting up the argc/argv/env values, and
  19. then passing pointers to the init/fini/main funcs to the internal libc main
  20. which in turn does more general bootstrapping before finally calling the real
  21. main function.
  22. glibc ports call this file 'start.S' while uClibc ports call this crt0.S or
  23. crt1.S (depending on what their gcc expects).
  24. crti.o
  25. Defines the function prologs for the .init and .fini sections (with the _init
  26. and _fini symbols respectively). This way they can be called directly. These
  27. symbols also trigger the linker to generate DT_INIT/DT_FINI dynamic ELF tags.
  28. These are to support the old style constructor/destructor system where all
  29. .init/.fini sections get concatenated at link time. Not to be confused with
  30. newer prioritized constructor/destructor .init_array/.fini_array sections and
  31. DT_INIT_ARRAY/DT_FINI_ARRAY ELF tags.
  32. glibc ports used to call this 'initfini.c', but now use 'crti.S'. uClibc
  33. also uses 'crti.S'.
  34. crtn.o
  35. Defines the function epilogs for the .init/.fini sections. See crti.o.
  36. glibc ports used to call this 'initfini.c', but now use 'crtn.S'. uClibc
  37. also uses 'crtn.S'.
  38. Scrt1.o
  39. Used in place of crt1.o when generating PIEs.
  40. gcrt1.o
  41. Used in place of crt1.o when generating code with profiling information.
  42. Compile with -pg. Produces output suitable for the gprof util.
  43. Mcrt1.o
  44. Like gcrt1.o, but is used with the prof utility. glibc installs this as
  45. a dummy file as it's useless on linux systems.
  46. crtbegin.o
  47. GCC uses this to find the start of the constructors.
  48. crtbeginS.o
  49. Used in place of crtbegin.o when generating shared objects/PIEs.
  50. crtbeginT.o
  51. Used in place of crtbegin.o when generating static executables.
  52. crtend.o
  53. GCC uses this to find the start of the destructors.
  54. crtendS.o
  55. Used in place of crtend.o when generating shared objects/PIEs.
  56. General linking order:
  57. crt1.o crti.o crtbegin.o [-L paths] [user objects] [gcc libs] [C libs] [gcc libs] crtend.o crtn.o
  58. More references:
  59. http://gcc.gnu.org/onlinedocs/gccint/Initialization.html