1 This is bfd.info, produced by makeinfo version 4.1 from bfd.texinfo.
4 * Bfd: (bfd). The Binary File Descriptor library.
7 This file documents the BFD library.
9 Copyright (C) 1991, 2000, 2001 Free Software Foundation, Inc.
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".
19 File: bfd.info, Node: File Caching, Next: Linker Functions, Prev: Internal, Up: BFD front end
24 The file caching mechanism is embedded within BFD and allows the
25 application to open as many BFDs as it wants without regard to the
26 underlying operating system's file descriptor limit (often as low as 20
27 open files). The module in `cache.c' maintains a least recently used
28 list of `BFD_CACHE_MAX_OPEN' files, and exports the name
29 `bfd_cache_lookup', which runs around and makes sure that the required
30 BFD is open. If not, then it chooses a file to close, closes it and
31 opens the one wanted, returning its file handle.
33 `BFD_CACHE_MAX_OPEN macro'
34 ..........................
37 The maximum number of files which the cache will keep open at one time.
38 #define BFD_CACHE_MAX_OPEN 10
44 extern bfd *bfd_last_cache;
46 Zero, or a pointer to the topmost BFD on the chain. This is used by
47 the `bfd_cache_lookup' macro in `libbfd.h' to determine when it can
48 avoid a function call.
54 Check to see if the required BFD is the same as the last one looked up.
55 If so, then it can use the stream in the BFD with impunity, since it
56 can't have changed since the last lookup; otherwise, it has to perform
57 the complicated lookup function.
58 #define bfd_cache_lookup(x) \
59 ((x)==bfd_last_cache? \
60 (FILE*) (bfd_last_cache->iostream): \
61 bfd_cache_lookup_worker(x))
67 boolean bfd_cache_init (bfd *abfd);
69 Add a newly opened BFD to the cache.
75 boolean bfd_cache_close (bfd *abfd);
77 Remove the BFD ABFD from the cache. If the attached file is open, then
81 `false' is returned if closing the file fails, `true' is returned if
88 FILE* bfd_open_file(bfd *abfd);
90 Call the OS to open a file for ABFD. Return the `FILE *' (possibly
91 `NULL') that results from this operation. Set up the BFD so that
92 future accesses know the file is open. If the `FILE *' returned is
93 `NULL', then it won't have been put in the cache, so it won't have to
96 `bfd_cache_lookup_worker'
97 .........................
100 FILE *bfd_cache_lookup_worker(bfd *abfd);
102 Called when the macro `bfd_cache_lookup' fails to find a quick answer.
103 Find a file descriptor for ABFD. If necessary, it open it. If there
104 are already more than `BFD_CACHE_MAX_OPEN' files open, it tries to
105 close one first, to avoid running out of file descriptors.
108 File: bfd.info, Node: Linker Functions, Next: Hash Tables, Prev: File Caching, Up: BFD front end
113 The linker uses three special entry points in the BFD target vector.
114 It is not necessary to write special routines for these entry points
115 when creating a new BFD back end, since generic versions are provided.
116 However, writing them can speed up linking and make it use
117 significantly less runtime memory.
119 The first routine creates a hash table used by the other routines.
120 The second routine adds the symbols from an object file to the hash
121 table. The third routine takes all the object files and links them
122 together to create the output file. These routines are designed so
123 that the linker proper does not need to know anything about the symbols
124 in the object files that it is linking. The linker merely arranges the
125 sections as directed by the linker script and lets BFD handle the
126 details of symbols and relocs.
128 The second routine and third routines are passed a pointer to a
129 `struct bfd_link_info' structure (defined in `bfdlink.h') which holds
130 information relevant to the link, including the linker hash table
131 (which was created by the first routine) and a set of callback
132 functions to the linker proper.
134 The generic linker routines are in `linker.c', and use the header
135 file `genlink.h'. As of this writing, the only back ends which have
136 implemented versions of these routines are a.out (in `aoutx.h') and
137 ECOFF (in `ecoff.c'). The a.out routines are used as examples
138 throughout this section.
142 * Creating a Linker Hash Table::
143 * Adding Symbols to the Hash Table::
144 * Performing the Final Link::
147 File: bfd.info, Node: Creating a Linker Hash Table, Next: Adding Symbols to the Hash Table, Prev: Linker Functions, Up: Linker Functions
149 Creating a linker hash table
150 ----------------------------
152 The linker routines must create a hash table, which must be derived
153 from `struct bfd_link_hash_table' described in `bfdlink.c'. *Note Hash
154 Tables::, for information on how to create a derived hash table. This
155 entry point is called using the target vector of the linker output file.
157 The `_bfd_link_hash_table_create' entry point must allocate and
158 initialize an instance of the desired hash table. If the back end does
159 not require any additional information to be stored with the entries in
160 the hash table, the entry point may simply create a `struct
161 bfd_link_hash_table'. Most likely, however, some additional
162 information will be needed.
164 For example, with each entry in the hash table the a.out linker
165 keeps the index the symbol has in the final output file (this index
166 number is used so that when doing a relocateable link the symbol index
167 used in the output file can be quickly filled in when copying over a
168 reloc). The a.out linker code defines the required structures and
169 functions for a hash table derived from `struct bfd_link_hash_table'.
170 The a.out linker hash table is created by the function
171 `NAME(aout,link_hash_table_create)'; it simply allocates space for the
172 hash table, initializes it, and returns a pointer to it.
174 When writing the linker routines for a new back end, you will
175 generally not know exactly which fields will be required until you have
176 finished. You should simply create a new hash table which defines no
177 additional fields, and then simply add fields as they become necessary.
180 File: bfd.info, Node: Adding Symbols to the Hash Table, Next: Performing the Final Link, Prev: Creating a Linker Hash Table, Up: Linker Functions
182 Adding symbols to the hash table
183 --------------------------------
185 The linker proper will call the `_bfd_link_add_symbols' entry point
186 for each object file or archive which is to be linked (typically these
187 are the files named on the command line, but some may also come from
188 the linker script). The entry point is responsible for examining the
189 file. For an object file, BFD must add any relevant symbol information
190 to the hash table. For an archive, BFD must determine which elements
191 of the archive should be used and adding them to the link.
193 The a.out version of this entry point is
194 `NAME(aout,link_add_symbols)'.
198 * Differing file formats::
199 * Adding symbols from an object file::
200 * Adding symbols from an archive::
203 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
205 Differing file formats
206 ......................
208 Normally all the files involved in a link will be of the same
209 format, but it is also possible to link together different format
210 object files, and the back end must support that. The
211 `_bfd_link_add_symbols' entry point is called via the target vector of
212 the file to be added. This has an important consequence: the function
213 may not assume that the hash table is the type created by the
214 corresponding `_bfd_link_hash_table_create' vector. All the
215 `_bfd_link_add_symbols' function can assume about the hash table is
216 that it is derived from `struct bfd_link_hash_table'.
218 Sometimes the `_bfd_link_add_symbols' function must store some
219 information in the hash table entry to be used by the `_bfd_final_link'
220 function. In such a case the `creator' field of the hash table must be
221 checked to make sure that the hash table was created by an object file
224 The `_bfd_final_link' routine must be prepared to handle a hash
225 entry without any extra information added by the
226 `_bfd_link_add_symbols' function. A hash entry without extra
227 information will also occur when the linker script directs the linker
228 to create a symbol. Note that, regardless of how a hash table entry is
229 added, all the fields will be initialized to some sort of null value by
230 the hash table entry initialization function.
232 See `ecoff_link_add_externals' for an example of how to check the
233 `creator' field before saving information (in this case, the ECOFF
234 external symbol debugging information) in a hash table entry.
237 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
239 Adding symbols from an object file
240 ..................................
242 When the `_bfd_link_add_symbols' routine is passed an object file,
243 it must add all externally visible symbols in that object file to the
244 hash table. The actual work of adding the symbol to the hash table is
245 normally handled by the function `_bfd_generic_link_add_one_symbol'.
246 The `_bfd_link_add_symbols' routine is responsible for reading all the
247 symbols from the object file and passing the correct information to
248 `_bfd_generic_link_add_one_symbol'.
250 The `_bfd_link_add_symbols' routine should not use
251 `bfd_canonicalize_symtab' to read the symbols. The point of providing
252 this routine is to avoid the overhead of converting the symbols into
253 generic `asymbol' structures.
255 `_bfd_generic_link_add_one_symbol' handles the details of combining
256 common symbols, warning about multiple definitions, and so forth. It
257 takes arguments which describe the symbol to add, notably symbol flags,
258 a section, and an offset. The symbol flags include such things as
259 `BSF_WEAK' or `BSF_INDIRECT'. The section is a section in the object
260 file, or something like `bfd_und_section_ptr' for an undefined symbol
261 or `bfd_com_section_ptr' for a common symbol.
263 If the `_bfd_final_link' routine is also going to need to read the
264 symbol information, the `_bfd_link_add_symbols' routine should save it
265 somewhere attached to the object file BFD. However, the information
266 should only be saved if the `keep_memory' field of the `info' argument
267 is true, so that the `-no-keep-memory' linker switch is effective.
269 The a.out function which adds symbols from an object file is
270 `aout_link_add_object_symbols', and most of the interesting work is in
271 `aout_link_add_symbols'. The latter saves pointers to the hash tables
272 entries created by `_bfd_generic_link_add_one_symbol' indexed by symbol
273 number, so that the `_bfd_final_link' routine does not have to call the
274 hash table lookup routine to locate the entry.
277 File: bfd.info, Node: Adding symbols from an archive, Prev: Adding symbols from an object file, Up: Adding Symbols to the Hash Table
279 Adding symbols from an archive
280 ..............................
282 When the `_bfd_link_add_symbols' routine is passed an archive, it
283 must look through the symbols defined by the archive and decide which
284 elements of the archive should be included in the link. For each such
285 element it must call the `add_archive_element' linker callback, and it
286 must add the symbols from the object file to the linker hash table.
288 In most cases the work of looking through the symbols in the archive
289 should be done by the `_bfd_generic_link_add_archive_symbols' function.
290 This function builds a hash table from the archive symbol table and
291 looks through the list of undefined symbols to see which elements
292 should be included. `_bfd_generic_link_add_archive_symbols' is passed
293 a function to call to make the final decision about adding an archive
294 element to the link and to do the actual work of adding the symbols to
295 the linker hash table.
297 The function passed to `_bfd_generic_link_add_archive_symbols' must
298 read the symbols of the archive element and decide whether the archive
299 element should be included in the link. If the element is to be
300 included, the `add_archive_element' linker callback routine must be
301 called with the element as an argument, and the elements symbols must
302 be added to the linker hash table just as though the element had itself
303 been passed to the `_bfd_link_add_symbols' function.
305 When the a.out `_bfd_link_add_symbols' function receives an archive,
306 it calls `_bfd_generic_link_add_archive_symbols' passing
307 `aout_link_check_archive_element' as the function argument.
308 `aout_link_check_archive_element' calls `aout_link_check_ar_symbols'.
309 If the latter decides to add the element (an element is only added if
310 it provides a real, non-common, definition for a previously undefined
311 or common symbol) it calls the `add_archive_element' callback and then
312 `aout_link_check_archive_element' calls `aout_link_add_symbols' to
313 actually add the symbols to the linker hash table.
315 The ECOFF back end is unusual in that it does not normally call
316 `_bfd_generic_link_add_archive_symbols', because ECOFF archives already
317 contain a hash table of symbols. The ECOFF back end searches the
318 archive itself to avoid the overhead of creating a new hash table.
321 File: bfd.info, Node: Performing the Final Link, Prev: Adding Symbols to the Hash Table, Up: Linker Functions
323 Performing the final link
324 -------------------------
326 When all the input files have been processed, the linker calls the
327 `_bfd_final_link' entry point of the output BFD. This routine is
328 responsible for producing the final output file, which has several
329 aspects. It must relocate the contents of the input sections and copy
330 the data into the output sections. It must build an output symbol
331 table including any local symbols from the input files and the global
332 symbols from the hash table. When producing relocateable output, it
333 must modify the input relocs and write them into the output file.
334 There may also be object format dependent work to be done.
336 The linker will also call the `write_object_contents' entry point
337 when the BFD is closed. The two entry points must work together in
338 order to produce the correct output file.
340 The details of how this works are inevitably dependent upon the
341 specific object file format. The a.out `_bfd_final_link' routine is
342 `NAME(aout,final_link)'.
346 * Information provided by the linker::
347 * Relocating the section contents::
348 * Writing the symbol table::
351 File: bfd.info, Node: Information provided by the linker, Next: Relocating the section contents, Prev: Performing the Final Link, Up: Performing the Final Link
353 Information provided by the linker
354 ..................................
356 Before the linker calls the `_bfd_final_link' entry point, it sets
357 up some data structures for the function to use.
359 The `input_bfds' field of the `bfd_link_info' structure will point
360 to a list of all the input files included in the link. These files are
361 linked through the `link_next' field of the `bfd' structure.
363 Each section in the output file will have a list of `link_order'
364 structures attached to the `link_order_head' field (the `link_order'
365 structure is defined in `bfdlink.h'). These structures describe how to
366 create the contents of the output section in terms of the contents of
367 various input sections, fill constants, and, eventually, other types of
368 information. They also describe relocs that must be created by the BFD
369 backend, but do not correspond to any input file; this is used to
370 support -Ur, which builds constructors while generating a relocateable
374 File: bfd.info, Node: Relocating the section contents, Next: Writing the symbol table, Prev: Information provided by the linker, Up: Performing the Final Link
376 Relocating the section contents
377 ...............................
379 The `_bfd_final_link' function should look through the `link_order'
380 structures attached to each section of the output file. Each
381 `link_order' structure should either be handled specially, or it should
382 be passed to the function `_bfd_default_link_order' which will do the
383 right thing (`_bfd_default_link_order' is defined in `linker.c').
385 For efficiency, a `link_order' of type `bfd_indirect_link_order'
386 whose associated section belongs to a BFD of the same format as the
387 output BFD must be handled specially. This type of `link_order'
388 describes part of an output section in terms of a section belonging to
389 one of the input files. The `_bfd_final_link' function should read the
390 contents of the section and any associated relocs, apply the relocs to
391 the section contents, and write out the modified section contents. If
392 performing a relocateable link, the relocs themselves must also be
393 modified and written out.
395 The functions `_bfd_relocate_contents' and
396 `_bfd_final_link_relocate' provide some general support for performing
397 the actual relocations, notably overflow checking. Their arguments
398 include information about the symbol the relocation is against and a
399 `reloc_howto_type' argument which describes the relocation to perform.
400 These functions are defined in `reloc.c'.
402 The a.out function which handles reading, relocating, and writing
403 section contents is `aout_link_input_section'. The actual relocation
404 is done in `aout_link_input_section_std' and
405 `aout_link_input_section_ext'.
408 File: bfd.info, Node: Writing the symbol table, Prev: Relocating the section contents, Up: Performing the Final Link
410 Writing the symbol table
411 ........................
413 The `_bfd_final_link' function must gather all the symbols in the
414 input files and write them out. It must also write out all the symbols
415 in the global hash table. This must be controlled by the `strip' and
416 `discard' fields of the `bfd_link_info' structure.
418 The local symbols of the input files will not have been entered into
419 the linker hash table. The `_bfd_final_link' routine must consider
420 each input file and include the symbols in the output file. It may be
421 convenient to do this when looking through the `link_order' structures,
422 or it may be done by stepping through the `input_bfds' list.
424 The `_bfd_final_link' routine must also traverse the global hash
425 table to gather all the externally visible symbols. It is possible
426 that most of the externally visible symbols may be written out when
427 considering the symbols of each input file, but it is still necessary
428 to traverse the hash table since the linker script may have defined
429 some symbols that are not in any of the input files.
431 The `strip' field of the `bfd_link_info' structure controls which
432 symbols are written out. The possible values are listed in
433 `bfdlink.h'. If the value is `strip_some', then the `keep_hash' field
434 of the `bfd_link_info' structure is a hash table of symbols to keep;
435 each symbol should be looked up in this hash table, and only symbols
436 which are present should be included in the output file.
438 If the `strip' field of the `bfd_link_info' structure permits local
439 symbols to be written out, the `discard' field is used to further
440 controls which local symbols are included in the output file. If the
441 value is `discard_l', then all local symbols which begin with a certain
442 prefix are discarded; this is controlled by the
443 `bfd_is_local_label_name' entry point.
445 The a.out backend handles symbols by calling
446 `aout_link_write_symbols' on each input BFD and then traversing the
447 global hash table with the function `aout_link_write_other_symbol'. It
448 builds a string table while writing out the symbols, which is written
449 to the output file at the end of `NAME(aout,final_link)'.
451 `bfd_link_split_section'
452 ........................
455 boolean bfd_link_split_section(bfd *abfd, asection *sec);
457 Return nonzero if SEC should be split during a reloceatable or final
459 #define bfd_link_split_section(abfd, sec) \
460 BFD_SEND (abfd, _bfd_link_split_section, (abfd, sec))
463 File: bfd.info, Node: Hash Tables, Prev: Linker Functions, Up: BFD front end
468 BFD provides a simple set of hash table functions. Routines are
469 provided to initialize a hash table, to free a hash table, to look up a
470 string in a hash table and optionally create an entry for it, and to
471 traverse a hash table. There is currently no routine to delete an
472 string from a hash table.
474 The basic hash table does not permit any data to be stored with a
475 string. However, a hash table is designed to present a base class from
476 which other types of hash tables may be derived. These derived types
477 may store additional information with the string. Hash tables were
478 implemented in this way, rather than simply providing a data pointer in
479 a hash table entry, because they were designed for use by the linker
480 back ends. The linker may create thousands of hash table entries, and
481 the overhead of allocating private data and storing and following
482 pointers becomes noticeable.
484 The basic hash table code is in `hash.c'.
488 * Creating and Freeing a Hash Table::
489 * Looking Up or Entering a String::
490 * Traversing a Hash Table::
491 * Deriving a New Hash Table Type::
494 File: bfd.info, Node: Creating and Freeing a Hash Table, Next: Looking Up or Entering a String, Prev: Hash Tables, Up: Hash Tables
496 Creating and freeing a hash table
497 ---------------------------------
499 To create a hash table, create an instance of a `struct
500 bfd_hash_table' (defined in `bfd.h') and call `bfd_hash_table_init' (if
501 you know approximately how many entries you will need, the function
502 `bfd_hash_table_init_n', which takes a SIZE argument, may be used).
503 `bfd_hash_table_init' returns `false' if some sort of error occurs.
505 The function `bfd_hash_table_init' take as an argument a function to
506 use to create new entries. For a basic hash table, use the function
507 `bfd_hash_newfunc'. *Note Deriving a New Hash Table Type::, for why
508 you would want to use a different value for this argument.
510 `bfd_hash_table_init' will create an objalloc which will be used to
511 allocate new entries. You may allocate memory on this objalloc using
514 Use `bfd_hash_table_free' to free up all the memory that has been
515 allocated for a hash table. This will not free up the `struct
516 bfd_hash_table' itself, which you must provide.
519 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
521 Looking up or entering a string
522 -------------------------------
524 The function `bfd_hash_lookup' is used both to look up a string in
525 the hash table and to create a new entry.
527 If the CREATE argument is `false', `bfd_hash_lookup' will look up a
528 string. If the string is found, it will returns a pointer to a `struct
529 bfd_hash_entry'. If the string is not found in the table
530 `bfd_hash_lookup' will return `NULL'. You should not modify any of the
531 fields in the returns `struct bfd_hash_entry'.
533 If the CREATE argument is `true', the string will be entered into
534 the hash table if it is not already there. Either way a pointer to a
535 `struct bfd_hash_entry' will be returned, either to the existing
536 structure or to a newly created one. In this case, a `NULL' return
537 means that an error occurred.
539 If the CREATE argument is `true', and a new entry is created, the
540 COPY argument is used to decide whether to copy the string onto the
541 hash table objalloc or not. If COPY is passed as `false', you must be
542 careful not to deallocate or modify the string as long as the hash table
546 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
548 Traversing a hash table
549 -----------------------
551 The function `bfd_hash_traverse' may be used to traverse a hash
552 table, calling a function on each element. The traversal is done in a
555 `bfd_hash_traverse' takes as arguments a function and a generic
556 `void *' pointer. The function is called with a hash table entry (a
557 `struct bfd_hash_entry *') and the generic pointer passed to
558 `bfd_hash_traverse'. The function must return a `boolean' value, which
559 indicates whether to continue traversing the hash table. If the
560 function returns `false', `bfd_hash_traverse' will stop the traversal
561 and return immediately.
564 File: bfd.info, Node: Deriving a New Hash Table Type, Prev: Traversing a Hash Table, Up: Hash Tables
566 Deriving a new hash table type
567 ------------------------------
569 Many uses of hash tables want to store additional information which
570 each entry in the hash table. Some also find it convenient to store
571 additional information with the hash table itself. This may be done
572 using a derived hash table.
574 Since C is not an object oriented language, creating a derived hash
575 table requires sticking together some boilerplate routines with a few
576 differences specific to the type of hash table you want to create.
578 An example of a derived hash table is the linker hash table. The
579 structures for this are defined in `bfdlink.h'. The functions are in
582 You may also derive a hash table from an already derived hash table.
583 For example, the a.out linker backend code uses a hash table derived
584 from the linker hash table.
588 * Define the Derived Structures::
589 * Write the Derived Creation Routine::
590 * Write Other Derived Routines::
593 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
595 Define the derived structures
596 .............................
598 You must define a structure for an entry in the hash table, and a
599 structure for the hash table itself.
601 The first field in the structure for an entry in the hash table must
602 be of the type used for an entry in the hash table you are deriving
603 from. If you are deriving from a basic hash table this is `struct
604 bfd_hash_entry', which is defined in `bfd.h'. The first field in the
605 structure for the hash table itself must be of the type of the hash
606 table you are deriving from itself. If you are deriving from a basic
607 hash table, this is `struct bfd_hash_table'.
609 For example, the linker hash table defines `struct
610 bfd_link_hash_entry' (in `bfdlink.h'). The first field, `root', is of
611 type `struct bfd_hash_entry'. Similarly, the first field in `struct
612 bfd_link_hash_table', `table', is of type `struct bfd_hash_table'.
615 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
617 Write the derived creation routine
618 ..................................
620 You must write a routine which will create and initialize an entry
621 in the hash table. This routine is passed as the function argument to
622 `bfd_hash_table_init'.
624 In order to permit other hash tables to be derived from the hash
625 table you are creating, this routine must be written in a standard way.
627 The first argument to the creation routine is a pointer to a hash
628 table entry. This may be `NULL', in which case the routine should
629 allocate the right amount of space. Otherwise the space has already
630 been allocated by a hash table type derived from this one.
632 After allocating space, the creation routine must call the creation
633 routine of the hash table type it is derived from, passing in a pointer
634 to the space it just allocated. This will initialize any fields used
635 by the base hash table.
637 Finally the creation routine must initialize any local fields for
638 the new hash table type.
640 Here is a boilerplate example of a creation routine. FUNCTION_NAME
641 is the name of the routine. ENTRY_TYPE is the type of an entry in the
642 hash table you are creating. BASE_NEWFUNC is the name of the creation
643 routine of the hash table type your hash table is derived from.
645 struct bfd_hash_entry *
646 FUNCTION_NAME (entry, table, string)
647 struct bfd_hash_entry *entry;
648 struct bfd_hash_table *table;
651 struct ENTRY_TYPE *ret = (ENTRY_TYPE *) entry;
653 /* Allocate the structure if it has not already been allocated by a
655 if (ret == (ENTRY_TYPE *) NULL)
657 ret = ((ENTRY_TYPE *)
658 bfd_hash_allocate (table, sizeof (ENTRY_TYPE)));
659 if (ret == (ENTRY_TYPE *) NULL)
663 /* Call the allocation method of the base class. */
664 ret = ((ENTRY_TYPE *)
665 BASE_NEWFUNC ((struct bfd_hash_entry *) ret, table, string));
667 /* Initialize the local fields here. */
669 return (struct bfd_hash_entry *) ret;
672 The creation routine for the linker hash table, which is in `linker.c',
673 looks just like this example. FUNCTION_NAME is
674 `_bfd_link_hash_newfunc'. ENTRY_TYPE is `struct bfd_link_hash_entry'.
675 BASE_NEWFUNC is `bfd_hash_newfunc', the creation routine for a basic
678 `_bfd_link_hash_newfunc' also initializes the local fields in a
679 linker hash table entry: `type', `written' and `next'.
682 File: bfd.info, Node: Write Other Derived Routines, Prev: Write the Derived Creation Routine, Up: Deriving a New Hash Table Type
684 Write other derived routines
685 ............................
687 You will want to write other routines for your new hash table, as
690 You will want an initialization routine which calls the
691 initialization routine of the hash table you are deriving from and
692 initializes any other local fields. For the linker hash table, this is
693 `_bfd_link_hash_table_init' in `linker.c'.
695 You will want a lookup routine which calls the lookup routine of the
696 hash table you are deriving from and casts the result. The linker hash
697 table uses `bfd_link_hash_lookup' in `linker.c' (this actually takes an
698 additional argument which it uses to decide how to return the looked up
701 You may want a traversal routine. This should just call the
702 traversal routine of the hash table you are deriving from with
703 appropriate casts. The linker hash table uses `bfd_link_hash_traverse'
706 These routines may simply be defined as macros. For example, the
707 a.out backend linker hash table, which is derived from the linker hash
708 table, uses macros for the lookup and traversal routines. These are
709 `aout_link_hash_lookup' and `aout_link_hash_traverse' in aoutx.h.
712 File: bfd.info, Node: BFD back ends, Next: GNU Free Documentation License, Prev: BFD front end, Up: Top
719 * What to Put Where::
720 * aout :: a.out backends
721 * coff :: coff backends
722 * elf :: elf backends
726 File: bfd.info, Node: What to Put Where, Next: aout, Prev: BFD back ends, Up: BFD back ends
728 All of BFD lives in one directory.
731 File: bfd.info, Node: aout, Next: coff, Prev: What to Put Where, Up: BFD back ends
737 BFD supports a number of different flavours of a.out format, though the
738 major differences are only the sizes of the structures on disk, and the
739 shape of the relocation information.
741 The support is split into a basic support file `aoutx.h' and other
742 files which derive functions from the base. One derivation file is
743 `aoutf1.h' (for a.out flavour 1), and adds to the basic a.out functions
744 support for sun3, sun4, 386 and 29k a.out files, to create a target
745 jump vector for a specific target.
747 This information is further split out into more specific files for
748 each machine, including `sunos.c' for sun3 and sun4, `newsos3.c' for
749 the Sony NEWS, and `demo64.c' for a demonstration of a 64 bit a.out
752 The base file `aoutx.h' defines general mechanisms for reading and
753 writing records to and from disk and various other methods which BFD
754 requires. It is included by `aout32.c' and `aout64.c' to form the names
755 `aout_32_swap_exec_header_in', `aout_64_swap_exec_header_in', etc.
757 As an example, this is what goes on to make the back end for a sun4,
766 aout_32_canonicalize_reloc
767 aout_32_find_nearest_line
769 aout_32_get_reloc_upper_bound
774 #define TARGET_NAME "a.out-sunos-big"
775 #define VECNAME sunos_big_vec
778 requires all the names from `aout32.c', and produces the jump vector
782 The file `host-aout.c' is a special case. It is for a large set of
783 hosts that use "more or less standard" a.out files, and for which
784 cross-debugging is not interesting. It uses the standard 32-bit a.out
785 support routines, but determines the file offsets and addresses of the
786 text, data, and BSS sections, the machine architecture and machine
787 type, and the entry point address, in a host-dependent manner. Once
788 these values have been determined, generic code is used to handle the
791 When porting it to run on a new system, you must supply:
795 HOST_MACHINE_ARCH (optional)
796 HOST_MACHINE_MACHINE (optional)
800 in the file `../include/sys/h-XXX.h' (for your host). These values,
801 plus the structures and macros defined in `a.out.h' on your host
802 system, will produce a BFD target that will access ordinary a.out files
803 on your host. To configure a new machine to use `host-aout.c', specify:
805 TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec
806 TDEPFILES= host-aout.o trad-core.o
808 in the `config/XXX.mt' file, and modify `configure.in' to use the
809 `XXX.mt' file (by setting "`bfd_target=XXX'") when your configuration
816 The file `aoutx.h' provides for both the _standard_ and _extended_
817 forms of a.out relocation records.
819 The standard records contain only an address, a symbol index, and a
820 type field. The extended records (used on 29ks and sparcs) also have a
821 full integer for an addend.
823 Internal entry points
824 ---------------------
827 `aoutx.h' exports several routines for accessing the contents of an
828 a.out file, which are gathered and exported in turn by various format
829 specific files (eg sunos.c).
831 `aout_SIZE_swap_exec_header_in'
832 ...............................
835 void aout_SIZE_swap_exec_header_in,
837 struct external_exec *raw_bytes,
838 struct internal_exec *execp);
840 Swap the information in an executable header RAW_BYTES taken from a raw
841 byte stream memory image into the internal exec header structure EXECP.
843 `aout_SIZE_swap_exec_header_out'
844 ................................
847 void aout_SIZE_swap_exec_header_out
849 struct internal_exec *execp,
850 struct external_exec *raw_bytes);
852 Swap the information in an internal exec header structure EXECP into
853 the buffer RAW_BYTES ready for writing to disk.
855 `aout_SIZE_some_aout_object_p'
856 ..............................
859 const bfd_target *aout_SIZE_some_aout_object_p
861 const bfd_target *(*callback_to_real_object_p) ());
863 Some a.out variant thinks that the file open in ABFD checking is an
864 a.out file. Do some more checking, and set up for access if it really
865 is. Call back to the calling environment's "finish up" function just
866 before returning, to handle any last-minute setup.
872 boolean aout_SIZE_mkobject, (bfd *abfd);
874 Initialize BFD ABFD for use with a.out files.
876 `aout_SIZE_machine_type'
877 ........................
880 enum machine_type aout_SIZE_machine_type
881 (enum bfd_architecture arch,
882 unsigned long machine));
884 Keep track of machine architecture and machine type for a.out's. Return
885 the `machine_type' for a particular architecture and machine, or
886 `M_UNKNOWN' if that exact architecture and machine can't be represented
889 If the architecture is understood, machine type 0 (default) is
892 `aout_SIZE_set_arch_mach'
893 .........................
896 boolean aout_SIZE_set_arch_mach,
898 enum bfd_architecture arch,
899 unsigned long machine));
901 Set the architecture and the machine of the BFD ABFD to the values ARCH
902 and MACHINE. Verify that ABFD's format can support the architecture
905 `aout_SIZE_new_section_hook'
906 ............................
909 boolean aout_SIZE_new_section_hook,
913 Called by the BFD in response to a `bfd_make_section' request.