2 |
7u83 |
1 |
-*- indented-text -*-
|
|
|
2 |
|
|
|
3 |
The TDF Linker - Program Documentation: Linker Requirements
|
|
|
4 |
===========================================================
|
|
|
5 |
|
|
|
6 |
Written: April 1994
|
|
|
7 |
====================
|
|
|
8 |
|
|
|
9 |
Last Modified: July 1995
|
|
|
10 |
========================
|
|
|
11 |
|
|
|
12 |
Author: Steve Folkes
|
|
|
13 |
====================
|
|
|
14 |
|
|
|
15 |
Issue Number: 4.0
|
|
|
16 |
=================
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
1. INTRODUCTION
|
|
|
20 |
===============
|
|
|
21 |
|
|
|
22 |
This document describes the required behaviour of the TDF linker (although
|
|
|
23 |
sometimes it refers to what the linker actually does). It assumes that the
|
|
|
24 |
reader understands the format of TDF capsules and libraries, as described in
|
|
|
25 |
the document "File Formats" found in the file "001_files" in the same
|
|
|
26 |
directory as this.
|
|
|
27 |
|
|
|
28 |
2. PURPOSE
|
|
|
29 |
==========
|
|
|
30 |
|
|
|
31 |
The TDF linker has four uses:
|
|
|
32 |
|
|
|
33 |
- To bind together a number of TDF capsules (including those in
|
|
|
34 |
libraries) to produce a single capsule.
|
|
|
35 |
|
|
|
36 |
- To produce a TDF library from a set of capsules.
|
|
|
37 |
|
|
|
38 |
- To list the contents of a TDF library.
|
|
|
39 |
|
|
|
40 |
- To extract capsules from a TDF library.
|
|
|
41 |
|
|
|
42 |
The most complex part of the linker is the normal linking process, which is
|
|
|
43 |
described in the next section. Constructing libraries is described in the
|
|
|
44 |
section after the one on linking. Listing the contents of a library, and
|
|
|
45 |
extracting capsules from a library are not very complicated so they aren't
|
|
|
46 |
described in this document.
|
|
|
47 |
|
|
|
48 |
3. TDF LINKING
|
|
|
49 |
==============
|
|
|
50 |
|
|
|
51 |
This section describes the requirements of linking capsules together. The
|
|
|
52 |
first sub-section describes the basic linking requirements. Subsequent
|
|
|
53 |
sub-sections detail the requirements of some more advanced features.
|
|
|
54 |
|
|
|
55 |
Before the linking process is described in detail, here is an outline of the
|
|
|
56 |
stages of the link process:
|
|
|
57 |
|
|
|
58 |
The linker is invoked with the following inputs: a set of input
|
|
|
59 |
capsules, a set of libraries, a set of hiding rules, a set of keeping
|
|
|
60 |
rules, a set of renaming rules, and a set of link suppression rules.
|
|
|
61 |
|
|
|
62 |
The first thing that the linker does is to enter the renaming rules into
|
|
|
63 |
the name hash table. The name entry lookup routines will automatically
|
|
|
64 |
pick up the new name when a renamed name is looked up in a name table.
|
|
|
65 |
|
|
|
66 |
The next stage is to load the input capsules, and to bind them together.
|
|
|
67 |
As part of this binding process, the capsule scope identifiers for all
|
|
|
68 |
input capsules are mapped into a single capsule scope (to be output to
|
|
|
69 |
the final capsule). The rules for this mapping are described below.
|
|
|
70 |
|
|
|
71 |
After binding the input capsules together, the linker tries to provide
|
|
|
72 |
definitions for undefined names using the specified libraries. When a
|
|
|
73 |
definition is found in a library (and it hasn't been suppressed by the
|
|
|
74 |
link suppression rules), the capsule that contains it is loaded and
|
|
|
75 |
bound to the input capsules as if it had been one itself.
|
|
|
76 |
|
|
|
77 |
After the library capsules have been bound in, external names are hidden
|
|
|
78 |
according to the hiding rules, and kept according to the keeping rules.
|
|
|
79 |
Hiding means removing an entry from the external name list of the output
|
|
|
80 |
capsule. Keeping means forcing an entry into the list, if it would
|
|
|
81 |
otherwise be hidden. It is illegal to hide names that have no
|
|
|
82 |
definition.
|
|
|
83 |
|
|
|
84 |
Finally the output capsule is written to a file.
|
|
|
85 |
|
|
|
86 |
3.1 BASIC LINKING
|
|
|
87 |
-----------------
|
|
|
88 |
|
|
|
89 |
This sub-section describes the process of binding capsules together in
|
|
|
90 |
greater detail.
|
|
|
91 |
|
|
|
92 |
The first thing that the linker does when reading a capsule is to read in
|
|
|
93 |
the magic number, and the major and minor version numbers. Capsules with an
|
|
|
94 |
incorrect magic number are rejected. The major version number of each
|
|
|
95 |
capsule read in must be at least four. In addition, the major version
|
|
|
96 |
numbers of all capsules that are read in must be the same.
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
After this, the linker reads the unit group type names (also called "prop
|
|
|
100 |
names"), and checks that the they are known and that they are in the correct
|
|
|
101 |
order. There is a default list of names built into the linker (the list
|
|
|
102 |
specified in the TDF specification) and that should be sufficient for most
|
|
|
103 |
uses of the linker, but it is possible to provide a new list by specifying a
|
|
|
104 |
file containing the new list on the command line.
|
|
|
105 |
|
|
|
106 |
The next thing the linker does is to read in the linkable entity names and
|
|
|
107 |
the capsule scope identifier limit for each linkable entity. It checks that
|
|
|
108 |
there are no duplicate names, and creates a mapping vector for each linkable
|
|
|
109 |
entity, to contain the mapping from the capsule scope identifiers in the
|
|
|
110 |
capsule being read in to the capsule scope identifiers in the capsule that
|
|
|
111 |
will be written out.
|
|
|
112 |
|
|
|
113 |
After reading the linkable entity names, the linker reads the external names
|
|
|
114 |
for each linkable entity. For each name, it checks that its capsule scope
|
|
|
115 |
identifier is in range, and maps that to the next available capsule scope
|
|
|
116 |
identifier (for the same linkable entity) in the output capsule, unless a
|
|
|
117 |
name with the same linkable entity and the same name (subject to the
|
|
|
118 |
renaming rules) has already been read (in which case it is mapped to the
|
|
|
119 |
same capsule scope identifier as the identical name). The linker also
|
|
|
120 |
checks to ensure that each capsule scope identifier has no more than one
|
|
|
121 |
external name bound to it.
|
|
|
122 |
|
|
|
123 |
The final phase of reading a capsule is to read the unit groups. For normal
|
|
|
124 |
(i.e. not "tld" or "tld2") unit groups, the following occurs for each unit
|
|
|
125 |
in the unit group:
|
|
|
126 |
|
|
|
127 |
The unit scope identifier limits for each linkable entity are read and
|
|
|
128 |
saved in the unit data structure (which is appended to the list of units
|
|
|
129 |
in that unit group for all input capsules). When the unit is written
|
|
|
130 |
out in the output capsule, it may be necessary to add extra unit scope
|
|
|
131 |
identifier limits (and extra mapping tables) as other capsules may have
|
|
|
132 |
different linkable entities, which will also need entries (they will
|
|
|
133 |
just be zero length).
|
|
|
134 |
|
|
|
135 |
The capsule scope to unit scope identifier mapping tables are read, and
|
|
|
136 |
the old capsule scope identifier (which is first checked to see if it is
|
|
|
137 |
in range) is replaced by a new capsule scope identifier. This
|
|
|
138 |
information is also saved in the unit data structure. The new capsule
|
|
|
139 |
scope identifiers are either the ones that were allocated when reading
|
|
|
140 |
in the external names (if the old identifier is bound to an external
|
|
|
141 |
name), or the next free capsule scope identifier of the required
|
|
|
142 |
linkable entity.
|
|
|
143 |
|
|
|
144 |
Finally, the unit body is read, and saved with the unit.
|
|
|
145 |
|
|
|
146 |
For "tld" and "tld2" unit groups, the unit group count is checked to ensure
|
|
|
147 |
that it is one, and the number of unit scope identifier limits and
|
|
|
148 |
identifier mapping tables are checked to ensure that they are both zero.
|
|
|
149 |
The size of the body is read (and it must be correct as this is checked
|
|
|
150 |
after reading the unit), and then the body is read. If the unit is a "tld"
|
|
|
151 |
unit, then the type is read, and the body is read depending upon the type;
|
|
|
152 |
if the unit is a "tld2" unit, then the body is read as if it where a type
|
|
|
153 |
zero "tld" unit.
|
|
|
154 |
|
|
|
155 |
A type zero "tld" unit consists of a number of integers: one for each
|
|
|
156 |
external token name, followed by one for each external tag name (in the same
|
|
|
157 |
order as the external name tables, but tokens always precede tags). A type
|
|
|
158 |
one "tld" unit consists of a number of integers: one for each external name
|
|
|
159 |
(of all linkable entities), in the same order as the external name tables.
|
|
|
160 |
|
|
|
161 |
Each of the integers is interpreted as a series of bits, with the bits
|
|
|
162 |
having the following meanings:
|
|
|
163 |
|
|
|
164 |
BIT MEANING IF SET
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
|
|
|
168 |
1 The name is declared within this capsule.
|
|
|
169 |
|
|
|
170 |
2 The name is uniquely defined within this capsule. If
|
|
|
171 |
this bit is set for a tag, then the declared bit
|
|
|
172 |
must also be set. It is illegal to have a name
|
|
|
173 |
uniquely defined in more than one capsule. If this
|
|
|
174 |
occurs, the linker will report an error.
|
|
|
175 |
|
|
|
176 |
3 The name is defined in this capsule, but may have
|
|
|
177 |
other definitions provided by other capsules. This
|
|
|
178 |
bit may not be set for tokens. If a tag has this
|
|
|
179 |
bit set, the declared bit must also be set. It is
|
|
|
180 |
possible for a name to provide a unique definition,
|
|
|
181 |
but still allow other non-unique definitions to be
|
|
|
182 |
linked in from other capsules.
|
|
|
183 |
|
|
|
184 |
All of the other bits in the integer are reserved. The linker uses the
|
|
|
185 |
information provided by this unit to check that names do not have multiple
|
|
|
186 |
unique definitions, and to decide whether libraries should be consulted to
|
|
|
187 |
provide a definition for a name. If a capsule contains no linker
|
|
|
188 |
information unit group, then the names in that capsule will have no
|
|
|
189 |
information, and hence will not receive the extra checking or library
|
|
|
190 |
definition.
|
|
|
191 |
|
|
|
192 |
3.2 RENAMING
|
|
|
193 |
------------
|
|
|
194 |
|
|
|
195 |
Renaming just requires that any occurrence of the name being renamed is
|
|
|
196 |
treated as though it were an occurrence of the name it is being renamed to.
|
|
|
197 |
This includes names read from library indices.
|
|
|
198 |
|
|
|
199 |
3.3 LIBRARY CAPSULES
|
|
|
200 |
--------------------
|
|
|
201 |
|
|
|
202 |
After reading in all of the specified capsules, the linker loads the
|
|
|
203 |
libraries. The library indices are read, and checked to ensure that there
|
|
|
204 |
is no more than one definition for any external name. If there is no unique
|
|
|
205 |
definition, but there is a single multiple definition, then this is
|
|
|
206 |
considered to be a definition (although this can be turned off with a
|
|
|
207 |
command line option).
|
|
|
208 |
|
|
|
209 |
Once the libraries have been loaded, each of the external names in the bound
|
|
|
210 |
capsules that are used, but not defined are looked up in the library index.
|
|
|
211 |
If a definition is found (and it hasn't been suppressed) then the defining
|
|
|
212 |
capsule is loaded from the library. This process is repeated until
|
|
|
213 |
definitions have been found for all external names that need them (and that
|
|
|
214 |
definitions exist for), including those that are undefined in the capsules
|
|
|
215 |
read in from the libraries.
|
|
|
216 |
|
|
|
217 |
3.4 HIDING
|
|
|
218 |
----------
|
|
|
219 |
|
|
|
220 |
Hiding and keeping just require that all names which should be hidden, and
|
|
|
221 |
are not required to be kept, are not written to the external name table of
|
|
|
222 |
the output capsule.
|
|
|
223 |
|
|
|
224 |
3.5 WRITING OUT THE CAPSULE
|
|
|
225 |
---------------------------
|
|
|
226 |
|
|
|
227 |
The magic number is written out, followed by the major and minor version
|
|
|
228 |
numbers. The major version number is the same as that in each of the loaded
|
|
|
229 |
capsules. The minor version number is the largest of the minor version
|
|
|
230 |
numbers in the loaded capsules.
|
|
|
231 |
|
|
|
232 |
The unit group type names are written out first. Only those unit groups
|
|
|
233 |
that are non-empty are actually written out. They are written out in the
|
|
|
234 |
order specified by the current unit group name list.
|
|
|
235 |
|
|
|
236 |
The linkable entity names are written out next, followed by their capsule
|
|
|
237 |
scope identifier limit. Again, only those linkable entity names that are
|
|
|
238 |
non empty (i.e. have some unit scope or capsule scope identifiers) are
|
|
|
239 |
written out.
|
|
|
240 |
|
|
|
241 |
After the linkable entity names have been written out, the external names
|
|
|
242 |
are written out. These are written out in an arbitrary order within their
|
|
|
243 |
linkable entities, with the linkable entities being written out in the same
|
|
|
244 |
order as in the linkable entity name section (which is itself arbitrary, but
|
|
|
245 |
must be repeatable). The names are written out with their new capsule scope
|
|
|
246 |
identifiers. External names that have been hidden must not be written out.
|
|
|
247 |
|
|
|
248 |
Finally the unit groups are written out in the same order as the unit group
|
|
|
249 |
type names in the first section. For normal units, the old counts (plus
|
|
|
250 |
some zero counts that may be necessary if there are new linkable entities
|
|
|
251 |
that weren't in the unit's original capsule) are written out in the same
|
|
|
252 |
order as the linkable entity names in section two. The counts are followed
|
|
|
253 |
by the new capsule scope to unit scope identifier mapping tables, in the
|
|
|
254 |
same order as the counts. Finally the old unit content is written out.
|
|
|
255 |
|
|
|
256 |
For "tld" unit groups, a single version one "tld" unit is written out
|
|
|
257 |
containing the use information for each of the external names, in the same
|
|
|
258 |
order that the external names were written out in.
|
|
|
259 |
|
|
|
260 |
4. CONSTRUCTING TDF LIBRARIES
|
|
|
261 |
=============================
|
|
|
262 |
|
|
|
263 |
This section describes the requirements of building TDF libraries. Here is
|
|
|
264 |
an outline of the stages of the construction process:
|
|
|
265 |
|
|
|
266 |
The linker is invoked with the following inputs: a set of input
|
|
|
267 |
capsules, a set of libraries, and a set of link suppression rules.
|
|
|
268 |
|
|
|
269 |
The first thing that the linker does is to load the input capsules
|
|
|
270 |
(including all capsules that are included in any of the specified
|
|
|
271 |
libraries), and to extract their external name information into a
|
|
|
272 |
central index. The index is checked to ensure that there is only one
|
|
|
273 |
definition for any given name. The capsules are read in in the same way
|
|
|
274 |
as for linking them (this checks them for validity).
|
|
|
275 |
|
|
|
276 |
The suppression rules are applied, to ensure that no suppressed external
|
|
|
277 |
name will end up in the index in the output library.
|
|
|
278 |
|
|
|
279 |
The library is written out. The library consists of a magic number, and
|
|
|
280 |
the major and minor version numbers of the TDF in the library
|
|
|
281 |
(calculated in the same way as for capsules), the type zero, followed by
|
|
|
282 |
the number of capsules. This is followed by that many capsule name and
|
|
|
283 |
capsule content pairs. Finally, the index is appended to the library.
|
|
|
284 |
|
|
|
285 |
The index only contains entries for linkable entities that have external
|
|
|
286 |
names defined by the library. Only external names for which there is a
|
|
|
287 |
definition are written into the index, although this is not a
|
|
|
288 |
requirement (when linking, the linker will ignore index entries that
|
|
|
289 |
don't provide a definition). Either a unique definition or a single
|
|
|
290 |
multiple definition are considered to be definitions (although the
|
|
|
291 |
latter can be disabled using a command line option).
|