1 |
104 |
markom |
This is bfd.info, produced by Makeinfo version 3.12f from bfd.texinfo.
|
2 |
|
|
|
3 |
|
|
START-INFO-DIR-ENTRY
|
4 |
|
|
* Bfd: (bfd). The Binary File Descriptor library.
|
5 |
|
|
END-INFO-DIR-ENTRY
|
6 |
|
|
|
7 |
|
|
This file documents the BFD library.
|
8 |
|
|
|
9 |
|
|
Copyright (C) 1991 Free Software Foundation, Inc.
|
10 |
|
|
|
11 |
|
|
Permission is granted to make and distribute verbatim copies of this
|
12 |
|
|
manual provided the copyright notice and this permission notice are
|
13 |
|
|
preserved on all copies.
|
14 |
|
|
|
15 |
|
|
Permission is granted to copy and distribute modified versions of
|
16 |
|
|
this manual under the conditions for verbatim copying, subject to the
|
17 |
|
|
terms of the GNU General Public License, which includes the provision
|
18 |
|
|
that the entire resulting derived work is distributed under the terms
|
19 |
|
|
of a permission notice identical to this one.
|
20 |
|
|
|
21 |
|
|
Permission is granted to copy and distribute translations of this
|
22 |
|
|
manual into another language, under the above conditions for modified
|
23 |
|
|
versions.
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
File: bfd.info, Node: Differing file formats, Next: Adding symbols from an object file, Prev: Adding Symbols to the Hash Table, Up: Adding Symbols to the Hash Table
|
27 |
|
|
|
28 |
|
|
Differing file formats
|
29 |
|
|
......................
|
30 |
|
|
|
31 |
|
|
Normally all the files involved in a link will be of the same
|
32 |
|
|
format, but it is also possible to link together different format
|
33 |
|
|
object files, and the back end must support that. The
|
34 |
|
|
`_bfd_link_add_symbols' entry point is called via the target vector of
|
35 |
|
|
the file to be added. This has an important consequence: the function
|
36 |
|
|
may not assume that the hash table is the type created by the
|
37 |
|
|
corresponding `_bfd_link_hash_table_create' vector. All the
|
38 |
|
|
`_bfd_link_add_symbols' function can assume about the hash table is
|
39 |
|
|
that it is derived from `struct bfd_link_hash_table'.
|
40 |
|
|
|
41 |
|
|
Sometimes the `_bfd_link_add_symbols' function must store some
|
42 |
|
|
information in the hash table entry to be used by the `_bfd_final_link'
|
43 |
|
|
function. In such a case the `creator' field of the hash table must be
|
44 |
|
|
checked to make sure that the hash table was created by an object file
|
45 |
|
|
of the same format.
|
46 |
|
|
|
47 |
|
|
The `_bfd_final_link' routine must be prepared to handle a hash
|
48 |
|
|
entry without any extra information added by the
|
49 |
|
|
`_bfd_link_add_symbols' function. A hash entry without extra
|
50 |
|
|
information will also occur when the linker script directs the linker
|
51 |
|
|
to create a symbol. Note that, regardless of how a hash table entry is
|
52 |
|
|
added, all the fields will be initialized to some sort of null value by
|
53 |
|
|
the hash table entry initialization function.
|
54 |
|
|
|
55 |
|
|
See `ecoff_link_add_externals' for an example of how to check the
|
56 |
|
|
`creator' field before saving information (in this case, the ECOFF
|
57 |
|
|
external symbol debugging information) in a hash table entry.
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
File: bfd.info, Node: Adding symbols from an object file, Next: Adding symbols from an archive, Prev: Differing file formats, Up: Adding Symbols to the Hash Table
|
61 |
|
|
|
62 |
|
|
Adding symbols from an object file
|
63 |
|
|
..................................
|
64 |
|
|
|
65 |
|
|
When the `_bfd_link_add_symbols' routine is passed an object file,
|
66 |
|
|
it must add all externally visible symbols in that object file to the
|
67 |
|
|
hash table. The actual work of adding the symbol to the hash table is
|
68 |
|
|
normally handled by the function `_bfd_generic_link_add_one_symbol'.
|
69 |
|
|
The `_bfd_link_add_symbols' routine is responsible for reading all the
|
70 |
|
|
symbols from the object file and passing the correct information to
|
71 |
|
|
`_bfd_generic_link_add_one_symbol'.
|
72 |
|
|
|
73 |
|
|
The `_bfd_link_add_symbols' routine should not use
|
74 |
|
|
`bfd_canonicalize_symtab' to read the symbols. The point of providing
|
75 |
|
|
this routine is to avoid the overhead of converting the symbols into
|
76 |
|
|
generic `asymbol' structures.
|
77 |
|
|
|
78 |
|
|
`_bfd_generic_link_add_one_symbol' handles the details of combining
|
79 |
|
|
common symbols, warning about multiple definitions, and so forth. It
|
80 |
|
|
takes arguments which describe the symbol to add, notably symbol flags,
|
81 |
|
|
a section, and an offset. The symbol flags include such things as
|
82 |
|
|
`BSF_WEAK' or `BSF_INDIRECT'. The section is a section in the object
|
83 |
|
|
file, or something like `bfd_und_section_ptr' for an undefined symbol
|
84 |
|
|
or `bfd_com_section_ptr' for a common symbol.
|
85 |
|
|
|
86 |
|
|
If the `_bfd_final_link' routine is also going to need to read the
|
87 |
|
|
symbol information, the `_bfd_link_add_symbols' routine should save it
|
88 |
|
|
somewhere attached to the object file BFD. However, the information
|
89 |
|
|
should only be saved if the `keep_memory' field of the `info' argument
|
90 |
|
|
is true, so that the `-no-keep-memory' linker switch is effective.
|
91 |
|
|
|
92 |
|
|
The a.out function which adds symbols from an object file is
|
93 |
|
|
`aout_link_add_object_symbols', and most of the interesting work is in
|
94 |
|
|
`aout_link_add_symbols'. The latter saves pointers to the hash tables
|
95 |
|
|
entries created by `_bfd_generic_link_add_one_symbol' indexed by symbol
|
96 |
|
|
number, so that the `_bfd_final_link' routine does not have to call the
|
97 |
|
|
hash table lookup routine to locate the entry.
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
File: bfd.info, Node: Adding symbols from an archive, Prev: Adding symbols from an object file, Up: Adding Symbols to the Hash Table
|
101 |
|
|
|
102 |
|
|
Adding symbols from an archive
|
103 |
|
|
..............................
|
104 |
|
|
|
105 |
|
|
When the `_bfd_link_add_symbols' routine is passed an archive, it
|
106 |
|
|
must look through the symbols defined by the archive and decide which
|
107 |
|
|
elements of the archive should be included in the link. For each such
|
108 |
|
|
element it must call the `add_archive_element' linker callback, and it
|
109 |
|
|
must add the symbols from the object file to the linker hash table.
|
110 |
|
|
|
111 |
|
|
In most cases the work of looking through the symbols in the archive
|
112 |
|
|
should be done by the `_bfd_generic_link_add_archive_symbols' function.
|
113 |
|
|
This function builds a hash table from the archive symbol table and
|
114 |
|
|
looks through the list of undefined symbols to see which elements
|
115 |
|
|
should be included. `_bfd_generic_link_add_archive_symbols' is passed
|
116 |
|
|
a function to call to make the final decision about adding an archive
|
117 |
|
|
element to the link and to do the actual work of adding the symbols to
|
118 |
|
|
the linker hash table.
|
119 |
|
|
|
120 |
|
|
The function passed to `_bfd_generic_link_add_archive_symbols' must
|
121 |
|
|
read the symbols of the archive element and decide whether the archive
|
122 |
|
|
element should be included in the link. If the element is to be
|
123 |
|
|
included, the `add_archive_element' linker callback routine must be
|
124 |
|
|
called with the element as an argument, and the elements symbols must
|
125 |
|
|
be added to the linker hash table just as though the element had itself
|
126 |
|
|
been passed to the `_bfd_link_add_symbols' function.
|
127 |
|
|
|
128 |
|
|
When the a.out `_bfd_link_add_symbols' function receives an archive,
|
129 |
|
|
it calls `_bfd_generic_link_add_archive_symbols' passing
|
130 |
|
|
`aout_link_check_archive_element' as the function argument.
|
131 |
|
|
`aout_link_check_archive_element' calls `aout_link_check_ar_symbols'.
|
132 |
|
|
If the latter decides to add the element (an element is only added if
|
133 |
|
|
it provides a real, non-common, definition for a previously undefined
|
134 |
|
|
or common symbol) it calls the `add_archive_element' callback and then
|
135 |
|
|
`aout_link_check_archive_element' calls `aout_link_add_symbols' to
|
136 |
|
|
actually add the symbols to the linker hash table.
|
137 |
|
|
|
138 |
|
|
The ECOFF back end is unusual in that it does not normally call
|
139 |
|
|
`_bfd_generic_link_add_archive_symbols', because ECOFF archives already
|
140 |
|
|
contain a hash table of symbols. The ECOFF back end searches the
|
141 |
|
|
archive itself to avoid the overhead of creating a new hash table.
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
File: bfd.info, Node: Performing the Final Link, Prev: Adding Symbols to the Hash Table, Up: Linker Functions
|
145 |
|
|
|
146 |
|
|
Performing the final link
|
147 |
|
|
-------------------------
|
148 |
|
|
|
149 |
|
|
When all the input files have been processed, the linker calls the
|
150 |
|
|
`_bfd_final_link' entry point of the output BFD. This routine is
|
151 |
|
|
responsible for producing the final output file, which has several
|
152 |
|
|
aspects. It must relocate the contents of the input sections and copy
|
153 |
|
|
the data into the output sections. It must build an output symbol
|
154 |
|
|
table including any local symbols from the input files and the global
|
155 |
|
|
symbols from the hash table. When producing relocateable output, it
|
156 |
|
|
must modify the input relocs and write them into the output file.
|
157 |
|
|
There may also be object format dependent work to be done.
|
158 |
|
|
|
159 |
|
|
The linker will also call the `write_object_contents' entry point
|
160 |
|
|
when the BFD is closed. The two entry points must work together in
|
161 |
|
|
order to produce the correct output file.
|
162 |
|
|
|
163 |
|
|
The details of how this works are inevitably dependent upon the
|
164 |
|
|
specific object file format. The a.out `_bfd_final_link' routine is
|
165 |
|
|
`NAME(aout,final_link)'.
|
166 |
|
|
|
167 |
|
|
* Menu:
|
168 |
|
|
|
169 |
|
|
* Information provided by the linker::
|
170 |
|
|
* Relocating the section contents::
|
171 |
|
|
* Writing the symbol table::
|
172 |
|
|
|
173 |
|
|
|
174 |
|
|
File: bfd.info, Node: Information provided by the linker, Next: Relocating the section contents, Prev: Performing the Final Link, Up: Performing the Final Link
|
175 |
|
|
|
176 |
|
|
Information provided by the linker
|
177 |
|
|
..................................
|
178 |
|
|
|
179 |
|
|
Before the linker calls the `_bfd_final_link' entry point, it sets
|
180 |
|
|
up some data structures for the function to use.
|
181 |
|
|
|
182 |
|
|
The `input_bfds' field of the `bfd_link_info' structure will point
|
183 |
|
|
to a list of all the input files included in the link. These files are
|
184 |
|
|
linked through the `link_next' field of the `bfd' structure.
|
185 |
|
|
|
186 |
|
|
Each section in the output file will have a list of `link_order'
|
187 |
|
|
structures attached to the `link_order_head' field (the `link_order'
|
188 |
|
|
structure is defined in `bfdlink.h'). These structures describe how to
|
189 |
|
|
create the contents of the output section in terms of the contents of
|
190 |
|
|
various input sections, fill constants, and, eventually, other types of
|
191 |
|
|
information. They also describe relocs that must be created by the BFD
|
192 |
|
|
backend, but do not correspond to any input file; this is used to
|
193 |
|
|
support -Ur, which builds constructors while generating a relocateable
|
194 |
|
|
object file.
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
File: bfd.info, Node: Relocating the section contents, Next: Writing the symbol table, Prev: Information provided by the linker, Up: Performing the Final Link
|
198 |
|
|
|
199 |
|
|
Relocating the section contents
|
200 |
|
|
...............................
|
201 |
|
|
|
202 |
|
|
The `_bfd_final_link' function should look through the `link_order'
|
203 |
|
|
structures attached to each section of the output file. Each
|
204 |
|
|
`link_order' structure should either be handled specially, or it should
|
205 |
|
|
be passed to the function `_bfd_default_link_order' which will do the
|
206 |
|
|
right thing (`_bfd_default_link_order' is defined in `linker.c').
|
207 |
|
|
|
208 |
|
|
For efficiency, a `link_order' of type `bfd_indirect_link_order'
|
209 |
|
|
whose associated section belongs to a BFD of the same format as the
|
210 |
|
|
output BFD must be handled specially. This type of `link_order'
|
211 |
|
|
describes part of an output section in terms of a section belonging to
|
212 |
|
|
one of the input files. The `_bfd_final_link' function should read the
|
213 |
|
|
contents of the section and any associated relocs, apply the relocs to
|
214 |
|
|
the section contents, and write out the modified section contents. If
|
215 |
|
|
performing a relocateable link, the relocs themselves must also be
|
216 |
|
|
modified and written out.
|
217 |
|
|
|
218 |
|
|
The functions `_bfd_relocate_contents' and
|
219 |
|
|
`_bfd_final_link_relocate' provide some general support for performing
|
220 |
|
|
the actual relocations, notably overflow checking. Their arguments
|
221 |
|
|
include information about the symbol the relocation is against and a
|
222 |
|
|
`reloc_howto_type' argument which describes the relocation to perform.
|
223 |
|
|
These functions are defined in `reloc.c'.
|
224 |
|
|
|
225 |
|
|
The a.out function which handles reading, relocating, and writing
|
226 |
|
|
section contents is `aout_link_input_section'. The actual relocation
|
227 |
|
|
is done in `aout_link_input_section_std' and
|
228 |
|
|
`aout_link_input_section_ext'.
|
229 |
|
|
|
230 |
|
|
|
231 |
|
|
File: bfd.info, Node: Writing the symbol table, Prev: Relocating the section contents, Up: Performing the Final Link
|
232 |
|
|
|
233 |
|
|
Writing the symbol table
|
234 |
|
|
........................
|
235 |
|
|
|
236 |
|
|
The `_bfd_final_link' function must gather all the symbols in the
|
237 |
|
|
input files and write them out. It must also write out all the symbols
|
238 |
|
|
in the global hash table. This must be controlled by the `strip' and
|
239 |
|
|
`discard' fields of the `bfd_link_info' structure.
|
240 |
|
|
|
241 |
|
|
The local symbols of the input files will not have been entered into
|
242 |
|
|
the linker hash table. The `_bfd_final_link' routine must consider
|
243 |
|
|
each input file and include the symbols in the output file. It may be
|
244 |
|
|
convenient to do this when looking through the `link_order' structures,
|
245 |
|
|
or it may be done by stepping through the `input_bfds' list.
|
246 |
|
|
|
247 |
|
|
The `_bfd_final_link' routine must also traverse the global hash
|
248 |
|
|
table to gather all the externally visible symbols. It is possible
|
249 |
|
|
that most of the externally visible symbols may be written out when
|
250 |
|
|
considering the symbols of each input file, but it is still necessary
|
251 |
|
|
to traverse the hash table since the linker script may have defined
|
252 |
|
|
some symbols that are not in any of the input files.
|
253 |
|
|
|
254 |
|
|
The `strip' field of the `bfd_link_info' structure controls which
|
255 |
|
|
symbols are written out. The possible values are listed in
|
256 |
|
|
`bfdlink.h'. If the value is `strip_some', then the `keep_hash' field
|
257 |
|
|
of the `bfd_link_info' structure is a hash table of symbols to keep;
|
258 |
|
|
each symbol should be looked up in this hash table, and only symbols
|
259 |
|
|
which are present should be included in the output file.
|
260 |
|
|
|
261 |
|
|
If the `strip' field of the `bfd_link_info' structure permits local
|
262 |
|
|
symbols to be written out, the `discard' field is used to further
|
263 |
|
|
controls which local symbols are included in the output file. If the
|
264 |
|
|
value is `discard_l', then all local symbols which begin with a certain
|
265 |
|
|
prefix are discarded; this is controlled by the
|
266 |
|
|
`bfd_is_local_label_name' entry point.
|
267 |
|
|
|
268 |
|
|
The a.out backend handles symbols by calling
|
269 |
|
|
`aout_link_write_symbols' on each input BFD and then traversing the
|
270 |
|
|
global hash table with the function `aout_link_write_other_symbol'. It
|
271 |
|
|
builds a string table while writing out the symbols, which is written
|
272 |
|
|
to the output file at the end of `NAME(aout,final_link)'.
|
273 |
|
|
|
274 |
|
|
`bfd_link_split_section'
|
275 |
|
|
........................
|
276 |
|
|
|
277 |
|
|
*Synopsis*
|
278 |
|
|
boolean bfd_link_split_section(bfd *abfd, asection *sec);
|
279 |
|
|
*Description*
|
280 |
|
|
Return nonzero if SEC should be split during a reloceatable or final
|
281 |
|
|
link.
|
282 |
|
|
#define bfd_link_split_section(abfd, sec) \
|
283 |
|
|
BFD_SEND (abfd, _bfd_link_split_section, (abfd, sec))
|
284 |
|
|
|
285 |
|
|
|
286 |
|
|
File: bfd.info, Node: Hash Tables, Prev: Linker Functions, Up: BFD front end
|
287 |
|
|
|
288 |
|
|
Hash Tables
|
289 |
|
|
===========
|
290 |
|
|
|
291 |
|
|
BFD provides a simple set of hash table functions. Routines are
|
292 |
|
|
provided to initialize a hash table, to free a hash table, to look up a
|
293 |
|
|
string in a hash table and optionally create an entry for it, and to
|
294 |
|
|
traverse a hash table. There is currently no routine to delete an
|
295 |
|
|
string from a hash table.
|
296 |
|
|
|
297 |
|
|
The basic hash table does not permit any data to be stored with a
|
298 |
|
|
string. However, a hash table is designed to present a base class from
|
299 |
|
|
which other types of hash tables may be derived. These derived types
|
300 |
|
|
may store additional information with the string. Hash tables were
|
301 |
|
|
implemented in this way, rather than simply providing a data pointer in
|
302 |
|
|
a hash table entry, because they were designed for use by the linker
|
303 |
|
|
back ends. The linker may create thousands of hash table entries, and
|
304 |
|
|
the overhead of allocating private data and storing and following
|
305 |
|
|
pointers becomes noticeable.
|
306 |
|
|
|
307 |
|
|
The basic hash table code is in `hash.c'.
|
308 |
|
|
|
309 |
|
|
* Menu:
|
310 |
|
|
|
311 |
|
|
* Creating and Freeing a Hash Table::
|
312 |
|
|
* Looking Up or Entering a String::
|
313 |
|
|
* Traversing a Hash Table::
|
314 |
|
|
* Deriving a New Hash Table Type::
|
315 |
|
|
|
316 |
|
|
|
317 |
|
|
File: bfd.info, Node: Creating and Freeing a Hash Table, Next: Looking Up or Entering a String, Prev: Hash Tables, Up: Hash Tables
|
318 |
|
|
|
319 |
|
|
Creating and freeing a hash table
|
320 |
|
|
---------------------------------
|
321 |
|
|
|
322 |
|
|
To create a hash table, create an instance of a `struct
|
323 |
|
|
bfd_hash_table' (defined in `bfd.h') and call `bfd_hash_table_init' (if
|
324 |
|
|
you know approximately how many entries you will need, the function
|
325 |
|
|
`bfd_hash_table_init_n', which takes a SIZE argument, may be used).
|
326 |
|
|
`bfd_hash_table_init' returns `false' if some sort of error occurs.
|
327 |
|
|
|
328 |
|
|
The function `bfd_hash_table_init' take as an argument a function to
|
329 |
|
|
use to create new entries. For a basic hash table, use the function
|
330 |
|
|
`bfd_hash_newfunc'. *Note Deriving a New Hash Table Type::, for why
|
331 |
|
|
you would want to use a different value for this argument.
|
332 |
|
|
|
333 |
|
|
`bfd_hash_table_init' will create an objalloc which will be used to
|
334 |
|
|
allocate new entries. You may allocate memory on this objalloc using
|
335 |
|
|
`bfd_hash_allocate'.
|
336 |
|
|
|
337 |
|
|
Use `bfd_hash_table_free' to free up all the memory that has been
|
338 |
|
|
allocated for a hash table. This will not free up the `struct
|
339 |
|
|
bfd_hash_table' itself, which you must provide.
|
340 |
|
|
|
341 |
|
|
|
342 |
|
|
File: bfd.info, Node: Looking Up or Entering a String, Next: Traversing a Hash Table, Prev: Creating and Freeing a Hash Table, Up: Hash Tables
|
343 |
|
|
|
344 |
|
|
Looking up or entering a string
|
345 |
|
|
-------------------------------
|
346 |
|
|
|
347 |
|
|
The function `bfd_hash_lookup' is used both to look up a string in
|
348 |
|
|
the hash table and to create a new entry.
|
349 |
|
|
|
350 |
|
|
If the CREATE argument is `false', `bfd_hash_lookup' will look up a
|
351 |
|
|
string. If the string is found, it will returns a pointer to a `struct
|
352 |
|
|
bfd_hash_entry'. If the string is not found in the table
|
353 |
|
|
`bfd_hash_lookup' will return `NULL'. You should not modify any of the
|
354 |
|
|
fields in the returns `struct bfd_hash_entry'.
|
355 |
|
|
|
356 |
|
|
If the CREATE argument is `true', the string will be entered into
|
357 |
|
|
the hash table if it is not already there. Either way a pointer to a
|
358 |
|
|
`struct bfd_hash_entry' will be returned, either to the existing
|
359 |
|
|
structure or to a newly created one. In this case, a `NULL' return
|
360 |
|
|
means that an error occurred.
|
361 |
|
|
|
362 |
|
|
If the CREATE argument is `true', and a new entry is created, the
|
363 |
|
|
COPY argument is used to decide whether to copy the string onto the
|
364 |
|
|
hash table objalloc or not. If COPY is passed as `false', you must be
|
365 |
|
|
careful not to deallocate or modify the string as long as the hash table
|
366 |
|
|
exists.
|
367 |
|
|
|
368 |
|
|
|
369 |
|
|
File: bfd.info, Node: Traversing a Hash Table, Next: Deriving a New Hash Table Type, Prev: Looking Up or Entering a String, Up: Hash Tables
|
370 |
|
|
|
371 |
|
|
Traversing a hash table
|
372 |
|
|
-----------------------
|
373 |
|
|
|
374 |
|
|
The function `bfd_hash_traverse' may be used to traverse a hash
|
375 |
|
|
table, calling a function on each element. The traversal is done in a
|
376 |
|
|
random order.
|
377 |
|
|
|
378 |
|
|
`bfd_hash_traverse' takes as arguments a function and a generic
|
379 |
|
|
`void *' pointer. The function is called with a hash table entry (a
|
380 |
|
|
`struct bfd_hash_entry *') and the generic pointer passed to
|
381 |
|
|
`bfd_hash_traverse'. The function must return a `boolean' value, which
|
382 |
|
|
indicates whether to continue traversing the hash table. If the
|
383 |
|
|
function returns `false', `bfd_hash_traverse' will stop the traversal
|
384 |
|
|
and return immediately.
|
385 |
|
|
|
386 |
|
|
|
387 |
|
|
File: bfd.info, Node: Deriving a New Hash Table Type, Prev: Traversing a Hash Table, Up: Hash Tables
|
388 |
|
|
|
389 |
|
|
Deriving a new hash table type
|
390 |
|
|
------------------------------
|
391 |
|
|
|
392 |
|
|
Many uses of hash tables want to store additional information which
|
393 |
|
|
each entry in the hash table. Some also find it convenient to store
|
394 |
|
|
additional information with the hash table itself. This may be done
|
395 |
|
|
using a derived hash table.
|
396 |
|
|
|
397 |
|
|
Since C is not an object oriented language, creating a derived hash
|
398 |
|
|
table requires sticking together some boilerplate routines with a few
|
399 |
|
|
differences specific to the type of hash table you want to create.
|
400 |
|
|
|
401 |
|
|
An example of a derived hash table is the linker hash table. The
|
402 |
|
|
structures for this are defined in `bfdlink.h'. The functions are in
|
403 |
|
|
`linker.c'.
|
404 |
|
|
|
405 |
|
|
You may also derive a hash table from an already derived hash table.
|
406 |
|
|
For example, the a.out linker backend code uses a hash table derived
|
407 |
|
|
from the linker hash table.
|
408 |
|
|
|
409 |
|
|
* Menu:
|
410 |
|
|
|
411 |
|
|
* Define the Derived Structures::
|
412 |
|
|
* Write the Derived Creation Routine::
|
413 |
|
|
* Write Other Derived Routines::
|
414 |
|
|
|
415 |
|
|
|
416 |
|
|
File: bfd.info, Node: Define the Derived Structures, Next: Write the Derived Creation Routine, Prev: Deriving a New Hash Table Type, Up: Deriving a New Hash Table Type
|
417 |
|
|
|
418 |
|
|
Define the derived structures
|
419 |
|
|
.............................
|
420 |
|
|
|
421 |
|
|
You must define a structure for an entry in the hash table, and a
|
422 |
|
|
structure for the hash table itself.
|
423 |
|
|
|
424 |
|
|
The first field in the structure for an entry in the hash table must
|
425 |
|
|
be of the type used for an entry in the hash table you are deriving
|
426 |
|
|
from. If you are deriving from a basic hash table this is `struct
|
427 |
|
|
bfd_hash_entry', which is defined in `bfd.h'. The first field in the
|
428 |
|
|
structure for the hash table itself must be of the type of the hash
|
429 |
|
|
table you are deriving from itself. If you are deriving from a basic
|
430 |
|
|
hash table, this is `struct bfd_hash_table'.
|
431 |
|
|
|
432 |
|
|
For example, the linker hash table defines `struct
|
433 |
|
|
bfd_link_hash_entry' (in `bfdlink.h'). The first field, `root', is of
|
434 |
|
|
type `struct bfd_hash_entry'. Similarly, the first field in `struct
|
435 |
|
|
bfd_link_hash_table', `table', is of type `struct bfd_hash_table'.
|
436 |
|
|
|
437 |
|
|
|
438 |
|
|
File: bfd.info, Node: Write the Derived Creation Routine, Next: Write Other Derived Routines, Prev: Define the Derived Structures, Up: Deriving a New Hash Table Type
|
439 |
|
|
|
440 |
|
|
Write the derived creation routine
|
441 |
|
|
..................................
|
442 |
|
|
|
443 |
|
|
You must write a routine which will create and initialize an entry
|
444 |
|
|
in the hash table. This routine is passed as the function argument to
|
445 |
|
|
`bfd_hash_table_init'.
|
446 |
|
|
|
447 |
|
|
In order to permit other hash tables to be derived from the hash
|
448 |
|
|
table you are creating, this routine must be written in a standard way.
|
449 |
|
|
|
450 |
|
|
The first argument to the creation routine is a pointer to a hash
|
451 |
|
|
table entry. This may be `NULL', in which case the routine should
|
452 |
|
|
allocate the right amount of space. Otherwise the space has already
|
453 |
|
|
been allocated by a hash table type derived from this one.
|
454 |
|
|
|
455 |
|
|
After allocating space, the creation routine must call the creation
|
456 |
|
|
routine of the hash table type it is derived from, passing in a pointer
|
457 |
|
|
to the space it just allocated. This will initialize any fields used
|
458 |
|
|
by the base hash table.
|
459 |
|
|
|
460 |
|
|
Finally the creation routine must initialize any local fields for
|
461 |
|
|
the new hash table type.
|
462 |
|
|
|
463 |
|
|
Here is a boilerplate example of a creation routine. FUNCTION_NAME
|
464 |
|
|
is the name of the routine. ENTRY_TYPE is the type of an entry in the
|
465 |
|
|
hash table you are creating. BASE_NEWFUNC is the name of the creation
|
466 |
|
|
routine of the hash table type your hash table is derived from.
|
467 |
|
|
|
468 |
|
|
struct bfd_hash_entry *
|
469 |
|
|
FUNCTION_NAME (entry, table, string)
|
470 |
|
|
struct bfd_hash_entry *entry;
|
471 |
|
|
struct bfd_hash_table *table;
|
472 |
|
|
const char *string;
|
473 |
|
|
{
|
474 |
|
|
struct ENTRY_TYPE *ret = (ENTRY_TYPE *) entry;
|
475 |
|
|
|
476 |
|
|
/* Allocate the structure if it has not already been allocated by a
|
477 |
|
|
derived class. */
|
478 |
|
|
if (ret == (ENTRY_TYPE *) NULL)
|
479 |
|
|
{
|
480 |
|
|
ret = ((ENTRY_TYPE *)
|
481 |
|
|
bfd_hash_allocate (table, sizeof (ENTRY_TYPE)));
|
482 |
|
|
if (ret == (ENTRY_TYPE *) NULL)
|
483 |
|
|
return NULL;
|
484 |
|
|
}
|
485 |
|
|
|
486 |
|
|
/* Call the allocation method of the base class. */
|
487 |
|
|
ret = ((ENTRY_TYPE *)
|
488 |
|
|
BASE_NEWFUNC ((struct bfd_hash_entry *) ret, table, string));
|
489 |
|
|
|
490 |
|
|
/* Initialize the local fields here. */
|
491 |
|
|
|
492 |
|
|
return (struct bfd_hash_entry *) ret;
|
493 |
|
|
}
|
494 |
|
|
*Description*
|
495 |
|
|
The creation routine for the linker hash table, which is in `linker.c',
|
496 |
|
|
looks just like this example. FUNCTION_NAME is
|
497 |
|
|
`_bfd_link_hash_newfunc'. ENTRY_TYPE is `struct bfd_link_hash_entry'.
|
498 |
|
|
BASE_NEWFUNC is `bfd_hash_newfunc', the creation routine for a basic
|
499 |
|
|
hash table.
|
500 |
|
|
|
501 |
|
|
`_bfd_link_hash_newfunc' also initializes the local fields in a
|
502 |
|
|
linker hash table entry: `type', `written' and `next'.
|
503 |
|
|
|
504 |
|
|
|
505 |
|
|
File: bfd.info, Node: Write Other Derived Routines, Prev: Write the Derived Creation Routine, Up: Deriving a New Hash Table Type
|
506 |
|
|
|
507 |
|
|
Write other derived routines
|
508 |
|
|
............................
|
509 |
|
|
|
510 |
|
|
You will want to write other routines for your new hash table, as
|
511 |
|
|
well.
|
512 |
|
|
|
513 |
|
|
You will want an initialization routine which calls the
|
514 |
|
|
initialization routine of the hash table you are deriving from and
|
515 |
|
|
initializes any other local fields. For the linker hash table, this is
|
516 |
|
|
`_bfd_link_hash_table_init' in `linker.c'.
|
517 |
|
|
|
518 |
|
|
You will want a lookup routine which calls the lookup routine of the
|
519 |
|
|
hash table you are deriving from and casts the result. The linker hash
|
520 |
|
|
table uses `bfd_link_hash_lookup' in `linker.c' (this actually takes an
|
521 |
|
|
additional argument which it uses to decide how to return the looked up
|
522 |
|
|
value).
|
523 |
|
|
|
524 |
|
|
You may want a traversal routine. This should just call the
|
525 |
|
|
traversal routine of the hash table you are deriving from with
|
526 |
|
|
appropriate casts. The linker hash table uses `bfd_link_hash_traverse'
|
527 |
|
|
in `linker.c'.
|
528 |
|
|
|
529 |
|
|
These routines may simply be defined as macros. For example, the
|
530 |
|
|
a.out backend linker hash table, which is derived from the linker hash
|
531 |
|
|
table, uses macros for the lookup and traversal routines. These are
|
532 |
|
|
`aout_link_hash_lookup' and `aout_link_hash_traverse' in aoutx.h.
|
533 |
|
|
|
534 |
|
|
|
535 |
|
|
File: bfd.info, Node: BFD back ends, Next: Index, Prev: BFD front end, Up: Top
|
536 |
|
|
|
537 |
|
|
BFD back ends
|
538 |
|
|
*************
|
539 |
|
|
|
540 |
|
|
* Menu:
|
541 |
|
|
|
542 |
|
|
* What to Put Where::
|
543 |
|
|
* aout :: a.out backends
|
544 |
|
|
* coff :: coff backends
|
545 |
|
|
* elf :: elf backends
|
546 |
|
|
|
547 |
|
|
|
548 |
|
|
File: bfd.info, Node: What to Put Where, Next: aout, Prev: BFD back ends, Up: BFD back ends
|
549 |
|
|
|
550 |
|
|
All of BFD lives in one directory.
|
551 |
|
|
|
552 |
|
|
|
553 |
|
|
File: bfd.info, Node: aout, Next: coff, Prev: What to Put Where, Up: BFD back ends
|
554 |
|
|
|
555 |
|
|
a.out backends
|
556 |
|
|
==============
|
557 |
|
|
|
558 |
|
|
*Description*
|
559 |
|
|
BFD supports a number of different flavours of a.out format, though the
|
560 |
|
|
major differences are only the sizes of the structures on disk, and the
|
561 |
|
|
shape of the relocation information.
|
562 |
|
|
|
563 |
|
|
The support is split into a basic support file `aoutx.h' and other
|
564 |
|
|
files which derive functions from the base. One derivation file is
|
565 |
|
|
`aoutf1.h' (for a.out flavour 1), and adds to the basic a.out functions
|
566 |
|
|
support for sun3, sun4, 386 and 29k a.out files, to create a target
|
567 |
|
|
jump vector for a specific target.
|
568 |
|
|
|
569 |
|
|
This information is further split out into more specific files for
|
570 |
|
|
each machine, including `sunos.c' for sun3 and sun4, `newsos3.c' for
|
571 |
|
|
the Sony NEWS, and `demo64.c' for a demonstration of a 64 bit a.out
|
572 |
|
|
format.
|
573 |
|
|
|
574 |
|
|
The base file `aoutx.h' defines general mechanisms for reading and
|
575 |
|
|
writing records to and from disk and various other methods which BFD
|
576 |
|
|
requires. It is included by `aout32.c' and `aout64.c' to form the names
|
577 |
|
|
`aout_32_swap_exec_header_in', `aout_64_swap_exec_header_in', etc.
|
578 |
|
|
|
579 |
|
|
As an example, this is what goes on to make the back end for a sun4,
|
580 |
|
|
from `aout32.c':
|
581 |
|
|
|
582 |
|
|
#define ARCH_SIZE 32
|
583 |
|
|
#include "aoutx.h"
|
584 |
|
|
|
585 |
|
|
Which exports names:
|
586 |
|
|
|
587 |
|
|
...
|
588 |
|
|
aout_32_canonicalize_reloc
|
589 |
|
|
aout_32_find_nearest_line
|
590 |
|
|
aout_32_get_lineno
|
591 |
|
|
aout_32_get_reloc_upper_bound
|
592 |
|
|
...
|
593 |
|
|
|
594 |
|
|
from `sunos.c':
|
595 |
|
|
|
596 |
|
|
#define TARGET_NAME "a.out-sunos-big"
|
597 |
|
|
#define VECNAME sunos_big_vec
|
598 |
|
|
#include "aoutf1.h"
|
599 |
|
|
|
600 |
|
|
requires all the names from `aout32.c', and produces the jump vector
|
601 |
|
|
|
602 |
|
|
sunos_big_vec
|
603 |
|
|
|
604 |
|
|
The file `host-aout.c' is a special case. It is for a large set of
|
605 |
|
|
hosts that use "more or less standard" a.out files, and for which
|
606 |
|
|
cross-debugging is not interesting. It uses the standard 32-bit a.out
|
607 |
|
|
support routines, but determines the file offsets and addresses of the
|
608 |
|
|
text, data, and BSS sections, the machine architecture and machine
|
609 |
|
|
type, and the entry point address, in a host-dependent manner. Once
|
610 |
|
|
these values have been determined, generic code is used to handle the
|
611 |
|
|
object file.
|
612 |
|
|
|
613 |
|
|
When porting it to run on a new system, you must supply:
|
614 |
|
|
|
615 |
|
|
HOST_PAGE_SIZE
|
616 |
|
|
HOST_SEGMENT_SIZE
|
617 |
|
|
HOST_MACHINE_ARCH (optional)
|
618 |
|
|
HOST_MACHINE_MACHINE (optional)
|
619 |
|
|
HOST_TEXT_START_ADDR
|
620 |
|
|
HOST_STACK_END_ADDR
|
621 |
|
|
|
622 |
|
|
in the file `../include/sys/h-XXX.h' (for your host). These values,
|
623 |
|
|
plus the structures and macros defined in `a.out.h' on your host
|
624 |
|
|
system, will produce a BFD target that will access ordinary a.out files
|
625 |
|
|
on your host. To configure a new machine to use `host-aout.c', specify:
|
626 |
|
|
|
627 |
|
|
TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec
|
628 |
|
|
TDEPFILES= host-aout.o trad-core.o
|
629 |
|
|
|
630 |
|
|
in the `config/XXX.mt' file, and modify `configure.in' to use the
|
631 |
|
|
`XXX.mt' file (by setting "`bfd_target=XXX'") when your configuration
|
632 |
|
|
is selected.
|
633 |
|
|
|
634 |
|
|
Relocations
|
635 |
|
|
-----------
|
636 |
|
|
|
637 |
|
|
*Description*
|
638 |
|
|
The file `aoutx.h' provides for both the _standard_ and _extended_
|
639 |
|
|
forms of a.out relocation records.
|
640 |
|
|
|
641 |
|
|
The standard records contain only an address, a symbol index, and a
|
642 |
|
|
type field. The extended records (used on 29ks and sparcs) also have a
|
643 |
|
|
full integer for an addend.
|
644 |
|
|
|
645 |
|
|
Internal entry points
|
646 |
|
|
---------------------
|
647 |
|
|
|
648 |
|
|
*Description*
|
649 |
|
|
`aoutx.h' exports several routines for accessing the contents of an
|
650 |
|
|
a.out file, which are gathered and exported in turn by various format
|
651 |
|
|
specific files (eg sunos.c).
|
652 |
|
|
|
653 |
|
|
`aout_SIZE_swap_exec_header_in'
|
654 |
|
|
...............................
|
655 |
|
|
|
656 |
|
|
*Synopsis*
|
657 |
|
|
void aout_SIZE_swap_exec_header_in,
|
658 |
|
|
(bfd *abfd,
|
659 |
|
|
struct external_exec *raw_bytes,
|
660 |
|
|
struct internal_exec *execp);
|
661 |
|
|
*Description*
|
662 |
|
|
Swap the information in an executable header RAW_BYTES taken from a raw
|
663 |
|
|
byte stream memory image into the internal exec header structure EXECP.
|
664 |
|
|
|
665 |
|
|
`aout_SIZE_swap_exec_header_out'
|
666 |
|
|
................................
|
667 |
|
|
|
668 |
|
|
*Synopsis*
|
669 |
|
|
void aout_SIZE_swap_exec_header_out
|
670 |
|
|
(bfd *abfd,
|
671 |
|
|
struct internal_exec *execp,
|
672 |
|
|
struct external_exec *raw_bytes);
|
673 |
|
|
*Description*
|
674 |
|
|
Swap the information in an internal exec header structure EXECP into
|
675 |
|
|
the buffer RAW_BYTES ready for writing to disk.
|
676 |
|
|
|
677 |
|
|
`aout_SIZE_some_aout_object_p'
|
678 |
|
|
..............................
|
679 |
|
|
|
680 |
|
|
*Synopsis*
|
681 |
|
|
const bfd_target *aout_SIZE_some_aout_object_p
|
682 |
|
|
(bfd *abfd,
|
683 |
|
|
const bfd_target *(*callback_to_real_object_p)());
|
684 |
|
|
*Description*
|
685 |
|
|
Some a.out variant thinks that the file open in ABFD checking is an
|
686 |
|
|
a.out file. Do some more checking, and set up for access if it really
|
687 |
|
|
is. Call back to the calling environment's "finish up" function just
|
688 |
|
|
before returning, to handle any last-minute setup.
|
689 |
|
|
|
690 |
|
|
`aout_SIZE_mkobject'
|
691 |
|
|
....................
|
692 |
|
|
|
693 |
|
|
*Synopsis*
|
694 |
|
|
boolean aout_SIZE_mkobject, (bfd *abfd);
|
695 |
|
|
*Description*
|
696 |
|
|
Initialize BFD ABFD for use with a.out files.
|
697 |
|
|
|
698 |
|
|
`aout_SIZE_machine_type'
|
699 |
|
|
........................
|
700 |
|
|
|
701 |
|
|
*Synopsis*
|
702 |
|
|
enum machine_type aout_SIZE_machine_type
|
703 |
|
|
(enum bfd_architecture arch,
|
704 |
|
|
unsigned long machine));
|
705 |
|
|
*Description*
|
706 |
|
|
Keep track of machine architecture and machine type for a.out's. Return
|
707 |
|
|
the `machine_type' for a particular architecture and machine, or
|
708 |
|
|
`M_UNKNOWN' if that exact architecture and machine can't be represented
|
709 |
|
|
in a.out format.
|
710 |
|
|
|
711 |
|
|
If the architecture is understood, machine type 0 (default) is
|
712 |
|
|
always understood.
|
713 |
|
|
|
714 |
|
|
`aout_SIZE_set_arch_mach'
|
715 |
|
|
.........................
|
716 |
|
|
|
717 |
|
|
*Synopsis*
|
718 |
|
|
boolean aout_SIZE_set_arch_mach,
|
719 |
|
|
(bfd *,
|
720 |
|
|
enum bfd_architecture arch,
|
721 |
|
|
unsigned long machine));
|
722 |
|
|
*Description*
|
723 |
|
|
Set the architecture and the machine of the BFD ABFD to the values ARCH
|
724 |
|
|
and MACHINE. Verify that ABFD's format can support the architecture
|
725 |
|
|
required.
|
726 |
|
|
|
727 |
|
|
`aout_SIZE_new_section_hook'
|
728 |
|
|
............................
|
729 |
|
|
|
730 |
|
|
*Synopsis*
|
731 |
|
|
boolean aout_SIZE_new_section_hook,
|
732 |
|
|
(bfd *abfd,
|
733 |
|
|
asection *newsect));
|
734 |
|
|
*Description*
|
735 |
|
|
Called by the BFD in response to a `bfd_make_section' request.
|
736 |
|
|
|