Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux program analysis tool: ldd and nm     - Oracle users to automatically increase the partition table (Database)

- 11G ASM disk group does not automatically handle MOUNT (Database)

- Oracle 11g maintenance partitions - Adding Partitions (Database)

- Hibernate Performance Optimization of reusing SessionFactory (Programming)

- Oracle user lock how to know what causes (Database)

- Installation in lxml Python module (Linux)

- 7 extremely dangerous Linux commands (Linux)

- The correct method to modify the maximum number of concurrent connections Tomcat 7 (Server)

- CentOS 6.5 start ActiveMQ being given to solve (Server)

- JavaScript prototype and prototype chain and project combat (Programming)

- Security of data to create a safe .mdb database (Linux)

- Oracle delete table space prompted ORA-00604 and ORA-38301 (Database)

- How to test your MongoDB application upgrade? (Database)

- Log4cplus logging facility configuration, installation, testing (Linux)

- To install CentOS 6.5 on your hard drive under Windows 7 (Linux)

- mysqldump implement database logical backup (Database)

- To install Ganglia configuration of experience under CentOS 5.5 (Linux)

- CentOS7 installation performance monitoring system (Server)

- Access.log Apache access log analysis and how to import it into MySQL (Server)

- Find details block device with Linux blkid command (Linux)

 
         
  Linux program analysis tool: ldd and nm
     
  Add Date : 2017-04-13      
         
         
         
  Idd and Linux nm is under two very practical program analysis tools. Wherein, ldd is used to analyze the program runs need to rely on the dynamic link library tool, nm specified program is a tool used to view information in the symbol table.

1 ldd

Format: ldd [options] file

Function: Lists the file needed to run the shared library

parameter:

      -d perform relocations and report any missing functions

      -r perform any function or object to the relocation functions and objects and to report the missing

    First, ldd is not an executable program, but a shell script. ldd can show dependency executable module, which works by setting a series of environmental variables, as follows: LD_TRACE_LOADED_OBJECTS, LD_WARN, LD_BIND_NOW, LD_LIBRARY_VERSION, LD_VERBOSE like. When LD_TRACE_LOADED_OBJECTS environment variable is not empty, any executable program at run time, it will show only the dependency module, and the program does not actually perform. Or you can test your terminal shell, as follows:

(1) export LD_TRACE_LOADED_OBJECTS = 1

(2) before performing any procedure, such as ls, etc., look at the results of the program.

    ldd displays executable module dependency works, and its essence is through ld-linux.so (elf dynamic library loader) to achieve. We know, ld-linux.so module will first work program in executable modules, and access control, so that when the above-mentioned environment variable is set, ld-linux.so chosen to show executable module dependency.

    Can actually be executed directly ld-linux.so modules, such as: /lib/ld-linux.so.2 --list program (which is equivalent to ldd program) ldd command to use (taken from ldd --help)

We choose to be tested for some applications, as follows:

 
// @ File tooltest.c
// @ Brief resource sharing between parent-process and sub-process
#include < stdio.h>
#include < stdlib.h>
#include < unistd.h>

int global = 1; / * global variable, stored at data section * /

int main (void)
{
    pid_t pid; // to store pid value
    int stack = 1; // local variable, stored at stack
    int * heap; // pointer to a heap variable

    heap = (int *) malloc (sizeof (int));
    * Heap = 2; // set the heap value to 2

    pid = fork (); // create a new process
    if (pid < 0)
    {
        // Error
        perror ( "fail to fork");
        exit (-1);
    }
    else if (pid == 0)
    {
        // Sub-process, change values
        global ++;
        stack ++;
        (* Heap) ++;
        // Print all values
        printf ( "In sub-process, global:% d, stack:% d, heap:% d \ n", global, stack, * heap);
        exit (0);
    }
    else
    {
        // Parent process
        sleep (2); // sleep 2 secends to make sure the sub-process runs first
        printf ( "In parent-process, global:% d, stack:% d, heap:% d \ n", global, stack, * heap);
    }

    return 0;
}
 
We then compile and run ldd command:

peter @ peter-machine: ~ / Documents / c_code $ ldd tooltest
    linux-gate.so.1 => (0xb775b000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7595000)
    /lib/ld-linux.so.2 (0xb775c000)
We can output the results into three ldd view:

The first column: What procedures need to rely on libraries

The second column: the name of the library and the library program requires a corresponding system provided

The third column: dependent libraries loaded start address

Through the above information, we can conclude the following purposes:

(1) by comparing the first and second columns, we can know the dynamic link library procedures and systems required to provide if compared to the actual distribution.

(2) through the third column, we can know the current dynamic-link library symbol in the process address space starting position.

2 nm

Format: nm [options] file

Function: Lists all symbols file

parameter:

    -C Symbols into user-level names

    -s When used .a file is a static library, the symbolic name is mapped to the output index defines the symbol module or member name

    -u display symbols defined outside the file or undefined symbols

    -l displays the line number of each symbol, or definition of the term is redefined symbol

Here is the output from running nm command:

 
peter @ peter-machine: ~ / Documents / c_code $ nm tooltest
0804a038 B __bss_start
0804a038 b completed.6590
0804a02c D __data_start
0804a02c W data_start
08048450 t deregister_tm_clones
080484c0 t __do_global_dtors_aux
08049f0c t __do_global_dtors_aux_fini_array_entry
0804a030 D __dso_handle
08049f14 d _DYNAMIC
0804a038 D _edata
0804a03c B _end
         U exit @@ GLIBC_2.0
08048674 T _fini
         U fork @@ GLIBC_2.0
08048688 R _fp_hw
080484e0 t frame_dummy
08049f08 t __frame_dummy_init_array_entry
080487e0 r __FRAME_END__
0804a034 D global
0804a000 d _GLOBAL_OFFSET_TABLE_
         w __gmon_start__
08048354 T _init
08049f0c t __init_array_end
08049f08 t __init_array_start
0804868c R _IO_stdin_used
         w _ITM_deregisterTMCloneTable
         w _ITM_registerTMCloneTable
08049f10 d __JCR_END__
08049f10 d __JCR_LIST__
         w _Jv_RegisterClasses
08048670 T __libc_csu_fini
08048600 T __libc_csu_init
         U __libc_start_main @@ GLIBC_2.0
0804850d T main
         U malloc @@ GLIBC_2.0
         U perror @@ GLIBC_2.0
         U printf @@ GLIBC_2.0
08048480 t register_tm_clones
         U sleep @@ GLIBC_2.0
08048410 T _start
0804a038 D __TMC_END__
08048440 T __x86.get_pc_thunk.bx
 
The above is tooltest this program all symbols, first tell us about the format of the output above:

The first column: the current symbol address.

The second column: current type symbol (on the type of instructions, you can view the manual page man nm read).

The third column: name of the current symbol.

There are about nm using the help of several aspects:

(1) Analyzing the specified program has not specified symbol, the more common way: nm -C program | grep symbol

(2) solving compiled undefined reference errors, as well as the multiple definition error.

(3) Check the address of a symbol, as well as in the process space approximate location (.bss, .data, .text segment, specifically through the second column to determine).

Some of the symbols Type Description

A: The value of this symbol is absolute, after the linking process is not allowed to change. Such symbolic value, often appear in the interrupt vector table, each represented by a symbol such as the interrupt vector function in the interrupt vector table location.

B: The value of this symbol appears in the non-initialized data section (.bss) in. For example, define a global static int test in a file. The type of the test symbol is b, located in the bss section. The value represents the symbol offset bss segment. Generally speaking, bss segment is allocated in RAM.

C: This symbol is common. common symbol is not the original, then the data segment. The symbol is not included in a general section in. Only in the linking process to be allocated. Value of the symbol of the symbol indicates the number of bytes needed. For example, in a c file, define int test, and the symbol is referenced elsewhere, the symbol type is C. Otherwise its type is B.

D: This symbol is located initialized data section. In general, allocated to the .data section. For example, define a global int baud_table [5] = {9600, 19200, 38400, 57600, 115200}, will be allocated to the initialization data section.

G: This symbol is also located in the initialized data section. Mainly used for small object to improve access to small data object in the way.

I: The symbol is an indirect reference to another symbol.

N: The symbol is a debugging symbol.

R: The symbol is located in a read-only data segment. For example, define a global const int test [] = {123, 123}; the test is a read-only area of the symbol data. Note If you are using gcc under cygwin compiled directly into MZ format, the corresponding source file test _test, and which type of symbol D, the initialization data section. But if you use m6812-elf-gcc cross compiler tools such as the source file corresponding to the target test file test, that is not underlined, and its symbol type R. In general, located rodata section. It is noteworthy that, if you define const char * test = "abc" in a function, const char test_int = 3. It will not get nm using symbolic information, but the string "abc" assign read-only memory, test in rodata section, the size of four.

S: Sign in a non-initialized data section for small object.

T: This symbol is located snippet text section.

U: This symbol is not defined in the current file that defines the symbol in another file. For example, the current file call a function defined in another file, this function is called in the current is undefined; however it is defined in the file type is T. But for global variables, in which it is defined in the file, its symbol type C, using it in a file whose type is U.

V: The symbol is a weak object.

W: The symbol is a weak symbol that has not been specifically tagged as a weak object symbol.

-: This symbol is a.out format file stabs symbol.

?: The symbol type is not defined.
     
         
         
         
  More:      
 
- GitLab issued Merge Request return error 500 when the two solutions log (Linux)
- Based AutoYaST automated installation of SUSE practice (Linux)
- Linux / BSD firewall M0n0wall Profile (Linux)
- Hadoop2.6.3 build clusters and the development of MapReduce WIN7 by Eclipse on Linux demo (Server)
- CentOS7 virtual machine settings, and bridging problems (Linux)
- MySQL & NoSQL - Memcached widget (Database)
- Linux system security settings after installation (Linux)
- Oracle large table to clean truncate .. reuse storage (Database)
- Ubuntu install ruby (Linux)
- Linux common commands MEMO (Linux)
- Java NIO1: I / O model overview (Programming)
- Java multi-threaded shared communications variables (Programming)
- init level settings for Linux / etc / inittab file into six (restart) or does not support the level of solution (Linux)
- build Android environment on Ubuntu 12.04 (Server)
- Apache Spark1.1.0 deployment and development environment to build (Server)
- HBase vs Oracle (Database)
- Nginx Beginner Guide (Server)
- Iptables principle (Linux)
- Use Hexo quickly build and deploy a blog to Github (Server)
- Linux Network Programming - raw socket instance: MAC header message analysis (Programming)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.