Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the usage of Mcrt1.o and Scrt1.o?

I'm sticking on the usage of following two files, which are Mcrt1.o and Scrt1.o. Can anyone help to let me know what are those two files for. How to use it? Let's take gcrt1.o for example, which is quite useful when compile with -pg option for performance test. Thanks

like image 427
Daniel Avatar asked May 08 '13 08:05

Daniel


1 Answers

Files of the form *crt*.o are invariably C runtime startup code (the bulk of the C runtime tends to exist in libraries, the startup code is an object file as it's always needed).

The description of the various types can be found here, copied below to make the answer self-contained. First some definitions:

Mini FAQ about the misc libc/gcc crt files.

Some definitions:
  PIC - position independent code (-fPIC)
  PIE - position independent executable (-fPIE -pie)
  crt - C runtime

Then the various startup object files:

crt0.o
  Older style of the initial runtime code ?  Usually not generated anymore
  with Linux toolchains, but often found in bare metal toolchains.  Serves
  same purpose as crt1.o (see below).
crt1.o
  Newer style of the initial runtime code.  Contains the _start symbol which
  sets up the env with argc/argv/libc _init/libc _fini before jumping to the
  libc main.  glibc calls this file 'start.S'.
crti.o
  Defines the function prolog; _init in the .init section and _fini in the
  .fini section.  glibc calls this 'initfini.c'.
crtn.o
  Defines the function epilog.  glibc calls this 'initfini.c'.
Scrt1.o
  Used in place of crt1.o when generating PIEs.
gcrt1.o
  Used in place of crt1.o when generating code with profiling information.
  Compile with -pg.  Produces output suitable for the gprof util.
Mcrt1.o
  Like gcrt1.o, but is used with the prof utility.  glibc installs this as
  a dummy file as it's useless on linux systems.

And some others:

crtbegin.o
  GCC uses this to find the start of the constructors.
crtbeginS.o
  Used in place of crtbegin.o when generating shared objects/PIEs.
crtbeginT.o
  Used in place of crtbegin.o when generating static executables.
crtend.o
  GCC uses this to find the start of the destructors.
crtendS.o
  Used in place of crtend.o when generating shared objects/PIEs.

Finally, common linking order:

General linking order:
  crt1.o crti.o crtbegin.o [-L paths] [user objects] [gcc libs]
    [C libs] [gcc libs] crtend.o crtn.o
like image 200
paxdiablo Avatar answered Oct 12 '22 18:10

paxdiablo