LoginSignup
7
8

More than 5 years have passed since last update.

nmコマンドでオブジェクトからシンボルのリストを表示

Posted at

nmコマンドを使うとオブジェクトからシンボルを表示させることができて便利です。

たとえば、

hello.c
#include <stdio.h>

int a;
static int b;

void
hello(void) {
    static int c;
    c = 3;
    int d = a + b + c;
    printf("Hello %d\n", a);
}

int
main(void) {
    a = 1;
    b = 2;
    hello();
    return 0;
}

をコンパイルしてシンボルを表示させてみます。

$ gcc -c hello.c
$ nm hello.o

結果は以下のようになります。

0000000000000004 C a
0000000000000000 b b
0000000000000004 b c.2046
0000000000000000 T hello
0000000000000047 T main
                 U printf

シンボルの型とシンボル名が表示されています。
シンボルの方は大文字がグローバル、小文字がローカルです。
bはデータセクションにあり、 Tはコードセクションにあることを表しています。

7
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
8