2 |
7u83 |
1 |
-*- indented-text -*-
|
|
|
2 |
|
|
|
3 |
The TDF Linker - Program Documentation: Program Overview
|
|
|
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 gives an overview of the linker source code. The next
|
|
|
22 |
section describes the directory structure. The remaining sections describe
|
|
|
23 |
how the various parts of the linker work.
|
|
|
24 |
|
|
|
25 |
2. DIRECTORY STRUCTURE
|
|
|
26 |
======================
|
|
|
27 |
|
|
|
28 |
The sources to the new version of the TDF linker are spread over several
|
|
|
29 |
directories. These directories are described below:
|
|
|
30 |
|
|
|
31 |
.
|
|
|
32 |
|
|
|
33 |
The top level directory contains the "main.[ce]" files that contain
|
|
|
34 |
the top level function for the linker.
|
|
|
35 |
|
|
|
36 |
os-interface
|
|
|
37 |
|
|
|
38 |
This directory contains the low level interface to the operating
|
|
|
39 |
system and compiler. All target dependent code should be in this
|
|
|
40 |
directory. Much of this code is shared with SID, so not all of the
|
|
|
41 |
functions will be used. Because this is intended to be shared code,
|
|
|
42 |
it is documented in the header files.
|
|
|
43 |
|
|
|
44 |
library
|
|
|
45 |
|
|
|
46 |
This directory contains some generic library routines. It is
|
|
|
47 |
similar to the "os-interface" directory except that all code in this
|
|
|
48 |
directory should be target independent. Much of this code is shared
|
|
|
49 |
with SID, so not all of the functions will be used. Because this is
|
|
|
50 |
intended to be shared code, it is documented in the header files.
|
|
|
51 |
|
|
|
52 |
generated
|
|
|
53 |
|
|
|
54 |
This directory is where the automatically generated files are put.
|
|
|
55 |
Currently this is just the error messages.
|
|
|
56 |
|
|
|
57 |
tdf
|
|
|
58 |
|
|
|
59 |
This is where the majority of the files that do the actual work are.
|
|
|
60 |
|
|
|
61 |
frontends
|
|
|
62 |
|
|
|
63 |
This is where the files that implement the frontends to the linker
|
|
|
64 |
are stored.
|
|
|
65 |
|
|
|
66 |
This document doesn't describe the behaviour of the content of the
|
|
|
67 |
"os-interface" and "library" directories, as it is documented in the header
|
|
|
68 |
files. It also doesn't describe the behaviour of the content of the
|
|
|
69 |
"generated" directory, as this is described (where necessary) in the files
|
|
|
70 |
from which it is generated.
|
|
|
71 |
|
|
|
72 |
3. HASH TABLES
|
|
|
73 |
==============
|
|
|
74 |
|
|
|
75 |
This section describes the four types of hash table that are used by the
|
|
|
76 |
linker. These data structures are fundamental to the linker, and most of
|
|
|
77 |
the linker's behaviour involves adding things to the hash tables or writing
|
|
|
78 |
out information stored in them.
|
|
|
79 |
|
|
|
80 |
The four types of hash table are the unit set table, the shape table, the
|
|
|
81 |
name table, and the mapping table. Name tables only exist as part of
|
|
|
82 |
entries in a shape table, and mapping tables only exist as part of entries
|
|
|
83 |
in a unit set table.
|
|
|
84 |
|
|
|
85 |
When linking, there is one unit set table and one shape table into which the
|
|
|
86 |
information read from capsules is stored. There is a second shape table
|
|
|
87 |
into which the information from the library index is stored.
|
|
|
88 |
|
|
|
89 |
When building libraries, one unit set table and one shape table are used for
|
|
|
90 |
reading capsules in the same way as for linking, but one shape table is used
|
|
|
91 |
for each library that is read (they are only used for checking the validity
|
|
|
92 |
of the index, and are discarded immediately after the library has been
|
|
|
93 |
read).
|
|
|
94 |
|
|
|
95 |
For showing the library content, and extracting capsules from a library,
|
|
|
96 |
only a single shape table is used to store the library index.
|
|
|
97 |
|
|
|
98 |
3.1 THE UNIT SET TABLE
|
|
|
99 |
----------------------
|
|
|
100 |
|
|
|
101 |
The first hash table type is the unit set hash table, defined in
|
|
|
102 |
"tdf/unit-table.[ch]". Each entry in the table (defined in
|
|
|
103 |
"tdf/unit-entry.[ch]") has the following information:
|
|
|
104 |
|
|
|
105 |
next
|
|
|
106 |
|
|
|
107 |
This is a pointer to the next entry in the hash table.
|
|
|
108 |
|
|
|
109 |
key
|
|
|
110 |
|
|
|
111 |
This is the unit set name.
|
|
|
112 |
|
|
|
113 |
order
|
|
|
114 |
|
|
|
115 |
This is the order number of the unit set. When reading unit set
|
|
|
116 |
names from a capsule, each unit set must have a higher order number
|
|
|
117 |
than the preceding unit sets.
|
|
|
118 |
|
|
|
119 |
head
|
|
|
120 |
tail
|
|
|
121 |
|
|
|
122 |
These are the start and end pointers of the list of units in the
|
|
|
123 |
unit set that this entry represents.
|
|
|
124 |
|
|
|
125 |
Each unit in the unit list contains the following information:
|
|
|
126 |
|
|
|
127 |
next
|
|
|
128 |
|
|
|
129 |
This is a pointer to the next unit in the list.
|
|
|
130 |
|
|
|
131 |
map_table
|
|
|
132 |
|
|
|
133 |
This is the unit mapping table. It contains the unit scope
|
|
|
134 |
identifier limits (counts) and the unit scope to capsule scope
|
|
|
135 |
identifier mapping tables for each shape in the capsule that the
|
|
|
136 |
unit came from.
|
|
|
137 |
|
|
|
138 |
contents
|
|
|
139 |
|
|
|
140 |
This is the unit's TDF content.
|
|
|
141 |
|
|
|
142 |
3.2 THE SHAPE TABLE
|
|
|
143 |
-------------------
|
|
|
144 |
|
|
|
145 |
The second main hash table type is the shape table defined in
|
|
|
146 |
"shape-table.[ch]". Each entry in the table (defined in "shape-entry.[ch]")
|
|
|
147 |
has the following information:
|
|
|
148 |
|
|
|
149 |
next
|
|
|
150 |
|
|
|
151 |
This is a pointer to the next entry in the hash table.
|
|
|
152 |
|
|
|
153 |
key
|
|
|
154 |
|
|
|
155 |
This is the shape name.
|
|
|
156 |
|
|
|
157 |
names
|
|
|
158 |
|
|
|
159 |
This is a table that contains the external names for the shape.
|
|
|
160 |
|
|
|
161 |
id_count
|
|
|
162 |
|
|
|
163 |
This stores the next available capsule scope identifier for the
|
|
|
164 |
shape.
|
|
|
165 |
|
|
|
166 |
non_empty
|
|
|
167 |
|
|
|
168 |
This is set to true during the capsule output routines if the shape
|
|
|
169 |
is to be output (if it has either unit scope identifiers or capsule
|
|
|
170 |
scope identifiers).
|
|
|
171 |
|
|
|
172 |
num_lib_names
|
|
|
173 |
|
|
|
174 |
This is used to cache the number of identifiers of the shape that
|
|
|
175 |
are going to be written out to the library index.
|
|
|
176 |
|
|
|
177 |
head
|
|
|
178 |
tail
|
|
|
179 |
|
|
|
180 |
These store a list of name entries as they are added to the name
|
|
|
181 |
table "names". As new names are added to the the name table, they
|
|
|
182 |
are also added to this list. When trying to resolve undefined
|
|
|
183 |
external names, the names are removed from the front of this list,
|
|
|
184 |
and definitions are looked up in the libraries. When all such lists
|
|
|
185 |
are empty, then all possible name resolution has been done.
|
|
|
186 |
|
|
|
187 |
3.3 NAME TABLES
|
|
|
188 |
---------------
|
|
|
189 |
|
|
|
190 |
The third hash table type is the name table defined in "name-table.[ch]".
|
|
|
191 |
Each entry in the table (defined in "name-entry.[ch]") has the following
|
|
|
192 |
information:
|
|
|
193 |
|
|
|
194 |
next
|
|
|
195 |
|
|
|
196 |
This is a pointer to the next entry in the hash table.
|
|
|
197 |
|
|
|
198 |
key
|
|
|
199 |
|
|
|
200 |
This is the name's name.
|
|
|
201 |
|
|
|
202 |
type
|
|
|
203 |
|
|
|
204 |
This is the type of the name. There are five types: "NT_INDIRECT",
|
|
|
205 |
"NT_INDIRECT_CYCLING", "NT_INDIRECT_DONE", "NT_DIRECT" and
|
|
|
206 |
"NT_PLACEHOLDER". The first three types are all indirect names
|
|
|
207 |
(used by the renaming); the last type is also used by the renaming.
|
|
|
208 |
The direct name type is the real name type.
|
|
|
209 |
|
|
|
210 |
When renaming information is read, it is entered into each name
|
|
|
211 |
table of the appropriate shape. Initially, a place holder name is
|
|
|
212 |
created for the new name, and an indirect name is created for the
|
|
|
213 |
old name. The indirect name contains a pointer to the place holder
|
|
|
214 |
name (actually, this may also be an indirect name if it has also
|
|
|
215 |
been renamed).
|
|
|
216 |
|
|
|
217 |
Once all of the renamed names have been added to the table, the
|
|
|
218 |
renamings are checked for cycles, and the indirect entries are set
|
|
|
219 |
so that they all point to a place holder entry (so that it will not
|
|
|
220 |
be necessary to follow chains of indirect entries). The other two
|
|
|
221 |
indirect types are used by this process. After the process has
|
|
|
222 |
completed, all entries in the table will be of type
|
|
|
223 |
"NT_INDIRECT_DONE" or "NT_PLACEHOLDER". At this stage, there will
|
|
|
224 |
be no direct entries.
|
|
|
225 |
|
|
|
226 |
Direct entries are added when capsules and libraries are read.
|
|
|
227 |
Place holder entries will automatically turn into direct entries
|
|
|
228 |
when a direct entry of the same name is added. Attempts to add an
|
|
|
229 |
entry with the same name as an indirect entry will result in the
|
|
|
230 |
entry it points to being used instead.
|
|
|
231 |
|
|
|
232 |
The name table hides all of the renaming: the functions that get
|
|
|
233 |
entries from the name table follow indirect entries, and ignore
|
|
|
234 |
place holder entries; the iteration function only iterates across
|
|
|
235 |
direct entries. In this way, nothing outside of the name table
|
|
|
236 |
structure needs to worry about renaming.
|
|
|
237 |
|
|
|
238 |
u.indirect
|
|
|
239 |
|
|
|
240 |
This contains a pointer to another entry that is to be used in place
|
|
|
241 |
of this entry. It is only used if the entry is an indirect entry of
|
|
|
242 |
some form.
|
|
|
243 |
|
|
|
244 |
u.direct.id
|
|
|
245 |
|
|
|
246 |
This contains the capsule scope identifier that has been allocated
|
|
|
247 |
for this name. It is only used if the entry is a direct entry (as
|
|
|
248 |
is the case for all other "u.direct.X" fields).
|
|
|
249 |
|
|
|
250 |
u.direct.use
|
|
|
251 |
|
|
|
252 |
This contains the name's usage information (as read from the linker
|
|
|
253 |
information unit). In addition, an otherwise unused bit is used to
|
|
|
254 |
indicate that the name is hidden.
|
|
|
255 |
|
|
|
256 |
u.direct.definition
|
|
|
257 |
|
|
|
258 |
This contains a pointer to the capsule object that defined the name.
|
|
|
259 |
It is used for reporting the original definition for multiply
|
|
|
260 |
defined names. It is also used to indicate that the name has a
|
|
|
261 |
definition (it is set to the nil pointer if the name has no
|
|
|
262 |
definition, or if the definition has been suppressed). It is only
|
|
|
263 |
used for names not in a library index.
|
|
|
264 |
|
|
|
265 |
u.direct.lib_definition
|
|
|
266 |
|
|
|
267 |
This contains a pointer to the library capsule object that defined
|
|
|
268 |
the name. It is only used for names in a library index, to indicate
|
|
|
269 |
which capsule should be loaded to define the name. It is set to
|
|
|
270 |
the nil pointer if the name has no library definition, or if the
|
|
|
271 |
definition has been suppressed.
|
|
|
272 |
|
|
|
273 |
u.direct.list_next
|
|
|
274 |
|
|
|
275 |
This contains a pointer to the next name in the list of names of
|
|
|
276 |
this shape (the list that the "head" and "tail" fields in the shape
|
|
|
277 |
entry structure represent).
|
|
|
278 |
|
|
|
279 |
3.4 MAPPING TABLES
|
|
|
280 |
------------------
|
|
|
281 |
|
|
|
282 |
The last hash table type is the mapping table defined in "map-table.[ch]".
|
|
|
283 |
Each entry in the table (defined in "map-entry.[ch]") has the following
|
|
|
284 |
information:
|
|
|
285 |
|
|
|
286 |
next
|
|
|
287 |
|
|
|
288 |
This is a pointer to the next entry in the hash table.
|
|
|
289 |
|
|
|
290 |
key
|
|
|
291 |
|
|
|
292 |
This is the shape name.
|
|
|
293 |
|
|
|
294 |
count
|
|
|
295 |
|
|
|
296 |
This contains the unit scope identifier limit for the shape in the
|
|
|
297 |
unit that contains the table that the entry is an entry in.
|
|
|
298 |
|
|
|
299 |
num_links
|
|
|
300 |
|
|
|
301 |
This contains the number of unit scope to capsule scope identifier
|
|
|
302 |
mappings for the shape in the unit that contains the table that the
|
|
|
303 |
entry is an entry in.
|
|
|
304 |
|
|
|
305 |
links
|
|
|
306 |
|
|
|
307 |
This contains the unit scope to capsule scope identifier mappings
|
|
|
308 |
for the shape in the unit that contains the table that the entry is
|
|
|
309 |
an entry in.
|