2013-05-08 9 views
5

Ich bleibe bei der Verwendung der folgenden zwei Dateien, die Mcrt1.o und Scrt1.o sind. Kann jemand mir helfen zu wissen, wofür diese zwei Dateien sind? Wie man es benutzt? Lassen Sie uns zum Beispiel gcrt1.o nehmen, was sehr nützlich ist, wenn Sie mit der Option -pg für den Leistungstest kompilieren. DankeWas ist die Verwendung von Mcrt1.o und Scrt1.o?

Antwort

7

Dateien des Formulars *crt*.o sind ausnahmslos C-Laufzeit-Startcode (der Großteil der C-Laufzeit besteht in Bibliotheken, der Startcode ist eine Objektdatei, wie sie immer benötigt wird).

Die Beschreibung der verschiedenen Typen kann here gefunden werden, kopiert unten, um die Antwort in sich geschlossen zu machen. Zunächst einige Definitionen:

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 

Dann werden die verschiedenen Startobjektdateien:

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. 

Und einige andere:

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. 

Schließlich gemeinsame Verknüpfung Reihenfolge:

General linking order: 
    crt1.o crti.o crtbegin.o [-L paths] [user objects] [gcc libs] 
    [C libs] [gcc libs] crtend.o crtn.o 
+0

I don Ich weiß nicht, in welchem ​​Szenario wir Scrt1.oi verwenden werden anstelle von crt1.o? – Daniel

Verwandte Themen