Reading Notes on Linkers & Loaders

工作中要用C++, 有时遇到些诡异的链接相关的问题解决不好。需要系统的学习下,2014.11开始读 Linkers And Loaders.2014.12.31终于读完。

目标:熟悉Linux环境下的ELF文件格式、静态库、动态库,及其相关工具基本使用,出现问题时能有解决思路。

link: http://www.iecc.com/linker/

Chapter 1 Intro

Chapter 2 Achitectural Issues

ABI
Intel X86 架构 //TODO
Paging and Virtual Memory
PIC p.252

Chapter 3 Object Files

BSS Segment(Block Started by Symbol) 用作未初始化的数据段
ELF 格式 //TODO
PE

Chapter 4 Storage allocation

C++ duplicate removal

Templates are essentially macros with arguments that are datatypes, and that expand into a distinct routines for every distinct set of type arguments.

The GNU linker deals with the template problem by defining a "link once" type of section similar to common blocks.

Chapter 5 Symbol Mangement

DWARF

DWARF is a widely used, standardized debugging data format. DWARF was originally designed along with Executable and Linkable Format (ELF), although it is independent of object file formats. The name is a medieval fantasy complement to "ELF" that has no official meaning, although the backronym 'Debugging With Attributed Record Formats' was later proposed.

  • Annotated C++ Reference Manual

Chapter 6 Libraries

readelf

查看一个 ELF 格式 .a文件里有哪些 .o文件
$ readelf -h libcommon.a |grep File

GNU Binary Utilities

ar,nm,ranlib,readelf等工具手册
https://sourceware.org/binutils/docs/binutils/index.html
ar: Create, modify, and extract from archives
nm: List symbols from object files
ranlib: Generate index to archive contents
readelf: Display the contents of ELF format files

Chapter 7 Relocation

Once a linker has scanned all of the input files to determin segment sizes, symbol definitions and symbol references, figured out which library moduleds to include, and decided where in the output address space all of the segments will go, the next stage is the heart of the linking process, relocation.

  • Hardware and software relocation
    Hardware relocation allows an operation system to give each process a separate address that starts at a fixed known address, which makes program loading easier and prevents buggy programs in one address space from damaging programs in otheraddress spaces. Software linker or loader relocation combines input files into one large file that's ready to be loaded into the address apace provided by hardware relocation, frequently with no load-time fixing up at all.

Chapter 8 Loading and overlays

Loading is a little different depending on whether a program is loaded by mapping into a process address space via the virtual memeory system or just read in using normal I/O calls.

  • PIC costs and benefits
    The advantages of PIC are straighforward; it makes it possible to load code without having to do load-time relocation, and to share memory pages of code among processes even though they don't all have the same address space allocated.

Chapter 9 Shared libraries

  • shatic linked shared libraries
    that is , libraries where program and data addresses in libraires are bound to executables at link time.

  • dynamic linked libraries

  • Binding time
    A much more interestin problem occurs when the library is present, but the library has changed since the program was linked. In a conventionally linked program, symbols are bound to addresses and library code is bound to the executable at link time, so the library the program was linked with is the one it uese reardless of subsequent changes to the libray. With static shared libraries, symbols are still bound to addresses at link time, but library code isn't bound to the executable until run time. (With dynamic shared biraries, they're both delayed until runtime.)

Chapter 10 Dynamic Linking and Loading

PLT: Procedure call table

Chapter 11 Advanced techniques

Techniques for C++

  • Trial linking
  • Duplicate code elimination

The Java linking model

What makes it interesting is that Java also defines a protable binary object code format, a virtual machine that executes programs in that binary format, and a loading system that permits a Java program to add code to itself on the fly.

A Java application can either use the built-in boosttrap class loader which loads classes from files on the local disk, or it can provide its own class loader which can create or retrieve classes any way it wants. Most commonly a custom class loader retrieves class files over a network conection, but it could equally well generate code on the fly or extract code from compressed or encypted files. When a class is loaded due to a reference from another class, the system uses same loader that loaded the referring class. Each class loader has its own separate name space, so even if an application run from the disk and one run over the net have identically named classes or class members, there's no name collision.

转载于:https://www.cnblogs.com/basalt/p/4148992.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Linkers and Loaders是指链接器和装载器,是计算机领域中的一种重要工具,主要用于将程序的各个部分合并在一起并最终加载到内存中运行。 链接器的主要工作是将多个目标文件合并成一个可执行文件。目标文件包含机器语言指令和符号表信息,链接器将各个目标文件的符号表信息进行合并,并解决模块之间的引用问题,使得程序能正确地执行。 装载器的主要工作是将可执行文件加载到计算机的内存中运行。装载器将可执行文件中的各个段按照一定的地址空间进行装载,并进行重定位等操作,确保程序能够在内存中正确执行。 总之,链接器和装载器是构建可执行程序需要用到的重要工具,对于程序的可靠性、效率和安全性都具有重要作用。 ### 回答2: linkers and loaders是计算机科学中用于程序编译的工具。Linkers在编译过程中将多个目标文件合并成一个可执行文件,同时也会解决外部和内部符号的引用问题。Loaders则是将可执行文件加载到内存中,并把符号解析成运行时地址,最终使程序在计算机上运行。 linkers在编译过程中实现了模块化编程,将单独编写的多个目标文件链接在一起。linkers将程序中各个部分之间的符号和引用关系整合在一起,实现一个完整的可执行程序。linkers主要有静态链接和动态链接两种形式,静态链接将库文件直接合并到可执行文件中,而动态链接则是在程序运行时动态加载库文件。 loaders则负责将可执行文件从磁盘加载到内存中去。借助加载器,操作系统可以根据可执行文件中文件头和段表信息将程序映射到内存中的相应地址,方便操作系统进行命令的调用和运行。 总之,linkers和loaders是编译过程中非常重要的组成部分。它们不仅使编译工作更加高效和灵活,同时也是计算机开发中程序正确性和性能的关键。 ### 回答3: linker是编译后的程序中用来处理符号链接的工具。它的作用是将不同程序模块(source file, object file)之间的符号联系起来。在链接过程中,linker会分析程序中使用到的符号,并将这些符号与其对应的地址进行关联,以便程序中的不同模块能够相互调用。同时,linker也会将所有的模块组合成一个可执行文件,方便程序的执行。 loader是将程序加载入内存并实现分页与映射的软件。loader的主要作用是将程序文件从磁盘上读入内存,并根据程序的逻辑要求,将其按照合适的方式映射到内存中的合适位置。同时,loader还负责分配与管理程序所需要的内存空间,维护程序在内存中的状态,以及实现程序的执行。 在计算机科学领域中,linkers和loaders是非常重要的工具。它们帮助编程人员将不同的程序模块链接起来,并在不同的系统中进行适当的加载。对于任何一个开发者而言,了解和掌握linkers和loaders都是非常重要的基本技能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值