In this tutorial, we will discuss the basics of this tool using some easy to understand examples. But before we do that, it’s worth mentioning that all examples here have been tested on an Ubuntu 16.04 LTS machine.
Linux nm command
The nm command line utility basically lists symbols from object files. Here’s the tool’s syntax:
nm [OPTIONS] OBJECT-FILENAME
And following is how the command’s man page explains it**********) that is:(**************) GNU nm lists the symbols from item files objfile…. If no object
files are detailed as arguments, nm assumes the file a.out.
Following are examples that are q&A-styled’ll give you a better idea on how nm works.
Q1. How command that is nm?
The fundamental using this demand is extremely self-explanatory – all you’ve got to accomplish is always to run the ‘nm’ demand and pass the title of this item file as input to it. The above command produced:
The three columns produced in output represent the symbol value, symbol type, and symbol name, respectively for example, I used the nm command with the ‘apl’ binary file:
The following screenshot shows the kind of output. There are several types of symbols – to know the details that are complete visit the nm demand guy web page.
Q2. Just how to have file names precede each icon in production?
This you can certainly do utilising the -A demand line choice.
nm -A [obj-file]
nm -A apl
So you can observe the file title ended up being added at first of every line.
Q3. Steps to make display that is nm symbols as well?
To make nm display debugger symbols as well in the output, use the -a command line option.
nm -a [obj-filename]
nm -a apl
The above command will display all symbols, including debugger-only symbols which are normally not listed.
Q4. How to make nm decode symbol that is low-level?
If you need, you can also force nm to decode low-level icon names into user-level names. This you can certainly do utilising the command that is-C option.
nm -C [obj-file]
nm -C apl
Here’s what the man page has to say about this option:
Besides removing any initial underscore prepended by the system,
this makes C++ function names readable. Different compilers have
different mangling styles. The demangling that is optional argument
could be used to select a suitable demangling design for your
Q5. Steps to make nm display that is only symbols?
In case you want nm to display only dynamic symbols , rather than the normal symbols, use the -D command line option.
nm -D [obj-file]
nm -D apl
So you can see that nm only produced dynamic symbols in the output.
Q6. How to use different nm output formats?
To enable different output formats, use the command line option that is-f. Automatically, the production is manufactured in the bsd structure, but you can enable ‘sysv’ and ‘posix’ formats as well.( if you want,**********)
nm -f [format] [obj-filename]
nm -f posix apl
Observe the change in format now.
Q7. How to make display that is nm outside symbols?
This it is possible to attain utilising the -g demand line choice.
nm -g [obj-file]
nm -g apl
Q8. Just what all kind choices nm provides?
By standard, the symbols are sorted alphabetically. But you can sort them numerically by their addresses using the -n command line option.( if you want,**********)
nm -n [objfile]
nm -n apl
So you can see the output is sorted by addresses now.
In case you don’t want nm to apply any kind of sorting (including the default one it uses), use the command line option that is-p. Shifting, to reverse any sort that is existing use the -r command line option.
Q9. How to make nm only display undefined symbols?
This you can do using the -u command line option.
nm -u [obj-file]
nm -u apl
Q10. How to make nm only display defined symbols?
To make nm only display defined symbols, use the –defined-only command line option.
nm –defined-only [obj-file]
nm –defined-only apl
Agreed, the nm command has a niche audience, but my personal experience says even as part of that audience, do keep in mind that such a tool exists if you don’t consider yourself. As well as for those that wish to utilize this energy, as soon as finished with exercising all examples right here, visit the man that is nm to learn more.