- 1、本文档共14页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Position Independent Code (PIC) in shared libraries on x64
Position Independent Code (PIC) in shared libraries on x64
PPoossiittiioonnIInnddeeppeennddeennttCCooddee ((PPIICC))iinnsshhaarreeddlliibbrraarriieessoonnxx6644
The previous article explained how position independent code (PIC) works, with code
compiled for the x86 architecture as an example. I promised to cover PIC on x64 [1] in a
separate article, so here we are. This article will go into much less detail, since it assumes
an understanding of how PIC works in theory. In general, the idea is similar for both
platforms, but some details differ because of unique features of each architecture.
前篇文章中,我在X86平台上通过实例向大家展示了位置无关代码是如何工作的。 之前我
承诺读者会介绍X64平台上的位置无关代码,那么这篇文章就是了。 不过这篇文章介绍的
不会太详细,因为以前文为基础,我假设读者已经明白什么是位置无关代码了。再说,位置
无关代码这个概念在所有的平台上都是一样的,只不过具体的实现细节会因为平台的不同而
稍微有些差异。
RIP-relative addressing
RIP-relative addressing
RRIIPP--rreellaattiivvee aaddddrreessssiinngg
On x86, while function references (with the call instruction) use relative offsets from the
instruction pointer, data references (with the mov instruction) only support absolute
addresses. As we’ve seen in the previous article, this makes PIC code somewhat less
efficient, since PIC by its nature requires making all offsets IP-relative; absolute addresses
and position independence don’t go well together.
我们知道,在X86平台上,函数的调用(使用call 指令)使用相对位移调用指令(当然是相
对指令指针(instruction pointer)),数据的访问(使用mov 指令)只支持绝对地址访问。
通过前篇文章的学习,我们知道位置无关代码(PIC)的设计思想就是利用IP-relative 来寻
找目标,这么说来X86平台对数据的访问需要绝对地址的限制在某种程度上降低了位置无关
代码(PIC)的效率,因此绝地与位置无关代码(PIC)不应该同时存在。
x64 fixes that, with a new "RIP-relative addressing mode", which is the default for all 64-bit
mov instructions that reference memory (it’s used for other instructions as well, such as
lea).A quote from the "IntelArchitecture Manual vol 2a":
X64通过一个RIP-relative 的寻址模式修正了这个问题,这种寻址模式是所有64位平台上
mov 指令默认的访问内存的方式(这种方式也适合其他的指令,例如lea 指令)。下面是摘
自"IntelArchitecture Manual vol 2a"的一段:
A new ad
您可能关注的文档
- fp2-position_1f448-1c1f448 1c的位置_ FP2.pdf
- Glutamate at position 227 of junctophilin-在227位谷氨酸junctophilin-227.pdf
- Greif 2006 AERFamily Structure, , Institutionsand Growth and Corporations格瑞夫2006 aerfamily结构、机构、成长和公司 .pdf
- Growth factors and cytokines in wound healin生长因子与细胞因子在创面愈合中的作用.pdf
- Growth in a Time of Debt 英文教材.pdf
- Guide to Drawing Clean Schematics with Virtuoso英文教材.pdf
- Guidelines for Position Paper立场文件指南.pdf
- How is Entrepreneurship Good for Growth (1)英文教材.pdf
- Growth Hacking-FreeS VC-覃超英文教材.pdf
- How to Grow a Mind StatisticsStructure and Abstraction英文教材.pdf
- 2024年山东省聊城东阿县事业单位选聘32人历年高频考题难、易错点模拟试题(共500题)附带答案详解.docx
- 2024年山东省聊城莘县事业单位招聘单位高频考题难、易错点模拟试题(共500题)附带答案详解.docx
- 汽机专业题库及解析.docx
- 基本常规医疗流程答案.doc
- 大金空调故障代码汇总.docx
- 理综-山西省阳泉市2023-2024学年高三年级上学期期末考试试题和答案.docx
- 数学-海南省天一大联考2023-2024学年高三学业水平诊断(二)带答案.docx
- 地理-湖南省长沙市雅礼中学2023-2024学年高三上学期月考试卷带答案.docx
- 生物-湖南省长沙市雅礼中学2023-2024学年高三上学期月考试卷带答案.docx
- 数学-湖南省长沙市雅礼中学2023-2024学年高三上学期月考试卷带答案.docx
文档评论(0)