Shared Library in X86/ARM
来源:互联网 发布:开淘宝店的心得体会 编辑:程序博客网 时间:2024/06/05 02:07
Reference Articles :
http://eli.thegreenplace.net/2011/11/03/position-independent-code-pic-in-shared-libraries/
http://eli.thegreenplace.net/2011/11/03/position-independent-code-pic-in-shared-libraries/
http://eli.thegreenplace.net/2012/01/03/understanding-the-x64-code-models/
http://eli.thegreenplace.net/2011/11/11/position-independent-code-pic-in-shared-libraries-on-x64/
X86 and X64
Shared library with dynamic relocation (without -fpic) works fine for X86 and X64 and introduced no performance penalty in running time, while the linker needs to scan whole object to fill the relocated data and function with correct and address. Also, the .text library can not be shared by other thread using the same library. ( the .data section is copyed for each process.)
PIC could be helpful to reuse the code in shared library. GOT table is introduced to record the actually virtual address of one data or function ( function introduce PLT also).
data = [GOT[data-index]]
function = call PLT -> jmp GOT[function-index]
It actually longer the pathlength with extra indirect jump which also brings more memory reference and register allocate pressure, especially in X86 which only has 6 register available at most time.
Another bad news is, X86 can not direct refer the EIP register, which means you are totally not able to use get one data value by [base-add + offset ] format. One trick needs to be done before use PIC, which is to fetch the address of EIP.
call TMPLABELTMPLABEL: pop ebx
Also the ebx register is occupied to hold the address, unless you choose the regenerate the EIP value every time needs it.
Things becomes more interesting in X64: first, the RIP(EIP) value can be directly referenced, it makes easy to refer the PIC data and function call. But call function by PC relative is limited with 32-bit sized offset (+- 2GB) as near function call. Far call and near call larger than 2GB distance which needs to encode whole 64-bit address into instruction( but actual unable) is actually implement by first move imm64 value into one register and call. Or directly call the imm64 address from memory. It is caused by the only instruction who has ability to encode whole 64-bit address : mov(movaps) instruction.
So, GCC actually include 3 types of flag:
-mcmodel=small : only support code in +-2GB relative reference, just use RIP reference
-mcmodel=large : support > 2GB reference, just use imm64 type refernce
-mcmodel=medium: those in 2GB distance use RIP reference, > 2GB use imm64 type.
As far as we know, the performance difference between X64-No-PIC and X64-PIC is few.
ARMv7 and ARMv8
- Shared Library in X86/ARM
- Detect ARM MOVW/MOVT relocations in shared library links
- Setting shared (dynamic) library in Eclipse C++ in Linux
- WebSphere Class Loaders and Shared Library, Part 3 (Class loader in WebSphre Portal + Shared Library )
- gcc option for looking for shared library in current path.
- How-to use a shared library in native-activity
- Failed to load the JNI shared library "C:\Program Files(X86)\Java\jdk1.8.0_45\bin\.....
- no libsigar-x86-linux.so in java.library.path
- no sigar-x86-winnt.dll in java.library.path
- no libsigar-x86-linux.so in java.library.path
- At least one valid code-source or import-shared-library element is required for shared-library "global.libraries" in /embedded-
- Qt 创建shared library,调用shared library
- Use MFC in a Static Library 和 use MFC in a Shared DLL 区别
- Use MFC in a Static Library 和 use MFC in a Shared DLL 的区别
- Solaris shared library FAQ
- Build Shared Library
- Shared Library Search Paths
- load shared library
- LeetCode 96 — Unique Binary Search Trees(C++ Java Python)
- 第三周作业循环与判断语句LeapYear
- CSDN的博客搜索功能太弱,教你怎么搜索自己博客的文章
- ASP.NET—009:前台传值的另一种方式$.post
- 黑马程序员09_类加载器
- Shared Library in X86/ARM
- 《Windows核心编程系列》十一谈谈Windows线程池
- listview因高度问题,重复调用getView
- android Bitmap学习总结
- 物体跟踪meanshift详解之密度估计
- Java Web编程经验(华迪实习)
- 清明 那年,那天,那分,那秒 的作业
- 详解大端模式和小端模式
- 把字符串转换成整数