zoukankan      html  css  js  c++  java
  • 编译和链接

    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、模块拼装——静态链接

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

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

  • 相关阅读:
    [经验] 如何在虚拟机上安装 CentOS
    [经验] Java 使用 netty 框架, 向 Unity 客户端的 C# 实现通信[2]
    [经验] Java 使用 netty 框架, 向 Unity 客户端的 C# 实现通信 [1]
    [经验] 关于 Java 中的非空判断
    [经验] Java Web 项目怎么部署到 Linux 系统上
    求和
    引用与指针
    C++学习前言
    大O
    ubuntu连接不上mysql问题
  • 原文地址:https://www.cnblogs.com/songdechiu/p/11440096.html
Copyright © 2011-2022 走看看