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
The short answer: Mcrt1.o is used when you're profiling your code, while Scrt1.o is used when generating PIEs (position-independent executables).
Mode detail below.
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).
One implementation had this description of the various types (originally extracted from a web site that has now disappeared) is below.
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 environment with argc, argv, etc before jumping to the libc main function.crti.o: Defines the function prolog; _init in the .init section and _fini in the .fini section.crtn.o: Defines the function epilog.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.Mcrt1.o: Like gcrt1.o, but is used with the profiler utility.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.