跳至主要内容

Linking

We know the process of building programs are divided into two parts, compiling and linking. Linking is a process that combine different part of codes and data into one executable program. Here is a general picture:

Preprocessing -> Compiling -> Assembling -> Linking

A linker mainly does two tasks: symbol resolution, and relocation. Symbol resolution relates every symbols referenced in the target object file (both code and data) to their definition. Relocation generate an absolute address for every symbols according their relative addresses, since code starts from address 0x00 after assembling.

Every object file will contain their own symbol tables. There are symbols defined in and not in the current object file. Function and initialized variables are strong symbols, and uninitialized variables are weak symbols. Rules for symbol resolution in Unix linker are defined as followes:

Rule.1 Only one strong symbol is allowed, otherwise is a linker error.

Rule.2 If there is a strong symbol and other weak symbols, choose strong symbol.

Rule.3 If there is no strong symbol, then choose any weak symbol at random.

Once the choice is made, symbols in object files not in the object file where choosen one stays will be resolved to the choosen one, i.e, reference to the choosen one.

Several important sections in executable files' headers are: .text, .rodata, .data, .bss. .rel.text, .rel.data. Section .text contains executable machine codes, .rodata contains readonly data, while section .data and .bss contain initialized and uninitialized global variables, respectively. Section .rel.text and .rel.data contains table needed for code and data relocation respectively.

Static libraries take additional space and memory because object file needed in final executables will be linked, dynamic libraries spare space and memory at the cost of time overhead because of dynamic linking at loading times.

(this is a summary on chapter 7 of the book "computer systems, a programmer's perspective")

评论

此博客中的热门博文

反转剧

这两天明显感到天气转冷,呱呱的家里也已经下起了大雪,南京则是阴冷潮湿,让人没有了出行的欲望。没想到躲在被子里看反转剧也成了度过寒冬的一剂良药。在PPLive越来越让人失望的时候,PPStream横空出世,虽然广告仍是少不了的主题,但从视频质量和播放连续性上来说都超过PPLive,实为居家必备之良品(由此可见,新事物一定会战胜旧事物......)。韩国的反转剧最近似乎比较流行,称之为反转剧就在于其结果总是让人出乎意料,不合常理,其间又不乏各种搞怪搞笑的镜头,各种当红帅哥美女也一定让DDMM们爱不释手,20~30分钟一集的剧情一改韩剧拖沓的风貌,想看就看,容易切入。 反转剧,今天你看了吗?

Computer Systems: A Programmer's Perspective

Bryant, R.E所著的这本Computer Systems: A Programmer's Perspective,在国内翻译为《深入理解计算机系统》,由中国电力出版社2004出版,应该算是一本重量级的书了。从同学推荐到今天看完,足足花了有5个月的时间,虽然看得不深,但总的感觉还是不错,在这里就对它作一个总结吧。 Computer Systems表明这本书讲解的是计算机系统知识,但A Programmer's Perspective却又告诉我们它与其它书籍的不同之处,便是从程序员的角度,即偏向软件的角度,而不过多地涉及硬件内容。计算机系统本身就是一门涉及面广,内容繁多的学科,这本书不可避免地从各个角度讲解了这些内容。下面以我个人的观点进行一些总结。 第1章:计算机系统漫游 主要是对全书内容作了一个简要的概括。 第2章:信息的表示和处理 这一章主要讲解了整数与浮点数。虽然对于整数我们已经很熟悉了,但是在实际中仍会犯下各种各样的错误,书中对不同整型数间的转换及运算作出了很详细的论述。浮点数似乎一直是计算机书籍里不愿涉及的话题,对于想了解浮点数表示及浮点数运算的人来说,这部分关于浮点的描述可以作为一个很好的起点。 第3章 程序的机器级表示 对于任何一个希望了解底层的人来说,这一章可说是相当精彩的。本章主要讲解了IA32的指令集,因此以汇编为主,在控制流指令部分还将C语言及对应的汇编形式进行了对照,在调用部分还详细讲解了本地栈。最后为对浮点感兴趣的人准备了IA32中用于处理浮点的指令集。 第4章 处理器体系结构 这一章是本书中最接近硬件的部分了,从设计一个简单的处理器Y86出发并逐步完善它,一步步地引导读者理解处理器体系结构。虽然我们可能永远也不会自己设计处理器,但了解它是何工作的能有助我们理解整个计算机系统是如何工作的,比如对程序优化就很有帮助。本章首先给出了Y86的指令集,并使用一种硬件描述语言HCL对硬件的逻辑结构进行了描述,然后将指令分成取指、译码、执行、访存、写回、更新PC六个阶段,给出了每条指令的每一部分的操作内容,并对每一部分的硬件实现分别进行了讨论。显然,这种顺序的实现过程是低效的,本章的后面部分便围统着流水线的实现以及遇到的问题展开了论述。 第5章 优化程序性能 本章介绍了一些代码优化的内容,如前面所说,只有理解了处理器系...

biblioscape, endnote, no, none of them

endnote在与word2003搭配时经常占据严重的CPU,非常不好用。今天听说biblioscape好,下之,唉,高兴的日子总是那么短暂,BUG一堆。它只支持rtf格式的转换,在word里format时,还要转为rtf格式后再转回来。甚至在重复转换过程中也产生了不一致,可能它在RTF和DOC之间的转换没有那么精确吧。好想用latex排,不过时间紧迫,现在懒得去学了。 都不用了,还是手工输入参考文献罢了。也许,open office?下一个先。