1 | This is bfd.info, produced by makeinfo version 4.3 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, 2000, 2001, 2003 Free Software Foundation, Inc.
|
---|
10 |
|
---|
11 | Permission is granted to copy, distribute and/or modify this document
|
---|
12 | under the terms of the GNU Free Documentation License, Version 1.1
|
---|
13 | or any later version published by the Free Software Foundation;
|
---|
14 | with no Invariant Sections, with no Front-Cover Texts, and with no
|
---|
15 | Back-Cover Texts. A copy of the license is included in the
|
---|
16 | section entitled "GNU Free Documentation License".
|
---|
17 |
|
---|
18 |
|
---|
19 | File: bfd.info, Node: Internal, Next: File Caching, Prev: Opening and Closing, Up: BFD front end
|
---|
20 |
|
---|
21 | Internal functions
|
---|
22 | ==================
|
---|
23 |
|
---|
24 | *Description*
|
---|
25 | These routines are used within BFD. They are not intended for export,
|
---|
26 | but are documented here for completeness.
|
---|
27 |
|
---|
28 | `bfd_write_bigendian_4byte_int'
|
---|
29 | ...............................
|
---|
30 |
|
---|
31 | *Synopsis*
|
---|
32 | bfd_boolean bfd_write_bigendian_4byte_int (bfd *, unsigned int);
|
---|
33 | *Description*
|
---|
34 | Write a 4 byte integer I to the output BFD ABFD, in big endian order
|
---|
35 | regardless of what else is going on. This is useful in archives.
|
---|
36 |
|
---|
37 | `bfd_put_size'
|
---|
38 | ..............
|
---|
39 |
|
---|
40 | `bfd_get_size'
|
---|
41 | ..............
|
---|
42 |
|
---|
43 | *Description*
|
---|
44 | These macros as used for reading and writing raw data in sections; each
|
---|
45 | access (except for bytes) is vectored through the target format of the
|
---|
46 | BFD and mangled accordingly. The mangling performs any necessary endian
|
---|
47 | translations and removes alignment restrictions. Note that types
|
---|
48 | accepted and returned by these macros are identical so they can be
|
---|
49 | swapped around in macros--for example, `libaout.h' defines `GET_WORD'
|
---|
50 | to either `bfd_get_32' or `bfd_get_64'.
|
---|
51 |
|
---|
52 | In the put routines, VAL must be a `bfd_vma'. If we are on a system
|
---|
53 | without prototypes, the caller is responsible for making sure that is
|
---|
54 | true, with a cast if necessary. We don't cast them in the macro
|
---|
55 | definitions because that would prevent `lint' or `gcc -Wall' from
|
---|
56 | detecting sins such as passing a pointer. To detect calling these with
|
---|
57 | less than a `bfd_vma', use `gcc -Wconversion' on a host with 64 bit
|
---|
58 | `bfd_vma''s.
|
---|
59 |
|
---|
60 | /* Byte swapping macros for user section data. */
|
---|
61 |
|
---|
62 | #define bfd_put_8(abfd, val, ptr) \
|
---|
63 | ((void) (*((unsigned char *) (ptr)) = (unsigned char) (val)))
|
---|
64 | #define bfd_put_signed_8 \
|
---|
65 | bfd_put_8
|
---|
66 | #define bfd_get_8(abfd, ptr) \
|
---|
67 | (*(unsigned char *) (ptr) & 0xff)
|
---|
68 | #define bfd_get_signed_8(abfd, ptr) \
|
---|
69 | (((*(unsigned char *) (ptr) & 0xff) ^ 0x80) - 0x80)
|
---|
70 |
|
---|
71 | #define bfd_put_16(abfd, val, ptr) \
|
---|
72 | BFD_SEND(abfd, bfd_putx16, ((val),(ptr)))
|
---|
73 | #define bfd_put_signed_16 \
|
---|
74 | bfd_put_16
|
---|
75 | #define bfd_get_16(abfd, ptr) \
|
---|
76 | BFD_SEND(abfd, bfd_getx16, (ptr))
|
---|
77 | #define bfd_get_signed_16(abfd, ptr) \
|
---|
78 | BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
|
---|
79 |
|
---|
80 | #define bfd_put_32(abfd, val, ptr) \
|
---|
81 | BFD_SEND(abfd, bfd_putx32, ((val),(ptr)))
|
---|
82 | #define bfd_put_signed_32 \
|
---|
83 | bfd_put_32
|
---|
84 | #define bfd_get_32(abfd, ptr) \
|
---|
85 | BFD_SEND(abfd, bfd_getx32, (ptr))
|
---|
86 | #define bfd_get_signed_32(abfd, ptr) \
|
---|
87 | BFD_SEND(abfd, bfd_getx_signed_32, (ptr))
|
---|
88 |
|
---|
89 | #define bfd_put_64(abfd, val, ptr) \
|
---|
90 | BFD_SEND(abfd, bfd_putx64, ((val), (ptr)))
|
---|
91 | #define bfd_put_signed_64 \
|
---|
92 | bfd_put_64
|
---|
93 | #define bfd_get_64(abfd, ptr) \
|
---|
94 | BFD_SEND(abfd, bfd_getx64, (ptr))
|
---|
95 | #define bfd_get_signed_64(abfd, ptr) \
|
---|
96 | BFD_SEND(abfd, bfd_getx_signed_64, (ptr))
|
---|
97 |
|
---|
98 | #define bfd_get(bits, abfd, ptr) \
|
---|
99 | ( (bits) == 8 ? (bfd_vma) bfd_get_8 (abfd, ptr) \
|
---|
100 | : (bits) == 16 ? bfd_get_16 (abfd, ptr) \
|
---|
101 | : (bits) == 32 ? bfd_get_32 (abfd, ptr) \
|
---|
102 | : (bits) == 64 ? bfd_get_64 (abfd, ptr) \
|
---|
103 | : (abort (), (bfd_vma) - 1))
|
---|
104 |
|
---|
105 | #define bfd_put(bits, abfd, val, ptr) \
|
---|
106 | ( (bits) == 8 ? bfd_put_8 (abfd, val, ptr) \
|
---|
107 | : (bits) == 16 ? bfd_put_16 (abfd, val, ptr) \
|
---|
108 | : (bits) == 32 ? bfd_put_32 (abfd, val, ptr) \
|
---|
109 | : (bits) == 64 ? bfd_put_64 (abfd, val, ptr) \
|
---|
110 | : (abort (), (void) 0))
|
---|
111 |
|
---|
112 | `bfd_h_put_size'
|
---|
113 | ................
|
---|
114 |
|
---|
115 | *Description*
|
---|
116 | These macros have the same function as their `bfd_get_x' brethren,
|
---|
117 | except that they are used for removing information for the header
|
---|
118 | records of object files. Believe it or not, some object files keep
|
---|
119 | their header records in big endian order and their data in little
|
---|
120 | endian order.
|
---|
121 |
|
---|
122 | /* Byte swapping macros for file header data. */
|
---|
123 |
|
---|
124 | #define bfd_h_put_8(abfd, val, ptr) \
|
---|
125 | bfd_put_8 (abfd, val, ptr)
|
---|
126 | #define bfd_h_put_signed_8(abfd, val, ptr) \
|
---|
127 | bfd_put_8 (abfd, val, ptr)
|
---|
128 | #define bfd_h_get_8(abfd, ptr) \
|
---|
129 | bfd_get_8 (abfd, ptr)
|
---|
130 | #define bfd_h_get_signed_8(abfd, ptr) \
|
---|
131 | bfd_get_signed_8 (abfd, ptr)
|
---|
132 |
|
---|
133 | #define bfd_h_put_16(abfd, val, ptr) \
|
---|
134 | BFD_SEND (abfd, bfd_h_putx16, (val, ptr))
|
---|
135 | #define bfd_h_put_signed_16 \
|
---|
136 | bfd_h_put_16
|
---|
137 | #define bfd_h_get_16(abfd, ptr) \
|
---|
138 | BFD_SEND (abfd, bfd_h_getx16, (ptr))
|
---|
139 | #define bfd_h_get_signed_16(abfd, ptr) \
|
---|
140 | BFD_SEND (abfd, bfd_h_getx_signed_16, (ptr))
|
---|
141 |
|
---|
142 | #define bfd_h_put_32(abfd, val, ptr) \
|
---|
143 | BFD_SEND (abfd, bfd_h_putx32, (val, ptr))
|
---|
144 | #define bfd_h_put_signed_32 \
|
---|
145 | bfd_h_put_32
|
---|
146 | #define bfd_h_get_32(abfd, ptr) \
|
---|
147 | BFD_SEND (abfd, bfd_h_getx32, (ptr))
|
---|
148 | #define bfd_h_get_signed_32(abfd, ptr) \
|
---|
149 | BFD_SEND (abfd, bfd_h_getx_signed_32, (ptr))
|
---|
150 |
|
---|
151 | #define bfd_h_put_64(abfd, val, ptr) \
|
---|
152 | BFD_SEND (abfd, bfd_h_putx64, (val, ptr))
|
---|
153 | #define bfd_h_put_signed_64 \
|
---|
154 | bfd_h_put_64
|
---|
155 | #define bfd_h_get_64(abfd, ptr) \
|
---|
156 | BFD_SEND (abfd, bfd_h_getx64, (ptr))
|
---|
157 | #define bfd_h_get_signed_64(abfd, ptr) \
|
---|
158 | BFD_SEND (abfd, bfd_h_getx_signed_64, (ptr))
|
---|
159 |
|
---|
160 | /* Refinements on the above, which should eventually go away. Save
|
---|
161 | cluttering the source with (bfd_vma) and (bfd_byte *) casts. */
|
---|
162 |
|
---|
163 | #define H_PUT_64(abfd, val, where) \
|
---|
164 | bfd_h_put_64 ((abfd), (bfd_vma) (val), (bfd_byte *) (where))
|
---|
165 |
|
---|
166 | #define H_PUT_32(abfd, val, where) \
|
---|
167 | bfd_h_put_32 ((abfd), (bfd_vma) (val), (bfd_byte *) (where))
|
---|
168 |
|
---|
169 | #define H_PUT_16(abfd, val, where) \
|
---|
170 | bfd_h_put_16 ((abfd), (bfd_vma) (val), (bfd_byte *) (where))
|
---|
171 |
|
---|
172 | #define H_PUT_8 bfd_h_put_8
|
---|
173 |
|
---|
174 | #define H_PUT_S64(abfd, val, where) \
|
---|
175 | bfd_h_put_signed_64 ((abfd), (bfd_vma) (val), (bfd_byte *) (where))
|
---|
176 |
|
---|
177 | #define H_PUT_S32(abfd, val, where) \
|
---|
178 | bfd_h_put_signed_32 ((abfd), (bfd_vma) (val), (bfd_byte *) (where))
|
---|
179 |
|
---|
180 | #define H_PUT_S16(abfd, val, where) \
|
---|
181 | bfd_h_put_signed_16 ((abfd), (bfd_vma) (val), (bfd_byte *) (where))
|
---|
182 |
|
---|
183 | #define H_PUT_S8 bfd_h_put_signed_8
|
---|
184 |
|
---|
185 | #define H_GET_64(abfd, where) \
|
---|
186 | bfd_h_get_64 ((abfd), (bfd_byte *) (where))
|
---|
187 |
|
---|
188 | #define H_GET_32(abfd, where) \
|
---|
189 | bfd_h_get_32 ((abfd), (bfd_byte *) (where))
|
---|
190 |
|
---|
191 | #define H_GET_16(abfd, where) \
|
---|
192 | bfd_h_get_16 ((abfd), (bfd_byte *) (where))
|
---|
193 |
|
---|
194 | #define H_GET_8 bfd_h_get_8
|
---|
195 |
|
---|
196 | #define H_GET_S64(abfd, where) \
|
---|
197 | bfd_h_get_signed_64 ((abfd), (bfd_byte *) (where))
|
---|
198 |
|
---|
199 | #define H_GET_S32(abfd, where) \
|
---|
200 | bfd_h_get_signed_32 ((abfd), (bfd_byte *) (where))
|
---|
201 |
|
---|
202 | #define H_GET_S16(abfd, where) \
|
---|
203 | bfd_h_get_signed_16 ((abfd), (bfd_byte *) (where))
|
---|
204 |
|
---|
205 | #define H_GET_S8 bfd_h_get_signed_8
|
---|
206 |
|
---|
207 | `bfd_log2'
|
---|
208 | ..........
|
---|
209 |
|
---|
210 | *Synopsis*
|
---|
211 | unsigned int bfd_log2 (bfd_vma x);
|
---|
212 | *Description*
|
---|
213 | Return the log base 2 of the value supplied, rounded up. E.g., an X of
|
---|
214 | 1025 returns 11. A X of 0 returns 0.
|
---|
215 |
|
---|
216 |
|
---|
217 | File: bfd.info, Node: File Caching, Next: Linker Functions, Prev: Internal, Up: BFD front end
|
---|
218 |
|
---|
219 | File caching
|
---|
220 | ============
|
---|
221 |
|
---|
222 | The file caching mechanism is embedded within BFD and allows the
|
---|
223 | application to open as many BFDs as it wants without regard to the
|
---|
224 | underlying operating system's file descriptor limit (often as low as 20
|
---|
225 | open files). The module in `cache.c' maintains a least recently used
|
---|
226 | list of `BFD_CACHE_MAX_OPEN' files, and exports the name
|
---|
227 | `bfd_cache_lookup', which runs around and makes sure that the required
|
---|
228 | BFD is open. If not, then it chooses a file to close, closes it and
|
---|
229 | opens the one wanted, returning its file handle.
|
---|
230 |
|
---|
231 | `BFD_CACHE_MAX_OPEN macro'
|
---|
232 | ..........................
|
---|
233 |
|
---|
234 | *Description*
|
---|
235 | The maximum number of files which the cache will keep open at one time.
|
---|
236 | #define BFD_CACHE_MAX_OPEN 10
|
---|
237 |
|
---|
238 | `bfd_last_cache'
|
---|
239 | ................
|
---|
240 |
|
---|
241 | *Synopsis*
|
---|
242 | extern bfd *bfd_last_cache;
|
---|
243 | *Description*
|
---|
244 | Zero, or a pointer to the topmost BFD on the chain. This is used by
|
---|
245 | the `bfd_cache_lookup' macro in `libbfd.h' to determine when it can
|
---|
246 | avoid a function call.
|
---|
247 |
|
---|
248 | `bfd_cache_lookup'
|
---|
249 | ..................
|
---|
250 |
|
---|
251 | *Description*
|
---|
252 | Check to see if the required BFD is the same as the last one looked up.
|
---|
253 | If so, then it can use the stream in the BFD with impunity, since it
|
---|
254 | can't have changed since the last lookup; otherwise, it has to perform
|
---|
255 | the complicated lookup function.
|
---|
256 | #define bfd_cache_lookup(x) \
|
---|
257 | ((x)==bfd_last_cache? \
|
---|
258 | (FILE*) (bfd_last_cache->iostream): \
|
---|
259 | bfd_cache_lookup_worker(x))
|
---|
260 |
|
---|
261 | `bfd_cache_init'
|
---|
262 | ................
|
---|
263 |
|
---|
264 | *Synopsis*
|
---|
265 | bfd_boolean bfd_cache_init (bfd *abfd);
|
---|
266 | *Description*
|
---|
267 | Add a newly opened BFD to the cache.
|
---|
268 |
|
---|
269 | `bfd_cache_close'
|
---|
270 | .................
|
---|
271 |
|
---|
272 | *Synopsis*
|
---|
273 | bfd_boolean bfd_cache_close (bfd *abfd);
|
---|
274 | *Description*
|
---|
275 | Remove the BFD ABFD from the cache. If the attached file is open, then
|
---|
276 | close it too.
|
---|
277 |
|
---|
278 | *Returns*
|
---|
279 | `FALSE' is returned if closing the file fails, `TRUE' is returned if
|
---|
280 | all is well.
|
---|
281 |
|
---|
282 | `bfd_open_file'
|
---|
283 | ...............
|
---|
284 |
|
---|
285 | *Synopsis*
|
---|
286 | FILE* bfd_open_file(bfd *abfd);
|
---|
287 | *Description*
|
---|
288 | Call the OS to open a file for ABFD. Return the `FILE *' (possibly
|
---|
289 | `NULL') that results from this operation. Set up the BFD so that
|
---|
290 | future accesses know the file is open. If the `FILE *' returned is
|
---|
291 | `NULL', then it won't have been put in the cache, so it won't have to
|
---|
292 | be removed from it.
|
---|
293 |
|
---|
294 | `bfd_cache_lookup_worker'
|
---|
295 | .........................
|
---|
296 |
|
---|
297 | *Synopsis*
|
---|
298 | FILE *bfd_cache_lookup_worker(bfd *abfd);
|
---|
299 | *Description*
|
---|
300 | Called when the macro `bfd_cache_lookup' fails to find a quick answer.
|
---|
301 | Find a file descriptor for ABFD. If necessary, it open it. If there
|
---|
302 | are already more than `BFD_CACHE_MAX_OPEN' files open, it tries to
|
---|
303 | close one first, to avoid running out of file descriptors.
|
---|
304 |
|
---|
305 |
|
---|
306 | File: bfd.info, Node: Linker Functions, Next: Hash Tables, Prev: File Caching, Up: BFD front end
|
---|
307 |
|
---|
308 | Linker Functions
|
---|
309 | ================
|
---|
310 |
|
---|
311 | The linker uses three special entry points in the BFD target vector.
|
---|
312 | It is not necessary to write special routines for these entry points
|
---|
313 | when creating a new BFD back end, since generic versions are provided.
|
---|
314 | However, writing them can speed up linking and make it use
|
---|
315 | significantly less runtime memory.
|
---|
316 |
|
---|
317 | The first routine creates a hash table used by the other routines.
|
---|
318 | The second routine adds the symbols from an object file to the hash
|
---|
319 | table. The third routine takes all the object files and links them
|
---|
320 | together to create the output file. These routines are designed so
|
---|
321 | that the linker proper does not need to know anything about the symbols
|
---|
322 | in the object files that it is linking. The linker merely arranges the
|
---|
323 | sections as directed by the linker script and lets BFD handle the
|
---|
324 | details of symbols and relocs.
|
---|
325 |
|
---|
326 | The second routine and third routines are passed a pointer to a
|
---|
327 | `struct bfd_link_info' structure (defined in `bfdlink.h') which holds
|
---|
328 | information relevant to the link, including the linker hash table
|
---|
329 | (which was created by the first routine) and a set of callback
|
---|
330 | functions to the linker proper.
|
---|
331 |
|
---|
332 | The generic linker routines are in `linker.c', and use the header
|
---|
333 | file `genlink.h'. As of this writing, the only back ends which have
|
---|
334 | implemented versions of these routines are a.out (in `aoutx.h') and
|
---|
335 | ECOFF (in `ecoff.c'). The a.out routines are used as examples
|
---|
336 | throughout this section.
|
---|
337 |
|
---|
338 | * Menu:
|
---|
339 |
|
---|
340 | * Creating a Linker Hash Table::
|
---|
341 | * Adding Symbols to the Hash Table::
|
---|
342 | * Performing the Final Link::
|
---|
343 |
|
---|
344 |
|
---|
345 | File: bfd.info, Node: Creating a Linker Hash Table, Next: Adding Symbols to the Hash Table, Prev: Linker Functions, Up: Linker Functions
|
---|
346 |
|
---|
347 | Creating a linker hash table
|
---|
348 | ----------------------------
|
---|
349 |
|
---|
350 | The linker routines must create a hash table, which must be derived
|
---|
351 | from `struct bfd_link_hash_table' described in `bfdlink.c'. *Note Hash
|
---|
352 | Tables::, for information on how to create a derived hash table. This
|
---|
353 | entry point is called using the target vector of the linker output file.
|
---|
354 |
|
---|
355 | The `_bfd_link_hash_table_create' entry point must allocate and
|
---|
356 | initialize an instance of the desired hash table. If the back end does
|
---|
357 | not require any additional information to be stored with the entries in
|
---|
358 | the hash table, the entry point may simply create a `struct
|
---|
359 | bfd_link_hash_table'. Most likely, however, some additional
|
---|
360 | information will be needed.
|
---|
361 |
|
---|
362 | For example, with each entry in the hash table the a.out linker
|
---|
363 | keeps the index the symbol has in the final output file (this index
|
---|
364 | number is used so that when doing a relocateable link the symbol index
|
---|
365 | used in the output file can be quickly filled in when copying over a
|
---|
366 | reloc). The a.out linker code defines the required structures and
|
---|
367 | functions for a hash table derived from `struct bfd_link_hash_table'.
|
---|
368 | The a.out linker hash table is created by the function
|
---|
369 | `NAME(aout,link_hash_table_create)'; it simply allocates space for the
|
---|
370 | hash table, initializes it, and returns a pointer to it.
|
---|
371 |
|
---|
372 | When writing the linker routines for a new back end, you will
|
---|
373 | generally not know exactly which fields will be required until you have
|
---|
374 | finished. You should simply create a new hash table which defines no
|
---|
375 | additional fields, and then simply add fields as they become necessary.
|
---|
376 |
|
---|
377 |
|
---|
378 | File: bfd.info, Node: Adding Symbols to the Hash Table, Next: Performing the Final Link, Prev: Creating a Linker Hash Table, Up: Linker Functions
|
---|
379 |
|
---|
380 | Adding symbols to the hash table
|
---|
381 | --------------------------------
|
---|
382 |
|
---|
383 | The linker proper will call the `_bfd_link_add_symbols' entry point
|
---|
384 | for each object file or archive which is to be linked (typically these
|
---|
385 | are the files named on the command line, but some may also come from
|
---|
386 | the linker script). The entry point is responsible for examining the
|
---|
387 | file. For an object file, BFD must add any relevant symbol information
|
---|
388 | to the hash table. For an archive, BFD must determine which elements
|
---|
389 | of the archive should be used and adding them to the link.
|
---|
390 |
|
---|
391 | The a.out version of this entry point is
|
---|
392 | `NAME(aout,link_add_symbols)'.
|
---|
393 |
|
---|
394 | * Menu:
|
---|
395 |
|
---|
396 | * Differing file formats::
|
---|
397 | * Adding symbols from an object file::
|
---|
398 | * Adding symbols from an archive::
|
---|
399 |
|
---|
400 |
|
---|
401 | 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
|
---|
402 |
|
---|
403 | Differing file formats
|
---|
404 | ......................
|
---|
405 |
|
---|
406 | Normally all the files involved in a link will be of the same
|
---|
407 | format, but it is also possible to link together different format
|
---|
408 | object files, and the back end must support that. The
|
---|
409 | `_bfd_link_add_symbols' entry point is called via the target vector of
|
---|
410 | the file to be added. This has an important consequence: the function
|
---|
411 | may not assume that the hash table is the type created by the
|
---|
412 | corresponding `_bfd_link_hash_table_create' vector. All the
|
---|
413 | `_bfd_link_add_symbols' function can assume about the hash table is
|
---|
414 | that it is derived from `struct bfd_link_hash_table'.
|
---|
415 |
|
---|
416 | Sometimes the `_bfd_link_add_symbols' function must store some
|
---|
417 | information in the hash table entry to be used by the `_bfd_final_link'
|
---|
418 | function. In such a case the `creator' field of the hash table must be
|
---|
419 | checked to make sure that the hash table was created by an object file
|
---|
420 | of the same format.
|
---|
421 |
|
---|
422 | The `_bfd_final_link' routine must be prepared to handle a hash
|
---|
423 | entry without any extra information added by the
|
---|
424 | `_bfd_link_add_symbols' function. A hash entry without extra
|
---|
425 | information will also occur when the linker script directs the linker
|
---|
426 | to create a symbol. Note that, regardless of how a hash table entry is
|
---|
427 | added, all the fields will be initialized to some sort of null value by
|
---|
428 | the hash table entry initialization function.
|
---|
429 |
|
---|
430 | See `ecoff_link_add_externals' for an example of how to check the
|
---|
431 | `creator' field before saving information (in this case, the ECOFF
|
---|
432 | external symbol debugging information) in a hash table entry.
|
---|
433 |
|
---|
434 |
|
---|
435 | 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
|
---|
436 |
|
---|
437 | Adding symbols from an object file
|
---|
438 | ..................................
|
---|
439 |
|
---|
440 | When the `_bfd_link_add_symbols' routine is passed an object file,
|
---|
441 | it must add all externally visible symbols in that object file to the
|
---|
442 | hash table. The actual work of adding the symbol to the hash table is
|
---|
443 | normally handled by the function `_bfd_generic_link_add_one_symbol'.
|
---|
444 | The `_bfd_link_add_symbols' routine is responsible for reading all the
|
---|
445 | symbols from the object file and passing the correct information to
|
---|
446 | `_bfd_generic_link_add_one_symbol'.
|
---|
447 |
|
---|
448 | The `_bfd_link_add_symbols' routine should not use
|
---|
449 | `bfd_canonicalize_symtab' to read the symbols. The point of providing
|
---|
450 | this routine is to avoid the overhead of converting the symbols into
|
---|
451 | generic `asymbol' structures.
|
---|
452 |
|
---|
453 | `_bfd_generic_link_add_one_symbol' handles the details of combining
|
---|
454 | common symbols, warning about multiple definitions, and so forth. It
|
---|
455 | takes arguments which describe the symbol to add, notably symbol flags,
|
---|
456 | a section, and an offset. The symbol flags include such things as
|
---|
457 | `BSF_WEAK' or `BSF_INDIRECT'. The section is a section in the object
|
---|
458 | file, or something like `bfd_und_section_ptr' for an undefined symbol
|
---|
459 | or `bfd_com_section_ptr' for a common symbol.
|
---|
460 |
|
---|
461 | If the `_bfd_final_link' routine is also going to need to read the
|
---|
462 | symbol information, the `_bfd_link_add_symbols' routine should save it
|
---|
463 | somewhere attached to the object file BFD. However, the information
|
---|
464 | should only be saved if the `keep_memory' field of the `info' argument
|
---|
465 | is TRUE, so that the `-no-keep-memory' linker switch is effective.
|
---|
466 |
|
---|
467 | The a.out function which adds symbols from an object file is
|
---|
468 | `aout_link_add_object_symbols', and most of the interesting work is in
|
---|
469 | `aout_link_add_symbols'. The latter saves pointers to the hash tables
|
---|
470 | entries created by `_bfd_generic_link_add_one_symbol' indexed by symbol
|
---|
471 | number, so that the `_bfd_final_link' routine does not have to call the
|
---|
472 | hash table lookup routine to locate the entry.
|
---|
473 |
|
---|
474 |
|
---|
475 | File: bfd.info, Node: Adding symbols from an archive, Prev: Adding symbols from an object file, Up: Adding Symbols to the Hash Table
|
---|
476 |
|
---|
477 | Adding symbols from an archive
|
---|
478 | ..............................
|
---|
479 |
|
---|
480 | When the `_bfd_link_add_symbols' routine is passed an archive, it
|
---|
481 | must look through the symbols defined by the archive and decide which
|
---|
482 | elements of the archive should be included in the link. For each such
|
---|
483 | element it must call the `add_archive_element' linker callback, and it
|
---|
484 | must add the symbols from the object file to the linker hash table.
|
---|
485 |
|
---|
486 | In most cases the work of looking through the symbols in the archive
|
---|
487 | should be done by the `_bfd_generic_link_add_archive_symbols' function.
|
---|
488 | This function builds a hash table from the archive symbol table and
|
---|
489 | looks through the list of undefined symbols to see which elements
|
---|
490 | should be included. `_bfd_generic_link_add_archive_symbols' is passed
|
---|
491 | a function to call to make the final decision about adding an archive
|
---|
492 | element to the link and to do the actual work of adding the symbols to
|
---|
493 | the linker hash table.
|
---|
494 |
|
---|
495 | The function passed to `_bfd_generic_link_add_archive_symbols' must
|
---|
496 | read the symbols of the archive element and decide whether the archive
|
---|
497 | element should be included in the link. If the element is to be
|
---|
498 | included, the `add_archive_element' linker callback routine must be
|
---|
499 | called with the element as an argument, and the elements symbols must
|
---|
500 | be added to the linker hash table just as though the element had itself
|
---|
501 | been passed to the `_bfd_link_add_symbols' function.
|
---|
502 |
|
---|
503 | When the a.out `_bfd_link_add_symbols' function receives an archive,
|
---|
504 | it calls `_bfd_generic_link_add_archive_symbols' passing
|
---|
505 | `aout_link_check_archive_element' as the function argument.
|
---|
506 | `aout_link_check_archive_element' calls `aout_link_check_ar_symbols'.
|
---|
507 | If the latter decides to add the element (an element is only added if
|
---|
508 | it provides a real, non-common, definition for a previously undefined
|
---|
509 | or common symbol) it calls the `add_archive_element' callback and then
|
---|
510 | `aout_link_check_archive_element' calls `aout_link_add_symbols' to
|
---|
511 | actually add the symbols to the linker hash table.
|
---|
512 |
|
---|
513 | The ECOFF back end is unusual in that it does not normally call
|
---|
514 | `_bfd_generic_link_add_archive_symbols', because ECOFF archives already
|
---|
515 | contain a hash table of symbols. The ECOFF back end searches the
|
---|
516 | archive itself to avoid the overhead of creating a new hash table.
|
---|
517 |
|
---|
518 |
|
---|
519 | File: bfd.info, Node: Performing the Final Link, Prev: Adding Symbols to the Hash Table, Up: Linker Functions
|
---|
520 |
|
---|
521 | Performing the final link
|
---|
522 | -------------------------
|
---|
523 |
|
---|
524 | When all the input files have been processed, the linker calls the
|
---|
525 | `_bfd_final_link' entry point of the output BFD. This routine is
|
---|
526 | responsible for producing the final output file, which has several
|
---|
527 | aspects. It must relocate the contents of the input sections and copy
|
---|
528 | the data into the output sections. It must build an output symbol
|
---|
529 | table including any local symbols from the input files and the global
|
---|
530 | symbols from the hash table. When producing relocateable output, it
|
---|
531 | must modify the input relocs and write them into the output file.
|
---|
532 | There may also be object format dependent work to be done.
|
---|
533 |
|
---|
534 | The linker will also call the `write_object_contents' entry point
|
---|
535 | when the BFD is closed. The two entry points must work together in
|
---|
536 | order to produce the correct output file.
|
---|
537 |
|
---|
538 | The details of how this works are inevitably dependent upon the
|
---|
539 | specific object file format. The a.out `_bfd_final_link' routine is
|
---|
540 | `NAME(aout,final_link)'.
|
---|
541 |
|
---|
542 | * Menu:
|
---|
543 |
|
---|
544 | * Information provided by the linker::
|
---|
545 | * Relocating the section contents::
|
---|
546 | * Writing the symbol table::
|
---|
547 |
|
---|
548 |
|
---|
549 | File: bfd.info, Node: Information provided by the linker, Next: Relocating the section contents, Prev: Performing the Final Link, Up: Performing the Final Link
|
---|
550 |
|
---|
551 | Information provided by the linker
|
---|
552 | ..................................
|
---|
553 |
|
---|
554 | Before the linker calls the `_bfd_final_link' entry point, it sets
|
---|
555 | up some data structures for the function to use.
|
---|
556 |
|
---|
557 | The `input_bfds' field of the `bfd_link_info' structure will point
|
---|
558 | to a list of all the input files included in the link. These files are
|
---|
559 | linked through the `link_next' field of the `bfd' structure.
|
---|
560 |
|
---|
561 | Each section in the output file will have a list of `link_order'
|
---|
562 | structures attached to the `link_order_head' field (the `link_order'
|
---|
563 | structure is defined in `bfdlink.h'). These structures describe how to
|
---|
564 | create the contents of the output section in terms of the contents of
|
---|
565 | various input sections, fill constants, and, eventually, other types of
|
---|
566 | information. They also describe relocs that must be created by the BFD
|
---|
567 | backend, but do not correspond to any input file; this is used to
|
---|
568 | support -Ur, which builds constructors while generating a relocateable
|
---|
569 | object file.
|
---|
570 |
|
---|
571 |
|
---|
572 | File: bfd.info, Node: Relocating the section contents, Next: Writing the symbol table, Prev: Information provided by the linker, Up: Performing the Final Link
|
---|
573 |
|
---|
574 | Relocating the section contents
|
---|
575 | ...............................
|
---|
576 |
|
---|
577 | The `_bfd_final_link' function should look through the `link_order'
|
---|
578 | structures attached to each section of the output file. Each
|
---|
579 | `link_order' structure should either be handled specially, or it should
|
---|
580 | be passed to the function `_bfd_default_link_order' which will do the
|
---|
581 | right thing (`_bfd_default_link_order' is defined in `linker.c').
|
---|
582 |
|
---|
583 | For efficiency, a `link_order' of type `bfd_indirect_link_order'
|
---|
584 | whose associated section belongs to a BFD of the same format as the
|
---|
585 | output BFD must be handled specially. This type of `link_order'
|
---|
586 | describes part of an output section in terms of a section belonging to
|
---|
587 | one of the input files. The `_bfd_final_link' function should read the
|
---|
588 | contents of the section and any associated relocs, apply the relocs to
|
---|
589 | the section contents, and write out the modified section contents. If
|
---|
590 | performing a relocateable link, the relocs themselves must also be
|
---|
591 | modified and written out.
|
---|
592 |
|
---|
593 | The functions `_bfd_relocate_contents' and
|
---|
594 | `_bfd_final_link_relocate' provide some general support for performing
|
---|
595 | the actual relocations, notably overflow checking. Their arguments
|
---|
596 | include information about the symbol the relocation is against and a
|
---|
597 | `reloc_howto_type' argument which describes the relocation to perform.
|
---|
598 | These functions are defined in `reloc.c'.
|
---|
599 |
|
---|
600 | The a.out function which handles reading, relocating, and writing
|
---|
601 | section contents is `aout_link_input_section'. The actual relocation
|
---|
602 | is done in `aout_link_input_section_std' and
|
---|
603 | `aout_link_input_section_ext'.
|
---|
604 |
|
---|
605 |
|
---|
606 | File: bfd.info, Node: Writing the symbol table, Prev: Relocating the section contents, Up: Performing the Final Link
|
---|
607 |
|
---|
608 | Writing the symbol table
|
---|
609 | ........................
|
---|
610 |
|
---|
611 | The `_bfd_final_link' function must gather all the symbols in the
|
---|
612 | input files and write them out. It must also write out all the symbols
|
---|
613 | in the global hash table. This must be controlled by the `strip' and
|
---|
614 | `discard' fields of the `bfd_link_info' structure.
|
---|
615 |
|
---|
616 | The local symbols of the input files will not have been entered into
|
---|
617 | the linker hash table. The `_bfd_final_link' routine must consider
|
---|
618 | each input file and include the symbols in the output file. It may be
|
---|
619 | convenient to do this when looking through the `link_order' structures,
|
---|
620 | or it may be done by stepping through the `input_bfds' list.
|
---|
621 |
|
---|
622 | The `_bfd_final_link' routine must also traverse the global hash
|
---|
623 | table to gather all the externally visible symbols. It is possible
|
---|
624 | that most of the externally visible symbols may be written out when
|
---|
625 | considering the symbols of each input file, but it is still necessary
|
---|
626 | to traverse the hash table since the linker script may have defined
|
---|
627 | some symbols that are not in any of the input files.
|
---|
628 |
|
---|
629 | The `strip' field of the `bfd_link_info' structure controls which
|
---|
630 | symbols are written out. The possible values are listed in
|
---|
631 | `bfdlink.h'. If the value is `strip_some', then the `keep_hash' field
|
---|
632 | of the `bfd_link_info' structure is a hash table of symbols to keep;
|
---|
633 | each symbol should be looked up in this hash table, and only symbols
|
---|
634 | which are present should be included in the output file.
|
---|
635 |
|
---|
636 | If the `strip' field of the `bfd_link_info' structure permits local
|
---|
637 | symbols to be written out, the `discard' field is used to further
|
---|
638 | controls which local symbols are included in the output file. If the
|
---|
639 | value is `discard_l', then all local symbols which begin with a certain
|
---|
640 | prefix are discarded; this is controlled by the
|
---|
641 | `bfd_is_local_label_name' entry point.
|
---|
642 |
|
---|
643 | The a.out backend handles symbols by calling
|
---|
644 | `aout_link_write_symbols' on each input BFD and then traversing the
|
---|
645 | global hash table with the function `aout_link_write_other_symbol'. It
|
---|
646 | builds a string table while writing out the symbols, which is written
|
---|
647 | to the output file at the end of `NAME(aout,final_link)'.
|
---|
648 |
|
---|
649 | `bfd_link_split_section'
|
---|
650 | ........................
|
---|
651 |
|
---|
652 | *Synopsis*
|
---|
653 | bfd_boolean bfd_link_split_section(bfd *abfd, asection *sec);
|
---|
654 | *Description*
|
---|
655 | Return nonzero if SEC should be split during a reloceatable or final
|
---|
656 | link.
|
---|
657 | #define bfd_link_split_section(abfd, sec) \
|
---|
658 | BFD_SEND (abfd, _bfd_link_split_section, (abfd, sec))
|
---|
659 |
|
---|
660 |
|
---|
661 | File: bfd.info, Node: Hash Tables, Prev: Linker Functions, Up: BFD front end
|
---|
662 |
|
---|
663 | Hash Tables
|
---|
664 | ===========
|
---|
665 |
|
---|
666 | BFD provides a simple set of hash table functions. Routines are
|
---|
667 | provided to initialize a hash table, to free a hash table, to look up a
|
---|
668 | string in a hash table and optionally create an entry for it, and to
|
---|
669 | traverse a hash table. There is currently no routine to delete an
|
---|
670 | string from a hash table.
|
---|
671 |
|
---|
672 | The basic hash table does not permit any data to be stored with a
|
---|
673 | string. However, a hash table is designed to present a base class from
|
---|
674 | which other types of hash tables may be derived. These derived types
|
---|
675 | may store additional information with the string. Hash tables were
|
---|
676 | implemented in this way, rather than simply providing a data pointer in
|
---|
677 | a hash table entry, because they were designed for use by the linker
|
---|
678 | back ends. The linker may create thousands of hash table entries, and
|
---|
679 | the overhead of allocating private data and storing and following
|
---|
680 | pointers becomes noticeable.
|
---|
681 |
|
---|
682 | The basic hash table code is in `hash.c'.
|
---|
683 |
|
---|
684 | * Menu:
|
---|
685 |
|
---|
686 | * Creating and Freeing a Hash Table::
|
---|
687 | * Looking Up or Entering a String::
|
---|
688 | * Traversing a Hash Table::
|
---|
689 | * Deriving a New Hash Table Type::
|
---|
690 |
|
---|
691 |
|
---|
692 | File: bfd.info, Node: Creating and Freeing a Hash Table, Next: Looking Up or Entering a String, Prev: Hash Tables, Up: Hash Tables
|
---|
693 |
|
---|
694 | Creating and freeing a hash table
|
---|
695 | ---------------------------------
|
---|
696 |
|
---|
697 | To create a hash table, create an instance of a `struct
|
---|
698 | bfd_hash_table' (defined in `bfd.h') and call `bfd_hash_table_init' (if
|
---|
699 | you know approximately how many entries you will need, the function
|
---|
700 | `bfd_hash_table_init_n', which takes a SIZE argument, may be used).
|
---|
701 | `bfd_hash_table_init' returns `FALSE' if some sort of error occurs.
|
---|
702 |
|
---|
703 | The function `bfd_hash_table_init' take as an argument a function to
|
---|
704 | use to create new entries. For a basic hash table, use the function
|
---|
705 | `bfd_hash_newfunc'. *Note Deriving a New Hash Table Type::, for why
|
---|
706 | you would want to use a different value for this argument.
|
---|
707 |
|
---|
708 | `bfd_hash_table_init' will create an objalloc which will be used to
|
---|
709 | allocate new entries. You may allocate memory on this objalloc using
|
---|
710 | `bfd_hash_allocate'.
|
---|
711 |
|
---|
712 | Use `bfd_hash_table_free' to free up all the memory that has been
|
---|
713 | allocated for a hash table. This will not free up the `struct
|
---|
714 | bfd_hash_table' itself, which you must provide.
|
---|
715 |
|
---|
716 |
|
---|
717 | 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
|
---|
718 |
|
---|
719 | Looking up or entering a string
|
---|
720 | -------------------------------
|
---|
721 |
|
---|
722 | The function `bfd_hash_lookup' is used both to look up a string in
|
---|
723 | the hash table and to create a new entry.
|
---|
724 |
|
---|
725 | If the CREATE argument is `FALSE', `bfd_hash_lookup' will look up a
|
---|
726 | string. If the string is found, it will returns a pointer to a `struct
|
---|
727 | bfd_hash_entry'. If the string is not found in the table
|
---|
728 | `bfd_hash_lookup' will return `NULL'. You should not modify any of the
|
---|
729 | fields in the returns `struct bfd_hash_entry'.
|
---|
730 |
|
---|
731 | If the CREATE argument is `TRUE', the string will be entered into
|
---|
732 | the hash table if it is not already there. Either way a pointer to a
|
---|
733 | `struct bfd_hash_entry' will be returned, either to the existing
|
---|
734 | structure or to a newly created one. In this case, a `NULL' return
|
---|
735 | means that an error occurred.
|
---|
736 |
|
---|
737 | If the CREATE argument is `TRUE', and a new entry is created, the
|
---|
738 | COPY argument is used to decide whether to copy the string onto the
|
---|
739 | hash table objalloc or not. If COPY is passed as `FALSE', you must be
|
---|
740 | careful not to deallocate or modify the string as long as the hash table
|
---|
741 | exists.
|
---|
742 |
|
---|
743 |
|
---|
744 | 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
|
---|
745 |
|
---|
746 | Traversing a hash table
|
---|
747 | -----------------------
|
---|
748 |
|
---|
749 | The function `bfd_hash_traverse' may be used to traverse a hash
|
---|
750 | table, calling a function on each element. The traversal is done in a
|
---|
751 | random order.
|
---|
752 |
|
---|
753 | `bfd_hash_traverse' takes as arguments a function and a generic
|
---|
754 | `void *' pointer. The function is called with a hash table entry (a
|
---|
755 | `struct bfd_hash_entry *') and the generic pointer passed to
|
---|
756 | `bfd_hash_traverse'. The function must return a `boolean' value, which
|
---|
757 | indicates whether to continue traversing the hash table. If the
|
---|
758 | function returns `FALSE', `bfd_hash_traverse' will stop the traversal
|
---|
759 | and return immediately.
|
---|
760 |
|
---|
761 |
|
---|
762 | File: bfd.info, Node: Deriving a New Hash Table Type, Prev: Traversing a Hash Table, Up: Hash Tables
|
---|
763 |
|
---|
764 | Deriving a new hash table type
|
---|
765 | ------------------------------
|
---|
766 |
|
---|
767 | Many uses of hash tables want to store additional information which
|
---|
768 | each entry in the hash table. Some also find it convenient to store
|
---|
769 | additional information with the hash table itself. This may be done
|
---|
770 | using a derived hash table.
|
---|
771 |
|
---|
772 | Since C is not an object oriented language, creating a derived hash
|
---|
773 | table requires sticking together some boilerplate routines with a few
|
---|
774 | differences specific to the type of hash table you want to create.
|
---|
775 |
|
---|
776 | An example of a derived hash table is the linker hash table. The
|
---|
777 | structures for this are defined in `bfdlink.h'. The functions are in
|
---|
778 | `linker.c'.
|
---|
779 |
|
---|
780 | You may also derive a hash table from an already derived hash table.
|
---|
781 | For example, the a.out linker backend code uses a hash table derived
|
---|
782 | from the linker hash table.
|
---|
783 |
|
---|
784 | * Menu:
|
---|
785 |
|
---|
786 | * Define the Derived Structures::
|
---|
787 | * Write the Derived Creation Routine::
|
---|
788 | * Write Other Derived Routines::
|
---|
789 |
|
---|
790 |
|
---|
791 | 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
|
---|
792 |
|
---|
793 | Define the derived structures
|
---|
794 | .............................
|
---|
795 |
|
---|
796 | You must define a structure for an entry in the hash table, and a
|
---|
797 | structure for the hash table itself.
|
---|
798 |
|
---|
799 | The first field in the structure for an entry in the hash table must
|
---|
800 | be of the type used for an entry in the hash table you are deriving
|
---|
801 | from. If you are deriving from a basic hash table this is `struct
|
---|
802 | bfd_hash_entry', which is defined in `bfd.h'. The first field in the
|
---|
803 | structure for the hash table itself must be of the type of the hash
|
---|
804 | table you are deriving from itself. If you are deriving from a basic
|
---|
805 | hash table, this is `struct bfd_hash_table'.
|
---|
806 |
|
---|
807 | For example, the linker hash table defines `struct
|
---|
808 | bfd_link_hash_entry' (in `bfdlink.h'). The first field, `root', is of
|
---|
809 | type `struct bfd_hash_entry'. Similarly, the first field in `struct
|
---|
810 | bfd_link_hash_table', `table', is of type `struct bfd_hash_table'.
|
---|
811 |
|
---|
812 |
|
---|
813 | 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
|
---|
814 |
|
---|
815 | Write the derived creation routine
|
---|
816 | ..................................
|
---|
817 |
|
---|
818 | You must write a routine which will create and initialize an entry
|
---|
819 | in the hash table. This routine is passed as the function argument to
|
---|
820 | `bfd_hash_table_init'.
|
---|
821 |
|
---|
822 | In order to permit other hash tables to be derived from the hash
|
---|
823 | table you are creating, this routine must be written in a standard way.
|
---|
824 |
|
---|
825 | The first argument to the creation routine is a pointer to a hash
|
---|
826 | table entry. This may be `NULL', in which case the routine should
|
---|
827 | allocate the right amount of space. Otherwise the space has already
|
---|
828 | been allocated by a hash table type derived from this one.
|
---|
829 |
|
---|
830 | After allocating space, the creation routine must call the creation
|
---|
831 | routine of the hash table type it is derived from, passing in a pointer
|
---|
832 | to the space it just allocated. This will initialize any fields used
|
---|
833 | by the base hash table.
|
---|
834 |
|
---|
835 | Finally the creation routine must initialize any local fields for
|
---|
836 | the new hash table type.
|
---|
837 |
|
---|
838 | Here is a boilerplate example of a creation routine. FUNCTION_NAME
|
---|
839 | is the name of the routine. ENTRY_TYPE is the type of an entry in the
|
---|
840 | hash table you are creating. BASE_NEWFUNC is the name of the creation
|
---|
841 | routine of the hash table type your hash table is derived from.
|
---|
842 |
|
---|
843 | struct bfd_hash_entry *
|
---|
844 | FUNCTION_NAME (entry, table, string)
|
---|
845 | struct bfd_hash_entry *entry;
|
---|
846 | struct bfd_hash_table *table;
|
---|
847 | const char *string;
|
---|
848 | {
|
---|
849 | struct ENTRY_TYPE *ret = (ENTRY_TYPE *) entry;
|
---|
850 |
|
---|
851 | /* Allocate the structure if it has not already been allocated by a
|
---|
852 | derived class. */
|
---|
853 | if (ret == (ENTRY_TYPE *) NULL)
|
---|
854 | {
|
---|
855 | ret = ((ENTRY_TYPE *)
|
---|
856 | bfd_hash_allocate (table, sizeof (ENTRY_TYPE)));
|
---|
857 | if (ret == (ENTRY_TYPE *) NULL)
|
---|
858 | return NULL;
|
---|
859 | }
|
---|
860 |
|
---|
861 | /* Call the allocation method of the base class. */
|
---|
862 | ret = ((ENTRY_TYPE *)
|
---|
863 | BASE_NEWFUNC ((struct bfd_hash_entry *) ret, table, string));
|
---|
864 |
|
---|
865 | /* Initialize the local fields here. */
|
---|
866 |
|
---|
867 | return (struct bfd_hash_entry *) ret;
|
---|
868 | }
|
---|
869 | *Description*
|
---|
870 | The creation routine for the linker hash table, which is in `linker.c',
|
---|
871 | looks just like this example. FUNCTION_NAME is
|
---|
872 | `_bfd_link_hash_newfunc'. ENTRY_TYPE is `struct bfd_link_hash_entry'.
|
---|
873 | BASE_NEWFUNC is `bfd_hash_newfunc', the creation routine for a basic
|
---|
874 | hash table.
|
---|
875 |
|
---|
876 | `_bfd_link_hash_newfunc' also initializes the local fields in a
|
---|
877 | linker hash table entry: `type', `written' and `next'.
|
---|
878 |
|
---|
879 |
|
---|
880 | File: bfd.info, Node: Write Other Derived Routines, Prev: Write the Derived Creation Routine, Up: Deriving a New Hash Table Type
|
---|
881 |
|
---|
882 | Write other derived routines
|
---|
883 | ............................
|
---|
884 |
|
---|
885 | You will want to write other routines for your new hash table, as
|
---|
886 | well.
|
---|
887 |
|
---|
888 | You will want an initialization routine which calls the
|
---|
889 | initialization routine of the hash table you are deriving from and
|
---|
890 | initializes any other local fields. For the linker hash table, this is
|
---|
891 | `_bfd_link_hash_table_init' in `linker.c'.
|
---|
892 |
|
---|
893 | You will want a lookup routine which calls the lookup routine of the
|
---|
894 | hash table you are deriving from and casts the result. The linker hash
|
---|
895 | table uses `bfd_link_hash_lookup' in `linker.c' (this actually takes an
|
---|
896 | additional argument which it uses to decide how to return the looked up
|
---|
897 | value).
|
---|
898 |
|
---|
899 | You may want a traversal routine. This should just call the
|
---|
900 | traversal routine of the hash table you are deriving from with
|
---|
901 | appropriate casts. The linker hash table uses `bfd_link_hash_traverse'
|
---|
902 | in `linker.c'.
|
---|
903 |
|
---|
904 | These routines may simply be defined as macros. For example, the
|
---|
905 | a.out backend linker hash table, which is derived from the linker hash
|
---|
906 | table, uses macros for the lookup and traversal routines. These are
|
---|
907 | `aout_link_hash_lookup' and `aout_link_hash_traverse' in aoutx.h.
|
---|
908 |
|
---|
909 |
|
---|
910 | File: bfd.info, Node: BFD back ends, Next: GNU Free Documentation License, Prev: BFD front end, Up: Top
|
---|
911 |
|
---|
912 | BFD back ends
|
---|
913 | *************
|
---|
914 |
|
---|
915 | * Menu:
|
---|
916 |
|
---|
917 | * What to Put Where::
|
---|
918 | * aout :: a.out backends
|
---|
919 | * coff :: coff backends
|
---|
920 | * elf :: elf backends
|
---|
921 | * mmo :: mmo backend
|
---|
922 |
|
---|
923 |
|
---|
924 | File: bfd.info, Node: What to Put Where, Next: aout, Prev: BFD back ends, Up: BFD back ends
|
---|
925 |
|
---|
926 | All of BFD lives in one directory.
|
---|
927 |
|
---|
928 |
|
---|
929 | File: bfd.info, Node: aout, Next: coff, Prev: What to Put Where, Up: BFD back ends
|
---|
930 |
|
---|
931 | a.out backends
|
---|
932 | ==============
|
---|
933 |
|
---|
934 | *Description*
|
---|
935 | BFD supports a number of different flavours of a.out format, though the
|
---|
936 | major differences are only the sizes of the structures on disk, and the
|
---|
937 | shape of the relocation information.
|
---|
938 |
|
---|
939 | The support is split into a basic support file `aoutx.h' and other
|
---|
940 | files which derive functions from the base. One derivation file is
|
---|
941 | `aoutf1.h' (for a.out flavour 1), and adds to the basic a.out functions
|
---|
942 | support for sun3, sun4, 386 and 29k a.out files, to create a target
|
---|
943 | jump vector for a specific target.
|
---|
944 |
|
---|
945 | This information is further split out into more specific files for
|
---|
946 | each machine, including `sunos.c' for sun3 and sun4, `newsos3.c' for
|
---|
947 | the Sony NEWS, and `demo64.c' for a demonstration of a 64 bit a.out
|
---|
948 | format.
|
---|
949 |
|
---|
950 | The base file `aoutx.h' defines general mechanisms for reading and
|
---|
951 | writing records to and from disk and various other methods which BFD
|
---|
952 | requires. It is included by `aout32.c' and `aout64.c' to form the names
|
---|
953 | `aout_32_swap_exec_header_in', `aout_64_swap_exec_header_in', etc.
|
---|
954 |
|
---|
955 | As an example, this is what goes on to make the back end for a sun4,
|
---|
956 | from `aout32.c':
|
---|
957 |
|
---|
958 | #define ARCH_SIZE 32
|
---|
959 | #include "aoutx.h"
|
---|
960 |
|
---|
961 | Which exports names:
|
---|
962 |
|
---|
963 | ...
|
---|
964 | aout_32_canonicalize_reloc
|
---|
965 | aout_32_find_nearest_line
|
---|
966 | aout_32_get_lineno
|
---|
967 | aout_32_get_reloc_upper_bound
|
---|
968 | ...
|
---|
969 |
|
---|
970 | from `sunos.c':
|
---|
971 |
|
---|
972 | #define TARGET_NAME "a.out-sunos-big"
|
---|
973 | #define VECNAME sunos_big_vec
|
---|
974 | #include "aoutf1.h"
|
---|
975 |
|
---|
976 | requires all the names from `aout32.c', and produces the jump vector
|
---|
977 |
|
---|
978 | sunos_big_vec
|
---|
979 |
|
---|
980 | The file `host-aout.c' is a special case. It is for a large set of
|
---|
981 | hosts that use "more or less standard" a.out files, and for which
|
---|
982 | cross-debugging is not interesting. It uses the standard 32-bit a.out
|
---|
983 | support routines, but determines the file offsets and addresses of the
|
---|
984 | text, data, and BSS sections, the machine architecture and machine
|
---|
985 | type, and the entry point address, in a host-dependent manner. Once
|
---|
986 | these values have been determined, generic code is used to handle the
|
---|
987 | object file.
|
---|
988 |
|
---|
989 | When porting it to run on a new system, you must supply:
|
---|
990 |
|
---|
991 | HOST_PAGE_SIZE
|
---|
992 | HOST_SEGMENT_SIZE
|
---|
993 | HOST_MACHINE_ARCH (optional)
|
---|
994 | HOST_MACHINE_MACHINE (optional)
|
---|
995 | HOST_TEXT_START_ADDR
|
---|
996 | HOST_STACK_END_ADDR
|
---|
997 |
|
---|
998 | in the file `../include/sys/h-XXX.h' (for your host). These values,
|
---|
999 | plus the structures and macros defined in `a.out.h' on your host
|
---|
1000 | system, will produce a BFD target that will access ordinary a.out files
|
---|
1001 | on your host. To configure a new machine to use `host-aout.c', specify:
|
---|
1002 |
|
---|
1003 | TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec
|
---|
1004 | TDEPFILES= host-aout.o trad-core.o
|
---|
1005 |
|
---|
1006 | in the `config/XXX.mt' file, and modify `configure.in' to use the
|
---|
1007 | `XXX.mt' file (by setting "`bfd_target=XXX'") when your configuration
|
---|
1008 | is selected.
|
---|
1009 |
|
---|
1010 | Relocations
|
---|
1011 | -----------
|
---|
1012 |
|
---|
1013 | *Description*
|
---|
1014 | The file `aoutx.h' provides for both the _standard_ and _extended_
|
---|
1015 | forms of a.out relocation records.
|
---|
1016 |
|
---|
1017 | The standard records contain only an address, a symbol index, and a
|
---|
1018 | type field. The extended records (used on 29ks and sparcs) also have a
|
---|
1019 | full integer for an addend.
|
---|
1020 |
|
---|
1021 | Internal entry points
|
---|
1022 | ---------------------
|
---|
1023 |
|
---|
1024 | *Description*
|
---|
1025 | `aoutx.h' exports several routines for accessing the contents of an
|
---|
1026 | a.out file, which are gathered and exported in turn by various format
|
---|
1027 | specific files (eg sunos.c).
|
---|
1028 |
|
---|
1029 | `aout_SIZE_swap_exec_header_in'
|
---|
1030 | ...............................
|
---|
1031 |
|
---|
1032 | *Synopsis*
|
---|
1033 | void aout_SIZE_swap_exec_header_in,
|
---|
1034 | (bfd *abfd,
|
---|
1035 | struct external_exec *raw_bytes,
|
---|
1036 | struct internal_exec *execp);
|
---|
1037 | *Description*
|
---|
1038 | Swap the information in an executable header RAW_BYTES taken from a raw
|
---|
1039 | byte stream memory image into the internal exec header structure EXECP.
|
---|
1040 |
|
---|
1041 | `aout_SIZE_swap_exec_header_out'
|
---|
1042 | ................................
|
---|
1043 |
|
---|
1044 | *Synopsis*
|
---|
1045 | void aout_SIZE_swap_exec_header_out
|
---|
1046 | (bfd *abfd,
|
---|
1047 | struct internal_exec *execp,
|
---|
1048 | struct external_exec *raw_bytes);
|
---|
1049 | *Description*
|
---|
1050 | Swap the information in an internal exec header structure EXECP into
|
---|
1051 | the buffer RAW_BYTES ready for writing to disk.
|
---|
1052 |
|
---|
1053 | `aout_SIZE_some_aout_object_p'
|
---|
1054 | ..............................
|
---|
1055 |
|
---|
1056 | *Synopsis*
|
---|
1057 | const bfd_target *aout_SIZE_some_aout_object_p
|
---|
1058 | (bfd *abfd,
|
---|
1059 | const bfd_target *(*callback_to_real_object_p) ());
|
---|
1060 | *Description*
|
---|
1061 | Some a.out variant thinks that the file open in ABFD checking is an
|
---|
1062 | a.out file. Do some more checking, and set up for access if it really
|
---|
1063 | is. Call back to the calling environment's "finish up" function just
|
---|
1064 | before returning, to handle any last-minute setup.
|
---|
1065 |
|
---|
1066 | `aout_SIZE_mkobject'
|
---|
1067 | ....................
|
---|
1068 |
|
---|
1069 | *Synopsis*
|
---|
1070 | bfd_boolean aout_SIZE_mkobject, (bfd *abfd);
|
---|
1071 | *Description*
|
---|
1072 | Initialize BFD ABFD for use with a.out files.
|
---|
1073 |
|
---|
1074 | `aout_SIZE_machine_type'
|
---|
1075 | ........................
|
---|
1076 |
|
---|
1077 | *Synopsis*
|
---|
1078 | enum machine_type aout_SIZE_machine_type
|
---|
1079 | (enum bfd_architecture arch,
|
---|
1080 | unsigned long machine));
|
---|
1081 | *Description*
|
---|
1082 | Keep track of machine architecture and machine type for a.out's. Return
|
---|
1083 | the `machine_type' for a particular architecture and machine, or
|
---|
1084 | `M_UNKNOWN' if that exact architecture and machine can't be represented
|
---|
1085 | in a.out format.
|
---|
1086 |
|
---|
1087 | If the architecture is understood, machine type 0 (default) is
|
---|
1088 | always understood.
|
---|
1089 |
|
---|
1090 | `aout_SIZE_set_arch_mach'
|
---|
1091 | .........................
|
---|
1092 |
|
---|
1093 | *Synopsis*
|
---|
1094 | bfd_boolean aout_SIZE_set_arch_mach,
|
---|
1095 | (bfd *,
|
---|
1096 | enum bfd_architecture arch,
|
---|
1097 | unsigned long machine));
|
---|
1098 | *Description*
|
---|
1099 | Set the architecture and the machine of the BFD ABFD to the values ARCH
|
---|
1100 | and MACHINE. Verify that ABFD's format can support the architecture
|
---|
1101 | required.
|
---|
1102 |
|
---|
1103 | `aout_SIZE_new_section_hook'
|
---|
1104 | ............................
|
---|
1105 |
|
---|
1106 | *Synopsis*
|
---|
1107 | bfd_boolean aout_SIZE_new_section_hook,
|
---|
1108 | (bfd *abfd,
|
---|
1109 | asection *newsect));
|
---|
1110 | *Description*
|
---|
1111 | Called by the BFD in response to a `bfd_make_section' request.
|
---|
1112 |
|
---|