源码:
main.c
#include <stdio.h>
#include <stdlib.h>
int add(int a, int b)
{
return a + b;
}
int main(int argc, char** argv)
{
int a = 0;
int b = 0;
int c = 0;
a = 100;
b = 100;
c = add(a, b);
printf("c is: %d\n", c);
return 0;
}
编译:
$ arm-none-linux-gnueabi-gcc -o main_arm main.c
生成:
main_arm
属性:
$ file main_arm
main_arm: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, not stripped
$ arm-none-linux-gnueabi-readelf --help
Usage: readelf <option(s)> elf-file(s)-h --file-header Display the ELF file header
$ arm-none-linux-gnueabi-readelf -h main_arm
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: ARM
Version: 0x1
Entry point address: 0x8380
Start of program headers: 52 (bytes into file)
Start of section headers: 2260 (bytes into file)
Flags: 0x5000002, has entry point, Version5 EABI
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: 30
Section header string table index: 27
--segments An alias for --program-headers
$ arm-none-linux-gnueabi-readelf -l main_arm
Elf file type is EXEC (Executable file)
Entry point 0x8380
There are 8 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
EXIDX 0x0005d0 0x000085d0 0x000085d0 0x00040 0x00040 R 0x4
PHDR 0x000034 0x00008034 0x00008034 0x00100 0x00100 R E 0x4
INTERP 0x000134 0x00008134 0x00008134 0x00013 0x00013 R 0x1
[Requesting program interpreter: /lib/ld-linux.so.3]
LOAD 0x000000 0x00008000 0x00008000 0x00610 0x00610 R E 0x8000
LOAD 0x000610 0x00010610 0x00010610 0x00124 0x00128 RW 0x8000
DYNAMIC 0x00061c 0x0001061c 0x0001061c 0x000f0 0x000f0 RW 0x4
NOTE 0x000148 0x00008148 0x00008148 0x00020 0x00020 R 0x4
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4
Section to Segment mapping:
Segment Sections...
00 .ARM.exidx
01
02 .interp
03 .interp .note.ABI-tag .hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .ARM.extab .ARM.exidx
04 .init_array .fini_array .jcr .dynamic .got .data .bss
05 .dynamic
06 .note.ABI-tag
07
-S --section-headers Display the sections' header
--sections An alias for --section-headers
$ arm-none-linux-gnueabi-readelf -S main_arm
There are 30 section headers, starting at offset 0x8d4:
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 00008134 000134 000013 00 A 0 0 1
[ 2] .note.ABI-tag NOTE 00008148 000148 000020 00 A 0 0 4
[ 3] .hash HASH 00008168 000168 000034 04 A 4 0 4
[ 4] .dynsym DYNSYM 0000819c 00019c 000080 10 A 5 1 4
[ 5] .dynstr STRTAB 0000821c 00021c 00009b 00 A 0 0 1
[ 6] .gnu.version VERSYM 000082b8 0002b8 000010 02 A 4 0 2
[ 7] .gnu.version_r VERNEED 000082c8 0002c8 000040 00 A 5 2 4
[ 8] .rel.dyn REL 00008308 000308 000008 08 A 4 0 4
[ 9] .rel.plt REL 00008310 000310 000020 08 A 4 11 4
[10] .init PROGBITS 00008330 000330 00000c 00 AX 0 0 4
[11] .plt PROGBITS 0000833c 00033c 000044 04 AX 0 0 4
[12] .text PROGBITS 00008380 000380 000220 00 AX 0 0 4
[13] .fini PROGBITS 000085a0 0005a0 000008 00 AX 0 0 4
[14] .rodata PROGBITS 000085a8 0005a8 000010 00 A 0 0 4
[15] .ARM.extab PROGBITS 000085b8 0005b8 000018 00 A 0 0 4
[16] .ARM.exidx ARM_EXIDX 000085d0 0005d0 000040 00 AL 12 0 4
[17] .init_array INIT_ARRAY 00010610 000610 000004 00 WA 0 0 4
[18] .fini_array FINI_ARRAY 00010614 000614 000004 00 WA 0 0 4
[19] .jcr PROGBITS 00010618 000618 000004 00 WA 0 0 4
[20] .dynamic DYNAMIC 0001061c 00061c 0000f0 08 WA 5 0 4
[21] .got PROGBITS 0001070c 00070c 000020 04 WA 0 0 4
[22] .data PROGBITS 0001072c 00072c 000008 00 WA 0 0 4
[23] .bss NOBITS 00010734 000734 000004 00 WA 0 0 1
[24] .ARM.attributes ARM_ATTRIBUTES 00000000 000734 00002b 00 0 0 1
[25] .comment PROGBITS 00000000 00075f 00002b 00 0 0 1
[26] .debug_frame PROGBITS 00000000 00078c 000044 00 0 0 4
[27] .shstrtab STRTAB 00000000 0007d0 000101 00 0 0 1
[28] .symtab SYMTAB 00000000 000d84 000680 10 29 79 4
[29] .strtab STRTAB 00000000 001404 000266 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)
-g --section-groups Display the section groups
$ arm-none-linux-gnueabi-readelf -g main_arm
There are no section groups in this file.
-t --section-details Display the section details
$ arm-none-linux-gnueabi-readelf -t main_arm
There are 30 section headers, starting at offset 0x8d4:
Section Headers:
[Nr] Name
Type Addr Off Size ES Lk Inf Al
Flags
[ 0]
NULL 00000000 000000 000000 00 0 0 0
[00000000]:
[ 1] .interp
PROGBITS 00008134 000134 000013 00 0 0 1
[00000002]: ALLOC
[ 2] .note.ABI-tag
NOTE 00008148 000148 000020 00 0 0 4
[00000002]: ALLOC
[ 3] .hash
HASH 00008168 000168 000034 04 4 0 4
[00000002]: ALLOC
[ 4] .dynsym
DYNSYM 0000819c 00019c 000080 10 5 1 4
[00000002]: ALLOC
[ 5] .dynstr
STRTAB 0000821c 00021c 00009b 00 0 0 1
[00000002]: ALLOC
[ 6] .gnu.version
VERSYM 000082b8 0002b8 000010 02 4 0 2
[00000002]: ALLOC
[ 7] .gnu.version_r
VERNEED 000082c8 0002c8 000040 00 5 2 4
[00000002]: ALLOC
[ 8] .rel.dyn
REL 00008308 000308 000008 08 4 0 4
[00000002]: ALLOC
[ 9] .rel.plt
REL 00008310 000310 000020 08 4 11 4
[00000002]: ALLOC
[10] .init
PROGBITS 00008330 000330 00000c 00 0 0 4
[00000006]: ALLOC, EXEC
[11] .plt
PROGBITS 0000833c 00033c 000044 04 0 0 4
[00000006]: ALLOC, EXEC
[12] .text
PROGBITS 00008380 000380 000220 00 0 0 4
[00000006]: ALLOC, EXEC
[13] .fini
PROGBITS 000085a0 0005a0 000008 00 0 0 4
[00000006]: ALLOC, EXEC
[14] .rodata
PROGBITS 000085a8 0005a8 000010 00 0 0 4
[00000002]: ALLOC
[15] .ARM.extab
PROGBITS 000085b8 0005b8 000018 00 0 0 4
[00000002]: ALLOC
[16] .ARM.exidx
ARM_EXIDX 000085d0 0005d0 000040 00 12 0 4
[00000082]: ALLOC, LINK ORDER
[17] .init_array
INIT_ARRAY 00010610 000610 000004 00 0 0 4
[00000003]: WRITE, ALLOC
[18] .fini_array
FINI_ARRAY 00010614 000614 000004 00 0 0 4
[00000003]: WRITE, ALLOC
[19] .jcr
PROGBITS 00010618 000618 000004 00 0 0 4
[00000003]: WRITE, ALLOC
[20] .dynamic
DYNAMIC 0001061c 00061c 0000f0 08 5 0 4
[00000003]: WRITE, ALLOC
[21] .got
PROGBITS 0001070c 00070c 000020 04 0 0 4
[00000003]: WRITE, ALLOC
[22] .data
PROGBITS 0001072c 00072c 000008 00 0 0 4
[00000003]: WRITE, ALLOC
[23] .bss
NOBITS 00010734 000734 000004 00 0 0 1
[00000003]: WRITE, ALLOC
[24] .ARM.attributes
ARM_ATTRIBUTES 00000000 000734 00002b 00 0 0 1
[00000000]:
[25] .comment
PROGBITS 00000000 00075f 00002b 00 0 0 1
[00000000]:
[26] .debug_frame
PROGBITS 00000000 00078c 000044 00 0 0 4
[00000000]:
[27] .shstrtab
STRTAB 00000000 0007d0 000101 00 0 0 1
[00000000]:
[28] .symtab
SYMTAB 00000000 000d84 000680 10 29 79 4
[00000000]:
[29] .strtab
STRTAB 00000000 001404 000266 00 0 0 1
[00000000]:
-s --syms Display the symbol table
--symbols An alias for --syms
$ arm-none-linux-gnueabi-readelf -s main_arm
Symbol table '.dynsym' contains 8 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00008350 0 FUNC GLOBAL DEFAULT UND abort@GLIBC_2.4 (2)
2: 0000835c 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.4 (2)
3: 00000000 0 FUNC GLOBAL DEFAULT UND __aeabi_unwind_cpp_pr0@GCC_3.5 (3)
4: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
5: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses
6: 00008374 0 FUNC GLOBAL DEFAULT UND printf@GLIBC_2.4 (2)
7: 00000000 0 FUNC GLOBAL DEFAULT UND __aeabi_unwind_cpp_pr1@GCC_3.5 (3)
Symbol table '.symtab' contains 104 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00008134 0 SECTION LOCAL DEFAULT 1
2: 00008148 0 SECTION LOCAL DEFAULT 2
3: 00008168 0 SECTION LOCAL DEFAULT 3
4: 0000819c 0 SECTION LOCAL DEFAULT 4
5: 0000821c 0 SECTION LOCAL DEFAULT 5
6: 000082b8 0 SECTION LOCAL DEFAULT 6
7: 000082c8 0 SECTION LOCAL DEFAULT 7
8: 00008308 0 SECTION LOCAL DEFAULT 8
9: 00008310 0 SECTION LOCAL DEFAULT 9
10: 00008330 0 SECTION LOCAL DEFAULT 10
11: 0000833c 0 SECTION LOCAL DEFAULT 11
12: 00008380 0 SECTION LOCAL DEFAULT 12
13: 000085a0 0 SECTION LOCAL DEFAULT 13
14: 000085a8 0 SECTION LOCAL DEFAULT 14
15: 000085b8 0 SECTION LOCAL DEFAULT 15
16: 000085d0 0 SECTION LOCAL DEFAULT 16
17: 00010610 0 SECTION LOCAL DEFAULT 17
18: 00010614 0 SECTION LOCAL DEFAULT 18
19: 00010618 0 SECTION LOCAL DEFAULT 19
20: 0001061c 0 SECTION LOCAL DEFAULT 20
21: 0001070c 0 SECTION LOCAL DEFAULT 21
22: 0001072c 0 SECTION LOCAL DEFAULT 22
23: 00010734 0 SECTION LOCAL DEFAULT 23
24: 00000000 0 SECTION LOCAL DEFAULT 24
25: 00000000 0 SECTION LOCAL DEFAULT 25
26: 00000000 0 SECTION LOCAL DEFAULT 26
27: 000083bc 0 NOTYPE LOCAL DEFAULT 12 $a
28: 000083bc 0 FUNC LOCAL DEFAULT 12 call_gmon_start
29: 000083d8 0 NOTYPE LOCAL DEFAULT 12 $d
30: 00008330 0 NOTYPE LOCAL DEFAULT 10 $a
31: 000085a0 0 NOTYPE LOCAL DEFAULT 13 $a
32: 00008148 0 NOTYPE LOCAL DEFAULT 2 $d
33: 00008380 0 NOTYPE LOCAL DEFAULT 12 $a
34: 000085d0 0 NOTYPE LOCAL DEFAULT 16 $d
35: 000083b0 0 NOTYPE LOCAL DEFAULT 12 $d
36: 00000000 0 FILE LOCAL DEFAULT ABS init.c
37: 000085a8 0 NOTYPE LOCAL DEFAULT 14 $d
38: 0001072c 0 NOTYPE LOCAL DEFAULT 22 $d
39: 00008338 0 NOTYPE LOCAL DEFAULT 10 $a
40: 000085a4 0 NOTYPE LOCAL DEFAULT 13 $a
41: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
42: 00010618 0 OBJECT LOCAL DEFAULT 19 __JCR_LIST__
43: 00010730 0 NOTYPE LOCAL DEFAULT 22 $d
44: 000083e0 0 NOTYPE LOCAL DEFAULT 12 $a
45: 000083e0 0 FUNC LOCAL DEFAULT 12 __do_global_dtors_aux
46: 000083f8 0 NOTYPE LOCAL DEFAULT 12 $d
47: 00010734 1 OBJECT LOCAL DEFAULT 23 completed.6102
48: 000085d8 0 NOTYPE LOCAL DEFAULT 16 $d
49: 00010614 0 NOTYPE LOCAL DEFAULT 18 $d
50: 00010614 0 OBJECT LOCAL DEFAULT 18 __do_global_dtors_aux_fin
51: 000083fc 0 NOTYPE LOCAL DEFAULT 12 $a
52: 000083fc 0 FUNC LOCAL DEFAULT 12 frame_dummy
53: 00008424 0 NOTYPE LOCAL DEFAULT 12 $d
54: 000085b8 0 NOTYPE LOCAL DEFAULT 15 $d
55: 00010610 0 NOTYPE LOCAL DEFAULT 17 $d
56: 00010610 0 OBJECT LOCAL DEFAULT 17 __frame_dummy_init_array_
57: 00010734 0 NOTYPE LOCAL DEFAULT 23 $d
58: 00000000 0 FILE LOCAL DEFAULT ABS main.c
59: 0000842c 0 NOTYPE LOCAL DEFAULT 12 $a
60: 000085e8 0 NOTYPE LOCAL DEFAULT 16 $d
61: 000085ac 0 NOTYPE LOCAL DEFAULT 14 $d
62: 000084cc 0 NOTYPE LOCAL DEFAULT 12 $d
63: 000085c4 0 NOTYPE LOCAL DEFAULT 15 $d
64: 00000000 0 FILE LOCAL DEFAULT ABS elf-init.c
65: 000084d0 0 NOTYPE LOCAL DEFAULT 12 $a
66: 000085f8 0 NOTYPE LOCAL DEFAULT 16 $d
67: 00008594 0 NOTYPE LOCAL DEFAULT 12 $d
68: 00000010 0 NOTYPE LOCAL DEFAULT 26 $d
69: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
70: 00010618 0 NOTYPE LOCAL DEFAULT 19 $d
71: 00010618 0 OBJECT LOCAL DEFAULT 19 __JCR_END__
72: 0001070c 0 OBJECT LOCAL HIDDEN 21 _GLOBAL_OFFSET_TABLE_
73: 00010614 0 NOTYPE LOCAL HIDDEN 17 __init_array_end
74: 00010610 0 NOTYPE LOCAL HIDDEN 17 __init_array_start
75: 0001061c 0 OBJECT LOCAL HIDDEN 20 _DYNAMIC
76: 0000833c 0 NOTYPE LOCAL DEFAULT 11 $a
77: 0000834c 0 NOTYPE LOCAL DEFAULT 11 $d
78: 00008350 0 NOTYPE LOCAL DEFAULT 11 $a
79: 0001072c 0 NOTYPE WEAK DEFAULT 22 data_start
80: 00008350 0 FUNC GLOBAL DEFAULT UND abort@@GLIBC_2.4
81: 000084d0 4 FUNC GLOBAL DEFAULT 12 __libc_csu_fini
82: 00008380 0 FUNC GLOBAL DEFAULT 12 _start
83: 0000835c 0 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_
84: 00000000 0 FUNC GLOBAL DEFAULT UND __aeabi_unwind_cpp_pr0@@G
85: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
86: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses
87: 000085a0 0 FUNC GLOBAL DEFAULT 13 _fini
88: 000085a8 4 OBJECT GLOBAL DEFAULT 14 _IO_stdin_used
89: 0001072c 0 NOTYPE GLOBAL DEFAULT 22 __data_start
90: 00010734 0 NOTYPE GLOBAL DEFAULT ABS __bss_start__
91: 00010730 0 OBJECT GLOBAL HIDDEN 22 __dso_handle
92: 00010738 0 NOTYPE GLOBAL DEFAULT ABS __end__
93: 000084d4 204 FUNC GLOBAL DEFAULT 12 __libc_csu_init
94: 00010738 0 NOTYPE GLOBAL DEFAULT ABS __bss_end__
95: 00008374 0 FUNC GLOBAL DEFAULT UND printf@@GLIBC_2.4
96: 0000842c 48 FUNC GLOBAL DEFAULT 12 add
97: 00010734 0 NOTYPE GLOBAL DEFAULT ABS __bss_start
98: 00010738 0 NOTYPE GLOBAL DEFAULT ABS _bss_end__
99: 00010738 0 NOTYPE GLOBAL DEFAULT ABS _end
100: 00010734 0 NOTYPE GLOBAL DEFAULT ABS _edata
101: 00000000 0 FUNC GLOBAL DEFAULT UND __aeabi_unwind_cpp_pr1@@G
102: 0000845c 116 FUNC GLOBAL DEFAULT 12 main
103: 00008330 0 FUNC GLOBAL DEFAULT 10 _init
-n --notes Display the core notes (if present)
$ arm-none-linux-gnueabi-readelf -n main_arm
Notes at offset 0x00000148 with length 0x00000020:
Owner Data size Description
GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag)
-r --relocs Display the relocations (if present)
$ arm-none-linux-gnueabi-readelf -r main_arm
Relocation section '.rel.dyn' at offset 0x308 contains 1 entries:
Offset Info Type Sym.Value Sym. Name
00010728 00000415 R_ARM_GLOB_DAT 00000000 __gmon_start__
Relocation section '.rel.plt' at offset 0x310 contains 4 entries:
Offset Info Type Sym.Value Sym. Name
00010718 00000116 R_ARM_JUMP_SLOT 00008350 abort
0001071c 00000216 R_ARM_JUMP_SLOT 0000835c __libc_start_main
00010720 00000416 R_ARM_JUMP_SLOT 00000000 __gmon_start__
00010724 00000616 R_ARM_JUMP_SLOT 00008374 printf
-u --unwind Display the unwind info (if present)
$ arm-none-linux-gnueabi-readelf -u main_arm
There are no unwind sections in this file.
-d --dynamic Display the dynamic section (if present)
$ arm-none-linux-gnueabi-readelf -d main_arm
Dynamic section at offset 0x61c contains 25 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x00000001 (NEEDED) Shared library: [libc.so.6]
0x0000000c (INIT) 0x8330
0x0000000d (FINI) 0x85a0
0x00000019 (INIT_ARRAY) 0x10610
0x0000001b (INIT_ARRAYSZ) 4 (bytes)
0x0000001a (FINI_ARRAY) 0x10614
0x0000001c (FINI_ARRAYSZ) 4 (bytes)
0x00000004 (HASH) 0x8168
0x00000005 (STRTAB) 0x821c
0x00000006 (SYMTAB) 0x819c
0x0000000a (STRSZ) 155 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000015 (DEBUG) 0x0
0x00000003 (PLTGOT) 0x1070c
0x00000002 (PLTRELSZ) 32 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x8310
0x00000011 (REL) 0x8308
0x00000012 (RELSZ) 8 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x6ffffffe (VERNEED) 0x82c8
0x6fffffff (VERNEEDNUM) 2
0x6ffffff0 (VERSYM) 0x82b8
0x00000000 (NULL) 0x0
-V --version-info Display the version sections (if present)
$ arm-none-linux-gnueabi-readelf -V main_arm
Version symbols section '.gnu.version' contains 8 entries:
Addr: 00000000000082b8 Offset: 0x0002b8 Link: 4 (.dynsym)
000: 0 (*local*) 2 (GLIBC_2.4) 2 (GLIBC_2.4) 3 (GCC_3.5)
004: 0 (*local*) 0 (*local*) 2 (GLIBC_2.4) 3 (GCC_3.5)
Version needs section '.gnu.version_r' contains 2 entries:
Addr: 0x00000000000082c8 Offset: 0x0002c8 Link: 5 (.dynstr)
000000: Version: 1 File: libgcc_s.so.1 Cnt: 1
0x0010: Name: GCC_3.5 Flags: none Version: 3
0x0020: Version: 1 File: libc.so.6 Cnt: 1
0x0030: Name: GLIBC_2.4 Flags: none Version: 2
-A --arch-specific Display architecture specific information (if any).
$ arm-none-linux-gnueabi-readelf -A main_arm
Attribute Section: aeabi
File Attributes
Tag_CPU_name: "5TE"
Tag_CPU_arch: v5TE
Tag_ARM_ISA_use: Yes
Tag_THUMB_ISA_use: Thumb-1
Tag_ABI_PCS_wchar_t: 4
Tag_ABI_FP_denormal: Needed
Tag_ABI_FP_exceptions: Needed
Tag_ABI_FP_number_model: IEEE 754
Tag_ABI_align_needed: 8-byte
Tag_ABI_align_preserved: 8-byte, except leaf SP
Tag_ABI_enum_size: int
Tag_DIV_use: Not allowed
-c --archive-index Display the symbol/file index in an archive
$ arm-none-linux-gnueabi-readelf -c main_arm
readelf: Error: File main_arm is not an archive so its index cannot be displayed.