0
(in situations where-in you need information related to symbols in an object file*******)If you are a Linux user who is also into system level software development, you may find yourself. You’ll be glad to know there exists a command line utility – dubbed nm – that you can use in these situations.

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:

Linux nm Command Tutorial for newbies (10 Examples) 13

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:

nm apl

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]

For instance:

nm -A apl

Linux nm Command Tutorial for newbies (10 Examples) 14

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]

For example:

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]

For example:

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
           compiler.

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]

For example:

nm -D apl

Linux nm Command Tutorial for newbies (10 Examples) 15

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]

For example:

nm -f posix apl

Linux nm Command Tutorial for newbies (10 Examples) 16

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]

For instance:

nm -g  apl

Linux nm Command Tutorial for newbies (10 Examples) 17

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]

For example:

nm -n apl

Linux nm Command Tutorial for newbies (10 Examples) 18

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]

For example:

nm -u apl

Linux nm Command Tutorial for newbies (10 Examples) 19

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]

For example:

nm –defined-only apl

Linux nm Command Tutorial for newbies (10 Examples) 20

Conclusion

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.

How exactly to create let us Encrypt with Nginx Server Blocks on Ubuntu 16.04

Previous article

Just how to Install Module Monsta File Manager in Sentora Open supply Web Hosting Panel

Next article

You may also like

Comments

Leave a Reply

More in Linux