编译和链接

1、预编译

gcc -E hello.c -o hello.i      //stop after the stage of preprocessing stage, do not run the compiler proper

2、编译

gcc -S hello.c -o hello.s    //stop after the stage of compilation proper, do not assemble

3、汇编

as hello.s -o hello.o

gcc -c hello.s -o hello.o   //compile or assemble the source files, but do not link

gcc -c hello.c -o hello.o

 

4、编译的过程

(1)词法分析

扫描器,分割为一个个记号。lex程序可以实现词法扫描。

(2)语法分析

对输入的记号序列进行解析,构建出一颗语法树yacc,可以实现语法分析。

(3)语义分析

每个表达式,都被标识了类型

(4)中间语言生成

中间代码有:三地址码和P-代码

编译器前端负责产生机器无关的中间代码,编译器后端将中间代码转换成目标机器代码。

(5)目标代码生成与优化

代码生成器和目标代码优化器

 

5、链接器

程序修改时,位置都需要重新计算,重新计算各个目标地址的过程叫做重定位

汇编语言,使用符号来标记位置。汇编器在汇编程序时会重新计算符号的地址。

一个程序被分割为多个模块,模块之间通过符号进行通信,模块间拼接过程就是链接

 

6、模块拼装——静态链接

链接器与”程序员人工调整地址“本质上没有两样,也就是重定位,每个需要被修正的地方叫重定位入口

链接过程包括了地址和空间分配符号决议重定位等步骤。

 

posted @ 2019-08-31 19:04  我是老邱  阅读(334)  评论(0编辑  收藏  举报