Nm
lastmod 2020-11-20created 2016-02-018 edits
GNU nm lists the symbols of the object file objfile. If no object file is given as an argument, it assumes 'a.out'.
Types
If the letter is lowercase, the symbol is local; if uppercase, it is global (External).
- A
- The symbol's value is absolute and will not be changed by further linking.
- B
- The symbol is in the uninitialized data section (known as BSS).
- C
- The symbol is common. Common symbols are uninitialized data. When linking, multiple common symbols may appear with the same name. If the symbol is defined anywhere, the common symbols are treated as undefined references. For more details on common symbols, see the description of the
--warn-commonoption in 'Linker options' of The GNU linker.
- D
- The symbol is in the initialized data section.
- G
- The symbol is in an initialized data section for small objects. Some object file formats permit more efficient access to small data objects, such as a global int variable as opposed to a large global array.
- I
- The symbol is an indirect reference to another symbol. This is a GNU extension to the rarely used a.out object file format.
- N
- The symbol is a debugging symbol.
- R
- The symbol is in a read-only section.
- S
- The symbol is in an uninitialized data section for small objects.
- T
- The symbol is in the text (code) section.
- U
- The symbol is undefined.
- V
- The symbol is a weak object. When a weak object is linked with a defined symbol, the defined symbol is used with no error. When an undefined weak symbol is linked and there is no defined symbol, the value of the weak symbol becomes zero with no error.
- W
- The symbol is a weak symbol that has not been specifically tagged as a weak object symbol. When a weak object is linked with a defined symbol, the defined symbol is used with no error. When an undefined weak symbol is linked and there is no defined symbol, the value of the weak symbol becomes zero with no error.
- -
- The symbol is a stabs symbol in an a.out object file. In this case, the next values printed are the stabs other field, the stabs desc field, and the stab type. Stabs symbols hold debugging information. See `Stabs Overview' in The "stabs" debug format. (Translator's note: this document is included in the GNU GDB source code.)
- ?
- The symbol type is unknown or depends on the object file format.
c++filt
Because of C++ name mangling, symbol names can be hard to read. In that case, the tool c++filt(1) makes them easy to read.
cinsk:~$ nm nm-ex.o | c++filt
0000001e T foo::work(int)
00000018 T foo::work()
00000006 T foo::foo()
00000000 T foo::foo()
00000012 T foo::~foo()
0000000c T foo::~foo()
Find symbol bash script
Finds object files (*.o) in subdirectories and searches them for the desired symbol.
#!/usr/bin/env bash
FIND_DIR=$1
FIND_SYMBOL=$2
if [[ -z $FIND_DIR || -z $FIND_SYMBOL ]]; then
echo 'find-symbol {dir} {symbol}'
exit 1
fi
OBJECT_FILES=`find $FIND_DIR -iname '*.o'`
for i in $OBJECT_FILES; do
find_result=`nm $i | c++filt | grep $FIND_SYMBOL`
if [[ ! -z $find_result ]]; then
echo "File: "$i
echo "Result: " $find_result
fi
done
See also
- GNU Binutils
- Nmae mangling
- gcc
- c++filt
- Cutter