Nm (Unix) - Nm Output Sample

Nm Output Sample

/* * File name: test.c * For C code compile with: * gcc -c test.c * * For C++ code compile with: * g++ -c test.c */ int global_var; int global_var_init = 26; static int static_var; static int static_var_init = 25; static int static_function { return 0; } int global_function(int p) { static int local_static_var; static int local_static_var_init=5; local_static_var = p; return local_static_var_init + local_static_var; } int global_function2 { int x; int y; return x+y; } #ifdef __cplusplus extern "C" #endif void non_mangled_function { // I do nothing } int main(void) { global_var = 1; static_var = 2; return 0; }

If the previous code is compiled with the gcc C compiler, the output of nm command would be the following:

# nm test.o 0000000a T global_function 00000025 T global_function2 00000004 C global_var 00000000 D global_var_init 00000004 b local_static_var.1255 00000008 d local_static_var_init.1256 0000003b T main 00000036 T non_mangled_function 00000000 t static_function 00000000 b static_var 00000004 d static_var_init

When using the c++ compiler the output differs:

# nm test.o 0000000a T _Z15global_functioni 00000025 T _Z16global_function2v 00000004 b _ZL10static_var 00000000 t _ZL15static_functionv 00000004 d _ZL15static_var_init 00000008 b _ZZ15global_functioniE16local_static_var 00000008 d _ZZ15global_functioniE21local_static_var_init U __gxx_personality_v0 00000000 B global_var 00000000 D global_var_init 0000003b T main 00000036 T non_mangled_function

The differences between the outputs show also an example on how to solve the name mangling problem by using extern "C" in C++ code.

Read more about this topic:  Nm (Unix)

Famous quotes containing the words output and/or sample:

    Lizzie Borden took an axe
    And gave her mother forty whacks;
    When she saw what she had done,
    She gave her father forty-one.
    —Anonymous. Late 19th century ballad.

    The quatrain refers to the famous case of Lizzie Borden, tried for the murder of her father and stepmother on Aug. 4, 1892, in Fall River, Massachusetts. Though she was found innocent, there were many who contested the verdict, occasioning a prodigious output of articles and books, including, most recently, Frank Spiering’s Lizzie (1985)

    All that a city will ever allow you is an angle on it—an oblique, indirect sample of what it contains, or what passes through it; a point of view.
    Peter Conrad (b. 1948)