Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 初級開發 >> android Dynamic Linker

android Dynamic Linker

編輯:初級開發

源碼在bionic/linker

linker 主要用於實現共享庫的加載與鏈接。它支持應用程序對庫函數的隱式和顯式調用。對於隱式調用,應用程序的編譯與靜態庫大致相同,只是在靜態鏈接的時候通過--dynamic-linker /system/bin/linker 指定動態鏈接器,(該信息將被存放在ELF文件的.interp節中,內核執行目標映像文件前將通過該信息加載並運行相應的解釋器程序linker.)並鏈接相應的共享庫。與ld.so不同的是,Linker目前沒有提供Lazy Binding機制,所有外部過程引用都在映像執行之前解析。對於顯式調用,可以同過linker中提供的接口dlopen,dlsym,dlerror和dlclose來動態加載和鏈接共享庫。

prelinking:

System librarIEs in android are internally prelinked, which means that any internal relocations within them are stripped from the corresponding shared object, in order to reduce size and speed up loading.

Such libraries can only be loaded at the very specific virtual memory address they have been prelinked to (during the build process). The list of prelinked system librarIEs and their corresponding virtual memory address is found in the file:

   build/core/prelink-Linux-<arch>.map

It should be updated each time a new system library is added to the system.

The prelink step happens at build time, and uses the 'soslim' and 'apriori' tools:

  - 'apriori' is the real prelink tool which removes relocations from the   shared object, however, it must be given a list of symbols to remove   from the file.

  - 'soslim' is used to find symbols in an executable ELF file   and generate a list that can be passed to 'apriori'.

prelink-Linux-arm.map:

# 0xC0000000 - 0xFFFFFFFF Kernel 3G-4G
# 0xB0100000 - 0xBFFFFFFF Thread 0 Stack 
# 0xB0000000 - 0xB00FFFFF Linker
# 0xA0000000 - 0xBFFFFFFF Prelinked System LibrarIEs
# 0x90000000 - 0x9FFFFFFF Prelinked App LibrarIEs
# 0x80000000 - 0x8FFFFFFF Non-prelinked LibrarIEs
# 0x40000000 - 0x7FFFFFFF mmap'd stuff
# 0x10000000 - 0x3FFFFFFF Thread Stacks
# 0x00000000 - 0x0FFFFFFF .text / .data / heap

# Note: The general rule is that libraries should be aligned on 1MB boundarIEs. For ease of updating this file, you will find a comment
# on each line, indicating the observed size of the library, which is one of:
#     [<64K] observed to be less than 64K
#     [~1M] rounded up, one megabyte (similarly for other sizes)
#     [???] no size observed, assumed to be one megabyte

# core system librarIEs
libdl.so                0xAFF00000 # [<64K]
libc.so                 0xAFD00000 # [~2M]
libstdc++.so            0xAFC00000 # [<64K]
libm.so                 0xAFB00000 # [~1M]
liblog.so               0xAFA00000 # [<64K]
libcutils.so            0xAF900000 # [~1M]
libthread_db.so         0xAF800000 # [<64K]
libz.so                 0xAF700000 # [~1M]
libevent.so             0xAF600000 # [???]
libssl.so               0xAF400000 # [~2M]
libcrypto.so            0xAF000000 # [~4M]
libsysutils.so          0xAEF00000 # [~1M]

即庫的加載位置已經固定。

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved