6 |
7u83 |
1 |
<?xml version="1.0" standalone="no"?>
|
|
|
2 |
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
|
|
3 |
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
|
|
4 |
|
|
|
5 |
<!--
|
|
|
6 |
$Id$
|
|
|
7 |
-->
|
|
|
8 |
|
|
|
9 |
<book>
|
|
|
10 |
<bookinfo>
|
|
|
11 |
<title>The TDF Linker</title>
|
|
|
12 |
|
|
|
13 |
<corpauthor>The TenDRA Project</corpauthor>
|
|
|
14 |
|
|
|
15 |
<author>
|
|
|
16 |
<firstname>Jeroen</firstname>
|
|
|
17 |
|
|
|
18 |
<surname>Ruigrok van der Werven</surname>
|
|
|
19 |
</author>
|
|
|
20 |
|
|
|
21 |
<authorinitials>JRvdW</authorinitials>
|
|
|
22 |
|
|
|
23 |
<pubdate>2006</pubdate>
|
|
|
24 |
|
|
|
25 |
<copyright>
|
|
|
26 |
<year>2006</year>
|
|
|
27 |
|
|
|
28 |
<holder>The TenDRA Project</holder>
|
|
|
29 |
</copyright>
|
|
|
30 |
|
|
|
31 |
<copyright>
|
|
|
32 |
<year>1998</year>
|
|
|
33 |
|
|
|
34 |
<holder>DERA</holder>
|
|
|
35 |
</copyright>
|
|
|
36 |
</bookinfo>
|
|
|
37 |
|
|
|
38 |
<chapter id="introduction">
|
|
|
39 |
<title>Introduction</title>
|
|
|
40 |
|
|
|
41 |
<para>This document describes the formats of the files used by the TDF
|
|
|
42 |
linker and the linker's required behaviour. There are two file formats:
|
|
|
43 |
the capsule format and the library format. It also describes the format
|
|
|
44 |
of the linker information units within capsules. The capsule format is
|
|
|
45 |
described in more detail in the TDF specification.</para>
|
|
|
46 |
</chapter>
|
|
|
47 |
|
|
|
48 |
<chapter id="basic-tdf-structures">
|
|
|
49 |
<title>Basic TDF structures</title>
|
|
|
50 |
|
|
|
51 |
<para>The structure of a TDF capsule is defined properly in the TDF
|
|
|
52 |
specification. This section describes the basic components of the TDF
|
|
|
53 |
format that the linker uses, and the remaining sections describe the
|
|
|
54 |
format of a TDF capsule, a TDF library and a linker information unit in
|
|
|
55 |
terms of these components. The basic components are:
|
|
|
56 |
|
|
|
57 |
<table id="tdf-components-and-their-meanings">
|
|
|
58 |
<title>TDF components and their meanings</title>
|
|
|
59 |
|
|
|
60 |
<tgroup cols="2">
|
|
|
61 |
<tbody>
|
|
|
62 |
<row>
|
|
|
63 |
<entry><code>ALIGN</code></entry>
|
|
|
64 |
|
|
|
65 |
<entry>This is a byte alignment. It forces the next object to
|
|
|
66 |
begin on an eight bit boundary.</entry>
|
|
|
67 |
</row>
|
|
|
68 |
|
|
|
69 |
<row>
|
|
|
70 |
<entry><code>TDFINT</code></entry>
|
|
|
71 |
|
|
|
72 |
<entry>This is an unsigned number of unbounded size. Its
|
|
|
73 |
representation is described properly in the TDF specification.
|
|
|
74 |
It is a series of nibbles (four bits), with the high bit used
|
|
|
75 |
as a terminator and the low three bits used as an octal digit.
|
|
|
76 |
The terminator bit is set on the final octal digit. As an
|
|
|
77 |
example, the number ten would be represented (in binary) as:
|
|
|
78 |
0001 1010.</entry>
|
|
|
79 |
</row>
|
|
|
80 |
|
|
|
81 |
<row>
|
|
|
82 |
<entry><code>BYTE</code></entry>
|
|
|
83 |
|
|
|
84 |
<entry>This is an eight bit quantity. <code>BYTE</code>s are
|
|
|
85 |
always aligned on an eight bit boundary.</entry>
|
|
|
86 |
</row>
|
|
|
87 |
|
|
|
88 |
<row>
|
|
|
89 |
<entry><code>TDFIDENT</code></entry>
|
|
|
90 |
|
|
|
91 |
<entry>A <code>TDFIDENT</code> is a sequence of characters. It
|
|
|
92 |
is possible to change the size of the characters, although the
|
|
|
93 |
current implementation will produce an error for
|
|
|
94 |
<code>TDFIDENT</code> s with character sizes other than eight
|
|
|
95 |
bits. A <code>TDFIDENT</code> is represented by two
|
|
|
96 |
<code>TDFINT</code>s (the size of the characters in bits and
|
|
|
97 |
the number of characters in the <code>TDFIDENT</code>), and a
|
|
|
98 |
sequence of <code>BYTE</code>s.</entry>
|
|
|
99 |
</row>
|
|
|
100 |
|
|
|
101 |
<row>
|
|
|
102 |
<entry><code>UNIQUE</code></entry>
|
|
|
103 |
|
|
|
104 |
<entry>A <code>UNIQUE</code> is a list of <code>TDFIDENT</code>
|
|
|
105 |
s. It is represented as a <code>TDFINT</code> specifying the
|
|
|
106 |
number of <code>TDFIDENT</code>s in the <code>UNIQUE</code>,
|
|
|
107 |
followed by that many <code>TDFIDENT</code>s.</entry>
|
|
|
108 |
</row>
|
|
|
109 |
|
|
|
110 |
<row>
|
|
|
111 |
<entry><code>EXTERNAL</code></entry>
|
|
|
112 |
|
|
|
113 |
<entry>An <code>EXTERNAL</code> is a mechanism for identifying
|
|
|
114 |
external identifiers. It is represented as a discriminating
|
|
|
115 |
tag, followed by a byte alignment, followed by either a
|
|
|
116 |
<code>TDFIDENT</code> or a <code>UNIQUE</code>. The tag is a
|
|
|
117 |
two bit number, where one represents a <code>TDFIDENT</code>,
|
|
|
118 |
two represents a <code>UNIQUE</code>, and zero and three are
|
|
|
119 |
currently illegal. <code>UNIQUE</code> s are only used as part
|
|
|
120 |
of an <code>EXTERNAL</code>; <code>TDFIDENT</code> s are used
|
|
|
121 |
as entities in their own right, as well as in
|
|
|
122 |
<code>EXTERNAL</code> s.</entry>
|
|
|
123 |
</row>
|
|
|
124 |
</tbody>
|
|
|
125 |
</tgroup>
|
|
|
126 |
</table>
|
|
|
127 |
</para>
|
|
|
128 |
|
|
|
129 |
<para>In the following descriptions, the syntax <token>name: type</token>
|
|
|
130 |
is used to specify an object in the structure. The <token>name</token>
|
|
|
131 |
is used to describe the purpose of the object; the <token>type</token>
|
|
|
132 |
is used to describe what the object is. A <token>type</token> is one of
|
|
|
133 |
the following:
|
|
|
134 |
|
|
|
135 |
<table id="token-types">
|
|
|
136 |
<title>Token types</title>
|
|
|
137 |
|
|
|
138 |
<tgroup cols="2">
|
|
|
139 |
<thead>
|
|
|
140 |
<row>
|
|
|
141 |
<entry>Type</entry>
|
|
|
142 |
|
|
|
143 |
<entry>Meaning</entry>
|
|
|
144 |
</row>
|
|
|
145 |
</thead>
|
|
|
146 |
|
|
|
147 |
<tbody>
|
|
|
148 |
<row>
|
|
|
149 |
<entry><token>basic_type</token></entry>
|
|
|
150 |
|
|
|
151 |
<entry>This represents one of the basic types listed
|
|
|
152 |
above.</entry>
|
|
|
153 |
</row>
|
|
|
154 |
|
|
|
155 |
<row>
|
|
|
156 |
<entry><token>type</token> * <token>integer</token></entry>
|
|
|
157 |
|
|
|
158 |
<entry>This represents a sequence of objects of the specified
|
|
|
159 |
type. The <token>integer</token> may be either an integer
|
|
|
160 |
literal, or a name that has been previously mentioned and is a
|
|
|
161 |
<code>TDFINT</code> object.</entry>
|
|
|
162 |
</row>
|
|
|
163 |
|
|
|
164 |
<row>
|
|
|
165 |
<entry>{ <token>name1</token>: <token>type1</token> ...
|
|
|
166 |
<token>nameN</token>: <token>typeN</token> }</entry>
|
|
|
167 |
|
|
|
168 |
<entry>This represents a structure composed of the elements
|
|
|
169 |
<token>name1: type1</token> to <token>nameN: typeN</token>.
|
|
|
170 |
It is used for sequences of objects where the objects are
|
|
|
171 |
not of basic types.</entry>
|
|
|
172 |
</row>
|
|
|
173 |
|
|
|
174 |
<row>
|
|
|
175 |
<entry><token>type</token> = ( <token>value1</token> | ... |
|
|
|
176 |
<token>valueN</token> )</entry>
|
|
|
177 |
|
|
|
178 |
<entry>This represents a type with a constraint imposed upon it.
|
|
|
179 |
The object value must be one of <token>value1</token> to
|
|
|
180 |
<token>valueN</token>.</entry>
|
|
|
181 |
</row>
|
|
|
182 |
</tbody>
|
|
|
183 |
</tgroup>
|
|
|
184 |
</table>
|
|
|
185 |
</para>
|
|
|
186 |
</chapter>
|
|
|
187 |
|
|
|
188 |
<chapter id="structure-of-a-tdf-capsule">
|
|
|
189 |
<title>Structure of a TDF Capsule</title>
|
|
|
190 |
|
|
|
191 |
<para>A TDF capsule has the following structure:
|
|
|
192 |
|
|
|
193 |
<programlisting>
|
|
|
194 |
magic BYTE * 4 = "TDFC"
|
|
|
195 |
major_version TDFINT
|
|
|
196 |
minor_version TDFINT
|
|
|
197 |
ALIGN
|
|
|
198 |
num_prop_names: TDFINT
|
|
|
199 |
prop_names: TDFIDENT * num_prop_names
|
|
|
200 |
num_linkable_entities: TDFINT
|
|
|
201 |
linkable_entities: {
|
|
|
202 |
name: TDFIDENT
|
|
|
203 |
num_capsule_scope_identifiers: TDFINT
|
|
|
204 |
} * num_linkable_entities
|
|
|
205 |
num_external_linkages: TDFINT = num_linkable_entities
|
|
|
206 |
external_linkages: {
|
|
|
207 |
num_entries: TDFINT
|
|
|
208 |
entries: {
|
|
|
209 |
capsule_scope_id: TDFINT
|
|
|
210 |
external_name: EXTERNAL
|
|
|
211 |
} * num_entries
|
|
|
212 |
} * num_external_linkages
|
|
|
213 |
num_unit_groups: TDFINT = num_prop_names
|
|
|
214 |
unit_groups: {
|
|
|
215 |
num_units: TDFINT
|
|
|
216 |
units: {
|
|
|
217 |
num_counts: TDFINT = (num_linkable_entities | 0)
|
|
|
218 |
counts: TDFINT * num_counts
|
|
|
219 |
num_link_sets: TDFINT = num_counts
|
|
|
220 |
link_sets: {
|
|
|
221 |
num_links: TDFINT
|
|
|
222 |
links: {
|
|
|
223 |
internal: TDFINT
|
|
|
224 |
external: TDFINT
|
|
|
225 |
} * num_links
|
|
|
226 |
} * num_link_sets
|
|
|
227 |
num_bytes_tdf: TDFINT
|
|
|
228 |
tdf: BYTE * num_bytes_tdf
|
|
|
229 |
} * num_units
|
|
|
230 |
} * num_unit_groups
|
|
|
231 |
</programlisting></para>
|
|
|
232 |
|
|
|
233 |
<para>The rest of this section describes the format of a capsule.</para>
|
|
|
234 |
|
|
|
235 |
<para>The capsule begins with a header that contains a four byte magic
|
|
|
236 |
number (<token>magic</token>: "TDFC"), followed by the major
|
|
|
237 |
(<token>major_version</token>) and minor (<token>minor_version</token>)
|
|
|
238 |
version numbers of the TDF in the capsule. This is then followed by a
|
|
|
239 |
byte alignment and then the the capsule body.</para>
|
|
|
240 |
|
|
|
241 |
<para>The first part of a capsule tells the linker how many types of unit
|
|
|
242 |
groups there are in the capsule (<token>num_prop_names</token>), and
|
|
|
243 |
what the names of these unit group types are
|
|
|
244 |
(<token>prop_names</token>). There can be many unit group types, but
|
|
|
245 |
the linker must know what they are called, and the order in which they
|
|
|
246 |
should occur. At present the linker knows about <token>tld</token>,
|
|
|
247 |
<token>tld2</token>, <token>versions</token>, <token>tokdec</token>,
|
|
|
248 |
<token>tokdef</token>, <token>aldef</token>, <token>diagtype</token>,
|
|
|
249 |
<token>tagdec</token>, <token>diagdef</token>, <token>tagdef</token> and
|
|
|
250 |
<token>linkinfo</token> (this can be changed from the command line).
|
|
|
251 |
There is nothing special about any unit group type except for the
|
|
|
252 |
<token>tld</token> unit group type, which contains information that the
|
|
|
253 |
linker uses (and the <token>tld2</token> unit group type, which is
|
|
|
254 |
obsolete, but is treated as a special case of the <token>tld</token>
|
|
|
255 |
unit group type). The format of the <token>tld</token> unit group type
|
|
|
256 |
is described in a later section.</para>
|
|
|
257 |
|
|
|
258 |
<para>The second part of the capsule tells the linker how many linkable
|
|
|
259 |
entities it should be linking on (<token>num_linkable_entities</token>),
|
|
|
260 |
the name of each linkable entity (<token>name</token>), and the number
|
|
|
261 |
of identifiers of each linkable entity at capsule scope
|
|
|
262 |
(<token>num_capsule_scope_identifiers</token>). Identifiers at capsule
|
|
|
263 |
scope should be numbers from zero to one less than
|
|
|
264 |
<token>num_capsule_scope_identifiers</token>. The identifier allocation
|
|
|
265 |
may be sparse, but the linker is optimized for continuous identifier
|
|
|
266 |
allocation.</para>
|
|
|
267 |
|
|
|
268 |
<para>The third part of the capsule tells the linker which external names
|
|
|
269 |
the capsule contains for each linkable entity. For each linkable entity
|
|
|
270 |
listed in the second part, the number of external names of that linkable
|
|
|
271 |
entity are listed in this part (<token>num_entries</token>), along with
|
|
|
272 |
each of the external names (<token>external_name</token>) and the
|
|
|
273 |
corresponding capsule scope identifiers
|
|
|
274 |
(<token>capsule_scope_id</token>). The ordering of the linkable entities
|
|
|
275 |
in part three must be identical to the ordering of linkable entities in
|
|
|
276 |
part two.</para>
|
|
|
277 |
|
|
|
278 |
<para>The fourth and final part of the capsule contains the unit groups
|
|
|
279 |
themselves. The unit groups occur in the same order as the unit group
|
|
|
280 |
types were listed in part one. For each unit group, there is a
|
|
|
281 |
<code>TDFINT</code> specifying the number of units in that unit group
|
|
|
282 |
(<token>num_units</token>), followed by that many units.</para>
|
|
|
283 |
|
|
|
284 |
<para>Each unit contains a list of counts (<token>counts</token>) and the
|
|
|
285 |
number of counts in that list (<token>num_counts</token>), which must be
|
|
|
286 |
either zero or the same as the number of linkable entities in the
|
|
|
287 |
capsule (<token>num_linkable_entities</token> ). Each count contains the
|
|
|
288 |
number of unit scope identifiers of the given linkable entity in the
|
|
|
289 |
unit. If the number of counts is non-zero, then the counts must be in
|
|
|
290 |
the same order as the linkable entity names.</para>
|
|
|
291 |
|
|
|
292 |
<para>After the counts come the unit scope identifier to capsule scope
|
|
|
293 |
identifier mapping tables. The number of these tables is specified by
|
|
|
294 |
<token>num_link_sets</token> and must be the same as the number of
|
|
|
295 |
counts (<token>num_counts</token>), which is either zero or the same as
|
|
|
296 |
the number of linkable entities in the capsule. There is one table for
|
|
|
297 |
each linkable entity (if <token>num_link_sets</token> is non-zero), and
|
|
|
298 |
each table contains <token>num_links</token> pairs of
|
|
|
299 |
<code>TDFINT</code>s. The <token>internal</token> <code>TDFINT</code> is
|
|
|
300 |
the unit scope identifier; the <token>external</token>
|
|
|
301 |
<code>TDFINT</code> is the capsule scope identifier.</para>
|
|
|
302 |
|
|
|
303 |
<para>After the mapping tables there is a length
|
|
|
304 |
(<token>num_bytes_tdf</token>), and that many bytes of TDF data
|
|
|
305 |
(<token>tdf</token>).</para>
|
|
|
306 |
</chapter>
|
|
|
307 |
|
|
|
308 |
<chapter id="linker-information-unit">
|
|
|
309 |
<title>Linker information unit groups</title>
|
|
|
310 |
|
|
|
311 |
<para>The <token>tld</token> unit group (if it exists in the capsule)
|
|
|
312 |
should contain one unit only. This unit should begin with two zeroes
|
|
|
313 |
(i.e. no counts, and no identifier mapping tables), a length (which must
|
|
|
314 |
be correct), and a sequence of bytes.</para>
|
|
|
315 |
|
|
|
316 |
<para>The bytes encode information useful to the linker. The first thing
|
|
|
317 |
in the byte sequence of a <token>tld</token> unit is a
|
|
|
318 |
<code>TDFINT</code> that is the type of the unit. What follows depends
|
|
|
319 |
upon the type. There are currently two types that are supported: zero
|
|
|
320 |
and one. Type zero units contain the same information as the old
|
|
|
321 |
<token>tld2</token> units (if a <token>tld2</token> unit is read, it is
|
|
|
322 |
treated as if it were a <token>tld</token> unit that began with a type
|
|
|
323 |
of zero; it is illegal for a capsule to contain both a
|
|
|
324 |
<token>tld</token> unit group and a <token>tld2</token> unit group).
|
|
|
325 |
Type one units contain more information (described below), and are what
|
|
|
326 |
the linker writes out in the generated capsule.</para>
|
|
|
327 |
|
|
|
328 |
<para>A version one unit contains a sequence of <code>TDFINT</code>s.
|
|
|
329 |
There is one <code>TDFINT</code> for each external name in part two of
|
|
|
330 |
the capsule. These <code>TDFINT</code>s should be in the same order as
|
|
|
331 |
the external names were. The <code>TDFINT</code>s are treated as a
|
|
|
332 |
sequence of bits, with the following meanings:
|
|
|
333 |
|
|
|
334 |
<table id="tdfint-bit-meanings">
|
|
|
335 |
<title>TDFINT bit meanings</title>
|
|
|
336 |
|
|
|
337 |
<tgroup cols="2">
|
|
|
338 |
<thead>
|
|
|
339 |
<row>
|
|
|
340 |
<entry>Bit</entry>
|
|
|
341 |
|
|
|
342 |
<entry>Meaning</entry>
|
|
|
343 |
</row>
|
|
|
344 |
</thead>
|
|
|
345 |
|
|
|
346 |
<tbody>
|
|
|
347 |
<row>
|
|
|
348 |
<entry>0</entry>
|
|
|
349 |
|
|
|
350 |
<entry>The name is used within this capsule.</entry>
|
|
|
351 |
</row>
|
|
|
352 |
|
|
|
353 |
<row>
|
|
|
354 |
<entry>1</entry>
|
|
|
355 |
|
|
|
356 |
<entry>The name is declared within this capsule.</entry>
|
|
|
357 |
</row>
|
|
|
358 |
|
|
|
359 |
<row>
|
|
|
360 |
<entry>2</entry>
|
|
|
361 |
|
|
|
362 |
<entry>The name is uniquely defined within this capsule. If this
|
|
|
363 |
bit is set for a tag, then the declared bit must also be set
|
|
|
364 |
(i.e. a declaration must exist).</entry>
|
|
|
365 |
</row>
|
|
|
366 |
|
|
|
367 |
<row>
|
|
|
368 |
<entry>3</entry>
|
|
|
369 |
|
|
|
370 |
<entry>The name is defined in this capsule, but may have other
|
|
|
371 |
definitions provided by other capsules. This bit may not be
|
|
|
372 |
set for tokens. If a tag has this bit set, then the declared
|
|
|
373 |
bit must also be set (i.e. a declaration must exist).</entry>
|
|
|
374 |
</row>
|
|
|
375 |
</tbody>
|
|
|
376 |
</tgroup>
|
|
|
377 |
</table>
|
|
|
378 |
</para>
|
|
|
379 |
|
|
|
380 |
<para>All of the other bits in the <code>TDFINT</code> are reserved. The
|
|
|
381 |
linker uses the information provided by this unit to check that names do
|
|
|
382 |
not have multiple unique definitions, and to decide whether libraries
|
|
|
383 |
should be consulted to provide a definition for an external name. If a
|
|
|
384 |
capsule contains no linker information unit group, then the external
|
|
|
385 |
names in that capsule will have no information, and hence these checks
|
|
|
386 |
will not be made. A similar situation arises when the information for a
|
|
|
387 |
name has no bits set.</para>
|
|
|
388 |
|
|
|
389 |
<para>A version zero unit contains a sequence of <code>TDFINT</code>s.
|
|
|
390 |
There is one <code>TDFINT</code> for each external token name, and one
|
|
|
391 |
<code>TDFINT</code> for each external tag name. These
|
|
|
392 |
<code>TDFINT</code>s should be in the same order as the external names
|
|
|
393 |
were (but the tokens always come before the tags). The
|
|
|
394 |
<code>TDFINT</code>s are treated as a sequence of bits, with the same
|
|
|
395 |
meanings as above.</para>
|
|
|
396 |
</chapter>
|
|
|
397 |
|
|
|
398 |
<chapter id="structure-of-a-tdf-library">
|
|
|
399 |
<title>Structure of a TDF library</title>
|
|
|
400 |
|
|
|
401 |
<para>A TDF library begins with a header, followed by a
|
|
|
402 |
<code>TDFINT</code>, that is the type of the library. At present only
|
|
|
403 |
type zero libraries are supported. The format of a type zero library is
|
|
|
404 |
as follows:
|
|
|
405 |
|
|
|
406 |
<programlisting>
|
|
|
407 |
magic: BYTE * 4 = "TDFL"
|
|
|
408 |
major_version: TDFINT
|
|
|
409 |
minor_version: TDFINT
|
|
|
410 |
ALIGN
|
|
|
411 |
type: TDFINT = 0
|
|
|
412 |
num_capsules: TDFINT
|
|
|
413 |
capsules: {
|
|
|
414 |
capsule_name: TDFIDENT
|
|
|
415 |
capsule_length: TDFINT
|
|
|
416 |
capsule_body: BYTE * capsule_length
|
|
|
417 |
} * num_capsules
|
|
|
418 |
num_linkable_entities: TDFINT
|
|
|
419 |
linkable_entities: {
|
|
|
420 |
linkable_entity_name: TDFIDENT
|
|
|
421 |
num_this_linkable_entity: TDFINT
|
|
|
422 |
this_linkable_entity_names: {
|
|
|
423 |
name: EXTERNAL
|
|
|
424 |
info: TDFINT
|
|
|
425 |
capsule: TDFINT
|
|
|
426 |
} * num_this_linkable_entity
|
|
|
427 |
} * num_linkable_entities
|
|
|
428 |
</programlisting></para>
|
|
|
429 |
|
|
|
430 |
<para>The library begins with a four byte magic number
|
|
|
431 |
(<token>magic</token>: "TDFL"), followed by the major
|
|
|
432 |
(<token>major_version</token>) and minor (<token>minor_version</token>)
|
|
|
433 |
versions of the TDF in the library (the major version must be the same
|
|
|
434 |
for each capsule in the library; the minor version is the highest of the
|
|
|
435 |
minor version numbers of all of the the capsules contained in the
|
|
|
436 |
library). This is followed by a byte alignment, the type of the library
|
|
|
437 |
(<token>type</token>: 0), and the number of capsules in the library
|
|
|
438 |
(<token>num_capsules</token>), followed by that many capsules.</para>
|
|
|
439 |
|
|
|
440 |
<para>Each of the <token>capsules</token> has a name
|
|
|
441 |
(<token>capsule_name</token>), and the capsule content, which consists
|
|
|
442 |
of the length of the capsule (<token>capsule_length</token> ) and that
|
|
|
443 |
many bytes (<token>capsule_body</token>). The capsule name is the name
|
|
|
444 |
of the file from which the capsule was obtained when the library was
|
|
|
445 |
built. The names of capsules within a library must all be
|
|
|
446 |
different.</para>
|
|
|
447 |
|
|
|
448 |
<para>The library is terminated by the index. This contains information
|
|
|
449 |
about where to find definitions for external names. The index begins
|
|
|
450 |
with the number of linkable entities whose external names the library
|
|
|
451 |
will provide definitions for
|
|
|
452 |
(<token>num_linkable_entities</token>).</para>
|
|
|
453 |
|
|
|
454 |
<para>For each of these linkable entities, the linkable entity index
|
|
|
455 |
begins with the name of the linkable entity
|
|
|
456 |
(<token>linkable_entity_name</token>), followed by the number of
|
|
|
457 |
external names of the linkable entity that have entries in the index
|
|
|
458 |
(<token>num_this_linkable_entity</token>). This is followed by the index
|
|
|
459 |
information for each of the names.</para>
|
|
|
460 |
|
|
|
461 |
<para>For each name, the index contains the name (<token>name</token>); a
|
|
|
462 |
<code>TDFINT</code> that provides information about the name
|
|
|
463 |
(<token>info</token>) with the same meaning as the <code>TDFINT</code>s
|
|
|
464 |
in the linker information units; and the index of the capsule that
|
|
|
465 |
contains the definition for the name (<token>capsule</token>). The index
|
|
|
466 |
of the first capsule is zero.</para>
|
|
|
467 |
</chapter>
|
|
|
468 |
|
|
|
469 |
<chapter id="purpose">
|
|
|
470 |
<title>Purpose</title>
|
|
|
471 |
|
|
|
472 |
<para>The TDF linker has four uses:
|
|
|
473 |
|
|
|
474 |
<itemizedlist>
|
|
|
475 |
<listitem>
|
|
|
476 |
<para>To bind together a number of TDF capsules (including those in
|
|
|
477 |
libraries) to produce a single capsule.</para>
|
|
|
478 |
</listitem>
|
|
|
479 |
|
|
|
480 |
<listitem>
|
|
|
481 |
<para>To produce a TDF library from a set of capsules.</para>
|
|
|
482 |
</listitem>
|
|
|
483 |
|
|
|
484 |
<listitem>
|
|
|
485 |
<para>To list the contents of a TDF library.</para>
|
|
|
486 |
</listitem>
|
|
|
487 |
|
|
|
488 |
<listitem>
|
|
|
489 |
<para>To extract capsules from a TDF library.</para>
|
|
|
490 |
</listitem>
|
|
|
491 |
</itemizedlist></para>
|
|
|
492 |
|
|
|
493 |
<para>The most complex part of the linker is the normal linking process,
|
|
|
494 |
which is described in the next section. Constructing libraries is
|
|
|
495 |
described in the section after the one on linking. Listing the contents
|
|
|
496 |
of a library, and extracting capsules from a library are not very
|
|
|
497 |
complicated so they aren't described in this document.</para>
|
|
|
498 |
</chapter>
|
|
|
499 |
|
|
|
500 |
<chapter id="tdf-linking">
|
|
|
501 |
<title>TDF Linking</title>
|
|
|
502 |
|
|
|
503 |
<para>This section describes the requirements of linking capsules
|
|
|
504 |
together. The first sub-section describes the basic linking
|
|
|
505 |
requirements. Subsequent sub-sections detail the requirements of
|
|
|
506 |
some more advanced features.</para>
|
|
|
507 |
|
|
|
508 |
<para>Before the linking process is described in detail, here is an
|
|
|
509 |
outline of the stages of the link process:
|
|
|
510 |
|
|
|
511 |
<itemizedlist>
|
|
|
512 |
<listitem>
|
|
|
513 |
<para>The linker is invoked with the following inputs: a set of
|
|
|
514 |
input capsules, a set of libraries, a set of hiding rules, a set
|
|
|
515 |
of keeping rules, a set of renaming rules, and a set of link
|
|
|
516 |
suppression rules.</para>
|
|
|
517 |
</listitem>
|
|
|
518 |
|
|
|
519 |
<listitem>
|
|
|
520 |
<para>The first thing that the linker does is to enter the renaming
|
|
|
521 |
rules into the name hash table. The name entry lookup routines
|
|
|
522 |
will automatically pick up the new name when a renamed name is
|
|
|
523 |
looked up in a name table.</para>
|
|
|
524 |
</listitem>
|
|
|
525 |
|
|
|
526 |
<listitem>
|
|
|
527 |
<para>The next stage is to load the input capsules, and to bind them
|
|
|
528 |
together. As part of this binding process, the capsule scope
|
|
|
529 |
identifiers for all input capsules are mapped into a single
|
|
|
530 |
capsule scope (to be output to the final capsule). The rules for
|
|
|
531 |
this mapping are described below.</para>
|
|
|
532 |
</listitem>
|
|
|
533 |
|
|
|
534 |
<listitem>
|
|
|
535 |
<para>After binding the input capsules together, the linker tries to
|
|
|
536 |
provide definitions for undefined names using the specified
|
|
|
537 |
libraries. When a definition is found in a library (and it hasn't
|
|
|
538 |
been suppressed by the link suppression rules), the capsule that
|
|
|
539 |
contains it is loaded and bound to the input capsules as if it had
|
|
|
540 |
been one itself.</para>
|
|
|
541 |
</listitem>
|
|
|
542 |
|
|
|
543 |
<listitem>
|
|
|
544 |
<para>After the library capsules have been bound in, external names
|
|
|
545 |
are hidden according to the hiding rules, and kept according to
|
|
|
546 |
the keeping rules. Hiding means removing an entry from the
|
|
|
547 |
external name list of the output capsule. Keeping means forcing an
|
|
|
548 |
entry into the list, if it would otherwise be hidden. It is
|
|
|
549 |
illegal to hide names that have no definition.</para>
|
|
|
550 |
</listitem>
|
|
|
551 |
|
|
|
552 |
<listitem>
|
|
|
553 |
<para>Finally the output capsule is written to a file.</para>
|
|
|
554 |
</listitem>
|
|
|
555 |
</itemizedlist></para>
|
|
|
556 |
|
|
|
557 |
<sect1 id="basic-linking">
|
|
|
558 |
<title>Basic linking</title>
|
|
|
559 |
|
|
|
560 |
<para>This sub-section describes the process of binding capsules
|
|
|
561 |
together in greater detail.</para>
|
|
|
562 |
|
|
|
563 |
<para>The first thing that the linker does when reading a capsule is to
|
|
|
564 |
read in the magic number, and the major and minor version numbers.
|
|
|
565 |
Capsules with an incorrect magic number are rejected. The major
|
|
|
566 |
version number of each capsule read in must be at least four. In
|
|
|
567 |
addition, the major version numbers of all capsules that are read in
|
|
|
568 |
must be the same.</para>
|
|
|
569 |
|
|
|
570 |
<para>After this, the linker reads the unit group type names (also
|
|
|
571 |
called `prop names'), and checks that the they are known and that they
|
|
|
572 |
are in the correct order. There is a default list of names built into
|
|
|
573 |
the linker (the list specified in the TDF specification) and that
|
|
|
574 |
should be sufficient for most uses of the linker, but it is possible
|
|
|
575 |
to provide a new list by specifying a file containing the new list on
|
|
|
576 |
the command line.</para>
|
|
|
577 |
|
|
|
578 |
<para>The next thing the linker does is to read in the linkable entity
|
|
|
579 |
names and the capsule scope identifier limit for each linkable entity.
|
|
|
580 |
It checks that there are no duplicate names, and creates a mapping
|
|
|
581 |
vector for each linkable entity, to contain the mapping from the
|
|
|
582 |
capsule scope identifiers in the capsule being read in to the capsule
|
|
|
583 |
scope identifiers in the capsule that will be written out.</para>
|
|
|
584 |
|
|
|
585 |
<para>After reading the linkable entity names, the linker reads the
|
|
|
586 |
external names for each linkable entity. For each name, it checks that
|
|
|
587 |
its capsule scope identifier is in range, and maps that to the next
|
|
|
588 |
available capsule scope identifier (for the same linkable entity) in
|
|
|
589 |
the output capsule, unless a name with the same linkable entity and
|
|
|
590 |
the same name (subject to the renaming rules) has already been read
|
|
|
591 |
(in which case it is mapped to the same capsule scope identifier as
|
|
|
592 |
the identical name). The linker also checks to ensure that each
|
|
|
593 |
capsule scope identifier has no more than one external name bound to
|
|
|
594 |
it.</para>
|
|
|
595 |
|
|
|
596 |
<para>The final phase of reading a capsule is to read the unit groups.
|
|
|
597 |
For normal (i.e. not <token>tld</token> or <token>tld2</token>) unit
|
|
|
598 |
groups, the following occurs for each unit in the unit group:
|
|
|
599 |
|
|
|
600 |
<itemizedlist>
|
|
|
601 |
<listitem>
|
|
|
602 |
<para>The unit scope identifier limits for each linkable entity
|
|
|
603 |
are read and saved in the unit data structure (which is appended
|
|
|
604 |
to the list of units in that unit group for all input capsules).
|
|
|
605 |
When the unit is written out in the output capsule, it may be
|
|
|
606 |
necessary to add extra unit scope identifier limits (and extra
|
|
|
607 |
mapping tables) as other capsules may have different linkable
|
|
|
608 |
entities, which will also need entries (they will just be zero
|
|
|
609 |
length).</para>
|
|
|
610 |
</listitem>
|
|
|
611 |
|
|
|
612 |
<listitem>
|
|
|
613 |
<para>The capsule scope to unit scope identifier mapping tables
|
|
|
614 |
are read, and the old capsule scope identifier (which is first
|
|
|
615 |
checked to see if it is in range) is replaced by a new capsule
|
|
|
616 |
scope identifier. This information is also saved in the unit
|
|
|
617 |
data structure. The new capsule scope identifiers are either the
|
|
|
618 |
ones that were allocated when reading in the external names (if
|
|
|
619 |
the old identifier is bound to an external name), or the next
|
|
|
620 |
free capsule scope identifier of the required linkable
|
|
|
621 |
entity.</para>
|
|
|
622 |
</listitem>
|
|
|
623 |
|
|
|
624 |
<listitem>
|
|
|
625 |
<para>Finally, the unit body is read, and saved with the
|
|
|
626 |
unit.</para>
|
|
|
627 |
</listitem>
|
|
|
628 |
</itemizedlist></para>
|
|
|
629 |
|
|
|
630 |
<para>For <token>tld</token> and <token>tld2</token> unit groups, the
|
|
|
631 |
unit group count is checked to ensure that it is one, and the number
|
|
|
632 |
of unit scope identifier limits and identifier mapping tables are
|
|
|
633 |
checked to ensure that they are both zero. The size of the body is
|
|
|
634 |
read (and it must be correct as this is checked after reading the
|
|
|
635 |
unit), and then the body is read. If the unit is a <token>tld</token>
|
|
|
636 |
unit, then the type is read, and the body is read depending upon the
|
|
|
637 |
type; if the unit is a <token>tld2</token> unit, then the body is read
|
|
|
638 |
as if it where a type zero <token>tld</token> unit.</para>
|
|
|
639 |
|
|
|
640 |
<para>A type zero <token>tld</token> unit consists of a number of
|
|
|
641 |
integers: one for each external token name, followed by one for each
|
|
|
642 |
external tag name (in the same order as the external name tables, but
|
|
|
643 |
tokens always precede tags). A type one <token>tld</token> unit
|
|
|
644 |
consists of a number of integers: one for each external name (of all
|
|
|
645 |
linkable entities), in the same order as the external name
|
|
|
646 |
tables.</para>
|
|
|
647 |
|
|
|
648 |
<para>Each of the integers is interpreted as a series of bits, with the
|
|
|
649 |
bits having the following meanings:
|
|
|
650 |
|
|
|
651 |
<table id="type-zero-unit-integer-meanings">
|
|
|
652 |
<title>Type zero unit integer meanings</title>
|
|
|
653 |
|
|
|
654 |
<tgroup cols="2">
|
|
|
655 |
<thead>
|
|
|
656 |
<row>
|
|
|
657 |
<entry>Bit</entry>
|
|
|
658 |
|
|
|
659 |
<entry>Meaning</entry>
|
|
|
660 |
</row>
|
|
|
661 |
</thead>
|
|
|
662 |
|
|
|
663 |
<tbody>
|
|
|
664 |
<row>
|
|
|
665 |
<entry>0</entry>
|
|
|
666 |
|
|
|
667 |
<entry>The name is used within this capsule.</entry>
|
|
|
668 |
</row>
|
|
|
669 |
|
|
|
670 |
<row>
|
|
|
671 |
<entry>1</entry>
|
|
|
672 |
|
|
|
673 |
<entry>The name is declared within this capsule.</entry>
|
|
|
674 |
</row>
|
|
|
675 |
|
|
|
676 |
<row>
|
|
|
677 |
<entry>2</entry>
|
|
|
678 |
|
|
|
679 |
<entry>The name is uniquely defined within this capsule. If
|
|
|
680 |
this bit is set for a tag, then the declared bit must also
|
|
|
681 |
be set. It is illegal to have a name uniquely defined in
|
|
|
682 |
more than one capsule. If this occurs, the linker will
|
|
|
683 |
report an error.</entry>
|
|
|
684 |
</row>
|
|
|
685 |
|
|
|
686 |
<row>
|
|
|
687 |
<entry>3</entry>
|
|
|
688 |
|
|
|
689 |
<entry>The name is defined in this capsule, but may have other
|
|
|
690 |
definitions provided by other capsules. This bit may not be
|
|
|
691 |
set for tokens. If a tag has this bit set, the declared bit
|
|
|
692 |
must also be set. It is possible for a name to provide a
|
|
|
693 |
unique definition, but still allow other non-unique
|
|
|
694 |
definitions to be linked in from other capsules.</entry>
|
|
|
695 |
</row>
|
|
|
696 |
</tbody>
|
|
|
697 |
</tgroup>
|
|
|
698 |
</table>
|
|
|
699 |
</para>
|
|
|
700 |
|
|
|
701 |
<para>All of the other bits in the integer are reserved. The linker
|
|
|
702 |
uses the information provided by this unit to check that names do not
|
|
|
703 |
have multiple unique definitions, and to decide whether libraries
|
|
|
704 |
should be consulted to provide a definition for a name. If a capsule
|
|
|
705 |
contains no linker information unit group, then the names in that
|
|
|
706 |
capsule will have no information, and hence will not receive the extra
|
|
|
707 |
checking or library definition.</para>
|
|
|
708 |
</sect1>
|
|
|
709 |
|
|
|
710 |
<sect1 id="renaming">
|
|
|
711 |
<title>Renaming</title>
|
|
|
712 |
|
|
|
713 |
<para>Renaming just requires that any occurrence of the name being
|
|
|
714 |
renamed is treated as though it were an occurrence of the name it is
|
|
|
715 |
being renamed to. This includes names read from library
|
|
|
716 |
indices.</para>
|
|
|
717 |
</sect1>
|
|
|
718 |
|
|
|
719 |
<sect1 id="library-capsules">
|
|
|
720 |
<title>Library capsules</title>
|
|
|
721 |
|
|
|
722 |
<para>After reading in all of the specified capsules, the linker loads
|
|
|
723 |
the libraries. The library indices are read, and checked to ensure
|
|
|
724 |
that there is no more than one definition for any external name. If
|
|
|
725 |
there is no unique definition, but there is a single multiple
|
|
|
726 |
definition, then this is considered to be a definition (although this
|
|
|
727 |
can be turned off with a command line option).</para>
|
|
|
728 |
|
|
|
729 |
<para>Once the libraries have been loaded, each of the external names in
|
|
|
730 |
the bound capsules that are used, but not defined are looked up in the
|
|
|
731 |
library index. If a definition is found (and it hasn't been
|
|
|
732 |
suppressed) then the defining capsule is loaded from the library. This
|
|
|
733 |
process is repeated until definitions have been found for all external
|
|
|
734 |
names that need them (and that definitions exist for), including those
|
|
|
735 |
that are undefined in the capsules read in from the libraries.</para>
|
|
|
736 |
</sect1>
|
|
|
737 |
|
|
|
738 |
<sect1 id="hiding">
|
|
|
739 |
<title>Hiding</title>
|
|
|
740 |
|
|
|
741 |
<para>Hiding and keeping just require that all names which should be
|
|
|
742 |
hidden, and are not required to be kept, are not written to the
|
|
|
743 |
external name table of the output capsule.</para>
|
|
|
744 |
</sect1>
|
|
|
745 |
|
|
|
746 |
<sect1 id="writing-out-the-capsule">
|
|
|
747 |
<title>Writing out the capsule</title>
|
|
|
748 |
|
|
|
749 |
<para>The magic number is written out, followed by the major and minor
|
|
|
750 |
version numbers. The major version number is the same as that in each
|
|
|
751 |
of the loaded capsules. The minor version number is the largest of the
|
|
|
752 |
minor version numbers in the loaded capsules.</para>
|
|
|
753 |
|
|
|
754 |
<para>The unit group type names are written out first. Only those unit
|
|
|
755 |
groups that are non-empty are actually written out. They are written
|
|
|
756 |
out in the order specified by the current unit group name list.</para>
|
|
|
757 |
|
|
|
758 |
<para>The linkable entity names are written out next, followed by their
|
|
|
759 |
capsule scope identifier limit. Again, only those linkable entity
|
|
|
760 |
names that are non empty (i.e. have some unit scope or capsule scope
|
|
|
761 |
identifiers) are written out.</para>
|
|
|
762 |
|
|
|
763 |
<para>After the linkable entity names have been written out, the
|
|
|
764 |
external names are written out. These are written out in an arbitrary
|
|
|
765 |
order within their linkable entities, with the linkable entities being
|
|
|
766 |
written out in the same order as in the linkable entity name section
|
|
|
767 |
(which is itself arbitrary, but must be repeatable). The names are
|
|
|
768 |
written out with their new capsule scope identifiers. External names
|
|
|
769 |
that have been hidden must not be written out.</para>
|
|
|
770 |
|
|
|
771 |
<para>Finally the unit groups are written out in the same order as the
|
|
|
772 |
unit group type names in the first section. For normal units, the old
|
|
|
773 |
counts (plus some zero counts that may be necessary if there are new
|
|
|
774 |
linkable entities that weren't in the unit's original capsule) are
|
|
|
775 |
written out in the same order as the linkable entity names in section
|
|
|
776 |
two. The counts are followed by the new capsule scope to unit scope
|
|
|
777 |
identifier mapping tables, in the same order as the counts. Finally
|
|
|
778 |
the old unit content is written out.</para>
|
|
|
779 |
|
|
|
780 |
<para>For <token>tld</token> unit groups, a single version one
|
|
|
781 |
<token>tld</token> unit is written out containing the use information
|
|
|
782 |
for each of the external names, in the same order that the external
|
|
|
783 |
names were written out in.</para>
|
|
|
784 |
</sect1>
|
|
|
785 |
</chapter>
|
|
|
786 |
|
|
|
787 |
<chapter id="constructing-tdf-libraries">
|
|
|
788 |
<title>Constructing TDF Libraries</title>
|
|
|
789 |
|
|
|
790 |
<para>This section describes the requirements of building TDF libraries.
|
|
|
791 |
Here is an outline of the stages of the construction process:</para>
|
|
|
792 |
|
|
|
793 |
<itemizedlist>
|
|
|
794 |
<listitem>
|
|
|
795 |
<para>The linker is invoked with the following inputs: a set of input
|
|
|
796 |
capsules, a set of libraries, and a set of link suppression
|
|
|
797 |
rules.</para>
|
|
|
798 |
</listitem>
|
|
|
799 |
|
|
|
800 |
<listitem>
|
|
|
801 |
<para>The first thing that the linker does is to load the input capsules
|
|
|
802 |
(including all capsules that are included in any of the specified
|
|
|
803 |
libraries), and to extract their external name information into a
|
|
|
804 |
central index. The index is checked to ensure that there is only one
|
|
|
805 |
definition for any given name. The capsules are read in in the same
|
|
|
806 |
way as for linking them (this checks them for validity).</para>
|
|
|
807 |
</listitem>
|
|
|
808 |
|
|
|
809 |
<listitem>
|
|
|
810 |
<para>The suppression rules are applied, to ensure that no suppressed
|
|
|
811 |
external name will end up in the index in the output library.</para>
|
|
|
812 |
</listitem>
|
|
|
813 |
|
|
|
814 |
<listitem>
|
|
|
815 |
<para>The library is written out. The library consists of a magic
|
|
|
816 |
number, and the major and minor version numbers of the TDF in the
|
|
|
817 |
library (calculated in the same way as for capsules), the type zero,
|
|
|
818 |
followed by the number of capsules. This is followed by that many
|
|
|
819 |
capsule name and capsule content pairs. Finally, the index is appended
|
|
|
820 |
to the library.</para>
|
|
|
821 |
</listitem>
|
|
|
822 |
|
|
|
823 |
<listitem>
|
|
|
824 |
<para>The index only contains entries for linkable entities that have
|
|
|
825 |
external names defined by the library. Only external names for which
|
|
|
826 |
there is a definition are written into the index, although this is not
|
|
|
827 |
a requirement (when linking, the linker will ignore index entries that
|
|
|
828 |
don't provide a definition). Either a unique definition or a single
|
|
|
829 |
multiple definition are considered to be definitions (although the
|
|
|
830 |
latter can be disabled using a command line option).</para>
|
|
|
831 |
</listitem>
|
|
|
832 |
</itemizedlist>
|
|
|
833 |
</chapter>
|
|
|
834 |
</book>
|