OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [VER_5_3/] [gdb-5.3/] [bfd/] [doc/] [bfd.info-6] - Blame information for rev 1783

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1181 sfurman
This is bfd.info, produced by makeinfo version 4.1 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 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: File Caching,  Next: Linker Functions,  Prev: Internal,  Up: BFD front end
20
 
21
File caching
22
============
23
 
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.
32
 
33
`BFD_CACHE_MAX_OPEN macro'
34
..........................
35
 
36
   *Description*
37
The maximum number of files which the cache will keep open at one time.
38
     #define BFD_CACHE_MAX_OPEN 10
39
 
40
`bfd_last_cache'
41
................
42
 
43
   *Synopsis*
44
     extern bfd *bfd_last_cache;
45
   *Description*
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.
49
 
50
`bfd_cache_lookup'
51
..................
52
 
53
   *Description*
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))
62
 
63
`bfd_cache_init'
64
................
65
 
66
   *Synopsis*
67
     boolean bfd_cache_init (bfd *abfd);
68
   *Description*
69
Add a newly opened BFD to the cache.
70
 
71
`bfd_cache_close'
72
.................
73
 
74
   *Synopsis*
75
     boolean bfd_cache_close (bfd *abfd);
76
   *Description*
77
Remove the BFD ABFD from the cache. If the attached file is open, then
78
close it too.
79
 
80
   *Returns*
81
`false' is returned if closing the file fails, `true' is returned if
82
all is well.
83
 
84
`bfd_open_file'
85
...............
86
 
87
   *Synopsis*
88
     FILE* bfd_open_file(bfd *abfd);
89
   *Description*
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
94
be removed from it.
95
 
96
`bfd_cache_lookup_worker'
97
.........................
98
 
99
   *Synopsis*
100
     FILE *bfd_cache_lookup_worker(bfd *abfd);
101
   *Description*
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.
106
 
107

108
File: bfd.info,  Node: Linker Functions,  Next: Hash Tables,  Prev: File Caching,  Up: BFD front end
109
 
110
Linker Functions
111
================
112
 
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.
118
 
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.
127
 
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.
133
 
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.
139
 
140
* Menu:
141
 
142
* Creating a Linker Hash Table::
143
* Adding Symbols to the Hash Table::
144
* Performing the Final Link::
145
 
146

147
File: bfd.info,  Node: Creating a Linker Hash Table,  Next: Adding Symbols to the Hash Table,  Prev: Linker Functions,  Up: Linker Functions
148
 
149
Creating a linker hash table
150
----------------------------
151
 
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.
156
 
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.
163
 
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.
173
 
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.
178
 
179

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
181
 
182
Adding symbols to the hash table
183
--------------------------------
184
 
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.
192
 
193
   The a.out version of this entry point is
194
`NAME(aout,link_add_symbols)'.
195
 
196
* Menu:
197
 
198
* Differing file formats::
199
* Adding symbols from an object file::
200
* Adding symbols from an archive::
201
 
202

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
204
 
205
Differing file formats
206
......................
207
 
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'.
217
 
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
222
of the same format.
223
 
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.
231
 
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.
235
 
236

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
238
 
239
Adding symbols from an object file
240
..................................
241
 
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'.
249
 
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.
254
 
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.
262
 
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.
268
 
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.
275
 
276

277
File: bfd.info,  Node: Adding symbols from an archive,  Prev: Adding symbols from an object file,  Up: Adding Symbols to the Hash Table
278
 
279
Adding symbols from an archive
280
..............................
281
 
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.
287
 
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.
296
 
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.
304
 
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.
314
 
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.
319
 
320

321
File: bfd.info,  Node: Performing the Final Link,  Prev: Adding Symbols to the Hash Table,  Up: Linker Functions
322
 
323
Performing the final link
324
-------------------------
325
 
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.
335
 
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.
339
 
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)'.
343
 
344
* Menu:
345
 
346
* Information provided by the linker::
347
* Relocating the section contents::
348
* Writing the symbol table::
349
 
350

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
352
 
353
Information provided by the linker
354
..................................
355
 
356
   Before the linker calls the `_bfd_final_link' entry point, it sets
357
up some data structures for the function to use.
358
 
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.
362
 
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
371
object file.
372
 
373

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
375
 
376
Relocating the section contents
377
...............................
378
 
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').
384
 
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.
394
 
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'.
401
 
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'.
406
 
407

408
File: bfd.info,  Node: Writing the symbol table,  Prev: Relocating the section contents,  Up: Performing the Final Link
409
 
410
Writing the symbol table
411
........................
412
 
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.
417
 
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.
423
 
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.
430
 
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.
437
 
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.
444
 
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)'.
450
 
451
`bfd_link_split_section'
452
........................
453
 
454
   *Synopsis*
455
     boolean bfd_link_split_section(bfd *abfd, asection *sec);
456
   *Description*
457
Return nonzero if SEC should be split during a reloceatable or final
458
link.
459
     #define bfd_link_split_section(abfd, sec) \
460
            BFD_SEND (abfd, _bfd_link_split_section, (abfd, sec))
461
 
462

463
File: bfd.info,  Node: Hash Tables,  Prev: Linker Functions,  Up: BFD front end
464
 
465
Hash Tables
466
===========
467
 
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.
473
 
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.
483
 
484
   The basic hash table code is in `hash.c'.
485
 
486
* Menu:
487
 
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::
492
 
493

494
File: bfd.info,  Node: Creating and Freeing a Hash Table,  Next: Looking Up or Entering a String,  Prev: Hash Tables,  Up: Hash Tables
495
 
496
Creating and freeing a hash table
497
---------------------------------
498
 
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.
504
 
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.
509
 
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
512
`bfd_hash_allocate'.
513
 
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.
517
 
518

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
520
 
521
Looking up or entering a string
522
-------------------------------
523
 
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.
526
 
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'.
532
 
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.
538
 
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
543
exists.
544
 
545

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
547
 
548
Traversing a hash table
549
-----------------------
550
 
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
553
random order.
554
 
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.
562
 
563

564
File: bfd.info,  Node: Deriving a New Hash Table Type,  Prev: Traversing a Hash Table,  Up: Hash Tables
565
 
566
Deriving a new hash table type
567
------------------------------
568
 
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.
573
 
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.
577
 
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
580
`linker.c'.
581
 
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.
585
 
586
* Menu:
587
 
588
* Define the Derived Structures::
589
* Write the Derived Creation Routine::
590
* Write Other Derived Routines::
591
 
592

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
594
 
595
Define the derived structures
596
.............................
597
 
598
   You must define a structure for an entry in the hash table, and a
599
structure for the hash table itself.
600
 
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'.
608
 
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'.
613
 
614

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
616
 
617
Write the derived creation routine
618
..................................
619
 
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'.
623
 
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.
626
 
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.
631
 
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.
636
 
637
   Finally the creation routine must initialize any local fields for
638
the new hash table type.
639
 
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.
644
 
645
     struct bfd_hash_entry *
646
     FUNCTION_NAME (entry, table, string)
647
          struct bfd_hash_entry *entry;
648
          struct bfd_hash_table *table;
649
          const char *string;
650
     {
651
       struct ENTRY_TYPE *ret = (ENTRY_TYPE *) entry;
652
 
653
      /* Allocate the structure if it has not already been allocated by a
654
         derived class.  */
655
       if (ret == (ENTRY_TYPE *) NULL)
656
         {
657
           ret = ((ENTRY_TYPE *)
658
                  bfd_hash_allocate (table, sizeof (ENTRY_TYPE)));
659
           if (ret == (ENTRY_TYPE *) NULL)
660
             return NULL;
661
         }
662
 
663
      /* Call the allocation method of the base class.  */
664
       ret = ((ENTRY_TYPE *)
665
             BASE_NEWFUNC ((struct bfd_hash_entry *) ret, table, string));
666
 
667
      /* Initialize the local fields here.  */
668
 
669
       return (struct bfd_hash_entry *) ret;
670
     }
671
   *Description*
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
676
hash table.
677
 
678
   `_bfd_link_hash_newfunc' also initializes the local fields in a
679
linker hash table entry: `type', `written' and `next'.
680
 
681

682
File: bfd.info,  Node: Write Other Derived Routines,  Prev: Write the Derived Creation Routine,  Up: Deriving a New Hash Table Type
683
 
684
Write other derived routines
685
............................
686
 
687
   You will want to write other routines for your new hash table, as
688
well.
689
 
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'.
694
 
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
699
value).
700
 
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'
704
in `linker.c'.
705
 
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.
710
 
711

712
File: bfd.info,  Node: BFD back ends,  Next: GNU Free Documentation License,  Prev: BFD front end,  Up: Top
713
 
714
BFD back ends
715
*************
716
 
717
* Menu:
718
 
719
* What to Put Where::
720
* aout ::       a.out backends
721
* coff ::       coff backends
722
* elf  ::       elf backends
723
* mmo  ::       mmo backend
724
 
725

726
File: bfd.info,  Node: What to Put Where,  Next: aout,  Prev: BFD back ends,  Up: BFD back ends
727
 
728
   All of BFD lives in one directory.
729
 
730

731
File: bfd.info,  Node: aout,  Next: coff,  Prev: What to Put Where,  Up: BFD back ends
732
 
733
a.out backends
734
==============
735
 
736
   *Description*
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.
740
 
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.
746
 
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
750
format.
751
 
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.
756
 
757
   As an example, this is what goes on to make the back end for a sun4,
758
from `aout32.c':
759
 
760
            #define ARCH_SIZE 32
761
            #include "aoutx.h"
762
 
763
   Which exports names:
764
 
765
            ...
766
            aout_32_canonicalize_reloc
767
            aout_32_find_nearest_line
768
            aout_32_get_lineno
769
            aout_32_get_reloc_upper_bound
770
            ...
771
 
772
   from `sunos.c':
773
 
774
            #define TARGET_NAME "a.out-sunos-big"
775
            #define VECNAME    sunos_big_vec
776
            #include "aoutf1.h"
777
 
778
   requires all the names from `aout32.c', and produces the jump vector
779
 
780
            sunos_big_vec
781
 
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
789
object file.
790
 
791
   When porting it to run on a new system, you must supply:
792
 
793
             HOST_PAGE_SIZE
794
             HOST_SEGMENT_SIZE
795
             HOST_MACHINE_ARCH       (optional)
796
             HOST_MACHINE_MACHINE    (optional)
797
             HOST_TEXT_START_ADDR
798
             HOST_STACK_END_ADDR
799
 
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:
804
 
805
            TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec
806
            TDEPFILES= host-aout.o trad-core.o
807
 
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
810
is selected.
811
 
812
Relocations
813
-----------
814
 
815
   *Description*
816
The file `aoutx.h' provides for both the _standard_ and _extended_
817
forms of a.out relocation records.
818
 
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.
822
 
823
Internal entry points
824
---------------------
825
 
826
   *Description*
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).
830
 
831
`aout_SIZE_swap_exec_header_in'
832
...............................
833
 
834
   *Synopsis*
835
     void aout_SIZE_swap_exec_header_in,
836
        (bfd *abfd,
837
         struct external_exec *raw_bytes,
838
         struct internal_exec *execp);
839
   *Description*
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.
842
 
843
`aout_SIZE_swap_exec_header_out'
844
................................
845
 
846
   *Synopsis*
847
     void aout_SIZE_swap_exec_header_out
848
        (bfd *abfd,
849
         struct internal_exec *execp,
850
         struct external_exec *raw_bytes);
851
   *Description*
852
Swap the information in an internal exec header structure EXECP into
853
the buffer RAW_BYTES ready for writing to disk.
854
 
855
`aout_SIZE_some_aout_object_p'
856
..............................
857
 
858
   *Synopsis*
859
     const bfd_target *aout_SIZE_some_aout_object_p
860
        (bfd *abfd,
861
         const bfd_target *(*callback_to_real_object_p) ());
862
   *Description*
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.
867
 
868
`aout_SIZE_mkobject'
869
....................
870
 
871
   *Synopsis*
872
     boolean aout_SIZE_mkobject, (bfd *abfd);
873
   *Description*
874
Initialize BFD ABFD for use with a.out files.
875
 
876
`aout_SIZE_machine_type'
877
........................
878
 
879
   *Synopsis*
880
     enum machine_type  aout_SIZE_machine_type
881
        (enum bfd_architecture arch,
882
         unsigned long machine));
883
   *Description*
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
887
in a.out format.
888
 
889
   If the architecture is understood, machine type 0 (default) is
890
always understood.
891
 
892
`aout_SIZE_set_arch_mach'
893
.........................
894
 
895
   *Synopsis*
896
     boolean aout_SIZE_set_arch_mach,
897
        (bfd *,
898
         enum bfd_architecture arch,
899
         unsigned long machine));
900
   *Description*
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
903
required.
904
 
905
`aout_SIZE_new_section_hook'
906
............................
907
 
908
   *Synopsis*
909
     boolean aout_SIZE_new_section_hook,
910
        (bfd *abfd,
911
         asection *newsect));
912
   *Description*
913
Called by the BFD in response to a `bfd_make_section' request.
914
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.