首页 > 其他分享 >CS:APP--Chapter07 : Linking(part 1)

CS:APP--Chapter07 : Linking(part 1)

时间:2023-01-20 01:55:25浏览次数:45  
标签:code -- APP object Linking these file linking relocatable

CS:APP--Chapter07 : Linking(part 1)

标签(空格分隔): CS:APP

目录


prologue

So far what I have learnt is to comprehend the relationship between my code/program and hardward for example how to translate my code into assembly code. From this point forward, We can shift to another perspective to inspect our program, that's the relationship to operation system. Undoubtedly, OS is a significant interface between user and computer resource. But the structure of computer shown in chapter 4 simply enable us to have a closer look at how way complicate it is, OS can simplify the operation , which forces programmer who want make effective use of computer to have a better understand the mechansim under the hood when our program is being executed from source code to executable file.


one blank left for overview of this chapter


1. compiler drivers

As we said before, our source code such as hello.c is executed only when it is converted from source file to executable code which is loaded into memory and then executed by processor.

one diagram :

此处输入图片的描述

We perform compile driver in order to invoke pre-processor, compiler, assembler, linker to generate executable file which eventually is loaded into memory by loader and executed by CPU.

Now we move on the command line to process our code.
Note: Because my own computer only has windows OS, many demonstrations on the book cannot be implemented now but poosible later and otherwise I just look up for another solution to accomplish these concepts.

GCC provides some options:

  • v Display the programs invoked by the compiler.
  • E Preprocess only; do not compile, assemble or link.
  • S Compile only; do not assemble or link.
  • c Compile and assemble, but do not link.
  • o < file > Place the output into < file >.

computer is always performing works until there is transferring control over and interruped.

2. static linking

From a big point of view, dynamic linking seems more advanced and prevailing than static linking in terms of processing and simplicity. static linking is a kind of method we can come up with in a short period.

It just merges a collection of relocalable object files and command-line arguments and then generates a full linked executable file.

2.1 a glance at relocatable object file

relocatable object file comprises of instructions and data segments, which are a contigous sequence of bytes. According to the features of C, these bytes are functions and global and locak variables. What's more, these functios are stored in one block in memory, initialied global variables are in another section and uninitialized variables are in yet another section.

In this case, there are two steps need to be done to get executable file by linker which performs linking:

  • symbol resolution

several relocatable object files defines and references variables within their text such as function, global variables and static variables[1].

The relocatable onject file has organized these variable into different sections and thus linker should re-organize these sections.

  • relocation

Because these relocatable files start from address 0, the location of most instructions and data must be modified after linking. In this case, linker should relocate these sections by associating a new memory location with each definition and then modifying all references to these symbols.?????

2.2 object files

there are three types of object files:

name description
relocatable object file before linking
executable object file after linking
shared object file often used in dynamic linking at load or run time

the standard of each file varies from system to system, just taking Linux for example, we focus on Executable and Linkable Format.

2.3 relocatable object file

ELF header has 16 bytes where store the word size and ordering of the system, followed by several sections

此处输入图片的描述


  1. one variable is declared with static, which is invisable from external modules and object files. ↩︎

标签:code,--,APP,object,Linking,these,file,linking,relocatable
From: https://www.cnblogs.com/UQ-44636346/p/17062361.html

相关文章

  • 反射机制
    JavaReflection  Reflection(反射)是Java被视为动态语言的关键,反射机制允许程序在执行期借助于ReflectionAPI取得任何类的内部信息,并能直接操作任意对象的内部属性及方......
  • SpringCloud Sleuth链路追踪
    1、概要一般的,一个分布式服务跟踪系统,主要有三部分:数据收集数据存储数据展示然而这三个部分其实不都是由SpringCloudSleuth(下面我简称为Sleuth)完成的,Sleuth负责数......
  • node.js安装
    node.js安装1.官网下载安装包下载地址:https://nodejs.org/en/download/根据自己的电脑系统选择对应的安装包,由于我用的是windows电脑(64位),下载这个安装包,是一个.msi文......
  • 哲学思考:个人发展的思考
    哲学思考:个人发展的思考    个人应该以提升个人实力为核心,辅之以人际关系。实力,主宰人生的核心力量。人际关系,是放大“实力”的工具。人际关系,执行“共赢”理......
  • SOFAJRaft模块启动过程
    本篇文章旨在分析SOFAJRaft中jraft-example模块的启动过程,由于SOFAJRaft在持续开源的过程中,所以无法保证示例代码永远是最新的,要是有较大的变动若有纰漏或者错误的地方,欢......
  • 代码随想录算法训练营第九天 | 28. 实现 strStr(),459.重复的子字符串,字符串总结,双指针
    一、参考资料实现strStr()题目链接/文章讲解/视频讲解:https://programmercarl.com/0028.%E5%AE%9E%E7%8E%B0strStr.html重复的子字符串题目链接/文章讲解/视频讲解......
  • 《玉水明沙 谢岚岚》
    世人皆谓爱菱纱,谁怜杳然青峰下。唯愿梦醒一轮回,玉水河畔浣溪纱。 仙4音乐填词演唱,以回梦游仙与织梦行云各种版本最多,盖因其曲调宛转悠扬、节奏性强,容易填词。众多......
  • Python入门之变量
    """变量:在内存中存储数据"""#语法:#变量名称=对象#例如:name="张无忌"print(name)#语义:内存图#变量名:真实内存地址的别名#见名知意#......
  • 代码随想录算法训练营第八天 | 344.反转字符串,541.反转字符串II,剑指Offer05.替换空格,1
    一、参考资料反转字符串题目链接/文章讲解/视频讲解:https://programmercarl.com/0344.%E5%8F%8D%E8%BD%AC%E5%AD%97%E7%AC%A6%E4%B8%B2.html反转字符串II题目链接/......
  • string 接收 char 随机数abcd
    packagecom.fqs.demo;importjava.util.Random;publicclassCharAB{//输出26个小写字母和26个大写字母publicstaticvoidmain(String[]args){......