导出符号的意义

导出符号在软件链接过程中起关键作用,它们是目标文件间镶嵌的接入点。在链接时,符号被解析成合并后的文件内部地址,而在加载时,符号变为内存中的实际地址。内核的导出符号允许其他模块调用,并在System.map中可查。内核被Boot Loader加载到内存中,其导出符号为动态加载的模块提供引用地址转换。
摘要由CSDN通过智能技术生成

导出符号是什么?

符号,是软件链接过程的用到的术语。

我们编写自己的软件生成目标文件,但是通常情况下,只有自己的目标文件是不够的。

比如我们用c++编写的程序,必然要与C++的运行时库链接在一起才能工作,否则我们在代码中使用的fopen或者std::cout之类的符号要到哪里去找。

 

在链接的过程中,相当于是让目标文件之间镶嵌到一起,因此最重要的是找到精确的接入点,这就是符号。

符号是目标文件之间对地址的引用,即对函数和变量的地址的引用。

 

通常是一个目标文件A定义符号,而另外一个目标文件B引用A定义的符号,符号就成了目标文件A和B镶嵌到一起的接入点。

符号在A中是导出符号,在B中是导入符号

 

换句话说,符号就是地址,当CPU在执行链接后的目标文件组合体时,它并不关心符号的问题,而是关心某一条函数调用指令指向的具体地址。

 

从编写代码时的符号到程序执行时的地址,要经过以下两个步骤:

  • 链接,作用是将分散在几个不同的目标文件中的符号进行解析,将符号解析成合并后的目标文件内部的符号(是在文件层次)
  • 加载,作用是将目标文件按照其指明的方式,加载到物理内存(实际上是线性内存)中的某一个范围,这时符号就真正变成了地址,可以作为call指令的参数了

 

CALL Instruction Description
Saves procedure linking information on the stack and branches to the called procedure specified using the target operand. The target operand specifies the address of
the first instruction in the called procedure. The operand can be an immediate value,
a general-purpose register, or a memory location.

 

This instruction can be used to execute four types of calls:
Near Call — A call to a procedure in the current code segment (the segment
currently pointed to by the CS register), sometimes referred to as an intrasegment call.
Far Call — A call to a procedure located in a different segment than the current
code segment, sometimes referred to as an inter-segment call.
Inter-privilege-level far call — A far call to a procedure in a segment at a different
privilege level than that of the currently executing program or procedure.
Task switch — A

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值