How the dynamic loader computes the address of exported symbols

Discussion in 'Mac Programming' started by activefreeman, Jul 21, 2009.

  1. macrumors newbie

    Jul 21, 2009
    Hello, how can be calculated the address at which a exported symbol of a library will be loaded by the dynamic loader?

    If I use nm to obtain the symbols of my library, I obtain the following addresses:

    $nm libUsuario.dylib
    libUsuario.dylib(single module):
    00000fea T _GetNombre
    00001004 d _Nombre
    00000f9b T _SetNombre
    00000f6e t __SetNombre
    00000f60 t __dyld_func_lookup
    00000000 t __mh_dylib_header
    U _strcpy
    00001000 d dyld__mach_header
    00000f4c t dyld_stub_binding_helper

    When I obtain the address of this symbol from the program hack_usuario linked with the dynamic library:

    printf("dir: %x\n",Nombre);

    I obtain:

    dir: 6004

    However, otool says that the _Nombre symbol will be loaded in this __DATA segment:

    $otool -l hack_usuario
    Load command 2
    cmd LC_SEGMENT
    cmdsize 192
    segname __DATA
    vmaddr 0x00002000
    vmsize 0x00001000
    fileoff 4096
    filesize 4096
    maxprot 0x00000007
    initprot 0x00000003
    nsects 2
    flags 0x0
    sectname __data
    segname __DATA
    addr 0x00002000
    size 0x00000014
    offset 4096
    align 2^2 (4)
    reloff 0
    nreloc 0
    flags 0x00000000
    reserved1 0
    reserved2 0

Share This Page