Linux 可执行文件内容分析工具: nm objdump readelf size ar ldd
linux可执行文件的内容分析工具nm objdump readelf ar ldd size
1. nm
2. objdump
3. readelf
4. size
5. ar
6. ldd
http://www.ibm.com/developerworks/cn/aix/library/au-unixtools.html
级别: 中级
Bill Zimmerly (bill@zimmerly.com), 自由撰稿人兼知识工程师, Author
2007 年 3 月 06 日
UNIX(R) 系统中运行的程序遵守一种称为目标文件格式的精心设计。了解更多关于目标文件格式的内容,以及可以用来研究系统中目标文件的工具。
计算机编程的最新技术将一种特殊的人性与一组特殊的工具结合在一起,用以生产出对其他人非常有帮助的一种神奇的产品,即软件。计算机程序员是一群注 重细节的人,他们可以处理计算机中各种各样的困难。计算机的要求非常苛刻,并且不能容忍其中存在任何的偏差。毫无疑问,无论您的个性如何以及在工作中使用 了何种辅助工具,计算机程序的编写都是非常困难的。
在 UNIX® 和 Linux® 中,任何事物都是文件。您可以认为,UNIX 和 Linux 编程实际上是编写处理各种文件的代码。系统由许多类型的文件组成,但目标文件具有一种特殊的设计,提供了灵活和多样的用途。
目标文件是包含带有附加地址和值的助记符号的路线图。这些符号可以用来对各种代码段和数据段进行命名,包括经过初始化的和未初始化的。它们也可以用来定位嵌入的调试信息,就像语义 Web,非常适合由程序进行阅读。
计算机编程中使用的工具包括代码编辑器,如 vi 或 Emacs,您可以使用这些工具输入和编辑希望计算机在完成所需任务时执行的指令,以及编译器和连接器,它们可以生成真正实现这些目标的机器代码。
高级的工具,称为集成调试环境 (IDE),它以统一的外观集成了不同工具的功能。IDE 使得编辑器、编译器、连接器和调试器之间的界限变得很模糊。因此,为了更深入地研究和了解系统,在使用集成的套件之前,最好先单独地使用这些工具。(注意:IDE 也通常被称为集成开发环境。)
编译器可以将您在代码编辑器中创建的文本转换为目标文件。最初,目标文件被称为代码的中间表示形式,因为它用作连接编辑器(即连接器)的输入,而连接编辑器最终完成整个任务并生成可执行的程序作为输出。
从代码到可执行代码的转换过程经过了良好的定义并实现了自动化,而目标文件是这个链中有机的连接性环节。在这个转换过程中,目标文件作为连接编辑器所使用的映象,使得它们能够解析各种符号并将不同的代码和数据段连接在一起形成统一的整体。
计算机编程领域中存在许多著名的目标文件格式。DOS 系列包括 COM、OBJ 和 EXE 格式。UNIX 和 Linux 使用 a.out、COFF 和 ELF。Microsoft® Windows® 使用可移植的执行文件 (PE) 格式,而 Macintosh 使用 PEF、Mach-O 和其他文件格式。
最初,各种类型的计算机具有自己独特的目标文件格式,但随着 UNIX 和其他在不同硬件平台上提供可移植性的操作系统的出现,一些常用的文件格式上升为通用的标准。其中包括 a.out、COFF 和 ELF 格式。
要了解目标文件,需要一组可以读取目标文件中不同部分并以更易于读取的格式显示这些内容的工具。本文将讨论这些工具中比较重要的方面。但首先,您必须创建一个工作台,并在其中建立一个研究对象。
启动一个 xterm 会话,让我们先创建一个空白的工作台,并开始对目标文件进行研究。下面的命令创建了一个目录,可以将目标文件放到该目录中进行研究:
cdmkdir srccd srcmkdir hwcd hw |
然后,使用您最喜欢的代码编辑器,在 $HOME/src/hw 目录中输入清单 1 中的程序,并命名为 hw.c。
#include <stdio.h>int main(void){ printf("Hello World!/n"); return 0;}
|
要使用 UNIX 工具库中提供的各种工具,可以将这个简单的“Hello World”程序作为研究的对象。您将学习构建和查看目标文件的输出,而不是使用任何快捷方法直接创建可执行文件(的确有许多这样的快捷方法)。
C 编译器的正常输出是用于您所指定的目标处理器的汇编代码。汇编代码是汇编器的输入,在缺省情况下,汇编器将生成所有目标文件的祖先,即 a.out 文件。这个名称本身表示汇编输出 (Assembler Output)。要创建 a.out 文件,可以在 xterm 窗口中输入下面的命令:
cc hw.c |
注意:如果出现了任何错误或者没有创建 a.out 文件,那么您可能需要检查自己的系统或源文件 (hw.c),以找出其中的错误。还需要检查是否已将 cc 定义为运行您的 C/C++ 编译器。
最新的 C 编译器将编译和汇编步骤组合成一个步骤。您可以指定不同开关选项以查看 C 编译器的汇编输出。通过输入下面的命令,您可以看到 C 编译器的汇编输出:
cc -S hw.c |
这个命令生成了一个新的文件 hw.s,其中包含您通常无法看到的汇编输入文本,因为编译器在缺省情况下将生成 a.out 文件。正如所预期的,UNIX 汇编程序可以对这种输入文件进行汇编,以生成 a.out 文件。
假定编译过程一切顺利,那么在该目录中就有了一个 a.out 文件,下面让我们来对其进行研究。有许多可用于研究目标文件的有价值的工具,下面便是其中一组:
- nm:列出目标文件中的符号。
- objdump:显示目标文件中的详细信息。
- readelf:显示关于 ELF 目标文件的信息。
具体的readelf命令可以查看本博客的其他文章
列表中的第一个工具是 nm,它可以列出目标文件中的符号。如果您输入 nm 命令,您将注意到在缺省情况下,它会寻找一个名为 a.out 的文件。如果没有找到该文件,这个工具会给出相应的提示。然而,如果该工具找到了编译器创建的 a.out 文件,它将显示类似清单 2 的清单。
08049594 A __bss_start080482e4 t call_gmon_start08049594 b completed.446308049498 d __CTOR_END__08049494 d __CTOR_LIST__08049588 D __data_start08049588 W data_start0804842c t __do_global_ctors_aux0804830c t __do_global_dtors_aux0804958c D __dso_handle080494a0 d __DTOR_END__0804949c d __DTOR_LIST__080494a8 d _DYNAMIC08049594 A _edata08049598 A _end08048458 T _fini08049494 a __fini_array_end08049494 a __fini_array_start08048478 R _fp_hw0804833b t frame_dummy08048490 r __FRAME_END__08049574 d _GLOBAL_OFFSET_TABLE_ w __gmon_start__08048308 T __i686.get_pc_thunk.bx08048278 T _init08049494 a __init_array_end08049494 a __init_array_start0804847c R _IO_stdin_used080494a4 d __JCR_END__080494a4 d __JCR_LIST__ w _Jv_RegisterClasses080483e1 T __libc_csu_fini08048390 T __libc_csu_init U __libc_start_main@@GLIBC_2.008048360 T main08049590 d p.4462 U puts@@GLIBC_2.0080482c0 T _start |
这些包含可执行代码的段称为正文段。同样地,数据段包含了不可执行的信息或数据。另一种类型的段,称为 BSS 段,它包含以符号数据开头的块。
对于 nm 命令列出的每个符号,它们的值使用十六进制来表示(缺省行为),并且在该符号前面加上了一个表示符号类型的编码字符。常见的各种编码包括:A 表示绝对 (absolute),这意味着不能将该值更改为其他的连接;B 表示 BSS 段中的符号;而 C 表示引用未初始化的数据的一般符号。
可以将目标文件中所包含的不同的部分划分为段。段可以包含可执行代码、符号名称、初始数据值和许多其他类型的数据。有关这些类型的数据的详细信息,可以阅读 UNIX 中 nm 的 man 页面,其中按照该命令输出中的字符编码分别对每种类型进行了描述。
在目标文件阶段,即使是一个简单的 Hello World 程序,其中也包含了大量的细节信息。nm 程序可用于列举符号及其类型和值,但是,要更仔细地研究目标文件中这些命名段的内容,需要使用功能更强大的工具。
其中两种功能强大的工具是 objdump 和 readelf 程序。通过输入下面的命令,您可以看到目标文件中包含可执行代码的每个段的汇编清单。对于这么一个小的程序,编译器生成了这么多的代码,真的很令人惊异!
objdump -d a.out |
这个命令生成的输出如清单 3 所示。每个可执行代码段将在需要特定的事件时执行,这些事件包括库的初始化和该程序本身主入口点。
a.out: file format elf32-i386Disassembly of section .init:08048278 <_init>: 8048278: 55 push %ebp 8048279: 89 e5 mov %esp,%ebp 804827b: 83 ec 08 sub $0x8,%esp 804827e: e8 61 00 00 00 call 80482e4 <call_gmon_start> 8048283: e8 b3 00 00 00 call 804833b <frame_dummy> 8048288: e8 9f 01 00 00 call 804842c <__do_global_ctors_aux> 804828d: c9 leave 804828e: c3 retDisassembly of section .plt:08048290 <puts@plt-0x10>: 8048290: ff 35 78 95 04 08 pushl 0x8049578 8048296: ff 25 7c 95 04 08 jmp *0x804957c 804829c: 00 00 add %al,(%eax) ...080482a0 <puts@plt>: 80482a0: ff 25 80 95 04 08 jmp *0x8049580 80482a6: 68 00 00 00 00 push $0x0 80482ab: e9 e0 ff ff ff jmp 8048290 <_init+0x18>080482b0 <__libc_start_main@plt>: 80482b0: ff 25 84 95 04 08 jmp *0x8049584 80482b6: 68 08 00 00 00 push $0x8 80482bb: e9 d0 ff ff ff jmp 8048290 <_init+0x18>Disassembly of section .text:080482c0 <_start>: 80482c0: 31 ed xor %ebp,%ebp 80482c2: 5e pop %esi 80482c3: 89 e1 mov %esp,%ecx 80482c5: 83 e4 f0 and $0xfffffff0,%esp 80482c8: 50 push %eax 80482c9: 54 push %esp 80482ca: 52 push %edx 80482cb: 68 e1 83 04 08 push $0x80483e1 80482d0: 68 90 83 04 08 push $0x8048390 80482d5: 51 push %ecx 80482d6: 56 push %esi 80482d7: 68 60 83 04 08 push $0x8048360 80482dc: e8 cf ff ff ff call 80482b0 <__libc_start_main@plt> 80482e1: f4 hlt 80482e2: 90 nop 80482e3: 90 nop080482e4 <call_gmon_start>: 80482e4: 55 push %ebp 80482e5: 89 e5 mov %esp,%ebp 80482e7: 53 push %ebx 80482e8: e8 1b 00 00 00 call 8048308 <__i686.get_pc_thunk.bx> 80482ed: 81 c3 87 12 00 00 add $0x1287,%ebx 80482f3: 83 ec 04 sub $0x4,%esp 80482f6: 8b 83 fc ff ff ff mov 0xfffffffc(%ebx),%eax 80482fc: 85 c0 test %eax,%eax 80482fe: 74 02 je 8048302 <call_gmon_start+0x1e> 8048300: ff d0 call *%eax 8048302: 83 c4 04 add $0x4,%esp 8048305: 5b pop %ebx 8048306: 5d pop %ebp 8048307: c3 ret08048308 <__i686.get_pc_thunk.bx>: 8048308: 8b 1c 24 mov (%esp),%ebx 804830b: c3 ret0804830c <__do_global_dtors_aux>: 804830c: 55 push %ebp 804830d: 89 e5 mov %esp,%ebp 804830f: 83 ec 08 sub $0x8,%esp 8048312: 80 3d 94 95 04 08 00 cmpb $0x0,0x8049594 8048319: 74 0c je 8048327 <__do_global_dtors_aux+0x1b> 804831b: eb 1c jmp 8048339 <__do_global_dtors_aux+0x2d> 804831d: 83 c0 04 add $0x4,%eax 8048320: a3 90 95 04 08 mov %eax,0x8049590 8048325: ff d2 call *%edx 8048327: a1 90 95 04 08 mov 0x8049590,%eax 804832c: 8b 10 mov (%eax),%edx 804832e: 85 d2 test %edx,%edx 8048330: 75 eb jne 804831d <__do_global_dtors_aux+0x11> 8048332: c6 05 94 95 04 08 01 movb $0x1,0x8049594 8048339: c9 leave 804833a: c3 ret0804833b <frame_dummy>: 804833b: 55 push %ebp 804833c: 89 e5 mov %esp,%ebp 804833e: 83 ec 08 sub $0x8,%esp 8048341: a1 a4 94 04 08 mov 0x80494a4,%eax 8048346: 85 c0 test %eax,%eax 8048348: 74 12 je 804835c <frame_dummy+0x21> 804834a: b8 00 00 00 00 mov $0x0,%eax 804834f: 85 c0 test %eax,%eax 8048351: 74 09 je 804835c <frame_dummy+0x21> 8048353: c7 04 24 a4 94 04 08 movl $0x80494a4,(%esp) 804835a: ff d0 call *%eax 804835c: c9 leave 804835d: c3 ret 804835e: 90 nop 804835f: 90 nop08048360 <main>: 8048360: 55 push %ebp 8048361: 89 e5 mov %esp,%ebp 8048363: 83 ec 08 sub $0x8,%esp 8048366: 83 e4 f0 and $0xfffffff0,%esp 8048369: b8 00 00 00 00 mov $0x0,%eax 804836e: 83 c0 0f add $0xf,%eax 8048371: 83 c0 0f add $0xf,%eax 8048374: c1 e8 04 shr $0x4,%eax 8048377: c1 e0 04 shl $0x4,%eax 804837a: 29 c4 sub %eax,%esp 804837c: c7 04 24 80 84 04 08 movl $0x8048480,(%esp) 8048383: e8 18 ff ff ff call 80482a0 <puts@plt> 8048388: b8 00 00 00 00 mov $0x0,%eax 804838d: c9 leave 804838e: c3 ret 804838f: 90 nop08048390 <__libc_csu_init>: 8048390: 55 push %ebp 8048391: 89 e5 mov %esp,%ebp 8048393: 57 push %edi 8048394: 56 push %esi 8048395: 31 f6 xor %esi,%esi 8048397: 53 push %ebx 8048398: e8 6b ff ff ff call 8048308 <__i686.get_pc_thunk.bx> 804839d: 81 c3 d7 11 00 00 add $0x11d7,%ebx 80483a3: 83 ec 0c sub $0xc,%esp 80483a6: e8 cd fe ff ff call 8048278 <_init> 80483ab: 8d 83 20 ff ff ff lea 0xffffff20(%ebx),%eax 80483b1: 8d 93 20 ff ff ff lea 0xffffff20(%ebx),%edx 80483b7: 89 45 f0 mov %eax,0xfffffff0(%ebp) 80483ba: 29 d0 sub %edx,%eax 80483bc: c1 f8 02 sar $0x2,%eax 80483bf: 39 c6 cmp %eax,%esi 80483c1: 73 16 jae 80483d9 <__libc_csu_init+0x49> 80483c3: 89 d7 mov %edx,%edi 80483c5: ff 14 b2 call *(%edx,%esi,4) 80483c8: 8b 45 f0 mov 0xfffffff0(%ebp),%eax 80483cb: 83 c6 01 add $0x1,%esi 80483ce: 29 f8 sub %edi,%eax 80483d0: 89 fa mov %edi,%edx 80483d2: c1 f8 02 sar $0x2,%eax 80483d5: 39 c6 cmp %eax,%esi 80483d7: 72 ec jb 80483c5 <__libc_csu_init+0x35> 80483d9: 83 c4 0c add $0xc,%esp 80483dc: 5b pop %ebx 80483dd: 5e pop %esi 80483de: 5f pop %edi 80483df: 5d pop %ebp 80483e0: c3 ret080483e1 <__libc_csu_fini>: 80483e1: 55 push %ebp 80483e2: 89 e5 mov %esp,%ebp 80483e4: 83 ec 18 sub $0x18,%esp 80483e7: 89 5d f4 mov %ebx,0xfffffff4(%ebp) 80483ea: e8 19 ff ff ff call 8048308 <__i686.get_pc_thunk.bx> 80483ef: 81 c3 85 11 00 00 add $0x1185,%ebx 80483f5: 89 75 f8 mov %esi,0xfffffff8(%ebp) 80483f8: 89 7d fc mov %edi,0xfffffffc(%ebp) 80483fb: 8d b3 20 ff ff ff lea 0xffffff20(%ebx),%esi 8048401: 8d bb 20 ff ff ff lea 0xffffff20(%ebx),%edi 8048407: 29 fe sub %edi,%esi 8048409: c1 fe 02 sar $0x2,%esi 804840c: eb 03 jmp 8048411 <__libc_csu_fini+0x30> 804840e: ff 14 b7 call *(%edi,%esi,4) 8048411: 83 ee 01 sub $0x1,%esi 8048414: 83 fe ff cmp $0xffffffff,%esi 8048417: 75 f5 jne 804840e <__libc_csu_fini+0x2d> 8048419: e8 3a 00 00 00 call 8048458 <_fini> 804841e: 8b 5d f4 mov 0xfffffff4(%ebp),%ebx 8048421: 8b 75 f8 mov 0xfffffff8(%ebp),%esi 8048424: 8b 7d fc mov 0xfffffffc(%ebp),%edi 8048427: 89 ec mov %ebp,%esp 8048429: 5d pop %ebp 804842a: c3 ret 804842b: 90 nop0804842c <__do_global_ctors_aux>: 804842c: 55 push %ebp 804842d: 89 e5 mov %esp,%ebp 804842f: 53 push %ebx 8048430: 83 ec 04 sub $0x4,%esp 8048433: a1 94 94 04 08 mov 0x8049494,%eax 8048438: 83 f8 ff cmp $0xffffffff,%eax 804843b: 74 12 je 804844f <__do_global_ctors_aux+0x23> 804843d: bb 94 94 04 08 mov $0x8049494,%ebx 8048442: ff d0 call *%eax 8048444: 8b 43 fc mov 0xfffffffc(%ebx),%eax 8048447: 83 eb 04 sub $0x4,%ebx 804844a: 83 f8 ff cmp $0xffffffff,%eax 804844d: 75 f3 jne 8048442 <__do_global_ctors_aux+0x16> 804844f: 83 c4 04 add $0x4,%esp 8048452: 5b pop %ebx 8048453: 5d pop %ebp 8048454: c3 ret 8048455: 90 nop 8048456: 90 nop 8048457: 90 nopDisassembly of section .fini:08048458 <_fini>: 8048458: 55 push %ebp 8048459: 89 e5 mov %esp,%ebp 804845b: 53 push %ebx 804845c: e8 a7 fe ff ff call 8048308 <__i686.get_pc_thunk.bx> 8048461: 81 c3 13 11 00 00 add $0x1113,%ebx 8048467: 83 ec 04 sub $0x4,%esp 804846a: e8 9d fe ff ff call 804830c <__do_global_dtors_aux> 804846f: 83 c4 04 add $0x4,%esp 8048472: 5b pop %ebx 8048473: 5d pop %ebp 8048474: c3 ret |
对于那些着迷于底层编程细节的程序员来说,这是一个功能非常强大的工具,可用于研究编译器和汇编器的输出。细节信息,比如这段代码中所显示的这些信 息,可以揭示有关本地处理器本身运行方式的很多内容。对该处理器制造商提供的技术文档进行深入的研究,您可以收集关于一些有价值的信息,通过这些信息可以 深入地了解内部的运行机制,因为功能程序提供了清晰的输出。
类似地,readelf 程序也可以清楚地列出目标文件中的内容。输入下面的命令,您将可以看到这一点:
readelf -all a.out |
这个命令生成的输出如清单 4 所示。ELF Header 为该文件中所有段入口显示了详细的摘要。在列举出这些 Header 中的内容之前,您可以看到 Header 的具体数目。在研究一个较大的目标文件时,该信息可能非常有用。
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: 0x80482c0 Start of program headers: 52 (bytes into file) Start of section headers: 3504 (bytes into file) Flags: 0x0 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 7 Size of section headers: 40 (bytes) Number of section headers: 34 Section header string table index: 31Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .interp PROGBITS 08048114 000114 000013 00 A 0 0 1 [ 2] .note.ABI-tag NOTE 08048128 000128 000020 00 A 0 0 4 [ 3] .hash HASH 08048148 000148 00002c 04 A 4 0 4 [ 4] .dynsym DYNSYM 08048174 000174 000060 10 A 5 1 4 [ 5] .dynstr STRTAB 080481d4 0001d4 00005e 00 A 0 0 1 [ 6] .gnu.version VERSYM 08048232 000232 00000c 02 A 4 0 2 [ 7] .gnu.version_r VERNEED 08048240 000240 000020 00 A 5 1 4 [ 8] .rel.dyn REL 08048260 000260 000008 08 A 4 0 4 [ 9] .rel.plt REL 08048268 000268 000010 08 A 4 11 4 [10] .init PROGBITS 08048278 000278 000017 00 AX 0 0 1 [11] .plt PROGBITS 08048290 000290 000030 04 AX 0 0 4 [12] .text PROGBITS 080482c0 0002c0 000198 00 AX 0 0 4 [13] .fini PROGBITS 08048458 000458 00001d 00 AX 0 0 1 [14] .rodata PROGBITS 08048478 000478 000015 00 A 0 0 4 [15] .eh_frame PROGBITS 08048490 000490 000004 00 A 0 0 4 [16] .ctors PROGBITS 08049494 000494 000008 00 WA 0 0 4 [17] .dtors PROGBITS 0804949c 00049c 000008 00 WA 0 0 4 [18] .jcr PROGBITS 080494a4 0004a4 000004 00 WA 0 0 4 [19] .dynamic DYNAMIC 080494a8 0004a8 0000c8 08 WA 5 0 4 [20] .got PROGBITS 08049570 000570 000004 04 WA 0 0 4 [21] .got.plt PROGBITS 08049574 000574 000014 04 WA 0 0 4 [22] .data PROGBITS 08049588 000588 00000c 00 WA 0 0 4 [23] .bss NOBITS 08049594 000594 000004 00 WA 0 0 4 [24] .comment PROGBITS 00000000 000594 000126 00 0 0 1 [25] .debug_aranges PROGBITS 00000000 0006c0 000088 00 0 0 8 [26] .debug_pubnames PROGBITS 00000000 000748 000025 00 0 0 1 [27] .debug_info PROGBITS 00000000 00076d 00022b 00 0 0 1 [28] .debug_abbrev PROGBITS 00000000 000998 000076 00 0 0 1 [29] .debug_line PROGBITS 00000000 000a0e 0001bb 00 0 0 1 [30] .debug_str PROGBITS 00000000 000bc9 0000bf 01 MS 0 0 1 [31] .shstrtab STRTAB 00000000 000c88 000127 00 0 0 1 [32] .symtab SYMTAB 00000000 001300 000520 10 33 63 4 [33] .strtab STRTAB 00000000 001820 0002d2 00 0 0 1Key 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.Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align PHDR 0x000034 0x08048034 0x08048034 0x000e0 0x000e0 R E 0x4 INTERP 0x000114 0x08048114 0x08048114 0x00013 0x00013 R 0x1 [Requesting program interpreter: /lib/ld-linux.so.2] LOAD 0x000000 0x08048000 0x08048000 0x00494 0x00494 R E 0x1000 LOAD 0x000494 0x08049494 0x08049494 0x00100 0x00104 RW 0x1000 DYNAMIC 0x0004a8 0x080494a8 0x080494a8 0x000c8 0x000c8 RW 0x4 NOTE 0x000128 0x08048128 0x08048128 0x00020 0x00020 R 0x4 GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4 Section to Segment mapping: Segment Sections... 00 01 .interp 02 .interp .note.ABI-tag .hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame 03 .ctors .dtors .jcr .dynamic .got .got.plt .data .bss 04 .dynamic 05 .note.ABI-tag 06Dynamic section at offset 0x4a8 contains 20 entries: Tag Type Name/Value 0x00000001 (NEEDED) Shared library: [libc.so.6] 0x0000000c (INIT) 0x8048278 0x0000000d (FINI) 0x8048458 0x00000004 (HASH) 0x8048148 0x00000005 (STRTAB) 0x80481d4 0x00000006 (SYMTAB) 0x8048174 0x0000000a (STRSZ) 94 (bytes) 0x0000000b (SYMENT) 16 (bytes) 0x00000015 (DEBUG) 0x0 0x00000003 (PLTGOT) 0x8049574 0x00000002 (PLTRELSZ) 16 (bytes) 0x00000014 (PLTREL) REL 0x00000017 (JMPREL) 0x8048268 0x00000011 (REL) 0x8048260 0x00000012 (RELSZ) 8 (bytes) 0x00000013 (RELENT) 8 (bytes) 0x6ffffffe (VERNEED) 0x8048240 0x6fffffff (VERNEEDNUM) 1 0x6ffffff0 (VERSYM) 0x8048232 0x00000000 (NULL) 0x0Relocation section '.rel.dyn' at offset 0x260 contains 1 entries: Offset Info Type Sym.Value Sym. Name08049570 00000506 R_386_GLOB_DAT 00000000 __gmon_start__Relocation section '.rel.plt' at offset 0x268 contains 2 entries: Offset Info Type Sym.Value Sym. Name08049580 00000107 R_386_JUMP_SLOT 00000000 puts08049584 00000207 R_386_JUMP_SLOT 00000000 __libc_start_mainThere are no unwind sections in this file.Symbol table '.dynsym' contains 6 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 378 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.0 (2) 2: 00000000 230 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 (2) 3: 0804847c 4 OBJECT GLOBAL DEFAULT 14 _IO_stdin_used 4: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses 5: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__Symbol table '.symtab' contains 82 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 08048114 0 SECTION LOCAL DEFAULT 1 2: 08048128 0 SECTION LOCAL DEFAULT 2 3: 08048148 0 SECTION LOCAL DEFAULT 3 4: 08048174 0 SECTION LOCAL DEFAULT 4 5: 080481d4 0 SECTION LOCAL DEFAULT 5 6: 08048232 0 SECTION LOCAL DEFAULT 6 7: 08048240 0 SECTION LOCAL DEFAULT 7 8: 08048260 0 SECTION LOCAL DEFAULT 8 9: 08048268 0 SECTION LOCAL DEFAULT 9 10: 08048278 0 SECTION LOCAL DEFAULT 10 11: 08048290 0 SECTION LOCAL DEFAULT 11 12: 080482c0 0 SECTION LOCAL DEFAULT 12 13: 08048458 0 SECTION LOCAL DEFAULT 13 14: 08048478 0 SECTION LOCAL DEFAULT 14 15: 08048490 0 SECTION LOCAL DEFAULT 15 16: 08049494 0 SECTION LOCAL DEFAULT 16 17: 0804949c 0 SECTION LOCAL DEFAULT 17 18: 080494a4 0 SECTION LOCAL DEFAULT 18 19: 080494a8 0 SECTION LOCAL DEFAULT 19 20: 08049570 0 SECTION LOCAL DEFAULT 20 21: 08049574 0 SECTION LOCAL DEFAULT 21 22: 08049588 0 SECTION LOCAL DEFAULT 22 23: 08049594 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: 00000000 0 SECTION LOCAL DEFAULT 27 28: 00000000 0 SECTION LOCAL DEFAULT 28 29: 00000000 0 SECTION LOCAL DEFAULT 29 30: 00000000 0 SECTION LOCAL DEFAULT 30 31: 00000000 0 SECTION LOCAL DEFAULT 31 32: 00000000 0 SECTION LOCAL DEFAULT 32 33: 00000000 0 SECTION LOCAL DEFAULT 33 34: 00000000 0 FILE LOCAL DEFAULT ABS abi-note.S 35: 00000000 0 FILE LOCAL DEFAULT ABS ../sysdeps/i386/elf/start 36: 00000000 0 FILE LOCAL DEFAULT ABS init.c 37: 00000000 0 FILE LOCAL DEFAULT ABS initfini.c 38: 00000000 0 FILE LOCAL DEFAULT ABS /build/buildd/glibc-2.3.6 39: 080482e4 0 FUNC LOCAL DEFAULT 12 call_gmon_start 40: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c 41: 08049494 0 OBJECT LOCAL DEFAULT 16 __CTOR_LIST__ 42: 0804949c 0 OBJECT LOCAL DEFAULT 17 __DTOR_LIST__ 43: 080494a4 0 OBJECT LOCAL DEFAULT 18 __JCR_LIST__ 44: 08049594 1 OBJECT LOCAL DEFAULT 23 completed.4463 45: 08049590 0 OBJECT LOCAL DEFAULT 22 p.4462 46: 0804830c 0 FUNC LOCAL DEFAULT 12 __do_global_dtors_aux 47: 0804833b 0 FUNC LOCAL DEFAULT 12 frame_dummy 48: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c 49: 08049498 0 OBJECT LOCAL DEFAULT 16 __CTOR_END__ 50: 080494a0 0 OBJECT LOCAL DEFAULT 17 __DTOR_END__ 51: 08048490 0 OBJECT LOCAL DEFAULT 15 __FRAME_END__ 52: 080494a4 0 OBJECT LOCAL DEFAULT 18 __JCR_END__ 53: 0804842c 0 FUNC LOCAL DEFAULT 12 __do_global_ctors_aux 54: 00000000 0 FILE LOCAL DEFAULT ABS initfini.c 55: 00000000 0 FILE LOCAL DEFAULT ABS /build/buildd/glibc-2.3.6 56: 00000000 0 FILE LOCAL DEFAULT ABS hw.c 57: 080494a8 0 OBJECT LOCAL HIDDEN 19 _DYNAMIC 58: 08049494 0 NOTYPE LOCAL HIDDEN ABS __fini_array_end 59: 08049494 0 NOTYPE LOCAL HIDDEN ABS __fini_array_start 60: 08049494 0 NOTYPE LOCAL HIDDEN ABS __init_array_end 61: 08049574 0 OBJECT LOCAL HIDDEN 21 _GLOBAL_OFFSET_TABLE_ 62: 08049494 0 NOTYPE LOCAL HIDDEN ABS __init_array_start 63: 08048478 4 OBJECT GLOBAL DEFAULT 14 _fp_hw 64: 0804958c 0 OBJECT GLOBAL HIDDEN 22 __dso_handle 65: 080483e1 74 FUNC GLOBAL DEFAULT 12 __libc_csu_fini 66: 00000000 378 FUNC GLOBAL DEFAULT UND puts@@GLIBC_2.0 67: 08048278 0 FUNC GLOBAL DEFAULT 10 _init 68: 080482c0 0 FUNC GLOBAL DEFAULT 12 _start 69: 08048390 81 FUNC GLOBAL DEFAULT 12 __libc_csu_init 70: 08049594 0 NOTYPE GLOBAL DEFAULT ABS __bss_start 71: 08048360 47 FUNC GLOBAL DEFAULT 12 main 72: 00000000 230 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_ 73: 08049588 0 NOTYPE WEAK DEFAULT 22 data_start 74: 08048458 0 FUNC GLOBAL DEFAULT 13 _fini 75: 08049594 0 NOTYPE GLOBAL DEFAULT ABS _edata 76: 08048308 0 FUNC GLOBAL HIDDEN 12 __i686.get_pc_thunk.bx 77: 08049598 0 NOTYPE GLOBAL DEFAULT ABS _end 78: 0804847c 4 OBJECT GLOBAL DEFAULT 14 _IO_stdin_used 79: 08049588 0 NOTYPE GLOBAL DEFAULT 22 __data_start 80: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses 81: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__Histogram for bucket list length (total of 3 buckets): Length Number % of total Coverage 0 0 ( 0.0%) 1 1 ( 33.3%) 20.0% 2 2 ( 66.7%) 100.0%Version symbols section '.gnu.version' contains 6 entries: Addr: 0000000008048232 Offset: 0x000232 Link: 4 (.dynsym) 000: 0 (*local*) 2 (GLIBC_2.0) 2 (GLIBC_2.0) 1 (*global*) 004: 0 (*local*) 0 (*local*)Version needs section '.gnu.version_r' contains 1 entries: Addr: 0x0000000008048240 Offset: 0x000240 Link to section: 5 (.dynstr) 000000: Version: 1 File: libc.so.6 Cnt: 1 0x0010: Name: GLIBC_2.0 Flags: none Version: 2Notes at offset 0x00000128 with length 0x00000020: Owner Data size Description GNU 0x00000010 NT_VERSION (version) |
正如从该输出中看到的,简单的 a.out Hello World 文件中包含了大量有价值的细节信息,包括版本信息、柱状图、各种符号类型的表格,等等。通过使用本文中介绍的这几种工具分析目标文件,您可以慢慢地对可执行程序进行研究。
除了所有这些段之外,编译器可以将调试信息放入到目标文件中,并且还可以显示这些信息。输入下面的命令,仔细分析编译器的输出(假设您扮演了调试程序的角色):
readelf --debug-dump a.out | less |
这个命令生成的输出如清单 5 所示。调试工具,如 GDB,可以读取这些调试信息,并且当程序在调试器中运行的同时,您可以使用该工具显示更具描述性的标记,而不是对代码进行反汇编时的原始地址值。
The section .debug_aranges contains: Length: 28 Version: 2 Offset into .debug_info: 0 Pointer Size: 4 Segment Size: 0 Address Length 080482c0 34 Length: 52 Version: 2 Offset into .debug_info: 10b Pointer Size: 4 Segment Size: 0 Address Length 08048308 4 08048458 18 08048278 11 080482e4 36 Length: 44 Version: 2 Offset into .debug_info: 19b Pointer Size: 4 Segment Size: 0 Address Length 08048308 4 0804846f 6 0804828d 2Contents of the .debug_pubnames section: Length: 33 Version: 2 Offset into .debug_info section: 122 Size of area in .debug_info section: 145 Offset Name 121 _IO_stdin_usedThe section .debug_info contains: Compilation Unit @ offset 0x0: Length: 118 Version: 2 Abbrev Offset: 0 Pointer Size: 4 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit) DW_AT_stmt_list : 0 DW_AT_low_pc : 0x80482c0 DW_AT_high_pc : 0x80482e2 DW_AT_name : ../sysdeps/i386/elf/start.S DW_AT_comp_dir : /build/buildd/glibc-2.3.6/build-tree/glibc-2.3.6/csu DW_AT_producer : GNU AS 2.16.91 DW_AT_language : 32769 (MIPS assembler) Compilation Unit @ offset 0x7a: Length: 141 Version: 2 Abbrev Offset: 20 Pointer Size: 4 <0><85>: Abbrev Number: 1 (DW_TAG_compile_unit) DW_AT_stmt_list : 0x5b DW_AT_high_pc : 0x80482e4 DW_AT_low_pc : 0x80482e4 DW_AT_producer : (indirect string, offset: 0x62): GNU C 3.4.6 DW_AT_language : 1 (ANSI C) DW_AT_name : (indirect string, offset: 0x0): init.c DW_AT_comp_dir : (indirect string, offset: 0x11): /build/buildd/... <1><9f>: Abbrev Number: 2 (DW_TAG_base_type) DW_AT_name : (indirect string, offset: 0x90): unsigned int DW_AT_byte_size : 4 DW_AT_encoding : 7 (unsigned) <1><a6>: Abbrev Number: 2 (DW_TAG_base_type) DW_AT_name : (indirect string, offset: 0x54): unsigned char DW_AT_byte_size : 1 DW_AT_encoding : 8 (unsigned char) <1><ad>: Abbrev Number: 2 (DW_TAG_base_type) DW_AT_name : (indirect string, offset: 0x9d): short unsigned int DW_AT_byte_size : 2 DW_AT_encoding : 7 (unsigned) <1><b4>: Abbrev Number: 2 (DW_TAG_base_type) DW_AT_name : (indirect string, offset: 0x8b): long unsigned int DW_AT_byte_size : 4 DW_AT_encoding : 7 (unsigned) <1><bb>: Abbrev Number: 2 (DW_TAG_base_type) DW_AT_name : (indirect string, offset: 0x56): signed char DW_AT_byte_size : 1 DW_AT_encoding : 6 (signed char) <1><c2>: Abbrev Number: 2 (DW_TAG_base_type) DW_AT_name : (indirect string, offset: 0x7): short int DW_AT_byte_size : 2 DW_AT_encoding : 5 (signed) <1><c9>: Abbrev Number: 3 (DW_TAG_base_type) DW_AT_name : int DW_AT_byte_size : 4 DW_AT_encoding : 5 (signed) <1><d0>: Abbrev Number: 2 (DW_TAG_base_type) DW_AT_name : (indirect string, offset: 0x46): long long int DW_AT_byte_size : 8 DW_AT_encoding : 5 (signed) <1><d7>: Abbrev Number: 2 (DW_TAG_base_type) DW_AT_name : (indirect string, offset: 0x86): long long unsigned int DW_AT_byte_size : 8 DW_AT_encoding : 7 (unsigned) <1><de>: Abbrev Number: 2 (DW_TAG_base_type) DW_AT_name : (indirect string, offset: 0x4b): long int DW_AT_byte_size : 4 DW_AT_encoding : 5 (signed) <1><e5>: Abbrev Number: 2 (DW_TAG_base_type) DW_AT_name : (indirect string, offset: 0x90): unsigned int DW_AT_byte_size : 4 DW_AT_encoding : 7 (unsigned) <1><ec>: Abbrev Number: 2 (DW_TAG_base_type) DW_AT_name : (indirect string, offset: 0x5d): char DW_AT_byte_size : 1 DW_AT_encoding : 6 (signed char) <1><f3>: Abbrev Number: 4 (DW_TAG_variable) DW_AT_name : (indirect string, offset: 0xb0): _IO_stdin_used DW_AT_decl_file : 1 DW_AT_decl_line : 25 DW_AT_type : <105> DW_AT_external : 1 DW_AT_location : 5 byte block: 3 7c 84 4 8 (DW_OP_addr: 804847c) <1><105>: Abbrev Number: 5 (DW_TAG_const_type) DW_AT_type : <c9> Compilation Unit @ offset 0x10b: Length: 140 Version: 2 Abbrev Offset: 86 Pointer Size: 4 <0><116>: Abbrev Number: 1 (DW_TAG_compile_unit) DW_AT_stmt_list : 0x82 DW_AT_name : /build/buildd/glibc-2.3.6/build-tree/i386-libc/csu/crti.S DW_AT_comp_dir : /build/buildd/glibc-2.3.6/build-tree/glibc-2.3.6/csu DW_AT_producer : GNU AS 2.16.91 DW_AT_language : 32769 (MIPS assembler) Compilation Unit @ offset 0x19b: Length: 140 Version: 2 Abbrev Offset: 102 Pointer Size: 4 <0><1a6>: Abbrev Number: 1 (DW_TAG_compile_unit) DW_AT_stmt_list : 0x12f DW_AT_name : /build/buildd/glibc-2.3.6/build-tree/i386-libc/csu/crtn.S DW_AT_comp_dir : /build/buildd/glibc-2.3.6/build-tree/glibc-2.3.6/csu DW_AT_producer : GNU AS 2.16.91 DW_AT_language : 32769 (MIPS assembler)Contents of the .debug_abbrev section: Number TAG 1 DW_TAG_compile_unit [no children] DW_AT_stmt_list DW_FORM_data4 DW_AT_low_pc DW_FORM_addr DW_AT_high_pc DW_FORM_addr DW_AT_name DW_FORM_string DW_AT_comp_dir DW_FORM_string DW_AT_producer DW_FORM_string DW_AT_language DW_FORM_data2 Number TAG 1 DW_TAG_compile_unit [has children] DW_AT_stmt_list DW_FORM_data4 DW_AT_high_pc DW_FORM_addr DW_AT_low_pc DW_FORM_addr DW_AT_producer DW_FORM_strp DW_AT_language DW_FORM_data1 DW_AT_name DW_FORM_strp DW_AT_comp_dir DW_FORM_strp 2 DW_TAG_base_type [no children] DW_AT_name DW_FORM_strp DW_AT_byte_size DW_FORM_data1 DW_AT_encoding DW_FORM_data1 3 DW_TAG_base_type [no children] DW_AT_name DW_FORM_string DW_AT_byte_size DW_FORM_data1 DW_AT_encoding DW_FORM_data1 4 DW_TAG_variable [no children] DW_AT_name DW_FORM_strp DW_AT_decl_file DW_FORM_data1 DW_AT_decl_line DW_FORM_data1 DW_AT_type DW_FORM_ref4 DW_AT_external DW_FORM_flag DW_AT_location DW_FORM_block1 5 DW_TAG_const_type [no children] DW_AT_type DW_FORM_ref4 Number TAG 1 DW_TAG_compile_unit [no children] DW_AT_stmt_list DW_FORM_data4 DW_AT_name DW_FORM_string DW_AT_comp_dir DW_FORM_string DW_AT_producer DW_FORM_string DW_AT_language DW_FORM_data2 Number TAG 1 DW_TAG_compile_unit [no children] DW_AT_stmt_list DW_FORM_data4 DW_AT_name DW_FORM_string DW_AT_comp_dir DW_FORM_string DW_AT_producer DW_FORM_string DW_AT_language DW_FORM_data2Dump of debug contents of section .debug_line: Length: 87 DWARF Version: 2 Prologue Length: 50 Minimum Instruction Length: 1 Initial value of 'is_stmt': 1 Line Base: -5 Line Range: 14 Opcode Base: 13 (Pointer size: 4) Opcodes: Opcode 1 has 0 args Opcode 2 has 1 args Opcode 3 has 1 args Opcode 4 has 1 args Opcode 5 has 1 args Opcode 6 has 0 args Opcode 7 has 0 args Opcode 8 has 0 args Opcode 9 has 1 args Opcode 10 has 0 args Opcode 11 has 0 args Opcode 12 has 1 args The Directory Table: ../sysdeps/i386/elf The File Name Table: Entry Dir Time Size Name 1 1 0 0 start.S Line Number Statements: Extended opcode 2: set Address to 0x80482c0 Advance Line by 64 to 65 Copy Special opcode 38: advance Address by 2 to 0x80482c2 and Line by 5 to 70 Special opcode 20: advance Address by 1 to 0x80482c3 and Line by 1 to 71 Special opcode 39: advance Address by 2 to 0x80482c5 and Line by 6 to 77 Special opcode 48: advance Address by 3 to 0x80482c8 and Line by 1 to 78 Special opcode 24: advance Address by 1 to 0x80482c9 and Line by 5 to 83 Special opcode 21: advance Address by 1 to 0x80482ca and Line by 2 to 85 Advance Line by 24 to 109 Special opcode 19: advance Address by 1 to 0x80482cb and Line by 0 to 109 Special opcode 76: advance Address by 5 to 0x80482d0 and Line by 1 to 110 Special opcode 77: advance Address by 5 to 0x80482d5 and Line by 2 to 112 Special opcode 20: advance Address by 1 to 0x80482d6 and Line by 1 to 113 Special opcode 21: advance Address by 1 to 0x80482d7 and Line by 2 to 115 Special opcode 79: advance Address by 5 to 0x80482dc and Line by 4 to 119 Special opcode 78: advance Address by 5 to 0x80482e1 and Line by 3 to 122 Advance PC by 1 to 0x80482e2 Extended opcode 1: End of Sequence Length: 35 DWARF Version: 2 Prologue Length: 29 Minimum Instruction Length: 1 Initial value of 'is_stmt': 1 Line Base: -5 Line Range: 14 Opcode Base: 13 (Pointer size: 4) Opcodes: Opcode 1 has 0 args Opcode 2 has 1 args Opcode 3 has 1 args Opcode 4 has 1 args Opcode 5 has 1 args Opcode 6 has 0 args Opcode 7 has 0 args Opcode 8 has 0 args Opcode 9 has 1 args Opcode 10 has 0 args Opcode 11 has 0 args Opcode 12 has 1 args The Directory Table is empty. The File Name Table: Entry Dir Time Size Name 1 0 0 0 init.c Line Number Statements: Length: 169 DWARF Version: 2 Prologue Length: 80 Minimum Instruction Length: 1 Initial value of 'is_stmt': 1 Line Base: -5 Line Range: 14 Opcode Base: 13 (Pointer size: 4) Opcodes: Opcode 1 has 0 args Opcode 2 has 1 args Opcode 3 has 1 args Opcode 4 has 1 args Opcode 5 has 1 args Opcode 6 has 0 args Opcode 7 has 0 args Opcode 8 has 0 args Opcode 9 has 1 args Opcode 10 has 0 args Opcode 11 has 0 args Opcode 12 has 1 args The Directory Table: /build/buildd/glibc-2.3.6/build-tree/i386-libc/csu The File Name Table: Entry Dir Time Size Name 1 1 0 0 crti.S Line Number Statements: Extended opcode 2: set Address to 0x8048308 Advance Line by 64 to 65 Copy Special opcode 48: advance Address by 3 to 0x804830b and Line by 1 to 66 Advance PC by 1 to 0x804830c Extended opcode 1: End of Sequence Extended opcode 2: set Address to 0x8048458 Advance Line by 46 to 47 Copy Special opcode 20: advance Address by 1 to 0x8048459 and Line by 1 to 48 Special opcode 34: advance Address by 2 to 0x804845b and Line by 1 to 49 Special opcode 20: advance Address by 1 to 0x804845c and Line by 1 to 50 Special opcode 76: advance Address by 5 to 0x8048461 and Line by 1 to 51 Special opcode 90: advance Address by 6 to 0x8048467 and Line by 1 to 52 Advance PC by 3 to 0x804846a Extended opcode 1: End of Sequence Extended opcode 2: set Address to 0x8048278 Advance Line by 31 to 32 Copy Special opcode 20: advance Address by 1 to 0x8048279 and Line by 1 to 33 Special opcode 34: advance Address by 2 to 0x804827b and Line by 1 to 34 Special opcode 48: advance Address by 3 to 0x804827e and Line by 1 to 35 Advance PC by 5 to 0x8048283 Extended opcode 1: End of Sequence Extended opcode 2: set Address to 0x80482e4 Advance Line by 10 to 11 Copy Special opcode 20: advance Address by 1 to 0x80482e5 and Line by 1 to 12 Special opcode 34: advance Address by 2 to 0x80482e7 and Line by 1 to 13 Special opcode 20: advance Address by 1 to 0x80482e8 and Line by 1 to 14 Special opcode 76: advance Address by 5 to 0x80482ed and Line by 1 to 15 Special opcode 90: advance Address by 6 to 0x80482f3 and Line by 1 to 16 Special opcode 48: advance Address by 3 to 0x80482f6 and Line by 1 to 17 Special opcode 90: advance Address by 6 to 0x80482fc and Line by 1 to 18 Special opcode 34: advance Address by 2 to 0x80482fe and Line by 1 to 19 Special opcode 34: advance Address by 2 to 0x8048300 and Line by 1 to 20 Special opcode 35: advance Address by 2 to 0x8048302 and Line by 2 to 22 Special opcode 48: advance Address by 3 to 0x8048305 and Line by 1 to 23 Special opcode 20: advance Address by 1 to 0x8048306 and Line by 1 to 24 Special opcode 20: advance Address by 1 to 0x8048307 and Line by 1 to 25 Advance PC by 1 to 0x8048308 Extended opcode 1: End of Sequence Length: 136 DWARF Version: 2 Prologue Length: 80 Minimum Instruction Length: 1 Initial value of 'is_stmt': 1 Line Base: -5 Line Range: 14 Opcode Base: 13 (Pointer size: 4) Opcodes: Opcode 1 has 0 args Opcode 2 has 1 args Opcode 3 has 1 args Opcode 4 has 1 args Opcode 5 has 1 args Opcode 6 has 0 args Opcode 7 has 0 args Opcode 8 has 0 args Opcode 9 has 1 args Opcode 10 has 0 args Opcode 11 has 0 args Opcode 12 has 1 args The Directory Table: /build/buildd/glibc-2.3.6/build-tree/i386-libc/csu The File Name Table: Entry Dir Time Size Name 1 1 0 0 crtn.S Line Number Statements: Extended opcode 2: set Address to 0x8048308 Advance Line by 33 to 34 Copy Special opcode 48: advance Address by 3 to 0x804830b and Line by 1 to 35 Advance PC by 1 to 0x804830c Extended opcode 1: End of Sequence Extended opcode 2: set Address to 0x804846f Advance Line by 18 to 19 Copy Special opcode 48: advance Address by 3 to 0x8048472 and Line by 1 to 20 Special opcode 20: advance Address by 1 to 0x8048473 and Line by 1 to 21 Special opcode 20: advance Address by 1 to 0x8048474 and Line by 1 to 22 Advance PC by 1 to 0x8048475 Extended opcode 1: End of Sequence Extended opcode 2: set Address to 0x804828d Advance Line by 9 to 10 Copy Special opcode 20: advance Address by 1 to 0x804828e and Line by 1 to 11 Advance PC by 1 to 0x804828f Extended opcode 1: End of SequenceContents of the .debug_str section: 0x00000000 696e6974 2e630073 686f7274 20696e74 init.c.short int 0x00000010 002f6275 696c642f 6275696c 64642f67 ./build/buildd/g 0x00000020 6c696263 2d322e33 2e362f62 75696c64 libc-2.3.6/build 0x00000030 2d747265 652f676c 6962632d 322e332e -tree/glibc-2.3. 0x00000040 362f6373 75006c6f 6e67206c 6f6e6720 6/csu.long long 0x00000050 696e7400 756e7369 676e6564 20636861 int.unsigned cha 0x00000060 7200474e 55204320 332e342e 36202855 r.GNU C 3.4.6 (U 0x00000070 62756e74 7520332e 342e362d 31756275 buntu 3.4.6-1ubu 0x00000080 6e747532 29006c6f 6e67206c 6f6e6720 ntu2).long long 0x00000090 756e7369 676e6564 20696e74 0073686f unsigned int.sho 0x000000a0 72742075 6e736967 6e656420 696e7400 rt unsigned int. 0x000000b0 5f494f5f 73746469 6e5f7573 656400 _IO_stdin_used. |
在 UNIX 中,可执行文件是 目标文件,并且您可以像对 a.out 文件那样对它们进行分析。可以进行一次有益的练习,更改到 /bin 或 /local/bin 目录,然后针对一些您最常用的命令,如 pwd、ps、cat 或 rm,运行 nm、objdump 和 readelf。通常,在您编写需要某种功能的程序时,如果标准的工具已经提供了这个功能,那么通过运行 objdump -d <command>,可以查看这些工具究竟如何完成这项任务。
如果您倾向于使用编译器和其他的语言工具,那么您可以对组成计算机系统的各种目标文件进行仔细研究,并且您将会发现这项工作是非常值得的。UNIX 操作系统具有许多层次,那些通过工具查看目标文件所公开的层次,非常接近底层硬件。通过这种方式,您可以真实地接触到系统。
研究目标文件可以极大地加深您对 UNIX 操作系统的认识,并且可以更深入地了解如何对软件的源代码进行汇编。我鼓励您使用本文中介绍的目标文件工具对系统中 /bin 或 /local/bin 目录中的程序进行分析,仔细研究其输出结果,并找出您的硬件制造商所提供的系统文档。
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
当我们的程序中有经常使用的模块,而且这种模块在其他程序中也会用到,这时按照软件重用的思想,我们应该将它们生成库,使得以后编程可以减少开发代码量。这里介绍两个命令ar和nm,用来对库操作。
1.ar基本用法
2.nm基本用法命令
当我们的程序中有经常使用的模块,而且这种模块在其他程序中也会用到,这时按照软件重用的思想,我们应该将它们生成库,使得以后编程可以减少开发代码量。这里介绍两个命令ar和nm,用来对库操作。
1.ar基本用法
ar命令可以用来创建、修改库,也可以从库中提出单个模块。库是一单独的文件,里面包含了按照特定的结构组织起来的其它的一些文件(称做此库文件的member)。原始文件的内容、模式、时间戳、属主、组等属性都保留在库文件中。
下面是ar命令的格式:
ar [-]{dmpqrtx}[abcfilNoPsSuvV] [membername] [count] archive files...
例如我们可以用ar rv libtest.a hello.o
hello1.o来生成一个库,库名字是test,链接时可以用-ltest链接。该库中存放了两个模块hello.o和hello1.o。选项前可以有
‘-'字符,也可以没有。下面我们来看看命令的操作选项和任选项。现在我们把{dmpqrtx}部分称为操作选项,而[abcfilNoPsSuvV]部
分称为任选项。
{dmpqrtx}中的操作选项在命令中只能并且必须使用其中一个,它们的含义如下:
d:从库中删除模块。按模块原来的文件名指定要删除的模块。如果使用了任选项v则列出被删除的每个模块。
m:该操作是在一个库中移动成员。当库中如果有若干模块有相同的符号定义(如函数定义),则成员的位置顺序很重要。如果没有指定任选项,任何指定的成员将移到库的最后。也可以使用'a','b',或'I'任选项移动到指定的位置。
p:显示库中指定的成员到标准输出。如果指定任选项v,则在输出成员的内容前,将显示成员的名字。如果没有指定成员的名字,所有库中的文件将显示出来。
q:快速追加。增加新模块到库的结尾处。并不检查是否需要替换。'a','b',或'I'任选项对此操作没有影响,模块总是追加的库的结尾处。如果使用了任选项v则列出每个模块。 这时,库的符号表没有更新,可以用'ar s'或ranlib来更新库的符号表索引。
r:在库中插入模块(替换)。当插入的模块名已经在库中存在,则替换同名的模块。如果若干模块中有一个模块在库中不存在,ar显示一个错误消息,并不替换其他同名模块。默认的情况下,新的成员增加在库的结尾处,可以使用其他任选项来改变增加的位置。
t:显示库的模块表清单。一般只显示模块名。
x:从库中提取一个成员。如果不指定要提取的模块,则提取库中所有的模块。
下面在看看可与操作选项结合使用的任选项:
a:在库的一个已经存在的成员后面增加一个新的文件。如果使用任选项a,则应该为命令行中membername参数指定一个已经存在的成员名。
b:在库的一个已经存在的成员前面增加一个新的文件。如果使用任选项b,则应该为命令行中membername参数指定一个已经存在的成员名。
c:创建一个库。不管库是否存在,都将创建。
f:在库中截短指定的名字。缺省情况下,文件名的长度是不受限制的,可以使用此参数将文件名截短,以保证与其它系统的兼容。
i:在库的一个已经存在的成员前面增加一个新的文件。如果使用任选项i,则应该为命令行中membername参数指定一个已经存在的成员名(类似任选项b)。
l:暂未使用
N:与count参数一起使用,在库中有多个相同的文件名时指定提取或输出的个数。
o:当提取成员时,保留成员的原始数据。如果不指定该任选项,则提取出的模块的时间将标为提取出的时间。
P:进行文件名匹配时使用全路径名。ar在创建库时不能使用全路径名(这样的库文件不符合POSIX标准),但是有些工具可以。
s:写入一个目标文件索引到库中,或者更新一个存在的目标文件索引。甚至对于没有任何变化的库也作该动作。对一个库做ar s等同于对该库做ranlib。
S:不创建目标文件索引,这在创建较大的库时能加快时间。
u:一般说来,命令ar r...插入所有列出的文件到库中,如果你只想插入列出文件中那些比库中同名文件新的文件,就可以使用该任选项。该任选项只用于r操作选项。
v:该选项用来显示执行操作选项的附加信息。
V:显示ar的版本。
2.nm基本用法命令
nm用来列出目标文件的符号清单。下面是nm命令的格式:
nm [-a|--debug-syms] [-g|--extern-only] [-B][-C|--demangle] [-D|--dynamic] [-s|--print-armap][-o|--print-file-name] [-n|--numeric-sort][-p|--no-sort] [-r|--reverse-sort] [--size-sort][-u|--undefined-only] [-l|--line-numbers] [--help][--version] [-t radix|--radix=radix][-P|--portability] [-f format|--format=format][--target=bfdname] [objfile...]
如果没有为nm命令指出目标文件,则nm假定目标文件是a.out。下面列出该命令的任选项,大部分支持"-"开头的短格式和"—"开头的长格式。
-A、-o或--print-file-name:在找到的各个符号的名字前加上文件名,而不是在此文件的所有符号前只出现文件名一次。
例如nm libtest.a的输出如下:
CPThread.o:
00000068 T Main__8CPThreadPv
00000038 T Start__8CPThread
00000014 T _._8CPThread
00000000 T __8CPThread
00000000 ? __FRAME_BEGIN__
.......................................
则nm -A 的输出如下:
libtest.a:CPThread.o:00000068 T Main__8CPThreadPv
libtest.a:CPThread.o:00000038 T Start__8CPThread
libtest.a:CPThread.o:00000014 T _._8CPThread
libtest.a:CPThread.o:00000000 T __8CPThread
libtest.a:CPThread.o:00000000 ? __FRAME_BEGIN__
..................................................................
-a或--debug-syms:显示调试符号。
-B:等同于--format=bsd,用来兼容MIPS的nm。
-C或--demangle:将低级符号名解码(demangle)成用户级名字。这样可以使得C++函数名具有可读性。
-D或--dynamic:显示动态符号。该任选项仅对于动态目标(例如特定类型的共享库)有意义。
-f format:使用format格式输出。format可以选取bsd、sysv或posix,该选项在GNU的nm中有用。默认为bsd。
-g或--extern-only:仅显示外部符号。
-n、-v或--numeric-sort:按符号对应地址的顺序排序,而非按符号名的字符顺序。
-p或--no-sort:按目标文件中遇到的符号顺序显示,不排序。
-P或--portability:使用POSIX.2标准输出格式代替默认的输出格式。等同于使用任选项-f posix。
-s或--print-armap:当列出库中成员的符号时,包含索引。索引的内容包含:哪些模块包含哪些名字的映射。
-r或--reverse-sort:反转排序的顺序(例如,升序变为降序)。
--size-sort:按大小排列符号顺序。该大小是按照一个符号的值与它下一个符号的值进行计算的。
-t radix或--radix=radix:使用radix进制显示符号值。radix只能为"d"表示十进制、"o"表示八进制或"x"表示十六进制。
--target=bfdname:指定一个目标代码的格式,而非使用系统的默认格式。
-u或--undefined-only:仅显示没有定义的符号(那些外部符号)。
-l或--line-numbers:对每个符号,使用调试信息来试图找到文件名和行号。对于已定义的符号,查找符号地址的行号。对于未定义符号,查找指向符号重定位入口的行号。如果可以找到行号信息,显示在符号信息之后。
-V或--version:显示nm的版本号。
--help:显示nm的任选项。
////////////////////////////////////////////////////////////////////////////////////////////////////
1、ldd不是一个可执行程序,而只是一个shell脚本。
2、ldd能够显示可执行模块的dependency。
原理:通过设置一系列的环境变量,如:LD_TRACE_LOADED_OBJECTS、LD_WARN、LD_BIND_NOW、 LD_LIBRARY_VERSION、 LD_VERBOSE等。当LD_TRACE_LOADED_OBJECTS环境变量不为空,任何可执行程序在运行时,都会只显示模块的 dependency,而程序并不真正执行。我们可以在shell终端测试一下,具体测试如下:
(1) export LD_TRACE_LOADED_OBJECTS=1
(2) 再执行任何的程序,如ls等,看看程序的运行结果
3、ldd显示可执行模块dependency的工作原理,实质是通过ld-linux.so(elf动态库的装载器)来实现的。
众所周知,ld-linux.so模块会先于executable模块程序工作,并获得控制权,因此当上述的那些环境变量被设置时,ld-linux.so选择了显示可执行模块的dependency。
4、实际上我们可以直接执行ld-linux.so模块。如:/lib/ld-linux.so.2 --list program(这相当于ldd program)
ldd命令使用方法(摘自ldd --help)
名称 ldd - 打印共享库的依赖关系
大纲 ldd [选项]... 文件...
描述 ldd 输出在命令行上指定的每个程序或共享库需要的共享库。
选项
--version
打印ldd的版本号
-v --verbose
打印所有信息,例如包括符号的版本信息
-d --data-relocs
执行符号重部署,并报告缺少的目标对象(只对ELF格式适用)
-r --function-relocs
对目标对象和函数执行重新部署,并报告缺少的目标对象和函数(只对ELF格式适用)
--help 用法信息
注意事项:
ldd的标准版本与glibc2一起提供。Libc5与老版本以前提供,在一些系统中还存在。在libc5版本中长选项不支持。另一方面,glibc2版本不支持-V选项,只提供等价的--version选项。
如果命令行中给定的库名字包含'/',这个程序的libc5版本将使用它作为库名字;否则它将在标准位置搜索库。运行一个当前目录下的共享库,加前缀"./"。
5、相关说明:
ldd不能工作在a.out格式的共享库上。
ldd不能工作在一些非常老的a.out程序上,这些程序在支持ldd的编译器发行前已经创建。如果你在这种类型的程序上使用ldd,程序将尝试argc = 0的运行方式,其结果不可预知。
NM(1) GNU Development Tools NM(1)
NAME
nm - list symbols from object files
SYNOPSIS
nm [-a|--debug-syms]
[-g|--extern-only][--plugin name]
[-B] [-C|--demangle[=style]] [-D|--dynamic]
[-S|--print-size] [-s|--print-armap]
[-A|-o|--print-file-name][--special-syms]
[-n|-v|--numeric-sort] [-p|--no-sort]
[-r|--reverse-sort] [--size-sort] [-u|--undefined-only]
[-t radix|--radix=radix] [-P|--portability]
[--target=bfdname] [-fformat|--format=format]
[--defined-only] [-l|--line-numbers] [--no-demangle]
[-V|--version] [-X 32_64] [--help] [objfile...]
DESCRIPTION
GNU nm lists the symbols from object files objfile.... If no object files are listed as arguments, nm assumes the file a.out.
For each symbol, nm shows:
· The symbol value, in the radix selected by options (see below), or hexadecimal by default.
· The symbol type. At least the following types are used; others are, as well, depending on the object file format. If lowercase, the symbol is local; if uppercase,
the symbol is global (external).
"A" The symbolâs value is absolute, and will not be changed by further linking.
"B"
"b" The symbol is in the uninitialized data section (known as BSS).
"C" The symbol is common. Common symbols are uninitialized data. When linking, multiple common symbols may appear with the same name. If the symbol is defined
anywhere, the common symbols are treated as undefined references.
"D"
"d" The symbol is in the initialized data section.
"G"
"g" The symbol is in an initialized data section for small objects. Some object file formats permit more efficient access to small data objects, such as a global int
variable as opposed to a large global array.
"i" The symbol is in a section specific to the implementation of DLLs.
"N" The symbol is a debugging symbol.
"p" The symbols is in a stack unwind section.
"R"
"r" The symbol is in a read only data section.
"S"
"s" The symbol is in an uninitialized data section for small objects.
"T"
"t" The symbol is in the text (code) section.
"U" The symbol is undefined.
"V"
"v" The symbol is a weak object. When a weak defined symbol is linked with a normal defined symbol, the normal defined symbol is used with no error. When a weak
undefined symbol is linked and the symbol is not defined, the value of the weak symbol becomes zero with no error. On some systems, uppercase indicates that a
default value has been specified.
"W"
"w" The symbol is a weak symbol that has not been specifically tagged as a weak object symbol. When a weak defined symbol is linked with a normal defined symbol, the
normal defined symbol is used with no error. When a weak undefined symbol is linked and the symbol is not defined, the value of the symbol is determined in a
system-specific manner without error. On some systems, uppercase indicates that a default value has been specified.
"-" The symbol is a stabs symbol in an a.out object file. In this case, the next values printed are the stabs other field, the stabs desc field, and the stab type.
Stabs symbols are used to hold debugging information.
"?" The symbol type is unknown, or object file format specific.
· The symbol name.
OPTIONS
The long and short forms of options, shown here as alternatives, are equivalent.
-A
-o
--print-file-name
Precede each symbol by the name of the input file (or archive member) in which it was found, rather than identifying the input file once only, before all of its
symbols.
-a
--debug-syms
Display all symbols, even debugger-only symbols; normally these are not listed.
-B The same as --format=bsd (for compatibility with the MIPS nm).
-C
--demangle[=style]
Decode (demangle) low-level symbol names into user-level names. Besides removing any initial underscore prepended by the system, this makes C++ function names
readable. Different compilers have different mangling styles. The optional demangling style argument can be used to choose an appropriate demangling style for your
compiler.
--no-demangle
Do not demangle low-level symbol names. This is the default.
-D
--dynamic
Display the dynamic symbols rather than the normal symbols. This is only meaningful for dynamic objects, such as certain types of shared libraries.
-f format
--format=format
Use the output format format, which can be "bsd", "sysv", or "posix". The default is "bsd". Only the first character of format is significant; it can be either
upper or lower case.
-g
--extern-only
Display only external symbols.
--plugin name
Load the plugin called name to add support for extra target types. This option is only available if the toolchain has been built with plugin support enabled.
-l
--line-numbers
For each symbol, use debugging information to try to find a filename and line number. For a defined symbol, look for the line number of the address of the symbol.
For an undefined symbol, look for the line number of a relocation entry which refers to the symbol. If line number information can be found, print it after the other
symbol information.
-n
-v
--numeric-sort
Sort symbols numerically by their addresses, rather than alphabetically by their names.
-p
--no-sort
Do not bother to sort the symbols in any order; print them in the order encountered.
-P
--portability
Use the POSIX.2 standard output format instead of the default format. Equivalent to -f posix.
-S
--print-size
Print both value and size of defined symbols for the "bsd" output style. This option has no effect for object formats that do not record symbol sizes, unless
--size-sort is also used in which case a calculated size is displayed.
-s
--print-armap
When listing symbols from archive members, include the index: a mapping (stored in the archive by ar or ranlib) of which modules contain definitions for which names.
-r
--reverse-sort
Reverse the order of the sort (whether numeric or alphabetic); let the last come first.
--size-sort
Sort symbols by size. The size is computed as the difference between the value of the symbol and the value of the symbol with the next higher value. If the "bsd"
output format is used the size of the symbol is printed, rather than the value, and -S must be used in order both size and value to be printed.
--special-syms
Display symbols which have a target-specific special meaning. These symbols are usually used by the target for some special processing and are not normally helpful
when included included in the normal symbol lists. For example for ARM targets this option would skip the mapping symbols used to mark transitions between ARM code,
THUMB code and data.
-t radix
--radix=radix
Use radix as the radix for printing the symbol values. It must be d for decimal, o for octal, or x for hexadecimal.
--target=bfdname
Specify an object code format other than your systemâs default format.
-u
--undefined-only
Display only undefined symbols (those external to each object file).
--defined-only
Display only defined symbols for each object file.
-V
--version
Show the version number of nm and exit.
-X This option is ignored for compatibility with the AIX version of nm. It takes one parameter which must be the string 32_64. The default mode of AIX nm corresponds
to -X 32, which is not supported by GNU nm.
--help
Show a summary of the options to nm and exit.
@file
Read command-line options from file. The options read are inserted in place of the original @file option. If file does not exist, or cannot be read, then the option
will be treated literally, and not removed.
Options in file are separated by whitespace. A whitespace character may be included in an option by surrounding the entire option in either single or double quotes.
Any character (including a backslash) may be included by prefixing the character to be included with a backslash. The file may itself contain additional @file
options; any such options will be processed recursively.
SEE ALSO
ar(1), objdump(1), ranlib(1), and the Info entries for binutils.
COPYRIGHT
Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by
the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section
entitled "GNU Free Documentation License".
binutils-2.19.51.0.14 2010-02-09 NM(1)
READELF(1) GNU Development Tools READELF(1)
NAME
readelf - Displays information about ELF files.
SYNOPSIS
readelf [-a|--all]
[-h|--file-header]
[-l|--program-headers|--segments]
[-S|--section-headers|--sections]
[-g|--section-groups]
[-t|--section-details]
[-e|--headers]
[-s|--syms|--symbols]
[-n|--notes]
[-r|--relocs]
[-u|--unwind]
[-d|--dynamic]
[-V|--version-info]
[-A|--arch-specific]
[-D|--use-dynamic]
[-x <number or name>|--hex-dump=<number or name>]
[-p <number or name>|--string-dump=<number or name>]
[-R <number or name>|--relocated-dump=<number or name>]
[-c|--archive-index]
[-w[lLiaprmfFsoR]|
--debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=frames-interp,=str,=loc,=Ranges]]
[-I|-histogram]
[-v|--version]
[-W|--wide]
[-H|--help]
elffile...
DESCRIPTION
readelf displays information about one or more ELF format object files. The options control what particular information to display.
elffile... are the object files to be examined. 32-bit and 64-bit ELF files are supported, as are archives containing ELF files.
This program performs a similar function to objdump but it goes into more detail and it exists independently of the BFD library, so if there is a bug in BFD then readelf
will not be affected.
OPTIONS
The long and short forms of options, shown here as alternatives, are equivalent. At least one option besides -v or -H must be given.
-a
--all
Equivalent to specifying --file-header, --program-headers, --sections, --symbols, --relocs, --dynamic, --notes and --version-info.
-h
--file-header
Displays the information contained in the ELF header at the start of the file.
-l
--program-headers
--segments
Displays the information contained in the fileâs segment headers, if it has any.
-S
--sections
--section-headers
Displays the information contained in the fileâs section headers, if it has any.
-g
--section-groups
Displays the information contained in the fileâs section groups, if it has any.
-t
--section-details
Displays the detailed section information. Implies -S.
-s
--symbols
--syms
Displays the entries in symbol table section of the file, if it has one.
-e
--headers
Display all the headers in the file. Equivalent to -h -l -S.
-n
--notes
Displays the contents of the NOTE segments and/or sections, if any.
-r
--relocs
Displays the contents of the fileâs relocation section, if it has one.
-u
--unwind
Displays the contents of the fileâs unwind section, if it has one. Only the unwind sections for IA64 ELF files are currently supported.
-d
--dynamic
Displays the contents of the fileâs dynamic section, if it has one.
-V
--version-info
Displays the contents of the version sections in the file, it they exist.
-A
--arch-specific
Displays architecture-specific information in the file, if there is any.
-D
--use-dynamic
When displaying symbols, this option makes readelf use the symbol table in the fileâs dynamic section, rather than the one in the symbols section.
-x <number or name>
--hex-dump=<number or name>
Displays the contents of the indicated section as a hexadecimal bytes. A number identifies a particular section by index in the section table; any other string
identifies all sections with that name in the object file.
-R <number or name>
--relocated-dump=<number or name>
Displays the contents of the indicated section as a hexadecimal bytes. A number identifies a particular section by index in the section table; any other string
identifies all sections with that name in the object file. The contents of the section will be relocated before they are displayed.
-p <number or name>
--string-dump=<number or name>
Displays the contents of the indicated section as printable strings. A number identifies a particular section by index in the section table; any other string
identifies all sections with that name in the object file.
-c
--archive-index
Displays the file symbol index infomation contained in the header part of binary archives. Performs the same function as the t command to ar, but without using the
BFD library.
-w[lLiaprmfFsoR]
--debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=frames-interp,=str,=loc,=Ranges]
Displays the contents of the debug sections in the file, if any are present. If one of the optional letters or words follows the switch then only data found in those
specific sections will be dumped.
Note: the =decodedline option will display the interpreted contents of a .debug_line section whereas the =rawline option dumps the contents in a raw format.
-I
--histogram
Display a histogram of bucket list lengths when displaying the contents of the symbol tables.
-v
--version
Display the version number of readelf.
-W
--wide
Donât break output lines to fit into 80 columns. By default readelf breaks section header and segment listing lines for 64-bit ELF files, so that they fit into 80
columns. This option causes readelf to print each section header resp. each segment one a single line, which is far more readable on terminals wider than 80 columns.
-H
--help
Display the command line options understood by readelf.
@file
Read command-line options from file. The options read are inserted in place of the original @file option. If file does not exist, or cannot be read, then the option
will be treated literally, and not removed.
Options in file are separated by whitespace. A whitespace character may be included in an option by surrounding the entire option in either single or double quotes.
Any character (including a backslash) may be included by prefixing the character to be included with a backslash. The file may itself contain additional @file
options; any such options will be processed recursively.
SEE ALSO
objdump(1), and the Info entries for binutils.
COPYRIGHT
Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by
the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section
entitled "GNU Free Documentation License".
binutils-2.19.51.0.14 2010-02-09 READELF(1)
OBJDUMP(1) GNU Development Tools OBJDUMP(1)
NAME
objdump - display information from object files.
SYNOPSIS
objdump [-a|--archive-headers]
[-b bfdname|--target=bfdname]
[-C|--demangle[=style] ]
[-d|--disassemble]
[-D|--disassemble-all]
[-z|--disassemble-zeroes]
[-EB|-EL|--endian={big | little }]
[-f|--file-headers]
[-F|--file-offsets]
[--file-start-context]
[-g|--debugging]
[-e|--debugging-tags]
[-h|--section-headers|--headers]
[-i|--info]
[-j section|--section=section]
[-l|--line-numbers]
[-S|--source]
[-m machine|--architecture=machine]
[-M options|--disassembler-options=options]
[-p|--private-headers]
[-r|--reloc]
[-R|--dynamic-reloc]
[-s|--full-contents]
[-W[lLiaprmfFsoR]|
--dwarf[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=frames-interp,=str,=loc,=Ranges]]
[-G|--stabs]
[-t|--syms]
[-T|--dynamic-syms]
[-x|--all-headers]
[-w|--wide]
[--start-address=address]
[--stop-address=address]
[--prefix-addresses]
[--[no-]show-raw-insn]
[--adjust-vma=offset]
[--special-syms]
[--prefix=prefix]
[--prefix-strip=level]
[--insn-width=width]
[-V|--version]
[-H|--help]
objfile...
DESCRIPTION
objdump displays information about one or more object files. The options control what particular information to display. This information is mostly useful to
programmers who are working on the compilation tools, as opposed to programmers who just want their program to compile and work.
objfile... are the object files to be examined. When you specify archives, objdump shows information on each of the member object files.
OPTIONS
The long and short forms of options, shown here as alternatives, are equivalent. At least one option from the list -a,-d,-D,-e,-f,-g,-G,-h,-H,-p,-r,-R,-s,-S,-t,-T,-V,-x
must be given.
-a
--archive-header
If any of the objfile files are archives, display the archive header information (in a format similar to ls -l). Besides the information you could list with ar tv,
objdump -a shows the object file format of each archive member.
--adjust-vma=offset
When dumping information, first add offset to all the section addresses. This is useful if the section addresses do not correspond to the symbol table, which can
happen when putting sections at particular addresses when using a format which can not represent section addresses, such as a.out.
-b bfdname
--target=bfdname
Specify that the object-code format for the object files is bfdname. This option may not be necessary; objdump can automatically recognize many formats.
For example,
objdump -b oasys -m vax -h fu.o
displays summary information from the section headers (-h) of fu.o, which is explicitly identified (-m) as a VAX object file in the format produced by Oasys
compilers. You can list the formats available with the -i option.
-C
--demangle[=style]
Decode (demangle) low-level symbol names into user-level names. Besides removing any initial underscore prepended by the system, this makes C++ function names
readable. Different compilers have different mangling styles. The optional demangling style argument can be used to choose an appropriate demangling style for your
compiler.
-g
--debugging
Display debugging information. This attempts to parse STABS and IEEE debugging format information stored in the file and print it out using a C like syntax. If
neither of these formats are found this option falls back on the -W option to print any DWARF information in the file.
-e
--debugging-tags
Like -g, but the information is generated in a format compatible with ctags tool.
-d
--disassemble
Display the assembler mnemonics for the machine instructions from objfile. This option only disassembles those sections which are expected to contain instructions.
-D
--disassemble-all
Like -d, but disassemble the contents of all sections, not just those expected to contain instructions.
If the target is an ARM architecture this switch also has the effect of forcing the disassembler to decode pieces of data found in code sections as if they were
instructions.
--prefix-addresses
When disassembling, print the complete address on each line. This is the older disassembly format.
-EB
-EL
--endian={big|little}
Specify the endianness of the object files. This only affects disassembly. This can be useful when disassembling a file format which does not describe endianness
information, such as S-records.
-f
--file-headers
Display summary information from the overall header of each of the objfile files.
-F
--file-offsets
When disassembling sections, whenever a symbol is displayed, also display the file offset of the region of data that is about to be dumped. If zeroes are being
skipped, then when disassembly resumes, tell the user how many zeroes were skipped and the file offset of the location from where the disassembly resumes. When
dumping sections, display the file offset of the location from where the dump starts.
--file-start-context
Specify that when displaying interlisted source code/disassembly (assumes -S) from a file that has not yet been displayed, extend the context to the start of the
file.
-h
--section-headers
--headers
Display summary information from the section headers of the object file.
File segments may be relocated to nonstandard addresses, for example by using the -Ttext, -Tdata, or -Tbss options to ld. However, some object file formats, such as
a.out, do not store the starting address of the file segments. In those situations, although ld relocates the sections correctly, using objdump -h to list the file
section headers cannot show the correct addresses. Instead, it shows the usual addresses, which are implicit for the target.
-H
--help
Print a summary of the options to objdump and exit.
-i
--info
Display a list showing all architectures and object formats available for specification with -b or -m.
-j name
--section=name
Display information only for section name.
-l
--line-numbers
Label the display (using debugging information) with the filename and source line numbers corresponding to the object code or relocs shown. Only useful with -d, -D,
or -r.
-m machine
--architecture=machine
Specify the architecture to use when disassembling object files. This can be useful when disassembling object files which do not describe architecture information,
such as S-records. You can list the available architectures with the -i option.
If the target is an ARM architecture then this switch has an additional effect. It restricts the disassembly to only those instructions supported by the architecture
specified by machine. If it is necessary to use this switch because the input file does not contain any architecture information, but it is also desired to
disassemble all the instructions use -marm.
-M options
--disassembler-options=options
Pass target specific information to the disassembler. Only supported on some targets. If it is necessary to specify more than one disassembler option then multiple
-M options can be used or can be placed together into a comma separated list.
If the target is an ARM architecture then this switch can be used to select which register name set is used during disassembler. Specifying -M reg-names-std (the
default) will select the register names as used in ARMâs instruction set documentation, but with register 13 called âspâ, register 14 called âlrâ and register 15
called âpcâ. Specifying -M reg-names-apcs will select the name set used by the ARM Procedure Call Standard, whilst specifying -M reg-names-raw will just use r
followed by the register number.
There are also two variants on the APCS register naming scheme enabled by -M reg-names-atpcs and -M reg-names-special-atpcs which use the ARM/Thumb Procedure Call
Standard naming conventions. (Either with the normal register names or the special register names).
This option can also be used for ARM architectures to force the disassembler to interpret all instructions as Thumb instructions by using the switch
--disassembler-options=force-thumb. This can be useful when attempting to disassemble thumb code produced by other compilers.
For the x86, some of the options duplicate functions of the -m switch, but allow finer grained control. Multiple selections from the following may be specified as a
comma separated string. x86-64, i386 and i8086 select disassembly for the given architecture. intel and att select between intel syntax mode and AT&T syntax mode.
intel-mnemonic and att-mnemonic select between intel mnemonic mode and AT&T mnemonic mode. intel-mnemonic implies intel and att-mnemonic implies att. addr64, addr32,
addr16, data32 and data16 specify the default address size and operand size. These four options will be overridden if x86-64, i386 or i8086 appear later in the
option string. Lastly, suffix, when in AT&T mode, instructs the disassembler to print a mnemonic suffix even when the suffix could be inferred by the operands.
For PowerPC, booke controls the disassembly of BookE instructions. 32 and 64 select PowerPC and PowerPC64 disassembly, respectively. e300 selects disassembly for
the e300 family. 440 selects disassembly for the PowerPC 440. ppcps selects disassembly for the paired single instructions of the PPC750CL.
For MIPS, this option controls the printing of instruction mnemonic names and register names in disassembled instructions. Multiple selections from the following may
be specified as a comma separated string, and invalid options are ignored:
"no-aliases"
Print the ârawâ instruction mnemonic instead of some pseudo instruction mnemonic. I.e., print âdadduâ or âorâ instead of âmoveâ, âsllâ instead of ânopâ, etc.
"gpr-names=ABI"
Print GPR (general-purpose register) names as appropriate for the specified ABI. By default, GPR names are selected according to the ABI of the binary being
disassembled.
"fpr-names=ABI"
Print FPR (floating-point register) names as appropriate for the specified ABI. By default, FPR numbers are printed rather than names.
"cp0-names=ARCH"
Print CP0 (system control coprocessor; coprocessor 0) register names as appropriate for the CPU or architecture specified by ARCH. By default, CP0 register names
are selected according to the architecture and CPU of the binary being disassembled.
"hwr-names=ARCH"
Print HWR (hardware register, used by the "rdhwr" instruction) names as appropriate for the CPU or architecture specified by ARCH. By default, HWR names are
selected according to the architecture and CPU of the binary being disassembled.
"reg-names=ABI"
Print GPR and FPR names as appropriate for the selected ABI.
"reg-names=ARCH"
Print CPU-specific register names (CP0 register and HWR names) as appropriate for the selected CPU or architecture.
For any of the options listed above, ABI or ARCH may be specified as numeric to have numbers printed rather than names, for the selected types of registers. You can
list the available values of ABI and ARCH using the --help option.
For VAX, you can specify function entry addresses with -M entry:0xf00ba. You can use this multiple times to properly disassemble VAX binary files that donât contain
symbol tables (like ROM dumps). In these cases, the function entry mask would otherwise be decoded as VAX instructions, which would probably lead the rest of the
function being wrongly disassembled.
-p
--private-headers
Print information that is specific to the object file format. The exact information printed depends upon the object file format. For some object file formats, no
additional information is printed.
-r
--reloc
Print the relocation entries of the file. If used with -d or -D, the relocations are printed interspersed with the disassembly.
-R
--dynamic-reloc
Print the dynamic relocation entries of the file. This is only meaningful for dynamic objects, such as certain types of shared libraries. As for -r, if used with -d
or -D, the relocations are printed interspersed with the disassembly.
-s
--full-contents
Display the full contents of any sections requested. By default all non-empty sections are displayed.
-S
--source
Display source code intermixed with disassembly, if possible. Implies -d.
--prefix=prefix
Specify prefix to add to the absolute paths when used with -S.
--prefix-strip=level
Indicate how many initial directory names to strip off the hardwired absolute paths. It has no effect without --prefix=prefix.
--show-raw-insn
When disassembling instructions, print the instruction in hex as well as in symbolic form. This is the default except when --prefix-addresses is used.
--no-show-raw-insn
When disassembling instructions, do not print the instruction bytes. This is the default when --prefix-addresses is used.
--insn-width=width
Display width bytes on a single line when disassembling instructions.
-W[lLiaprmfFsoR]
--dwarf[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=frames-interp,=str,=loc,=Ranges]
Displays the contents of the debug sections in the file, if any are present. If one of the optional letters or words follows the switch then only data found in those
specific sections will be dumped.
-G
--stabs
Display the full contents of any sections requested. Display the contents of the .stab and .stab.index and .stab.excl sections from an ELF file. This is only useful
on systems (such as Solaris 2.0) in which ".stab" debugging symbol-table entries are carried in an ELF section. In most other file formats, debugging symbol-table
entries are interleaved with linkage symbols, and are visible in the --syms output.
--start-address=address
Start displaying data at the specified address. This affects the output of the -d, -r and -s options.
--stop-address=address
Stop displaying data at the specified address. This affects the output of the -d, -r and -s options.
-t
--syms
Print the symbol table entries of the file. This is similar to the information provided by the nm program, although the display format is different. The format of
the output depends upon the format of the file being dumped, but there are two main types. One looks like this:
[ 4](sec 3)(fl 0x00)(ty 0)(scl 3) (nx 1) 0x00000000 .bss
[ 6](sec 1)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 fred
where the number inside the square brackets is the number of the entry in the symbol table, the sec number is the section number, the fl value are the symbolâs flag
bits, the ty number is the symbolâs type, the scl number is the symbolâs storage class and the nx value is the number of auxilary entries associated with the symbol.
The last two fields are the symbolâs value and its name.
The other common output format, usually seen with ELF based files, looks like this:
00000000 l d .bss 00000000 .bss
00000000 g .text 00000000 fred
Here the first number is the symbolâs value (sometimes refered to as its address). The next field is actually a set of characters and spaces indicating the flag bits
that are set on the symbol. These characters are described below. Next is the section with which the symbol is associated or *ABS* if the section is absolute (ie
not connected with any section), or *UND* if the section is referenced in the file being dumped, but not defined there.
After the section name comes another field, a number, which for common symbols is the alignment and for other symbol is the size. Finally the symbolâs name is
displayed.
The flag characters are divided into 7 groups as follows:
"l"
"g"
"!" The symbol is local (l), global (g), neither (a space) or both (!). A symbol can be neither local or global for a variety of reasons, e.g., because it is used
for debugging, but it is probably an indication of a bug if it is ever both local and global.
"w" The symbol is weak (w) or strong (a space).
"C" The symbol denotes a constructor (C) or an ordinary symbol (a space).
"W" The symbol is a warning (W) or a normal symbol (a space). A warning symbolâs name is a message to be displayed if the symbol following the warning symbol is ever
referenced.
"I"
"i" The symbol is an indirect reference to another symbol (I), a function to be evaluated during reloc processing (i) or a normal symbol (a space).
"d"
"D" The symbol is a debugging symbol (d) or a dynamic symbol (D) or a normal symbol (a space).
"F"
"f"
"O" The symbol is the name of a function (F) or a file (f) or an object (O) or just a normal symbol (a space).
-T
--dynamic-syms
Print the dynamic symbol table entries of the file. This is only meaningful for dynamic objects, such as certain types of shared libraries. This is similar to the
information provided by the nm program when given the -D (--dynamic) option.
--special-syms
When displaying symbols include those which the target considers to be special in some way and which would not normally be of interest to the user.
-V
--version
Print the version number of objdump and exit.
-x
--all-headers
Display all available header information, including the symbol table and relocation entries. Using -x is equivalent to specifying all of -a -f -h -p -r -t.
-w
--wide
Format some lines for output devices that have more than 80 columns. Also do not truncate symbol names when they are displayed.
-z
--disassemble-zeroes
Normally the disassembly output will skip blocks of zeroes. This option directs the disassembler to disassemble those blocks, just like any other data.
@file
Read command-line options from file. The options read are inserted in place of the original @file option. If file does not exist, or cannot be read, then the option
will be treated literally, and not removed.
Options in file are separated by whitespace. A whitespace character may be included in an option by surrounding the entire option in either single or double quotes.
Any character (including a backslash) may be included by prefixing the character to be included with a backslash. The file may itself contain additional @file
options; any such options will be processed recursively.
SEE ALSO
nm(1), readelf(1), and the Info entries for binutils.
COPYRIGHT
Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by
the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section
entitled "GNU Free Documentation License".
binutils-2.19.51.0.14 2010-02-09 OBJDUMP(1)
LDD(1) Linux Programmerâs Manual LDD(1)
NAME
ldd - print shared library dependencies
SYNOPSIS
ldd [OPTION]... FILE...
DESCRIPTION
ldd prints the shared libraries required by each program or shared library specified on the command line.
OPTIONS
--version
Print the version number of ldd.
-v --verbose
Print all information, including, for example, symbol versioning information.
-u --unused
Print unused direct dependencies. (Since glibc 2.3.4.)
-d --data-relocs
Perform relocations and report any missing objects (ELF only).
-r --function-relocs
Perform relocations for both data objects and functions, and report any missing objects or functions (ELF only).
--help Usage information.
NOTES
The standard version of ldd comes with glibc2. Libc5 came with an older version, still present on some systems. The long options are not supported by the libc5 version.
On the other hand, the glibc2 version does not support -V and only has the equivalent --version.
The libc5 version of this program will use the name of a library given on the command line as-is when it contains a '/'; otherwise it searches for the library in the
standard locations. To run it on a shared library in the current directory, prefix the name with "./".
BUGS
ldd does not work on a.out shared libraries.
ldd does not work with some extremely old a.out programs which were built before ldd support was added to the compiler releases. If you use ldd on one of these programs,
the program will attempt to run with argc = 0 and the results will be unpredictable.
SEE ALSO
ld.so(8), ldconfig(8)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.ker-
nel.org/doc/man-pages/.
2000-10-30 LDD(1)
AR(1) GNU Development Tools AR(1)
NAME
ar - create, modify, and extract from archives
SYNOPSIS
ar [--plugin name] [-X32_64] [-]p[mod [relpos] [count]] archive [member...]
DESCRIPTION
The GNU ar program creates, modifies, and extracts from archives. An archive is a single file holding a collection of other files in a structure that makes it possible
to retrieve the original individual files (called members of the archive).
The original filesâ contents, mode (permissions), timestamp, owner, and group are preserved in the archive, and can be restored on extraction.
GNU ar can maintain archives whose members have names of any length; however, depending on how ar is configured on your system, a limit on member-name length may be
imposed for compatibility with archive formats maintained with other tools. If it exists, the limit is often 15 characters (typical of formats related to a.out) or 16
characters (typical of formats related to coff).
ar is considered a binary utility because archives of this sort are most often used as libraries holding commonly needed subroutines.
ar creates an index to the symbols defined in relocatable object modules in the archive when you specify the modifier s. Once created, this index is updated in the
archive whenever ar makes a change to its contents (save for the q update operation). An archive with such an index speeds up linking to the library, and allows routines
in the library to call each other without regard to their placement in the archive.
You may use nm -s or nm --print-armap to list this index table. If an archive lacks the table, another form of ar called ranlib can be used to add just the table.
GNU ar can optionally create a thin archive, which contains a symbol index and references to the original copies of the member files of the archives. Such an archive is
useful for building libraries for use within a local build, where the relocatable objects are expected to remain available, and copying the contents of each object would
only waste time and space. Thin archives are also flattened, so that adding one or more archives to a thin archive will add the elements of the nested archive
individually. The paths to the elements of the archive are stored relative to the archive itself.
GNU ar is designed to be compatible with two different facilities. You can control its activity using command-line options, like the different varieties of ar on Unix
systems; or, if you specify the single command-line option -M, you can control it with a script supplied via standard input, like the MRI "librarian" program.
OPTIONS
GNU ar allows you to mix the operation code p and modifier flags mod in any order, within the first command-line argument.
If you wish, you may begin the first command-line argument with a dash.
The p keyletter specifies what operation to execute; it may be any of the following, but you must specify only one of them:
d Delete modules from the archive. Specify the names of modules to be deleted as member...; the archive is untouched if you specify no files to delete.
If you specify the v modifier, ar lists each module as it is deleted.
m Use this operation to move members in an archive.
The ordering of members in an archive can make a difference in how programs are linked using the library, if a symbol is defined in more than one member.
If no modifiers are used with "m", any members you name in the member arguments are moved to the end of the archive; you can use the a, b, or i modifiers to move them
to a specified place instead.
p Print the specified members of the archive, to the standard output file. If the v modifier is specified, show the member name before copying its contents to standard
output.
If you specify no member arguments, all the files in the archive are printed.
q Quick append; Historically, add the files member... to the end of archive, without checking for replacement.
The modifiers a, b, and i do not affect this operation; new members are always placed at the end of the archive.
The modifier v makes ar list each file as it is appended.
Since the point of this operation is speed, the archiveâs symbol table index is not updated, even if it already existed; you can use ar s or ranlib explicitly to
update the symbol table index.
However, too many different systems assume quick append rebuilds the index, so GNU ar implements q as a synonym for r.
r Insert the files member... into archive (with replacement). This operation differs from q in that any previously existing members are deleted if their names match
those being added.
If one of the files named in member... does not exist, ar displays an error message, and leaves undisturbed any existing members of the archive matching that name.
By default, new members are added at the end of the file; but you may use one of the modifiers a, b, or i to request placement relative to some existing member.
The modifier v used with this operation elicits a line of output for each file inserted, along with one of the letters a or r to indicate whether the file was
appended (no old member deleted) or replaced.
t Display a table listing the contents of archive, or those of the files listed in member... that are present in the archive. Normally only the member name is shown;
if you also want to see the modes (permissions), timestamp, owner, group, and size, you can request that by also specifying the v modifier.
If you do not specify a member, all files in the archive are listed.
If there is more than one file with the same name (say, fie) in an archive (say b.a), ar t b.a fie lists only the first instance; to see them all, you must ask for a
complete listing---in our example, ar t b.a.
x Extract members (named member) from the archive. You can use the v modifier with this operation, to request that ar list each name as it extracts it.
If you do not specify a member, all files in the archive are extracted.
Files cannot be extracted from a thin archive.
A number of modifiers (mod) may immediately follow the p keyletter, to specify variations on an operationâs behavior:
a Add new files after an existing member of the archive. If you use the modifier a, the name of an existing archive member must be present as the relpos argument,
before the archive specification.
b Add new files before an existing member of the archive. If you use the modifier b, the name of an existing archive member must be present as the relpos argument,
before the archive specification. (same as i).
c Create the archive. The specified archive is always created if it did not exist, when you request an update. But a warning is issued unless you specify in advance
that you expect to create it, by using this modifier.
D Operate in deterministic mode. When adding files and the archive index use zero for UIDs, GIDs, timestamps, and use consistent file modes for all files. When this
option is used, if ar is used with identical options and identical input files, multiple runs will create identical output files regardless of the input filesâ
owners, groups, file modes, or modification times.
f Truncate names in the archive. GNU ar will normally permit file names of any length. This will cause it to create archives which are not compatible with the native
ar program on some systems. If this is a concern, the f modifier may be used to truncate file names when putting them in the archive.
i Insert new files before an existing member of the archive. If you use the modifier i, the name of an existing archive member must be present as the relpos argument,
before the archive specification. (same as b).
l This modifier is accepted but not used.
N Uses the count parameter. This is used if there are multiple entries in the archive with the same name. Extract or delete instance count of the given name from the
archive.
o Preserve the original dates of members when extracting them. If you do not specify this modifier, files extracted from the archive are stamped with the time of
extraction.
P Use the full path name when matching names in the archive. GNU ar can not create an archive with a full path name (such archives are not POSIX complaint), but other
archive creators can. This option will cause GNU ar to match file names using a complete path name, which can be convenient when extracting a single file from an
archive created by another tool.
s Write an object-file index into the archive, or update an existing one, even if no other change is made to the archive. You may use this modifier flag either with
any operation, or alone. Running ar s on an archive is equivalent to running ranlib on it.
S Do not generate an archive symbol table. This can speed up building a large library in several steps. The resulting archive can not be used with the linker. In
order to build a symbol table, you must omit the S modifier on the last execution of ar, or you must run ranlib on the archive.
T Make the specified archive a thin archive. If it already exists and is a regular archive, the existing members must be present in the same directory as archive.
u Normally, ar r... inserts all files listed into the archive. If you would like to insert only those of the files you list that are newer than existing members of the
same names, use this modifier. The u modifier is allowed only for the operation r (replace). In particular, the combination qu is not allowed, since checking the
timestamps would lose any speed advantage from the operation q.
v This modifier requests the verbose version of an operation. Many operations display additional information, such as filenames processed, when the modifier v is
appended.
V This modifier shows the version number of ar.
ar ignores an initial option spelt -X32_64, for compatibility with AIX. The behaviour produced by this option is the default for GNU ar. ar does not support any of the
other -X options; in particular, it does not support -X32 which is the default for AIX ar.
The optional command line switch --plugin name causes ar to load the plugin called name which adds support for more file formats. This option is only available if the
toolchain has been built with plugin support enabled.
@file
Read command-line options from file. The options read are inserted in place of the original @file option. If file does not exist, or cannot be read, then the option
will be treated literally, and not removed.
Options in file are separated by whitespace. A whitespace character may be included in an option by surrounding the entire option in either single or double quotes.
Any character (including a backslash) may be included by prefixing the character to be included with a backslash. The file may itself contain additional @file
options; any such options will be processed recursively.
SEE ALSO
nm(1), ranlib(1), and the Info entries for binutils.
COPYRIGHT
Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by
the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section
entitled "GNU Free Documentation License".
binutils-2.19.51.0.14 2010-02-09 AR(1)
SIZE(1) GNU Development Tools SIZE(1)
NAME
size - list section sizes and total size.
SYNOPSIS
size [-A|-B|--format=compatibility]
[--help]
[-d|-o|-x|--radix=number]
[--common]
[-t|--totals]
[--target=bfdname] [-V|--version]
[objfile...]
DESCRIPTION
The GNU size utility lists the section sizes---and the total size---for each of the object or archive files objfile in its argument list. By default, one line of output
is generated for each object file or each module in an archive.
objfile... are the object files to be examined. If none are specified, the file "a.out" will be used.
OPTIONS
The command line options have the following meanings:
-A
-B
--format=compatibility
Using one of these options, you can choose whether the output from GNU size resembles output from System V size (using -A, or --format=sysv), or Berkeley size (using
-B, or --format=berkeley). The default is the one-line format similar to Berkeleyâs.
Here is an example of the Berkeley (default) format of output from size:
$ size --format=Berkeley ranlib size
text data bss dec hex filename
294880 81920 11592 388392 5ed28 ranlib
294880 81920 11888 388688 5ee50 size
This is the same data, but displayed closer to System V conventions:
$ size --format=SysV ranlib size
ranlib :
section size addr
.text 294880 8192
.data 81920 303104
.bss 11592 385024
Total 388392
size :
section size addr
.text 294880 8192
.data 81920 303104
.bss 11888 385024
Total 388688
--help
Show a summary of acceptable arguments and options.
-d
-o
-x
--radix=number
Using one of these options, you can control whether the size of each section is given in decimal (-d, or --radix=10); octal (-o, or --radix=8); or hexadecimal (-x, or
--radix=16). In --radix=number, only the three values (8, 10, 16) are supported. The total size is always given in two radices; decimal and hexadecimal for -d or -x
output, or octal and hexadecimal if youâre using -o.
--common
Print total size of common symbols in each file. When using Berkeley format these are included in the bss size.
-t
--totals
Show totals of all objects listed (Berkeley format listing mode only).
--target=bfdname
Specify that the object-code format for objfile is bfdname. This option may not be necessary; size can automatically recognize many formats.
-V
--version
Display the version number of size.
@file
Read command-line options from file. The options read are inserted in place of the original @file option. If file does not exist, or cannot be read, then the option
will be treated literally, and not removed.
Options in file are separated by whitespace. A whitespace character may be included in an option by surrounding the entire option in either single or double quotes.
Any character (including a backslash) may be included by prefixing the character to be included with a backslash. The file may itself contain additional @file
options; any such options will be processed recursively.
SEE ALSO
ar(1), objdump(1), readelf(1), and the Info entries for binutils.
COPYRIGHT
Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by
the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section
entitled "GNU Free Documentation License".
binutils-2.19.51.0.14 2010-02-09 SIZE(1)

浙公网安备 33010602011771号