dyld binding test

=========================================================================
a.c
----------------------------------
void main (int argc, char **argv) {
    printf ("Salve, Munde!\n");
    printf ("Vale!\n");
    exit(0);
}
=========================================================================
dyldinfo -lazy_bind a
----------------------------------
lazy binding information (from lazy_bind part of dyld info):
segment section          address    index  dylib            symbol
__DATA  __la_symbol_ptr  0x100001010 0x0000 libSystem        _exit
__DATA  __la_symbol_ptr  0x100001018 0x000C libSystem        _printf
=========================================================================
otool -p _main -tV
----------------------------------
a:
(__TEXT,__text) section
_main:
0000000100000f10    pushq    %rbp
0000000100000f11    movq    %rsp, %rbp
0000000100000f14    subq    $0x20, %rsp
0000000100000f18    leaq    0x61(%rip), %rax ## literal pool for: "Salve, Munde!
"
0000000100000f1f    movl    %edi, -0x4(%rbp)
0000000100000f22    movq    %rsi, -0x10(%rbp)
0000000100000f26    movq    %rax, %rdi
0000000100000f29    movb    $0x0, %al
0000000100000f2b    callq    0x100000f54 ## symbol stub for: _printf    <------
0000000100000f30    leaq    0x58(%rip), %rdi ## literal pool for: "Vale!
"
0000000100000f37    movl    %eax, -0x14(%rbp)
0000000100000f3a    movb    $0x0, %al
0000000100000f3c    callq    0x100000f54 ## symbol stub for: _printf    <------
0000000100000f41    movl    $0x0, %edi
0000000100000f46    movl    %eax, -0x18(%rbp)
0000000100000f49    callq    0x100000f4e ## symbol stub for: _exit    <------
=========================================================================
otool -l -V a
----------------------------------
a:
Load command 0
      cmd LC_SEGMENT_64
  cmdsize 72
  segname __PAGEZERO
   vmaddr 0x0000000000000000
   vmsize 0x0000000100000000
  fileoff 0
 filesize 0
  maxprot ---
 initprot ---
   nsects 0
    flags (none)
Load command 1
      cmd LC_SEGMENT_64
  cmdsize 552
  segname __TEXT
   vmaddr 0x0000000100000000
   vmsize 0x0000000000001000
  fileoff 0
 filesize 4096
  maxprot rwx
 initprot r-x
   nsects 6
    flags (none)
Section
  sectname __text
   segname __TEXT
      addr 0x0000000100000f10
      size 0x000000000000003e
    offset 3856
     align 2^4 (16)
    reloff 0
    nreloc 0
      type S_REGULAR
attributes PURE_INSTRUCTIONS SOME_INSTRUCTIONS
 reserved1 0
 reserved2 0
Section
  sectname __stubs
   segname __TEXT
      addr 0x0000000100000f4e <------
      size 0x000000000000000c
    offset 3918
     align 2^1 (2)
    reloff 0
    nreloc 0
      type S_SYMBOL_STUBS
attributes PURE_INSTRUCTIONS SOME_INSTRUCTIONS
 reserved1 0 (index into indirect symbol table)
 reserved2 6 (size of stubs)
Section
  sectname __stub_helper
   segname __TEXT
      addr 0x0000000100000f5c
      size 0x0000000000000024
    offset 3932
     align 2^2 (4)
    reloff 0
    nreloc 0
      type S_REGULAR
attributes PURE_INSTRUCTIONS SOME_INSTRUCTIONS
 reserved1 0
 reserved2 0
Section
  sectname __cstring
   segname __TEXT
      addr 0x0000000100000f80
      size 0x0000000000000016
    offset 3968
     align 2^0 (1)
    reloff 0
    nreloc 0
      type S_CSTRING_LITERALS
attributes (none)
 reserved1 0
 reserved2 0
Section
  sectname __unwind_info
   segname __TEXT
      addr 0x0000000100000f96
      size 0x0000000000000048
    offset 3990
     align 2^0 (1)
    reloff 0
    nreloc 0
      type S_REGULAR
attributes (none)
 reserved1 0
 reserved2 0
Section
  sectname __eh_frame
   segname __TEXT
      addr 0x0000000100000fe0
      size 0x0000000000000018
    offset 4064
     align 2^3 (8)
    reloff 0
    nreloc 0
      type S_REGULAR
attributes (none)
 reserved1 0
 reserved2 0
Load command 2
      cmd LC_SEGMENT_64
  cmdsize 232
  segname __DATA
   vmaddr 0x0000000100001000
   vmsize 0x0000000000001000
  fileoff 4096
 filesize 4096
  maxprot rwx
 initprot rw-
   nsects 2
    flags (none)
Section
  sectname __nl_symbol_ptr
   segname __DATA
      addr 0x0000000100001000
      size 0x0000000000000010
    offset 4096
     align 2^3 (8)
    reloff 0
    nreloc 0
      type S_NON_LAZY_SYMBOL_POINTERS
attributes (none)
 reserved1 2 (index into indirect symbol table)
 reserved2 0
Section
  sectname __la_symbol_ptr
   segname __DATA
      addr 0x0000000100001010
      size 0x0000000000000010
    offset 4112
     align 2^3 (8)
    reloff 0
    nreloc 0
      type S_LAZY_SYMBOL_POINTERS
attributes (none)
 reserved1 4 (index into indirect symbol table)
 reserved2 0
Load command 3
      cmd LC_SEGMENT_64
  cmdsize 72
  segname __LINKEDIT
   vmaddr 0x0000000100002000
   vmsize 0x0000000000001000
  fileoff 8192
 filesize 352
  maxprot rwx
 initprot r--
   nsects 0
    flags (none)
Load command 4
            cmd LC_DYLD_INFO_ONLY
        cmdsize 48
     rebase_off 8192
    rebase_size 8
       bind_off 8200
      bind_size 24
  weak_bind_off 0
 weak_bind_size 0
  lazy_bind_off 8224
 lazy_bind_size 32
     export_off 8256
    export_size 48
Load command 5
     cmd LC_SYMTAB
 cmdsize 24
  symoff 8376
   nsyms 5
  stroff 8480
 strsize 64
Load command 6
            cmd LC_DYSYMTAB
        cmdsize 80
      ilocalsym 0
      nlocalsym 0
     iextdefsym 0
     nextdefsym 2
      iundefsym 2
      nundefsym 3
         tocoff 0
           ntoc 0
      modtaboff 0
        nmodtab 0
   extrefsymoff 0
    nextrefsyms 0
 indirectsymoff 8456
  nindirectsyms 6
      extreloff 0
        nextrel 0
      locreloff 0
        nlocrel 0
Load command 7
          cmd LC_LOAD_DYLINKER
      cmdsize 32
         name /usr/lib/dyld (offset 12)
Load command 8
     cmd LC_UUID
 cmdsize 24
    uuid AAF0A21D-08BD-30FB-BB08-2A3352D9D4B9
Load command 9
      cmd LC_VERSION_MIN_MACOSX
  cmdsize 16
  version 10.9
      sdk 10.9
Load command 10
      cmd LC_SOURCE_VERSION
  cmdsize 16
  version 0.0
Load command 11
       cmd LC_MAIN
   cmdsize 24
  entryoff 3856
 stacksize 0
Load command 12
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name /usr/lib/libSystem.B.dylib (offset 24)
   time stamp 2 Thu Jan  1 08:30:02 1970
      current version 1197.1.1
compatibility version 1.0.0
Load command 13
      cmd LC_FUNCTION_STARTS
  cmdsize 16
  dataoff 8304
 datasize 8
Load command 14
      cmd LC_DATA_IN_CODE
  cmdsize 16
  dataoff 8312
 datasize 0
Load command 15
      cmd LC_DYLIB_CODE_SIGN_DRS
  cmdsize 16
  dataoff 8312
 datasize 64
=========================================================================
nm a | grep "U "
----------------------------------
U _exit
U _printf
U dyld_stub_binder
=========================================================================
nm a | wc -l
----------------------------------
5
=========================================================================
x/2i 0x100000f4e
----------------------------------
0x100000f4e <dyld_stub_exit>:    jmpq   *0xbc(%rip)        # 0x100001010 <------
0x100000f54 <dyld_stub_printf>:    jmpq   *0xbe(%rip)        # 0x100001018 <------
=========================================================================
x/g 0x100001010
----------------------------------
0x100001010:    0x0000000100000f6c <------
=========================================================================
x/g 0x100001018
----------------------------------
0x100001018:    0x0000000100000f76 <------
=========================================================================
x/2i 0x0000000100000f6c <------
----------------------------------
0x100000f6c:    pushq  $0x0
0x100000f71:    jmpq   0x100000f5c <------
=========================================================================
x/2i 0x0000000100000f76 <------
----------------------------------
0x100000f76:    pushq  $0xc
0x100000f7b:    jmpq   0x100000f5c <------
=========================================================================
x/3i 0x100000f5c
----------------------------------
0x100000f5c:    lea    0xa5(%rip),%r11        # 0x100001008
0x100000f63:    push   %r11
0x100000f65:    jmpq   *0x95(%rip)              # 0x100001000 <------
=========================================================================
x/2g 0x100001000
----------------------------------
0x100001000:    0x0000000000000000    0x0000000000000000
=========================================================================
b main
----------------------------------
r
----------------------------------
x/2g 0x100001000
----------------------------------
0x100001000:    0x00007fff8a2bc210 <------    0x0000000000000000
=========================================================================
disass 0x00007fff8a2bc210
----------------------------------
Dump of assembler code for function dyld_stub_binder:
0x00007fff8a2bc210 <dyld_stub_binder+0>:    push   %rbp
0x00007fff8a2bc211 <dyld_stub_binder+1>:    mov    %rsp,%rbp
0x00007fff8a2bc214 <dyld_stub_binder+4>:    sub    $0x140,%rsp
0x00007fff8a2bc21b <dyld_stub_binder+11>:    mov    %rdi,(%rsp)
0x00007fff8a2bc21f <dyld_stub_binder+15>:    mov    %rsi,0x8(%rsp)
0x00007fff8a2bc224 <dyld_stub_binder+20>:    mov    %rdx,0x10(%rsp)
0x00007fff8a2bc229 <dyld_stub_binder+25>:    mov    %rcx,0x18(%rsp)
0x00007fff8a2bc22e <dyld_stub_binder+30>:    mov    %r8,0x20(%rsp)
0x00007fff8a2bc233 <dyld_stub_binder+35>:    mov    %r9,0x28(%rsp)
0x00007fff8a2bc238 <dyld_stub_binder+40>:    mov    %rax,0x30(%rsp)
End of assembler dump.
=========================================================================
x/i dyld_stub_exit
----------------------------------
0x100000f4e <dyld_stub_exit>:    jmpq   *0xbc(%rip)        # 0x100001010
=========================================================================
x/i dyld_stub_printf
----------------------------------
0x100000f54 <dyld_stub_printf>:    jmpq   *0xbe(%rip)        # 0x100001018
=========================================================================
x/g 0x100001018
----------------------------------
0x100001018:    0x0000000100000f76
=========================================================================
x/2i 0x0000000100000f76
----------------------------------
0x100000f76:    pushq  $0xc
0x100000f7b:    jmpq   0x100000f5c
=========================================================================
b *0x0000000100000f2b
b *0x0000000100000f3c
=========================================================================
x/g 0x100001018
----------------------------------
0x100001018:    0x0000000100000f76
=========================================================================
x/2i 0x0000000100000f76
----------------------------------
0x100000f76:    pushq  $0xc
0x100000f7b:    jmpq   0x100000f5c
=========================================================================
x/g 0x100001018
----------------------------------
0x100001018:    0x00007fff883ba8a8
=========================================================================
x/2i 0x00007fff883ba8a8
----------------------------------
0x7fff883ba8a8 <printf>:    push   %rbp
0x7fff883ba8a9 <printf+1>:    mov    %rsp,%rbp
=========================================================================

 

posted @ 2014-04-21 17:37  Proteas  阅读(436)  评论(0编辑  收藏  举报