source: trunk/src/binutils/bfd/doc/bfd.info-5@ 10

Last change on this file since 10 was 10, checked in by bird, 23 years ago

Initial revision

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