web-dev-qa-db-ja.com

nm出力の読み方は?

それが私のコードです:

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(){
}

main.oを生成し、nmの出力を理解しようとします。 nm main.o --printfile-name -aを使用すると、次の出力が得られます。

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

2列目と3列目はわかりましたが、最初の列が住所なのかサイズなのか本当にわかりません。 .bbs.comment.data.textセグメントについて考えていることは知っていますが、.eh_frame.note.GNU-stack.rodataとは何ですか?

9
Ice

...住所なのかサイズなのか、最初の列の内容が本当にわかりませんか?

私のローカルマンページ(man nmから)は言います

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.

つまり、最初の列はシンボルの「値」です。それが何を意味するのかを理解するには、ELFとランタイムリンカーについて何かを知っておくと役に立ちますが、一般的には、関連するセクションへのオフセットにすぎません。

ELFについて何かを理解することは、他の点にも役立ちます。man elfは、.rodataセクションが読み取り専用データであることを示します(つまり、プログラムにハードコードされた定数値は決して変更されません。文字列リテラルはここに)。

.eh_frameは、例外処理およびその他の呼び出しスタックフレームメタデータに使用されます(eh_frameの検索では、最初のヒットとして この質問 があります)。

4
Useless