Linkers 连接器

来源:互联网 发布:库存管理数据流程图 编辑:程序博客网 时间:2024/04/30 04:34

Traditionally, you can't get far without a linker, and thats a fact.
Linkers are important tools in the production of an Operating System.
传说中没有连接器你将寸步难行,这话肯定不假。在写操作系统的时候,连接器

是重要的工具。

They come in many flavours sizes shapes and formats. Some are flexable

and some are not.
它们来了,带着众多的芳香(有没搞错?)、尺寸

、形态还有格式。(句子优美啊……)其中的一些

富有弹性而另一些没有。

There are important considerations to make when using a linker.
当使用一个连接器时,以下是一些必须考虑的重要问题。


Does it support the output formats I require?
它是否支持我需要的输出格式?
Does it support the input formats I'm using?
它是否支持我使用的输入格式?
Can I specify address ranges for code and data?
我能够为代码和数据指定地址段吗?
Can I produce flat binary files?
我能处理平坦型二进制文件(flat binary files)吗?
Can it handle 32bit code?
它能处理32位代码吗?

Does it support the output formats I require
它是否支持我需要的输出格式?

Some linkers only support one kind of output file format, others

support every kind of format know to exist. Formats are often not

proprietory, having specifications available means if you wish to use

Win32/PE file format, you are not required to use Microsoft's Linker.
一些连接器只支持一种类型的输出文件格式,另一些支持现存已知的所有格式。

格式常常不是专有的,具有可利用的规范意味着,如果你希望使用WIN32/PE文件

格式,你将不需要使用M$的连接器。


Does it support the input formats I'm using?
它是否支持我使用的输入格式?

This can be important if your going to mix files around. For example,

stock DJGPP distribution works with COFF files, and if you link in a

TASM assembled OBJ/OMF file, DJGPP(LD) will not recognised it.
如果你打算混合身边的程序,这个问题就相当重要了。例如,DJGPP一般产生COFF

格式的文件,如果你用TASM汇编后的OBJ/OMF文件格式进行混编,DJGPP(LD)将不

会认可这种格式。

This is usually of less a concern than the other requirements.
与其他要求相比,这个问题通常不为人所关注。


Can I specify address ranges for code and data?
我能够为代码和数据指定地址段吗?

This can be very, very important! Especially if you want to product

flat binary files. (Like an unrelocated kernel image). You need to be

able to specify where the code starts and sometimes where the data

begins.
这个问题非常非常重要!特别是在你需要产生平坦模式的二进制文件时。(比如

一个不重新定位的内核映像)。


Can I produce flat binary files?
我能处理平坦型二进制文件(flat binary files)吗?

As with the above option, this can be important, even if you only need

to use it a couple of times.
作为上面说的选项,这个问题也是重要的,特别是在你仅仅需要用它们两三次的

时候。

Can it handle 32bit code?
它能处理32位代码吗?

You might think this a redundant question in the age of "32bit" but

there are many custom linkers out there that can't handle 32bit object

files.
你可以认为这个问题在今天“32位”的时代里显得多余,但现在仍有许多常规连

接器不能处理32位目标文件。

-----------------------------------------------------------------------


Linkers :: JLoc

JLoc is written by John Fines.
JLoc 由 John Fines 编写。

"This program is a linker/locator for use when you need more
control over placement of sections within the image, than a standard
linker provides."
“这个程序是一个连接器/定位器,与一个标准的连接器相比,它可以使你更大程

度上控制映像程序在段中的位置。”

JLoc can be tricky to use for first timers. Carefull reading of the

documentation is required. Its not a get-up-and-go linker like all the

other linkers. JLoc _requires_ you to write a custome script for each

"executable" image you want to link.
JLoc能用来欺骗第一个计时器(这句理解错了没?)

。首先要求仔细阅读它的文档。它像别的连接器那样,不是一个拿起来就能用的

连接器,JLoc *要求* 你为每个你要连接的可执行映像写一个脚本。

JLoc gives you flexibility over HOW the object files are linked,

regarding loaded addresses and so-forth.
JLoc给你极大的弹性用于*怎样*将目标文件连接,注意加载到的内存地址等等。

JLoc can be obtained here, http://www.erols.com/johnfine/
JLoc 能从这个网址得到:http://www.erols.com/johnfine/

needs more review!!
需要更多的观察 !!

Pros
优点

Supports OMF/OBJ, DJGPP/COFF
支持OMF/OBJ,DJGPP/COFF 格式
Supports 32bit code
支持32位代码
Supports flat binary file generation
支持生成平坦型二进制文件
Handles library files (OMF/OBJ)
能够处理库文件(OMF/OBJ)
OMF/OBJ debugging information
支持OMF/OBJ 的调试信息
Free
免费

Cons
缺点

Does not support any output file formats other than flat binary and

DOS/COM
不支持其他输出文件,除了平坦型二进制和DOS/COM型文件
Confusing to use for beginners
对初学者门槛太高
Can't create shared libraries
不能建立共享库

-----------------------------------------------------------------------


Linkers :: ALink

ALink (Anthony's Linker) was written as a companion to NASM, its aim to

provide a Free linker that supports Nasm's output formats and support

some of the more popular executable formats.
ALink (Anthony's Linker)是作为NASM的一部分编写的,它的目标是提供一个自

由的连接器用以支持NASM的输出格式和支持其他常见的可执行文件格式。

ALink can be obtained here,
ALink能够从以下网址得到:http://www.geocities.com/SiliconValley/Network

/4311/index.html

need more of a review!!
需要更多的观察 !!

Pros
优点

Its Free
自由软件
Supports input formats OMF/OBJ, Win32/COFF Objects
支持输入格式:OMF/OBJ, Win32/COFF 目标代码
Supports output as DOS/COM, DOS/EXE, Win32/PE
支持输出格式:DOS/COM, DOS/EXE, Win32/PE格式
Can build Win32/PE DLL files
能够建立Win32/PE DLL 文件
Can set the code address
能够设置代码的地址。
Suppots .LIB (OBJ) Library files
支持.LIB (OBJ) 库文件

Cons
缺点

Doesnt support flat binary images
不支持平坦模式二进制映像
Strips debugging information
剥离了调试信息
Can't create shared libraries
不能建立共享库

-----------------------------------------------------------------------


Linkers :: LD (GNU)

LD, the King of linkers. Supports more input and output formats than

any other linker in existance. Also the most flexable of the listed

linkers. Supports custom linking via scripts. Its advanced featers are

hard to use if you dont know what you are doing.
LD,连接器之王。比任何其他现存连接器支持更多的输入和输出格式。也是连接

器中最富弹性的。支持通过脚本文件自定义连接。如果你不知道你在做什么,则

难以使用它的高级技术。

LD has the most going for it in terms of functionality compared to the

other linkers (Thats _my_ opinion anyway...) but lacking OMF/OBJ

support is a BIG omission.
与其他连接器相比,LD也是目前功能性部分最多的(这只是 *我* 个人看法)但

是缺乏对 OMF/OBJ 格式的支持是一个大疏忽。

This description is based on the LD sources, that can compile to

support all formats. Please be aware that the LD that comes with DJGPP

is very limited in its output formats (DJGPP/COFF, A.Out, flat binary)

and so to with the LD that is part of Linux etc.
这些描述是建立在LD源代码的基础上的,它能够编译以支持所有格式。请明白在

DJGPP 中LD的输出格式是非常有限的(DJGPP/COFF, A.Out, flat binary)同样

在Linux等平台下的LD也是如此。

Pros
优点

Supports most known input formats (Elf, DJGPP/COFF, Win32/COFF, A.Out,

etc)
支持大部分已知输入格式(Elf, DJGPP/COFF, Win32/COFF, A.Out, 等)
Supports most known output formats (Elf, Win32/PE, A.Out, COFF, etc)
支持大部分已知输出格式(Elf, Win32/PE, A.Out, COFF等)
Supports creation of shared libraries
支持通过共享库建立
Can create flat binary files
能建立平台型二进制文件
Can specify code/data addresses
能指定代码/数据地址
Supports DWARF and ECOFF and STABS debugging information
支持DWARF, ECOFF,STABS 调试信息。
Its Free
自由软件

Cons
缺点

Does not support OMF/OBJ file format
不支持 OMF/OBJ 文件格式。
Can get complex writing custom linking scripts
撰写自定义连接脚本带来了复杂性
Can't create shared libraries
不能建立共享库

-----------------------------------------------------------------------


Linkers :: TLink / TLink32 (Borland)

TLink is the linker that comes with Borland C and their assembler TASM.

The difference between TLink and TLink32 is that TLink32 creates ONLY

Win32/PE (and DLL) files where as TLink creates Dos and Win16 files.
TLink来自于Borland C 及其汇编器TASM,TLink和TLink32是不同的,TLink32只

能建立Win32/PE (和 DLL)文件,TLink只建立DOS和WIN16平台下的文件。

Pros
优点

Supports Win32/COFF and OMF/OBJ
支持Win32/COFF 和 OMF/OBJ
Has support for libraries
支持库
Supports creating Win32/PE files and DLL's
支持建立Win32/PE files 和 DLL文件
Supports OMF/OBJ (and DWARF?) debugging information
支持OMF/OBJ (和 DWARF?) 调试信息

Cons
缺点

Lacking in both input and output fileformats
同时缺乏输入和输出文件格式
Can't create flat binary images
不能建立平坦型二进制映像
Can't create shared libraries
不能建立共享库

-----------------------------------------------------------------------


Linkers :: Link / NLink (Microsoft)

There are really three fundamentally different linkers.
实际上是由三个迥异的连接器组成。

Versions 1.x through 3.x can only produce DOS output. Technically, the

_really_ early ones can only produce .com files, and IIRC, starting

with 2.x they can also produce .exe files.
从1.x到3.x版,该连接器职能处理DOS的输出格式。严格的说,*实际上* 先前的

一个版本只能处理 .com 文件,直到2.x版才能处理.exe文件。

Starting with version 4.x, MS Link can also produce NE format output

files. These accept OMF/OBJ format with some MS extensions.
从4.x版开始,MS Link也能处理NE格式的输出文件了。也接受了 OMF/OBJ 格式,

但做了一些MS自己的扩展。

Starting with version 6.x, MS link can produce only PE format output

files.
从6.x版本开始,MS LINK仅仅能够输出PE格式的文件了。

These accept either COFF/PE or 32-bit OMF/OBJ format object files and

produce (only) PE files as output. They support a few things missing

from the Borland linker such as the ability to specify the entry point.
连接器既接受了 COFF/PE 也接受了32位的 OMF/OBJ 目标文件格式,而输出格式

仅有PE一种。他们从borland连接器中学来的对很多项目的支持不见了,比如指定

进入点的能力。

Debug formats supported include COFF and CodeView.
调试格式支持 COFF and CodeView。

Here I should note that I'm listing only the relatively mainstream

versions of MS link. They've also produced versions that produce

various other formats of output, mostly for OS/2 and/or Windows 3.x

VxDs (e.g. LE and LX format).
这里我应该注视我的列表仅仅是主流版本的MS Link。还有另外的版本以处理多种

其他的输出格式,主要是为 OS/2 和/或 WIN3.X的VxD (比如 LE和 LX 格式)。
-----------------------------------------------------------------------


Linkers :: VAL

VALink is an old old linker that has been floating around for ages. It

is showing its age quite well.
VALink 是一种很老很老的连接器,似乎已遍布岁月的痕迹。它显示出它的年纪太

大了。

There exists an Enhnaced VALink that needs a review!
存在一种加强型的 VALink ,有待观察!

Pros
优点

Its free
免费
Supports makeing DOS/EXE files.
支持建立DOS/EXE文件

Cons
缺点

Can ONLY handle 16bit code.
只支持16位代码。

-----------------------------------------------------------------------


Linkers :: WLink (Watcom Linker)

WLink is the linker that comes with Watcom C/C++. Supports a wide range

of options and is flexable to a degree.
WLink来自于 Watcom C/C++。支持一长串选项和灵活的等级。

But it can be quite braindead at times and its support for generating

ELF files is broken and seriously flawed.
它已经消亡很长时间了,而且它支持生成ELF文件的功能有破坏性,是非常严重的

缺陷。

Pros
优点

Supports range of input formats, OMF/OBJ, Win32/COFF, ELF
支持很多输入格式,OMF/OBJ, Win32/COFF, ELF
Supports library files
支持库文件
Supports many output file formats from EXE, LE, Win32/PE, Novell NLM

files, Pharlap files, QNX, OS2, etc.
支持很多输出文件格式如,EXE, LE, Win32/PE, Novell NLM files, Pharlap

files, QNX, OS2, 等等.
Handles setting code offset address
能够设置代码的地址偏移。
Supports Watcom, Codeview and Dward debugging information
支持 Watcom, Codeview 和 Dward 调试信息。

Cons
缺点

ELF output is broken
ELF输出有破坏性

Cant do flat binary files
不能生成平坦型二进制文件