What’s Inside Your .o File? A Beginner-Friendly Guide to the Linux nm Command
Source: Dev.to

What Is the nm Command?
nm is a Linux command that shows the symbols from the symbol table of an object file or executable.
In simple words, nm tells you what functions and variables exist inside a compiled file. It is commonly used after compilation to inspect what got created inside the object file:
nm file.o
What Is a Symbol?
A symbol is simply a name that represents something in your program. In C, a symbol is the name of a function or a global variable that the compiler records inside a compiled file so that the linker (and other parts of the system) can identify and connect different pieces of code together.
Typical symbols are:
- A function
- A global variable
Symbol Table
| Symbol | Meaning | Simple Explanation |
|---|---|---|
| T | Text (global) | Global function |
| t | Text (local) | Static function |
| D | Data (global) | Global initialized variable |
| d | Data (local) | Static initialized variable |
| B | BSS (global) | Global uninitialized variable |
| b | BSS (local) | Static uninitialized variable |
| U | Undefined | Used but defined elsewhere |
Sections Explained
- Text (
.text) – stores functions (code) - Data (
.data) – stores initialized variables - BSS (
.bss) – stores uninitialized variables - Undefined (
U) – symbol exists but is defined elsewhere
Memory Layout

Example
#include <stdio.h>
// Global variable
int global_var = 10;
// Static global variable
static int static_var = 20;
// Global function
void global_function() {
printf("Inside global function\n");
}
// Static function
static void static_function() {
printf("Inside static function\n");
}
int main() {
global_function();
static_function();
return 0;
}
Compilation Stages
Step 1 – Compile into an object file
gcc -c file.c
This creates file.o.
Step 2 – Run nm on the object file
nm file.o
Typical output:
0000000000000000 T global_function
0000000000000000 T main
0000000000000000 t static_function
0000000000000000 D global_var
0000000000000000 d static_var
U printf
Important Note for Beginners
- ✅ Global variables become symbols.
- ✅ Functions become symbols.
- ❌ Local variables inside functions usually are not symbols.
void func() {
int x = 10; // Not a symbol (local)
}
x is temporary and does not appear in nm output.
Why Aren’t Local Variables Listed?
Local variables are omitted because they are not needed for linking. The symbol table shown by nm is meant to help the linker connect different object files, and local variables live only on the stack inside a function; they never participate in the linking process.