Article From:https://www.cnblogs.com/blackpepper/p/9970592.html

From https://blog.csdn.net/qq_16683355/article/details/52297884

Use

$ nm [option(s)] [file(s)]

Common options

  • -A Print the name of the object file before each symbol information.
  • -C Output the symbolic name of demangle passed;
  • -D Print dynamic symbols;
  • -l Print out the source file and the line number using the debugging information in the object file.
  • -n Sort by address/symbol value;
  • -u Print out undefined symbols;

Common symbol types

  • -A The value of the symbol will not change in future links.
  • -B The symbol is placed in the BSS segment, usually the uninitialized global variables.
  • -D The symbol is placed in a common data segment, usually those global variables that have been initialized.
  • -T This symbol is placed in the code segment, usually those global non-static functions;
  • -U The symbol is undefined and needs to be linked in from other object files.
  • -W Weak link symbols that are not explicitly specified; use them if they are defined in other object files linked to them, or use the default values specified by a system.

Pay attention to some points.

  • -C It is always applicable to object files compiled by c++. Remember the overload in c++? In order to distinguish overloaded functions, the c++ compiler attaches information such as function return values/parameters to the function name to form a mangle symbol. When listing symbols with this option, do an inverse.Operations, output the original, understandable symbol names.
  • When using – l, you must ensure that your object file contains symbolic debugging information. This generally requires you to specify a – G option when compiling. See Linux: Gcc.
  • Before using nms, it’s better to first use Linux: File to view the processor architecture of the object file, and then use the corresponding Cross-versions of NMS tools.

$ nm -u hello.o # Displaying undefined symbols in hello.o requires links to other object files.$nm-A/usr/lib/* 2> /dev/null | grep "T memset"# in / usr / lib / itemRecord to find out which library file defines the memset function.

Leave a Reply

Your email address will not be published. Required fields are marked *