§7 链接

type
status
date
slug
summary
tags
category
icon
password

§7.1 链接

notion image

一、使用链接器的理由

  1. 模块化
程序可以编写为一个较小的源文件的集合,而不是一个整体巨大的一团
可以构建公共函数库
  1. 效率
时间:分开编译,更改一个源文件,编译,然后重新链接,不需要重新编译其他源文件
空间:可以将公共函数聚合为单个文件,而可执行文件和运行内存映像只包含它们实际使用的函数的代码

二、链接器的工作步骤

notion image
通用名字:ELF二进制文件
notion image
notion image
  1. 符号解析
notion image
notion image
notion image
notion image
notion image
  1. (删除)重定位
notion image
notion image
notion image
notion image
notion image
objdump -dxs addvec.o/main.o/prog > xxx.d
objdump -f test
显示test的文件头信息
objdump -d test
反汇编test中的需要执行指令的那些section
objdump -D test
与-d类似,但反汇编test中的所有section
objdump -h test
显示test的Section Header信息
objdump -x test
显示test的全部Header信息
objdump -s test
除了显示test的全部Header信息,还显示他们对应的十六进制文件代码
notion image
notion image
notion image
notion image
notion image

(删除)§7.2 案例学习:库打桩机制

notion image
notion image

期末真题

24春
notion image
D
notion image
notion image
×
23春
notion image
C
notion image
重定位
notion image
×
notion image
main.c
强符号:x, z, main, p1
弱符号:y
p1.c
强符号:p1
弱符号:x
x:0xBF F8 00 00 00 00 00 00
x:00 00 00 00→0
y:00 00→0
z:F8 BF→-18057
22春
notion image
A
目标文件(.o)是由汇编器在编译阶段生成的,而非链接器。链接器的作用是处理已有的目标文件,而非生成新的目标文件。
notion image
notion image
notion image
Loading...