2016-04-20 14 views
5

Das ist mein Code:Wie nm Ausgabe lesen?

int const const_global_init = 2; 
    int const const_global; 
    int global_init = 4; 
    int global; 

    static int static_global_init = 3; 
    static int static_global; 

    static int static_function(){ 
     return 2; 
    } 
    double function_with_param(int a){ 
     static int static_local_init = 3; 
     static int static_local; 

     return 2.2; 
    } 


    int main(){ 
} 

I erzeugen main.o und ich versuche nm Ausgang zu verstehen. Nachdem ich nm main.o --printfile-name -a verwenden bekomme ich folgende Ausgabe:

main.o:0000000000000000 b .bss 
main.o:0000000000000000 n .comment 
main.o:0000000000000004 C const_global 
main.o:0000000000000000 R const_global_init 
main.o:0000000000000000 d .data 
main.o:0000000000000000 r .eh_frame 
main.o:000000000000000b T function_with_param 
main.o:0000000000000004 C global 
main.o:0000000000000000 D global_init 
main.o:0000000000000027 T main 
main.o:0000000000000000 a main.c 
main.o:0000000000000000 n .note.GNU-stack 
main.o:0000000000000000 r .rodata 
main.o:0000000000000000 t static_function 
main.o:0000000000000000 b static_global 
main.o:0000000000000004 d static_global_init 
main.o:0000000000000004 b static_local.1733 
main.o:0000000000000008 d static_local_init.1732 
main.o:0000000000000000 t .text 

I 2. und 3. Säule verstanden, aber ich wirklich nicht wissen, was in der ersten Spalte ist, ob es die Adresse oder Größe? Ich weiß etwas über .bbs, .comment, .data und .text Segmente, aber was ist das .eh_frame, .note.GNU-stack und .rodata?

Antwort

3

... ich weiß wirklich nicht, was in der ersten Spalte ist, ob es die Adresse oder die Größe ist?

Mein lokaler manpage (von man nm) sagt

DESCRIPTION 
     GNU nm lists the symbols from object files objfile.... If no object files are listed as arguments, nm assumes the file a.out. 

     For each symbol, nm shows: 

     · The symbol value, in the radix selected by options (see below), or hexadecimal by default. 

, die die erste Spalte ist der 'Wert' des Symbols. Um zu verstehen, was das bedeutet, ist es hilfreich, etwas über ELF und den Laufzeit-Linker zu wissen, aber im Allgemeinen wird es einfach ein Offset in den relevanten Abschnitt sein.

Verständnis etwas über ELF wird auch mit den anderen Punkten helfen: man elf uns sagt, dass der .rodata Abschnitt schreibgeschützt Daten (dh:. Konstante Werte in das Programm fest einprogrammiert, die sich nie ändern Stringliterale könnte hier gehen).

.eh_frame wird für Ausnahmebehandlung und andere Call-Stack-Frame-Metadaten verwendet (eine Suche nach eh_frame hat this question als erster Treffer).