Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
-*- indented-text -*-
2
 
3
	    The TDF Linker - Program Documentation: File Formats
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
1. INTRODUCTION
19
===============
20
 
21
This document describes the formats of the files used by the TDF linker.
22
There are two file formats: the capsule format and the library format.  It
23
also describes the format of the linker information units within capsules.
24
The capsule format is described in more detail in the TDF specification.
25
 
26
2. BASIC TDF STRUCTURES
27
=======================
28
 
29
The structure of a TDF capsule is defined properly in the TDF specification.
30
This section describes the basic components of the TDF format that the
31
linker uses, and the remaining sections describe the format of a TDF
32
capsule, a TDF library and a linker information unit in terms of these
33
components.  The basic components are:
34
 
35
	ALIGN
36
 
37
		This is a byte alignment.  It forces the next object to
38
		begin on an eight bit boundary.
39
 
40
	TDFINT
41
 
42
		This is an unsigned number of unbounded size.  Its
43
		representation is described properly in the TDF
44
		specification.  It is a series of nibbles (four bits), with
45
		the high bit used as a terminator and the low three bits
46
		used as an octal digit.  The terminator bit is set on the
47
		final octal digit.  As an example, the number ten would be
48
		represented (in binary) as: 0001 1010.
49
 
50
	BYTE
51
 
52
		This is an eight bit quantity.  BYTEs are always aligned on
53
		an eight bit boundary.
54
 
55
	TDFIDENT
56
 
57
		A TDFIDENT is a sequence of characters.  It is possible to
58
		change the size of the characters, although the current
59
		implementation will produce an error for TDFIDENTs with
60
		character sizes other than eight bits.  A TDFIDENT is
61
		represented by two TDFINTs (the size of the characters in
62
		bits and the number of characters in the TDFIDENT), and a
63
		sequence of BYTEs.
64
 
65
	UNIQUE
66
 
67
		A UNIQUE is a list of TDFIDENTs.  It is represented as a
68
		TDFINT specifying the number of TDFIDENTs in the UNIQUE,
69
		followed by that many TDFIDENTs.
70
 
71
	EXTERNAL
72
 
73
		An EXTERNAL is a mechanism for identifying external
74
		identifiers.  It is represented as a discriminating tag,
75
		followed by a byte ALIGNment, followed by either a TDFIDENT
76
		or a UNIQUE.  The tag is a two bit number, where one
77
		represents a TDFIDENT, two represents a UNIQUE, and zero and
78
		three are currently illegal.  UNIQUEs are only used as part
79
		of an EXTERNAL; TDFIDENTs are used as entities in their own
80
		right, as well as in EXTERNALs.
81
 
82
In the following descriptions, the syntax "<name>: <type>" is used to
83
specify an object in the structure.  The "<name>" is used to describe the
84
purpose of the object; the "<type>" is used to describe what the object
85
is.  A "<type>" is one of the following:
86
 
87
	<basic_type>
88
 
89
		This represents one of the basic types listed above.
90
 
91
	<type> * <integer>
92
 
93
		This represents a sequence of objects of the specified
94
		type.  The <integer> may be either an integer literal, or a
95
		name that has been previously mentioned and is a TDFINT
96
		object.
97
 
98
	{ <name1>: <type1> ... <nameN>: <typeN> }
99
 
100
		This represents a structure composed of the elements
101
		"<name1>: <type1>" to "<nameN>: <typeN>".  It is used for
102
		sequences of objects where the objects are not of basic
103
		types.
104
 
105
	<type> = ( <value1> | ... | <valueN> )
106
 
107
		This represents a type with a constraint imposed upon it.
108
		The object value must be one of <value1> to <valueN>.
109
 
110
3. STRUCTURE OF A TDF CAPSULE
111
=============================
112
 
113
A TDF capsule has the following structure:
114
 
115
    magic				BYTE * 4 = "TDFC"
116
    major_version			TDFINT
117
    minor_version			TDFINT
118
					ALIGN
119
    num_prop_names:			TDFINT
120
    prop_names:				TDFIDENT * num_prop_names
121
    num_linkable_entities:		TDFINT
122
    linkable_entities:			{
123
	name:				TDFIDENT
124
	num_capsule_scope_identifiers:	TDFINT
125
    } * num_linkable_entities
126
    num_external_linkages:		TDFINT = num_linkable_entities
127
    external_linkages:			{
128
	num_entries:			TDFINT
129
	entries:			{
130
	    capsule_scope_id:		TDFINT
131
	    external_name:		EXTERNAL
132
	} * num_entries
133
    } * num_external_linkages
134
    num_unit_groups:			TDFINT = num_prop_names
135
    unit_groups:			{
136
	num_units:			TDFINT
137
	units:				{
138
	    num_counts:			TDFINT = (num_linkable_entities | 0)
139
	    counts:			TDFINT * num_counts
140
	    num_link_sets:		TDFINT = num_counts
141
	    link_sets:			{
142
		num_links:		TDFINT
143
		links:			{
144
		    internal:		TDFINT
145
		    external:		TDFINT
146
		} * num_links
147
	    } * num_link_sets
148
	    num_bytes_tdf:		TDFINT
149
	    tdf:			BYTE * num_bytes_tdf
150
	} * num_units
151
    } * num_unit_groups
152
 
153
The rest of this section describes the format of a capsule.
154
 
155
The capsule begins with a header that contains a four byte magic number
156
("<magic>": "TDFC"), followed by the major ("<major_version>") and minor
157
("<minor_version>") version numbers of the TDF in the capsule.  This is then
158
followed by a byte alignment and then the the capsule body.
159
 
160
The first part of a capsule tells the linker how many types of unit groups
161
there are in the capsule ("<num_prop_names>"), and what the names of these
162
unit group types are ("<prop_names>").  There can be many unit group types,
163
but the linker must know what they are called, and the order in which they
164
should occur.  At present the linker knows about "tld", "tld2", "versions",
165
"tokdec", "tokdef", "aldef", "diagtype", "tagdec", "diagdef", "tagdef" and
166
"linkinfo" (this can be changed from the command line).  There is nothing
167
special about any unit group type except for the "tld" unit group type,
168
which contains information that the linker uses (and the "tld2" unit group
169
type, which is obsolete, but is treated as a special case of the "tld" unit
170
group type).  The format of the "tld" unit group type is described in a
171
later section.
172
 
173
The second part of the capsule tells the linker how many linkable entities
174
it should be linking on ("<num_linkable_entities>"), the name of each
175
linkable entity ("<name>"), and the number of identifiers of each linkable
176
entity at capsule scope ("<num_capsule_scope_identifiers>").  Identifiers at
177
capsule scope should be numbers from zero to one less than
178
"<num_capsule_scope_identifiers>".  The identifier allocation may be sparse,
179
but the linker is optimized for continuous identifier allocation.
180
 
181
The third part of the capsule tells the linker which external names the
182
capsule contains for each linkable entity.  For each linkable entity listed
183
in the second part, the number of external names of that linkable entity are
184
listed in this part ("<num_entries>"), along with each of the external names
185
("<external_name>") and the corresponding capsule scope identifiers
186
("<capsule_scope_id>").  The ordering of the linkable entities in part three
187
must be identical to the ordering of linkable entities in part two.
188
 
189
The fourth and final part of the capsule contains the unit groups
190
themselves.  The unit groups occur in the same order as the unit group types
191
were listed in part one.  For each unit group, there is a TDFINT specifying
192
the number of units in that unit group ("<num_units>"), followed by that
193
many units.
194
 
195
Each unit contains a list of counts ("<counts>") and the number of counts in
196
that list ("<num_counts>"), which must be either zero or the same as the
197
number of linkable entities in the capsule ("<num_linkable_entities>").
198
Each count contains the number of unit scope identifiers of the given
199
linkable entity in the unit.  If the number of counts is non-zero, then the
200
counts must be in the same order as the linkable entity names.
201
 
202
After the counts come the unit scope identifier to capsule scope identifier
203
mapping tables.  The number of these tables is specified by
204
"<num_link_sets>" and must be the same as the number of counts
205
("<num_counts>"), which is either zero or the same as the number of linkable
206
entities in the capsule.  There is one table for each linkable entity (if
207
"<num_link_sets>" is non-zero), and each table contains "<num_links>" pairs
208
of TDFINTs.  The "<internal>" TDFINT is the unit scope identifier; the
209
"<external>" TDFINT is the capsule scope identifier.
210
 
211
After the mapping tables there is a length ("<num_bytes_tdf>"), and that many
212
bytes of TDF data ("<tdf>").
213
 
214
4. LINKER INFORMATION UNIT GROUPS
215
=================================
216
 
217
The "tld" unit group (if it exists in the capsule) should contain one unit
218
only.  This unit should begin with two zeroes (i.e. no counts, and no
219
identifier mapping tables), a length (which must be correct), and a sequence
220
of bytes.
221
 
222
The bytes encode information useful to the linker.  The first thing in the
223
byte sequence of a "tld" unit is a TDFINT that is the type of the unit.
224
What follows depends upon the type.  There are currently two types that are
225
supported: zero and one.  Type zero units contain the same information as
226
the old "tld2" units (if a "tld2" unit is read, it is treated as if it were
227
a "tld" unit that began with a type of zero; it is illegal for a capsule to
228
contain both a "tld" unit group and a "tld2" unit group).  Type one units
229
contain more information (described below), and are what the linker writes
230
out in the generated capsule.
231
 
232
A version one unit contains a sequence of TDFINTs.  There is one TDFINT for
233
each external name in part two of the capsule.  These TDFINTs should be in
234
the same order as the external names were.  The TDFINTs are treated as a
235
sequence of bits, with the following meanings:
236
 
237
	BIT		MEANING IF SET
238
 
239
 
240
 
241
	1		The name is declared within this capsule.
242
 
243
	2		The name is uniquely defined within this capsule.
244
			If this bit is set for a tag, then the declared bit
245
			must also be set (i.e. a declaration must exist).
246
 
247
	3		The name is defined in this capsule, but may have
248
			other definitions provided by other capsules.  This
249
			bit may not be set for tokens.  If a tag has this
250
			bit set, then the declared bit must also be set
251
			(i.e. a declaration must exist).
252
 
253
All of the other bits in the TDFINT are reserved.  The linker uses the
254
information provided by this unit to check that names do not have multiple
255
unique definitions, and to decide whether libraries should be consulted to
256
provide a definition for an external name.  If a capsule contains no linker
257
information unit group, then the external names in that capsule will have no
258
information, and hence these checks will not be made.  A similar situation
259
arises when the information for a name has no bits set.
260
 
261
A version zero unit contains a sequence of TDFINTs.  There is one TDFINT
262
for each external token name, and one TDFINT for each external tag name.
263
These TDFINTs should be in the same order as the external names were (but
264
the tokens always come before the tags).  The TDFINTs are treated as a
265
sequence of bits, with the same meanings as above.
266
 
267
5. STRUCTURE OF A TDF LIBRARY
268
=============================
269
 
270
A TDF library begins with a header, followed by a TDFINT, that is the type
271
of the library.  At present only type zero libraries are supported.  The
272
format of a type zero library is as follows:
273
 
274
    magic:				BYTE * 4 = "TDFL"
275
    major_version:			TDFINT
276
    minor_version:			TDFINT
277
					ALIGN
278
    type:				TDFINT = 0
279
    num_capsules:			TDFINT
280
    capsules:				{
281
	capsule_name:			TDFIDENT
282
	capsule_length:			TDFINT
283
	capsule_body:			BYTE * capsule_length
284
    } * num_capsules
285
    num_linkable_entities:		TDFINT
286
    linkable_entities:			{
287
	linkable_entity_name:		TDFIDENT
288
	num_this_linkable_entity:	TDFINT
289
	this_linkable_entity_names:	{
290
	    name:			EXTERNAL
291
	    info:			TDFINT
292
	    capsule:			TDFINT
293
        } * num_this_linkable_entity
294
    } * num_linkable_entities
295
 
296
The library begins with a four byte magic number ("<magic>": "TDFL"),
297
followed by the major ("<major_version>") and minor ("<minor_version>")
298
versions of the TDF in the library (the major version must be the same for
299
each capsule in the library; the minor version is the highest of the minor
300
version numbers of all of the the capsules contained in the library).  This
301
is followed by a byte alignment, the type of the library ("<type>": 0), and
302
the number of capsules in the library ("<num_capsules>"), followed by that
303
many capsules.
304
 
305
Each of the "<capsules>" has a name ("<capsule_name>"), and the capsule
306
content, which consists of the length of the capsule ("<capsule_length>")
307
and that many bytes ("<capsule_body>").  The capsule name is the name of the
308
file from which the capsule was obtained when the library was built.  The
309
names of capsules within a library must all be different.
310
 
311
The library is terminated by the index.  This contains information about
312
where to find definitions for external names.  The index begins with the
313
number of linkable entities whose external names the library will provide
314
definitions for ("<num_linkable_entities>").
315
 
316
For each of these linkable entities, the linkable entity index begins with
317
the name of the linkable entity ("<linkable_entity_name>"), followed by the
318
number of external names of the linkable entity that have entries in the
319
index ("<num_this_linkable_entity>").  This is followed by the index
320
information for each of the names.
321
 
322
For each name, the index contains the name ("<name>"); a TDFINT that
323
provides information about the name ("<info>") with the same meaning as the
324
TDFINTs in the linker information units; and the index of the capsule that
325
contains the definition for the name ("<capsule>").  The index of the first
326
capsule is zero.