Linux nm viewing symbols in dynamic and static libraries

Source: Internet
Author: User

Function

Lists Symbol Information in. O. A. So, including the value, type, and name of a symbol. Symbols usually refer to defined functions, global variables, and so on.

Use

NM [option (s)]

UsefulOptions:

    • -A prints the object file name before each symbol information;
    • -C: name of the demangle symbol;
    • -D: Print dynamic symbols;
    • -L use the debugging information in the object file to print the source file and row number;
    • -N is sorted by address/Symbol value;
    • -U prints undefined symbols;

CommonSymbol type:

    • A. The value of this symbol will not change in future links;
    • B. Place the symbol in the BSS segment, usually those uninitialized global variables.
    • D. Place the symbol in a common data segment, usually the initialized global variables.
    • T this symbol is placed in the Code section, which is usually a global non-static function.
    • U is undefined and must be linked from other object files.
    • W is not explicitly specified as a weak link symbol. Other Object files with the same link are defined as above, otherwise, a system-specific default value is used.

Notes:

    • -C always applies to object files compiled by C ++. Do you still remember the heavy load in C ++? To distinguish between overloaded functions, the C ++ compiler attaches the function return value/parameter information to the function name to form a mangle symbol. When this option is used to list symbols, perform an inverse operation to output the original and understandable Symbol names.
    • when using-l, you must ensure that your object file contains symbolic information, this usually requires you to specify a-g option during compilation. For details, see Linux: GCC.
    • before using nm, use Linux: file View the processor architecture of the object file, and then use the corresponding cross-version of the NM tool.

Example

For more details, see man page. Here is an example:

Nm-u hello. o
The undefined characters in hello. O are displayed and need to be linked to other object files.
nm-A/usr/lib/* 2>/dev/null | grep "t memset"

Find out which library file defines the memset function in the/usr/lib/directory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.