Linux 查看 elf可执行文件格式的两个命令

使用objdump 和readelf 两个命令,我们可以看到elf的各个节段的 信息还有 运行时需要那些动态链接库,elf中的汇编代码等等。 我就是想用来查看 这个elf运行需要哪些 *.so 文件

#include<stdio.h>

int test()
{
return 0;
}
int main(void)
{
int i;
int j =0;

//printf ("sizeof (int)=%d\n",sizeof (int));
if ( i = j )
     printf ("\ntrue\n",i);
return 0;
}

gcc main.c 编译后,

@linuxidc:~/桌面$ readelf -a a.out
ELF Header:
Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class:                             ELF32
Data:                              2's complement, little endian
Version:                           1 (current)
OS/ABI:                            UNIX - System V
ABI Version:                       0
Type:                              EXEC (Executable file)
Machine:                           Intel 80386
Version:                           0x1
Entry point address:               0x8048310
Start of program headers:          52 (bytes into file)
Start of section headers:          5996 (bytes into file)
Flags:                             0x0
Size of this header:               52 (bytes)
Size of program headers:           32 (bytes)
Number of program headers:         8
Size of section headers:           40 (bytes)
Number of section headers:         36
Section header string table index: 33

Section Headers:
[Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
[ 0]                   NULL            00000000 000000 000000 00      0   0 0
[ 1] .interp           PROGBITS        08048134 000134 000013 00   A 0   0 1
[ 2] .note.ABI-tag     NOTE            08048148 000148 000020 00   A 0   0 4
[ 3] .hash             HASH            08048168 000168 000028 04   A 5   0 4
[ 4] .gnu.hash         GNU_HASH        08048190 000190 000020 04   A 5   0 4
[ 5] .dynsym           DYNSYM          080481b0 0001b0 000050 10   A 6   1 4
[ 6] .dynstr           STRTAB          08048200 000200 00004c 00   A 0   0 1
[ 7] .gnu.version      VERSYM          0804824c 00024c 00000a 02   A 5   0 2
[ 8] .gnu.version_r    VERNEED         08048258 000258 000020 00   A 6   1 4
[ 9] .rel.dyn          REL             08048278 000278 000008 08   A 5   0 4
[10] .rel.plt          REL             08048280 000280 000018 08   A 5 12 4
[11] .init             PROGBITS        08048298 000298 000030 00 AX 0   0 4
[12] .plt              PROGBITS        080482c8 0002c8 000040 04 AX 0   0 4
[13] .text             PROGBITS        08048310 000310 0001ac 00 AX 0   0 16
[14] .fini             PROGBITS        080484bc 0004bc 00001c 00 AX 0   0 4
[15] .rodata           PROGBITS        080484d8 0004d8 00000f 00   A 0   0 4
[16] .eh_frame         PROGBITS        080484e8 0004e8 000004 00   A 0   0 4
[17] .ctors            PROGBITS        08049f0c 000f0c 000008 00 WA 0   0 4
[18] .dtors            PROGBITS        08049f14 000f14 000008 00 WA 0   0 4
[19] .jcr              PROGBITS        08049f1c 000f1c 000004 00 WA 0   0 4
[20] .dynamic          DYNAMIC         08049f20 000f20 0000d0 08 WA 6   0 4
[21] .got              PROGBITS        08049ff0 000ff0 000004 04 WA 0   0 4
[22] .got.plt          PROGBITS        08049ff4 000ff4 000018 04 WA 0   0 4
[23] .data             PROGBITS        0804a00c 00100c 000008 00 WA 0   0 4
[24] .bss              NOBITS          0804a014 001014 000008 00 WA 0   0 4
[25] .comment          PROGBITS        00000000 001014 0000fc 00      0   0 1
[26] .debug_aranges    PROGBITS        00000000 001110 000070 00      0   0 8
[27] .debug_pubnames   PROGBITS        00000000 001180 000025 00      0   0 1
[28] .debug_info       PROGBITS        00000000 0011a5 0001b5 00      0   0 1
[29] .debug_abbrev     PROGBITS        00000000 00135a 000083 00      0   0 1
[30] .debug_line       PROGBITS        00000000 0013dd 000180 00      0   0 1
[31] .debug_str        PROGBITS        00000000 00155d 00008e 01 MS 0   0 1
[32] .debug_ranges     PROGBITS        00000000 0015f0 000040 00      0   0 8
[33] .shstrtab         STRTAB          00000000 001630 000139 00      0   0 1
[34] .symtab           SYMTAB          00000000 001d0c 0004b0 10     35 54 4
[35] .strtab           STRTAB          00000000 0021bc 000213 00      0   0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)

There are no section groups in this file.

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/24172.html