程序员的自我修养-静态链接

程序员的自我修养-静态链接

列子演示

《深入理解计算机系统》中的例子

hello.h

#ifndef HELLO_H  
#define HELLO_H  
  
void hello(const char *name);  
  
#endif //HELLO_H 

hello.c

#include <stdio.h>
   
void hello(const char *name) {  
    printf("Hello %s!\n", name);  
} 

main.c

include "hello.h"  
int main() {  
    hello("everyone");  
    return 0;  
}  

mian.c中引用了hello函数,这里先对hello.c生成 .o 文件,然后再将hello.o 和 main一起加载,合并成一个可执行文件
静态链接

gcc -c hello.c

将hello.o打包成一个静态库,再编译main.c,跟静态库文件一起合并成一个可执行文件,最后运行
通过gdb反汇编hello文件,静态链接是将main函数和hello函数都打进这个hello程序里面了

ar cr libmyhello.a hello.o  
gcc -o hello main.c -L. -lmyhello  
./hello  
Hello everyone! 

gdb反汇编hello程序

(gdb) disas 
_DYNAMIC                                __do_global_dtors_aux_fini_array_entry  __libc_start_main                       deregister_tm_clones
_GLOBAL_OFFSET_TABLE_                   __dso_handle                            __libc_start_main@got.plt               frame_dummy
_IO_stdin_used                          __frame_dummy_init_array_entry          __libc_start_main@plt                   hello
__FRAME_END__                           __gmon_start__                          _edata                                  main
__JCR_END__                             __gmon_start__@got.plt                  _end                                    printf
__JCR_LIST__                            __gmon_start__@plt                      _fini                                   printf@got.plt
__TMC_END__                             __init_array_end                        _init                                   printf@plt
__bss_start                             __init_array_start                      _start                                  register_tm_clones
__data_start                            __libc_csu_fini                         completed.6354                          
__do_global_dtors_aux                   __libc_csu_init                         data_start                              
(gdb) disas main
//printf("11111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222333333333333333333333333333333333333333344444\n");

 

《程序员的自我修养–链接,加载和库》中的例子

a.c文件内容

extern int shared;  
int main() {  
    int a = 100;  
    swap(&a, &shared);  
}  

b.c文件内容

int shared = 1;  
void swap(int *a, int *b) {  
    *a ^= *b ^= *a ^= *b;  
} 

将a.o和b.o链接起来,生成 ab 可执行文件

ld a.o b.o -e main -o ab

空间分配策略,简单合并,a.o,b.o,c.o将各自的段依次叠加起来输出到一个目标文件中

更好的实现方案,将a.o,b.o,c.o中相同的段合并到一起

 

分析文件内容

a.o文件 objdump -d 结果
这里的 mov $0x0,%esi 还有 callq 25<main+0x25> 这两个指令对应的地址都是假地址
只是一个占位符,后面到真正链接的时候才会确定最终地址

a.o:     file format elf64-x86-64
 
 
Disassembly of section .text:
 
0000000000000000 <main>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   48 83 ec 10             sub    $0x10,%rsp
   8:   c7 45 fc 64 00 00 00    movl   $0x64,-0x4(%rbp)
   f:   48 8d 45 fc             lea    -0x4(%rbp),%rax
  13:   be 00 00 00 00          mov    $0x0,%esi
  18:   48 89 c7                mov    %rax,%rdi
  1b:   b8 00 00 00 00          mov    $0x0,%eax
  20:   e8 00 00 00 00          callq  25 <main+0x25>;
  25:   c9                      leaveq 
  26:   c3                      retq  

objdump -r a.o的结果

a.o:     file format elf64-x86-64

RELOCATION RECORDS FOR [.text]:
OFFSET           TYPE              VALUE 
0000000000000014 R_X86_64_32       shared
0000000000000021 R_X86_64_PC32     swap-0x0000000000000004

RELOCATION RECORDS FOR [.eh_frame]:
OFFSET           TYPE              VALUE 
0000000000000020 R_X86_64_PC32     .text

这里的R_X86_64_32是绝对寻址修正,之后连接器会将这两个地址修改成真正可以加载的地址

gdb反汇编ab的main函数
蓝色标注的两行就是重新定位地址,第一个是赋值语言重新定位了地址,第二个的函数调用也重新赋值了地址

Dump of assembler code for function main:
   0x00000000004004ed <+0>:     push   %rbp
   0x00000000004004ee <+1>:     mov    %rsp,%rbp
   0x00000000004004f1 <+4>:     sub    $0x10,%rsp
   0x00000000004004f5 <+8>:     movl   $0x64,-0x4(%rbp)
   0x00000000004004fc <+15>:    lea    -0x4(%rbp),%rax
   0x0000000000400500 <+19>:    mov    $0x60102c,%esi
   0x0000000000400505 <+24>:    mov    %rax,%rdi
   0x0000000000400508 <+27>:    mov    $0x0,%eax
   0x000000000040050d <+32>:    callq  0x400514 <swap>
   0x0000000000400512 <+37>:    leaveq 
   0x0000000000400513 <+38>:    retq   
End of assembler dump.

一个简单的hello.c程序,用 gcc –verbose编译出来的内容如下

gcc -static --verbose -fno-builtin hello.c
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-redhat-linux/4.8.5/cc1 -quiet -v hello.c -quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase hello -version -o /tmp/cczX7TMQ.s
GNU C (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-16) (x86_64-redhat-linux)
        compiled by GNU C version 4.8.5 20150623 (Red Hat 4.8.5-16), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=97 --param ggc-min-heapsize=127051
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include &lt;...&gt; search starts here:
 /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include
 /usr/local/include
 /usr/include
End of search list.
GNU C (GCC) version 4.8.5 20150623 (Red Hat 4.8.5-16) (x86_64-redhat-linux)
        compiled by GNU C version 4.8.5 20150623 (Red Hat 4.8.5-16), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=97 --param ggc-min-heapsize=127051
Compiler executable checksum: 25c276d835072ed72bab97eea8b3b665
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
 as -v --64 -o /tmp/ccoPro2p.o /tmp/cczX7TMQ.s
GNU assembler version 2.25.1 (x86_64-redhat-linux) using BFD version version 2.25.1-32.base.el7_4.2 
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.8.5/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/collect2 --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../.. /tmp/ccoPro2p.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crtn.o
//printf("111111111111111111122222222222222222222222222222222333333333333333333333444444444444555555555555566666666666666666666666667777777777777777779888888888888888888888888888899999999999999999999999990000000000000000000000000000000000000000000000000009888888888881111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222333333333333333333333333333333333333333333333333333333333333333333333333333333333333444444444444444444444444444444444444444444444444444444444444444444444444\n");

查看静态链接库里面的 .o文件

ar -t [xxx.a]

假设有一个hello.c文件,用了io库中的printf函数,单独将这个printf.o从libc.a 中拷贝出来,再链接是不行的
printf.o 又引用了其他 .o文件,而那些 .o文件又引用其他的,这些就没完了

 

特殊的hello world

一个没有main函数的程序,利用汇编和中断实现 hello world

char* str = "Hello World!\n";  
  
void print() {  
    //write函数原型 write(int filedesc, char* buffer, int size);
    //write的系统调用为4,即rax=4,
    //第一个参数是fd终端的fd是0 即bx=0,第二个参数是写缓冲地址也就是str字符串,传递给rbx
    //第三个参数是是字符串长度,这里是13传递给rdx,最后通过0x80中断实现
    asm("movq $13,%%rdx \n\t"  
        "movq %0,%%rcx \n\t"  
        "movq $0,%%rbx\n\t"  
        "movq $4,%%rax \n\t"  
        "int $0x80  \n\t"  
        ::"r"(str):"rdx","rcx","rbx");  
}  
  
void exit() {  
    //rbx表示退出的状态码为42,exit的系统调用为1即rax=1,这里也使用0x80中断调用
    asm("movq $42,%rbx \n\t"  
    "movq $1,%rax \n\t"  
    "int $0x80  \n\t"  
    );  
}  
  
void nomain() {  
    print();  
    exit();  
} 
//printf("111111111111111111122222222222222222222222344444445555555555555555555555555555\n");

编译并生成ELF文件,-fno-builtin 是禁止编译器优化,gcc会将一个参数的printf() 优化成puts

gcc -c -fno-builtin TinyHelloWorld.c

ld -static -e nomain -o TinyHelloWorld TinyHelloWorld.o

./TinyHelloWorld 

最终会产生的TinyHelloWorld会有如下sectioin

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .text             PROGBITS         00000000004000e8  000000e8
       0000000000000059  0000000000000000  AX       0     0     1
  [ 2] .rodata           PROGBITS         0000000000400141  00000141
       000000000000000e  0000000000000000   A       0     0     1
  [ 3] .eh_frame         PROGBITS         0000000000400150  00000150
       0000000000000078  0000000000000000   A       0     0     8
  [ 4] .data             PROGBITS         0000000000601000  00001000
       0000000000000008  0000000000000000  WA       0     0     8
  [ 5] .comment          PROGBITS         0000000000000000  00001008
       000000000000002d  0000000000000001  MS       0     0     1
  [ 6] .shstrtab         STRTAB           0000000000000000  00001035
       0000000000000042  0000000000000000           0     0     1
  [ 7] .symtab           SYMTAB           0000000000000000  00001078
       0000000000000150  0000000000000018           8     7     8
  [ 8] .strtab           STRTAB           0000000000000000  000011c8
       0000000000000040  0000000000000000           0     0     1
//printf("111111111111111111122222222222222222222222344444445555555555555555555555555555\n");

编写自定义的脚本链接文件,去掉多余的section
这里的意思是程序的入口函数是 nomain
起始地址是 0x08048000 + SIZEOF_HEADERS
然后将 .text, .data, .rodata合并成 tinytext段
最后丢弃 .comment等段

ENTRY(nomain)  
  
SECTIONS  {  
  . = 0x08048000 + SIZEOF_HEADERS;  
  tinytext : { *(.text) *(.data) *(.rodata)}  
  /DISCARD/ :{ *(.comment) *(.eh_frame) *(.shstrtab) *(.symtab) *(.strtab)}  
}  

链接命令

ld -static -T tiny.lds -o TinyHello -s TinyHelloWorld.o

最后生成的TinyHello的section如下,但奇怪的是最后生存的TinyHello却有 295424字节,比没去掉多余段的时候还大很多,用hexdump看了结果,貌似里面的内容没有TinyHelloWorld(就是那个没去掉多余段的文件)多,显示这么多字节可能是系统的问题

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] tinytext          PROGBITS         00000000080480b0  000480b0
       0000000000000076  0000000000000000 WAX       0     0     8
  [ 2] .shstrtab         STRTAB           0000000000000000  00048126
       0000000000000014  0000000000000000           0     0     1
//printf("111111111111111111122222222222222222222222222222222333333333333333333333444444444444\n");

参考

Linux下C程序的链接过程
一个没有main函数的的helloworld
《程序员的自我修养-链接,装载与库》

附录

ab ELF文件 执行 readelf -a 后的结果

ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x400400
  Start of program headers:          64 (bytes into file)
  Start of section headers:          6632 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         9
  Size of section headers:           64 (bytes)
  Number of section headers:         30
  Section header string table index: 27

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .interp           PROGBITS         0000000000400238  00000238
       000000000000001c  0000000000000000   A       0     0     1
  [ 2] .note.ABI-tag     NOTE             0000000000400254  00000254
       0000000000000020  0000000000000000   A       0     0     4
  [ 3] .note.gnu.build-i NOTE             0000000000400274  00000274
       0000000000000024  0000000000000000   A       0     0     4
  [ 4] .gnu.hash         GNU_HASH         0000000000400298  00000298
       000000000000001c  0000000000000000   A       5     0     8
  [ 5] .dynsym           DYNSYM           00000000004002b8  000002b8
       0000000000000048  0000000000000018   A       6     1     8
  [ 6] .dynstr           STRTAB           0000000000400300  00000300
       0000000000000038  0000000000000000   A       0     0     1
  [ 7] .gnu.version      VERSYM           0000000000400338  00000338
       0000000000000006  0000000000000002   A       5     0     2
  [ 8] .gnu.version_r    VERNEED          0000000000400340  00000340
       0000000000000020  0000000000000000   A       6     1     8
  [ 9] .rela.dyn         RELA             0000000000400360  00000360
       0000000000000018  0000000000000018   A       5     0     8
  [10] .rela.plt         RELA             0000000000400378  00000378
       0000000000000030  0000000000000018  AI       5    12     8
  [11] .init             PROGBITS         00000000004003a8  000003a8
       000000000000001a  0000000000000000  AX       0     0     4
  [12] .plt              PROGBITS         00000000004003d0  000003d0
       0000000000000030  0000000000000010  AX       0     0     16
  [13] .text             PROGBITS         0000000000400400  00000400
       00000000000001d2  0000000000000000  AX       0     0     16
  [14] .fini             PROGBITS         00000000004005d4  000005d4
       0000000000000009  0000000000000000  AX       0     0     4
  [15] .rodata           PROGBITS         00000000004005e0  000005e0
       0000000000000010  0000000000000000   A       0     0     8
  [16] .eh_frame_hdr     PROGBITS         00000000004005f0  000005f0
       000000000000003c  0000000000000000   A       0     0     4
  [17] .eh_frame         PROGBITS         0000000000400630  00000630
       0000000000000114  0000000000000000   A       0     0     8
  [18] .init_array       INIT_ARRAY       0000000000600e10  00000e10
       0000000000000008  0000000000000000  WA       0     0     8
  [19] .fini_array       FINI_ARRAY       0000000000600e18  00000e18
       0000000000000008  0000000000000000  WA       0     0     8
  [20] .jcr              PROGBITS         0000000000600e20  00000e20
       0000000000000008  0000000000000000  WA       0     0     8
  [21] .dynamic          DYNAMIC          0000000000600e28  00000e28
       00000000000001d0  0000000000000010  WA       6     0     8
  [22] .got              PROGBITS         0000000000600ff8  00000ff8
       0000000000000008  0000000000000008  WA       0     0     8
  [23] .got.plt          PROGBITS         0000000000601000  00001000
       0000000000000028  0000000000000008  WA       0     0     8
  [24] .data             PROGBITS         0000000000601028  00001028
       0000000000000008  0000000000000000  WA       0     0     4
  [25] .bss              NOBITS           0000000000601030  00001030
       0000000000000008  0000000000000000  WA       0     0     1
  [26] .comment          PROGBITS         0000000000000000  00001030
       000000000000002d  0000000000000001  MS       0     0     1
  [27] .shstrtab         STRTAB           0000000000000000  0000105d
       0000000000000108  0000000000000000           0     0     1
  [28] .symtab           SYMTAB           0000000000000000  00001168
       0000000000000648  0000000000000018          29    46     8
  [29] .strtab           STRTAB           0000000000000000  000017b0
       0000000000000231  0000000000000000           0     0     1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
  I (info), L (link order), G (group), T (TLS), E (exclude), 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              Flags  Align
  PHDR           0x0000000000000040 0x0000000000400040 0x0000000000400040
                 0x00000000000001f8 0x00000000000001f8  R E    8
  INTERP         0x0000000000000238 0x0000000000400238 0x0000000000400238
                 0x000000000000001c 0x000000000000001c  R      1
      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
  LOAD           0x0000000000000000 0x0000000000400000 0x0000000000400000
                 0x0000000000000744 0x0000000000000744  R E    200000
  LOAD           0x0000000000000e10 0x0000000000600e10 0x0000000000600e10
                 0x0000000000000220 0x0000000000000228  RW     200000
  DYNAMIC        0x0000000000000e28 0x0000000000600e28 0x0000000000600e28
                 0x00000000000001d0 0x00000000000001d0  RW     8
  NOTE           0x0000000000000254 0x0000000000400254 0x0000000000400254
                 0x0000000000000044 0x0000000000000044  R      4
  GNU_EH_FRAME   0x00000000000005f0 0x00000000004005f0 0x00000000004005f0
                 0x000000000000003c 0x000000000000003c  R      4
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     10
  GNU_RELRO      0x0000000000000e10 0x0000000000600e10 0x0000000000600e10
                 0x00000000000001f0 0x00000000000001f0  R      1

 Section to Segment mapping:
  Segment Sections...
   00     
   01     .interp 
   02     .interp .note.ABI-tag .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame 
   03     .init_array .fini_array .jcr .dynamic .got .got.plt .data .bss 
   04     .dynamic 
   05     .note.ABI-tag .note.gnu.build-id 
   06     .eh_frame_hdr 
   07     
   08     .init_array .fini_array .jcr .dynamic .got 

Dynamic section at offset 0xe28 contains 24 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000c (INIT)               0x4003a8
 0x000000000000000d (FINI)               0x4005d4
 0x0000000000000019 (INIT_ARRAY)         0x600e10
 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x600e18
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x400298
 0x0000000000000005 (STRTAB)             0x400300
 0x0000000000000006 (SYMTAB)             0x4002b8
 0x000000000000000a (STRSZ)              56 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000015 (DEBUG)              0x0
 0x0000000000000003 (PLTGOT)             0x601000
 0x0000000000000002 (PLTRELSZ)           48 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x400378
 0x0000000000000007 (RELA)               0x400360
 0x0000000000000008 (RELASZ)             24 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000006ffffffe (VERNEED)            0x400340
 0x000000006fffffff (VERNEEDNUM)         1
 0x000000006ffffff0 (VERSYM)             0x400338
 0x0000000000000000 (NULL)               0x0

Relocation section '.rela.dyn' at offset 0x360 contains 1 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000600ff8  000200000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0

Relocation section '.rela.plt' at offset 0x378 contains 2 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000601018  000100000007 R_X86_64_JUMP_SLO 0000000000000000 __libc_start_main + 0
000000601020  000200000007 R_X86_64_JUMP_SLO 0000000000000000 __gmon_start__ + 0

The decoding of unwind sections for machine type Advanced Micro Devices X86-64 is not currently supported.

Symbol table '.dynsym' contains 3 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __libc_start_main@GLIBC_2.2.5 (2)
     2: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__

Symbol table '.symtab' contains 67 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000400238     0 SECTION LOCAL  DEFAULT    1 
     2: 0000000000400254     0 SECTION LOCAL  DEFAULT    2 
     3: 0000000000400274     0 SECTION LOCAL  DEFAULT    3 
     4: 0000000000400298     0 SECTION LOCAL  DEFAULT    4 
     5: 00000000004002b8     0 SECTION LOCAL  DEFAULT    5 
     6: 0000000000400300     0 SECTION LOCAL  DEFAULT    6 
     7: 0000000000400338     0 SECTION LOCAL  DEFAULT    7 
     8: 0000000000400340     0 SECTION LOCAL  DEFAULT    8 
     9: 0000000000400360     0 SECTION LOCAL  DEFAULT    9 
    10: 0000000000400378     0 SECTION LOCAL  DEFAULT   10 
    11: 00000000004003a8     0 SECTION LOCAL  DEFAULT   11 
    12: 00000000004003d0     0 SECTION LOCAL  DEFAULT   12 
    13: 0000000000400400     0 SECTION LOCAL  DEFAULT   13 
    14: 00000000004005d4     0 SECTION LOCAL  DEFAULT   14 
    15: 00000000004005e0     0 SECTION LOCAL  DEFAULT   15 
    16: 00000000004005f0     0 SECTION LOCAL  DEFAULT   16 
    17: 0000000000400630     0 SECTION LOCAL  DEFAULT   17 
    18: 0000000000600e10     0 SECTION LOCAL  DEFAULT   18 
    19: 0000000000600e18     0 SECTION LOCAL  DEFAULT   19 
    20: 0000000000600e20     0 SECTION LOCAL  DEFAULT   20 
    21: 0000000000600e28     0 SECTION LOCAL  DEFAULT   21 
    22: 0000000000600ff8     0 SECTION LOCAL  DEFAULT   22 
    23: 0000000000601000     0 SECTION LOCAL  DEFAULT   23 
    24: 0000000000601028     0 SECTION LOCAL  DEFAULT   24 
    25: 0000000000601030     0 SECTION LOCAL  DEFAULT   25 
    26: 0000000000000000     0 SECTION LOCAL  DEFAULT   26 
    27: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
    28: 0000000000600e20     0 OBJECT  LOCAL  DEFAULT   20 __JCR_LIST__
    29: 0000000000400430     0 FUNC    LOCAL  DEFAULT   13 deregister_tm_clones
    30: 0000000000400460     0 FUNC    LOCAL  DEFAULT   13 register_tm_clones
    31: 00000000004004a0     0 FUNC    LOCAL  DEFAULT   13 __do_global_dtors_aux
    32: 0000000000601030     1 OBJECT  LOCAL  DEFAULT   25 completed.6354
    33: 0000000000600e18     0 OBJECT  LOCAL  DEFAULT   19 __do_global_dtors_aux_fin
    34: 00000000004004c0     0 FUNC    LOCAL  DEFAULT   13 frame_dummy
    35: 0000000000600e10     0 OBJECT  LOCAL  DEFAULT   18 __frame_dummy_init_array_
    36: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS a.c
    37: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS b.c
    38: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
    39: 0000000000400740     0 OBJECT  LOCAL  DEFAULT   17 __FRAME_END__
    40: 0000000000600e20     0 OBJECT  LOCAL  DEFAULT   20 __JCR_END__
    41: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS 
    42: 0000000000600e18     0 NOTYPE  LOCAL  DEFAULT   18 __init_array_end
    43: 0000000000600e28     0 OBJECT  LOCAL  DEFAULT   21 _DYNAMIC
    44: 0000000000600e10     0 NOTYPE  LOCAL  DEFAULT   18 __init_array_start
    45: 0000000000601000     0 OBJECT  LOCAL  DEFAULT   23 _GLOBAL_OFFSET_TABLE_
    46: 00000000004005d0     2 FUNC    GLOBAL DEFAULT   13 __libc_csu_fini
    47: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_deregisterTMCloneTab
    48: 0000000000601028     0 NOTYPE  WEAK   DEFAULT   24 data_start
    49: 0000000000601030     0 NOTYPE  GLOBAL DEFAULT   24 _edata
    50: 00000000004005d4     0 FUNC    GLOBAL DEFAULT   14 _fini
    51: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __libc_start_main@@GLIBC_
    52: 0000000000601028     0 NOTYPE  GLOBAL DEFAULT   24 __data_start
    53: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
    54: 00000000004005e8     0 OBJECT  GLOBAL HIDDEN    15 __dso_handle
    55: 00000000004005e0     4 OBJECT  GLOBAL DEFAULT   15 _IO_stdin_used
    56: 0000000000400560   101 FUNC    GLOBAL DEFAULT   13 __libc_csu_init
    57: 0000000000601038     0 NOTYPE  GLOBAL DEFAULT   25 _end
    58: 0000000000400400     0 FUNC    GLOBAL DEFAULT   13 _start
    59: 0000000000601030     0 NOTYPE  GLOBAL DEFAULT   25 __bss_start
    60: 00000000004004ed    39 FUNC    GLOBAL DEFAULT   13 main
    61: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _Jv_RegisterClasses
    62: 0000000000601030     0 OBJECT  GLOBAL HIDDEN    24 __TMC_END__
    63: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND _ITM_registerTMCloneTable
    64: 0000000000400514    74 FUNC    GLOBAL DEFAULT   13 swap
    65: 00000000004003a8     0 FUNC    GLOBAL DEFAULT   11 _init
    66: 000000000060102c     4 OBJECT  GLOBAL DEFAULT   24 shared

Version symbols section '.gnu.version' contains 3 entries:
 Addr: 0000000000400338  Offset: 0x000338  Link: 5 (.dynsym)
  000:   0 (*local*)       2 (GLIBC_2.2.5)   0 (*local*)    

Version needs section '.gnu.version_r' contains 1 entries:
 Addr: 0x0000000000400340  Offset: 0x000340  Link: 6 (.dynstr)
  000000: Version: 1  File: libc.so.6  Cnt: 1
  0x0010:   Name: GLIBC_2.2.5  Flags: none  Version: 2

Displaying notes found at file offset 0x00000254 with length 0x00000020:
  Owner                 Data size       Description
  GNU                  0x00000010       NT_GNU_ABI_TAG (ABI version tag)
    OS: Linux, ABI: 2.6.32

Displaying notes found at file offset 0x00000274 with length 0x00000024:
  Owner                 Data size       Description
  GNU                  0x00000014       NT_GNU_BUILD_ID (unique build ID bitstring)
    Build ID: a7c7f8327b46ef5d307fcbc17fb0ebf062d3cf97
//printf("111111111111111111122222222222222222222222344444445555555555555555555555555555666666666666666666666666666666666\n");

 

0 次阅读

发表评论

电子邮件地址不会被公开。