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

Subversion Repositories or1k

[/] [or1k/] [branches/] [oc/] [gdb-5.0/] [bfd/] [doc/] [bfd.info-4] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 104 markom
This is bfd.info, produced by Makeinfo version 3.12f from bfd.texinfo.
2
 
3
START-INFO-DIR-ENTRY
4
* Bfd: (bfd).                   The Binary File Descriptor library.
5
END-INFO-DIR-ENTRY
6
 
7
   This file documents the BFD library.
8
 
9
   Copyright (C) 1991 Free Software Foundation, Inc.
10
 
11
   Permission is granted to make and distribute verbatim copies of this
12
manual provided the copyright notice and this permission notice are
13
preserved on all copies.
14
 
15
   Permission is granted to copy and distribute modified versions of
16
this manual under the conditions for verbatim copying, subject to the
17
terms of the GNU General Public License, which includes the provision
18
that the entire resulting derived work is distributed under the terms
19
of a permission notice identical to this one.
20
 
21
   Permission is granted to copy and distribute translations of this
22
manual into another language, under the above conditions for modified
23
versions.
24
 
25

26
File: bfd.info,  Node: bfd_target,  Prev: Targets,  Up: Targets
27
 
28
bfd_target
29
----------
30
 
31
   *Description*
32
This structure contains everything that BFD knows about a target. It
33
includes things like its byte order, name, and which routines to call
34
to do various operations.
35
 
36
   Every BFD points to a target structure with its `xvec' member.
37
 
38
   The macros below are used to dispatch to functions through the
39
`bfd_target' vector. They are used in a number of macros further down
40
in `bfd.h', and are also used when calling various routines by hand
41
inside the BFD implementation.  The ARGLIST argument must be
42
parenthesized; it contains all the arguments to the called function.
43
 
44
   They make the documentation (more) unpleasant to read, so if someone
45
wants to fix this and not break the above, please do.
46
     #define BFD_SEND(bfd, message, arglist) \
47
                    ((*((bfd)->xvec->message)) arglist)
48
 
49
     #ifdef DEBUG_BFD_SEND
50
     #undef BFD_SEND
51
     #define BFD_SEND(bfd, message, arglist) \
52
       (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
53
         ((*((bfd)->xvec->message)) arglist) : \
54
         (bfd_assert (__FILE__,__LINE__), NULL))
55
     #endif
56
   For operations which index on the BFD format:
57
     #define BFD_SEND_FMT(bfd, message, arglist) \
58
                 (((bfd)->xvec->message[(int)((bfd)->format)]) arglist)
59
 
60
     #ifdef DEBUG_BFD_SEND
61
     #undef BFD_SEND_FMT
62
     #define BFD_SEND_FMT(bfd, message, arglist) \
63
       (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
64
        (((bfd)->xvec->message[(int)((bfd)->format)]) arglist) : \
65
        (bfd_assert (__FILE__,__LINE__), NULL))
66
     #endif
67
   This is the structure which defines the type of BFD this is.  The
68
`xvec' member of the struct `bfd' itself points here.  Each module that
69
implements access to a different target under BFD, defines one of these.
70
 
71
   FIXME, these names should be rationalised with the names of the
72
entry points which call them. Too bad we can't have one macro to define
73
them both!
74
     enum bfd_flavour {
75
       bfd_target_unknown_flavour,
76
       bfd_target_aout_flavour,
77
       bfd_target_coff_flavour,
78
       bfd_target_ecoff_flavour,
79
       bfd_target_elf_flavour,
80
       bfd_target_ieee_flavour,
81
       bfd_target_nlm_flavour,
82
       bfd_target_oasys_flavour,
83
       bfd_target_tekhex_flavour,
84
       bfd_target_srec_flavour,
85
       bfd_target_ihex_flavour,
86
       bfd_target_som_flavour,
87
       bfd_target_os9k_flavour,
88
       bfd_target_versados_flavour,
89
       bfd_target_msdos_flavour,
90
       bfd_target_ovax_flavour,
91
       bfd_target_evax_flavour
92
     };
93
 
94
     enum bfd_endian { BFD_ENDIAN_BIG, BFD_ENDIAN_LITTLE, BFD_ENDIAN_UNKNOWN };
95
 
96
      /* Forward declaration.  */
97
     typedef struct bfd_link_info _bfd_link_info;
98
 
99
     typedef struct bfd_target
100
     {
101
   Identifies the kind of target, e.g., SunOS4, Ultrix, etc.
102
       char *name;
103
   The "flavour" of a back end is a general indication about the
104
contents of a file.
105
       enum bfd_flavour flavour;
106
   The order of bytes within the data area of a file.
107
       enum bfd_endian byteorder;
108
   The order of bytes within the header parts of a file.
109
       enum bfd_endian header_byteorder;
110
   A mask of all the flags which an executable may have set - from the
111
set `BFD_NO_FLAGS', `HAS_RELOC', ...`D_PAGED'.
112
       flagword object_flags;
113
   A mask of all the flags which a section may have set - from the set
114
`SEC_NO_FLAGS', `SEC_ALLOC', ...`SET_NEVER_LOAD'.
115
       flagword section_flags;
116
   The character normally found at the front of a symbol (if any),
117
perhaps `_'.
118
       char symbol_leading_char;
119
   The pad character for file names within an archive header.
120
       char ar_pad_char;
121
   The maximum number of characters in an archive header.
122
       unsigned short ar_max_namelen;
123
   Entries for byte swapping for data. These are different from the
124
other entry points, since they don't take a BFD asthe first argument.
125
Certain other handlers could do the same.
126
       bfd_vma      (*bfd_getx64) PARAMS ((const bfd_byte *));
127
       bfd_signed_vma (*bfd_getx_signed_64) PARAMS ((const bfd_byte *));
128
       void         (*bfd_putx64) PARAMS ((bfd_vma, bfd_byte *));
129
       bfd_vma      (*bfd_getx32) PARAMS ((const bfd_byte *));
130
       bfd_signed_vma (*bfd_getx_signed_32) PARAMS ((const bfd_byte *));
131
       void         (*bfd_putx32) PARAMS ((bfd_vma, bfd_byte *));
132
       bfd_vma      (*bfd_getx16) PARAMS ((const bfd_byte *));
133
       bfd_signed_vma (*bfd_getx_signed_16) PARAMS ((const bfd_byte *));
134
       void         (*bfd_putx16) PARAMS ((bfd_vma, bfd_byte *));
135
   Byte swapping for the headers
136
       bfd_vma      (*bfd_h_getx64) PARAMS ((const bfd_byte *));
137
       bfd_signed_vma (*bfd_h_getx_signed_64) PARAMS ((const bfd_byte *));
138
       void         (*bfd_h_putx64) PARAMS ((bfd_vma, bfd_byte *));
139
       bfd_vma      (*bfd_h_getx32) PARAMS ((const bfd_byte *));
140
       bfd_signed_vma (*bfd_h_getx_signed_32) PARAMS ((const bfd_byte *));
141
       void         (*bfd_h_putx32) PARAMS ((bfd_vma, bfd_byte *));
142
       bfd_vma      (*bfd_h_getx16) PARAMS ((const bfd_byte *));
143
       bfd_signed_vma (*bfd_h_getx_signed_16) PARAMS ((const bfd_byte *));
144
       void         (*bfd_h_putx16) PARAMS ((bfd_vma, bfd_byte *));
145
   Format dependent routines: these are vectors of entry points within
146
the target vector structure, one for each format to check.
147
 
148
   Check the format of a file being read.  Return a `bfd_target *' or
149
zero.
150
       const struct bfd_target *(*_bfd_check_format[bfd_type_end]) PARAMS ((bfd *));
151
   Set the format of a file being written.
152
       boolean             (*_bfd_set_format[bfd_type_end]) PARAMS ((bfd *));
153
   Write cached information into a file being written, at `bfd_close'.
154
       boolean             (*_bfd_write_contents[bfd_type_end]) PARAMS ((bfd *));
155
   The general target vector.  These vectors are initialized using the
156
BFD_JUMP_TABLE macros.
157
 
158
        /* Generic entry points.  */
159
     #define BFD_JUMP_TABLE_GENERIC(NAME)\
160
     CAT(NAME,_close_and_cleanup),\
161
     CAT(NAME,_bfd_free_cached_info),\
162
     CAT(NAME,_new_section_hook),\
163
     CAT(NAME,_get_section_contents),\
164
     CAT(NAME,_get_section_contents_in_window)
165
 
166
        /* Called when the BFD is being closed to do any necessary cleanup.  */
167
       boolean       (*_close_and_cleanup) PARAMS ((bfd *));
168
        /* Ask the BFD to free all cached information.  */
169
       boolean (*_bfd_free_cached_info) PARAMS ((bfd *));
170
        /* Called when a new section is created.  */
171
       boolean       (*_new_section_hook) PARAMS ((bfd *, sec_ptr));
172
        /* Read the contents of a section.  */
173
       boolean       (*_bfd_get_section_contents) PARAMS ((bfd *, sec_ptr, PTR,
174
                                                 file_ptr, bfd_size_type));
175
       boolean       (*_bfd_get_section_contents_in_window)
176
                               PARAMS ((bfd *, sec_ptr, bfd_window *,
177
                                        file_ptr, bfd_size_type));
178
 
179
        /* Entry points to copy private data.  */
180
     #define BFD_JUMP_TABLE_COPY(NAME)\
181
     CAT(NAME,_bfd_copy_private_bfd_data),\
182
     CAT(NAME,_bfd_merge_private_bfd_data),\
183
     CAT(NAME,_bfd_copy_private_section_data),\
184
     CAT(NAME,_bfd_copy_private_symbol_data),\
185
     CAT(NAME,_bfd_set_private_flags),\
186
     CAT(NAME,_bfd_print_private_bfd_data)\
187
        /* Called to copy BFD general private data from one object file
188
          to another.  */
189
       boolean       (*_bfd_copy_private_bfd_data) PARAMS ((bfd *, bfd *));
190
        /* Called to merge BFD general private data from one object file
191
          to a common output file when linking.  */
192
       boolean       (*_bfd_merge_private_bfd_data) PARAMS ((bfd *, bfd *));
193
        /* Called to copy BFD private section data from one object file
194
          to another.  */
195
       boolean       (*_bfd_copy_private_section_data) PARAMS ((bfd *, sec_ptr,
196
                                                            bfd *, sec_ptr));
197
        /* Called to copy BFD private symbol data from one symbol
198
          to another.  */
199
       boolean       (*_bfd_copy_private_symbol_data) PARAMS ((bfd *, asymbol *,
200
                                                               bfd *, asymbol *));
201
        /* Called to set private backend flags */
202
       boolean       (*_bfd_set_private_flags) PARAMS ((bfd *, flagword));
203
 
204
        /* Called to print private BFD data */
205
       boolean       (*_bfd_print_private_bfd_data) PARAMS ((bfd *, PTR));
206
 
207
        /* Core file entry points.  */
208
     #define BFD_JUMP_TABLE_CORE(NAME)\
209
     CAT(NAME,_core_file_failing_command),\
210
     CAT(NAME,_core_file_failing_signal),\
211
     CAT(NAME,_core_file_matches_executable_p)
212
       char *   (*_core_file_failing_command) PARAMS ((bfd *));
213
       int      (*_core_file_failing_signal) PARAMS ((bfd *));
214
       boolean  (*_core_file_matches_executable_p) PARAMS ((bfd *, bfd *));
215
 
216
        /* Archive entry points.  */
217
     #define BFD_JUMP_TABLE_ARCHIVE(NAME)\
218
     CAT(NAME,_slurp_armap),\
219
     CAT(NAME,_slurp_extended_name_table),\
220
     CAT(NAME,_construct_extended_name_table),\
221
     CAT(NAME,_truncate_arname),\
222
     CAT(NAME,_write_armap),\
223
     CAT(NAME,_read_ar_hdr),\
224
     CAT(NAME,_openr_next_archived_file),\
225
     CAT(NAME,_get_elt_at_index),\
226
     CAT(NAME,_generic_stat_arch_elt),\
227
     CAT(NAME,_update_armap_timestamp)
228
       boolean  (*_bfd_slurp_armap) PARAMS ((bfd *));
229
       boolean  (*_bfd_slurp_extended_name_table) PARAMS ((bfd *));
230
       boolean  (*_bfd_construct_extended_name_table)
231
                  PARAMS ((bfd *, char **, bfd_size_type *, const char **));
232
       void     (*_bfd_truncate_arname) PARAMS ((bfd *, CONST char *, char *));
233
       boolean  (*write_armap) PARAMS ((bfd *arch,
234
                                   unsigned int elength,
235
                                   struct orl *map,
236
                                   unsigned int orl_count,
237
                                   int stridx));
238
       PTR (*_bfd_read_ar_hdr_fn) PARAMS ((bfd *));
239
       bfd *    (*openr_next_archived_file) PARAMS ((bfd *arch, bfd *prev));
240
     #define bfd_get_elt_at_index(b,i) BFD_SEND(b, _bfd_get_elt_at_index, (b,i))
241
       bfd *    (*_bfd_get_elt_at_index) PARAMS ((bfd *, symindex));
242
       int      (*_bfd_stat_arch_elt) PARAMS ((bfd *, struct stat *));
243
       boolean  (*_bfd_update_armap_timestamp) PARAMS ((bfd *));
244
 
245
        /* Entry points used for symbols.  */
246
     #define BFD_JUMP_TABLE_SYMBOLS(NAME)\
247
     CAT(NAME,_get_symtab_upper_bound),\
248
     CAT(NAME,_get_symtab),\
249
     CAT(NAME,_make_empty_symbol),\
250
     CAT(NAME,_print_symbol),\
251
     CAT(NAME,_get_symbol_info),\
252
     CAT(NAME,_bfd_is_local_label_name),\
253
     CAT(NAME,_get_lineno),\
254
     CAT(NAME,_find_nearest_line),\
255
     CAT(NAME,_bfd_make_debug_symbol),\
256
     CAT(NAME,_read_minisymbols),\
257
     CAT(NAME,_minisymbol_to_symbol)
258
       long  (*_bfd_get_symtab_upper_bound) PARAMS ((bfd *));
259
       long  (*_bfd_canonicalize_symtab) PARAMS ((bfd *,
260
                                                  struct symbol_cache_entry **));
261
       struct symbol_cache_entry  *
262
                     (*_bfd_make_empty_symbol) PARAMS ((bfd *));
263
       void          (*_bfd_print_symbol) PARAMS ((bfd *, PTR,
264
                                           struct symbol_cache_entry *,
265
                                           bfd_print_symbol_type));
266
     #define bfd_print_symbol(b,p,s,e) BFD_SEND(b, _bfd_print_symbol, (b,p,s,e))
267
       void          (*_bfd_get_symbol_info) PARAMS ((bfd *,
268
                                           struct symbol_cache_entry *,
269
                                           symbol_info *));
270
     #define bfd_get_symbol_info(b,p,e) BFD_SEND(b, _bfd_get_symbol_info, (b,p,e))
271
       boolean       (*_bfd_is_local_label_name) PARAMS ((bfd *, const char *));
272
 
273
       alent *    (*_get_lineno) PARAMS ((bfd *, struct symbol_cache_entry *));
274
       boolean    (*_bfd_find_nearest_line) PARAMS ((bfd *abfd,
275
                         struct sec *section, struct symbol_cache_entry **symbols,
276
                         bfd_vma offset, CONST char **file, CONST char **func,
277
                         unsigned int *line));
278
       /* Back-door to allow format-aware applications to create debug symbols
279
         while using BFD for everything else.  Currently used by the assembler
280
         when creating COFF files.  */
281
       asymbol *  (*_bfd_make_debug_symbol) PARAMS ((
282
            bfd *abfd,
283
            void *ptr,
284
            unsigned long size));
285
     #define bfd_read_minisymbols(b, d, m, s) \
286
       BFD_SEND (b, _read_minisymbols, (b, d, m, s))
287
       long  (*_read_minisymbols) PARAMS ((bfd *, boolean, PTR *,
288
                                           unsigned int *));
289
     #define bfd_minisymbol_to_symbol(b, d, m, f) \
290
       BFD_SEND (b, _minisymbol_to_symbol, (b, d, m, f))
291
       asymbol *(*_minisymbol_to_symbol) PARAMS ((bfd *, boolean, const PTR,
292
                                                  asymbol *));
293
 
294
        /* Routines for relocs.  */
295
     #define BFD_JUMP_TABLE_RELOCS(NAME)\
296
     CAT(NAME,_get_reloc_upper_bound),\
297
     CAT(NAME,_canonicalize_reloc),\
298
     CAT(NAME,_bfd_reloc_type_lookup)
299
       long  (*_get_reloc_upper_bound) PARAMS ((bfd *, sec_ptr));
300
       long  (*_bfd_canonicalize_reloc) PARAMS ((bfd *, sec_ptr, arelent **,
301
                                                 struct symbol_cache_entry **));
302
        /* See documentation on reloc types.  */
303
       reloc_howto_type *
304
            (*reloc_type_lookup) PARAMS ((bfd *abfd,
305
                                          bfd_reloc_code_real_type code));
306
 
307
        /* Routines used when writing an object file.  */
308
     #define BFD_JUMP_TABLE_WRITE(NAME)\
309
     CAT(NAME,_set_arch_mach),\
310
     CAT(NAME,_set_section_contents)
311
       boolean    (*_bfd_set_arch_mach) PARAMS ((bfd *, enum bfd_architecture,
312
                         unsigned long));
313
       boolean       (*_bfd_set_section_contents) PARAMS ((bfd *, sec_ptr, PTR,
314
                                                 file_ptr, bfd_size_type));
315
 
316
        /* Routines used by the linker.  */
317
     #define BFD_JUMP_TABLE_LINK(NAME)\
318
     CAT(NAME,_sizeof_headers),\
319
     CAT(NAME,_bfd_get_relocated_section_contents),\
320
     CAT(NAME,_bfd_relax_section),\
321
     CAT(NAME,_bfd_link_hash_table_create),\
322
     CAT(NAME,_bfd_link_add_symbols),\
323
     CAT(NAME,_bfd_final_link),\
324
     CAT(NAME,_bfd_link_split_section),\
325
     CAT(NAME,_bfd_gc_sections)
326
       int        (*_bfd_sizeof_headers) PARAMS ((bfd *, boolean));
327
       bfd_byte * (*_bfd_get_relocated_section_contents) PARAMS ((bfd *,
328
                         struct bfd_link_info *, struct bfd_link_order *,
329
                         bfd_byte *data, boolean relocateable,
330
                         struct symbol_cache_entry **));
331
 
332
       boolean    (*_bfd_relax_section) PARAMS ((bfd *, struct sec *,
333
                         struct bfd_link_info *, boolean *again));
334
 
335
        /* Create a hash table for the linker.  Different backends store
336
          different information in this table.  */
337
       struct bfd_link_hash_table *(*_bfd_link_hash_table_create) PARAMS ((bfd *));
338
 
339
        /* Add symbols from this object file into the hash table.  */
340
       boolean (*_bfd_link_add_symbols) PARAMS ((bfd *, struct bfd_link_info *));
341
 
342
        /* Do a link based on the link_order structures attached to each
343
          section of the BFD.  */
344
       boolean (*_bfd_final_link) PARAMS ((bfd *, struct bfd_link_info *));
345
 
346
        /* Should this section be split up into smaller pieces during linking.  */
347
       boolean (*_bfd_link_split_section) PARAMS ((bfd *, struct sec *));
348
 
349
        /* Remove sections that are not referenced from the output.  */
350
       boolean (*_bfd_gc_sections) PARAMS ((bfd *, struct bfd_link_info *));
351
 
352
        /* Routines to handle dynamic symbols and relocs.  */
353
     #define BFD_JUMP_TABLE_DYNAMIC(NAME)\
354
     CAT(NAME,_get_dynamic_symtab_upper_bound),\
355
     CAT(NAME,_canonicalize_dynamic_symtab),\
356
     CAT(NAME,_get_dynamic_reloc_upper_bound),\
357
     CAT(NAME,_canonicalize_dynamic_reloc)
358
        /* Get the amount of memory required to hold the dynamic symbols. */
359
       long  (*_bfd_get_dynamic_symtab_upper_bound) PARAMS ((bfd *));
360
        /* Read in the dynamic symbols.  */
361
       long  (*_bfd_canonicalize_dynamic_symtab)
362
         PARAMS ((bfd *, struct symbol_cache_entry **));
363
        /* Get the amount of memory required to hold the dynamic relocs.  */
364
       long  (*_bfd_get_dynamic_reloc_upper_bound) PARAMS ((bfd *));
365
        /* Read in the dynamic relocs.  */
366
       long  (*_bfd_canonicalize_dynamic_reloc)
367
         PARAMS ((bfd *, arelent **, struct symbol_cache_entry **));
368
   A pointer to an alternative bfd_target in case the current one is not
369
satisfactory.  This can happen when the target cpu supports both big
370
and little endian code, and target chosen by the linker has the wrong
371
endianness.  The function open_output() in ld/ldlang.c uses this field
372
to find an alternative output format that is suitable.
373
       /* Opposite endian version of this target.  */
374
      const struct bfd_target * alternative_target;
375
   Data for use by back-end routines, which isn't generic enough to
376
belong in this structure.
377
      PTR backend_data;
378
 
379
     } bfd_target;
380
 
381
`bfd_set_default_target'
382
........................
383
 
384
   *Synopsis*
385
     boolean bfd_set_default_target (const char *name);
386
   *Description*
387
Set the default target vector to use when recognizing a BFD.  This
388
takes the name of the target, which may be a BFD target name or a
389
configuration triplet.
390
 
391
`bfd_find_target'
392
.................
393
 
394
   *Synopsis*
395
     const bfd_target *bfd_find_target(CONST char *target_name, bfd *abfd);
396
   *Description*
397
Return a pointer to the transfer vector for the object target named
398
TARGET_NAME.  If TARGET_NAME is `NULL', choose the one in the
399
environment variable `GNUTARGET'; if that is null or not defined, then
400
choose the first entry in the target list.  Passing in the string
401
"default" or setting the environment variable to "default" will cause
402
the first entry in the target list to be returned, and
403
"target_defaulted" will be set in the BFD.  This causes
404
`bfd_check_format' to loop over all the targets to find the one that
405
matches the file being read.
406
 
407
`bfd_target_list'
408
.................
409
 
410
   *Synopsis*
411
     const char **bfd_target_list(void);
412
   *Description*
413
Return a freshly malloced NULL-terminated vector of the names of all
414
the valid BFD targets. Do not modify the names.
415
 
416
`bfd_seach_for_target'
417
......................
418
 
419
   *Synopsis*
420
     const bfd_target * bfd_search_for_target (int (* search_func)(const bfd_target *, void *), void *);
421
   *Description*
422
Return a pointer to the first transfer vector in the list of transfer
423
vectors maintained by BFD that produces a non-zero result when passed
424
to the function SEARCH_FUNC.  The parameter DATA is passed, unexamined,
425
to the search function.
426
 
427

428
File: bfd.info,  Node: Architectures,  Next: Opening and Closing,  Prev: Targets,  Up: BFD front end
429
 
430
Architectures
431
=============
432
 
433
   BFD keeps one atom in a BFD describing the architecture of the data
434
attached to the BFD: a pointer to a `bfd_arch_info_type'.
435
 
436
   Pointers to structures can be requested independently of a BFD so
437
that an architecture's information can be interrogated without access
438
to an open BFD.
439
 
440
   The architecture information is provided by each architecture
441
package.  The set of default architectures is selected by the macro
442
`SELECT_ARCHITECTURES'.  This is normally set up in the
443
`config/TARGET.mt' file of your choice.  If the name is not defined,
444
then all the architectures supported are included.
445
 
446
   When BFD starts up, all the architectures are called with an
447
initialize method.  It is up to the architecture back end to insert as
448
many items into the list of architectures as it wants to; generally
449
this would be one for each machine and one for the default case (an
450
item with a machine field of 0).
451
 
452
   BFD's idea of an architecture is implemented in `archures.c'.
453
 
454
bfd_architecture
455
----------------
456
 
457
   *Description*
458
This enum gives the object file's CPU architecture, in a global
459
sense--i.e., what processor family does it belong to?  Another field
460
indicates which processor within the family is in use.  The machine
461
gives a number which distinguishes different versions of the
462
architecture, containing, for example, 2 and 3 for Intel i960 KA and
463
i960 KB, and 68020 and 68030 for Motorola 68020 and 68030.
464
     enum bfd_architecture
465
     {
466
       bfd_arch_unknown,    /* File arch not known */
467
       bfd_arch_obscure,    /* Arch known, not one of these */
468
       bfd_arch_m68k,       /* Motorola 68xxx */
469
     #define bfd_mach_m68000 1
470
     #define bfd_mach_m68008 2
471
     #define bfd_mach_m68010 3
472
     #define bfd_mach_m68020 4
473
     #define bfd_mach_m68030 5
474
     #define bfd_mach_m68040 6
475
     #define bfd_mach_m68060 7
476
     #define bfd_mach_cpu32  8
477
       bfd_arch_vax,        /* DEC Vax */
478
       bfd_arch_i960,       /* Intel 960 */
479
          /* The order of the following is important.
480
            lower number indicates a machine type that
481
            only accepts a subset of the instructions
482
            available to machines with higher numbers.
483
            The exception is the "ca", which is
484
            incompatible with all other machines except
485
            "core". */
486
 
487
     #define bfd_mach_i960_core      1
488
     #define bfd_mach_i960_ka_sa     2
489
     #define bfd_mach_i960_kb_sb     3
490
     #define bfd_mach_i960_mc        4
491
     #define bfd_mach_i960_xa        5
492
     #define bfd_mach_i960_ca        6
493
     #define bfd_mach_i960_jx        7
494
     #define bfd_mach_i960_hx        8
495
 
496
       bfd_arch_a29k,       /* AMD 29000 */
497
       bfd_arch_sparc,      /* SPARC */
498
     #define bfd_mach_sparc                 1
499
      /* The difference between v8plus and v9 is that v9 is a true 64 bit env.  */
500
     #define bfd_mach_sparc_sparclet        2
501
     #define bfd_mach_sparc_sparclite       3
502
     #define bfd_mach_sparc_v8plus          4
503
     #define bfd_mach_sparc_v8plusa         5  /* with ultrasparc add'ns */
504
     #define bfd_mach_sparc_sparclite_le    6
505
     #define bfd_mach_sparc_v9              7
506
     #define bfd_mach_sparc_v9a             8  /* with ultrasparc add'ns */
507
      /* Nonzero if MACH has the v9 instruction set.  */
508
     #define bfd_mach_sparc_v9_p(mach) \
509
       ((mach) >= bfd_mach_sparc_v8plus && (mach) <= bfd_mach_sparc_v9a)
510
       bfd_arch_mips,       /* MIPS Rxxxx */
511
     #define bfd_mach_mips3000              3000
512
     #define bfd_mach_mips3900              3900
513
     #define bfd_mach_mips4000              4000
514
     #define bfd_mach_mips4010              4010
515
     #define bfd_mach_mips4100              4100
516
     #define bfd_mach_mips4111              4111
517
     #define bfd_mach_mips4300              4300
518
     #define bfd_mach_mips4400              4400
519
     #define bfd_mach_mips4600              4600
520
     #define bfd_mach_mips4650              4650
521
     #define bfd_mach_mips5000              5000
522
     #define bfd_mach_mips6000              6000
523
     #define bfd_mach_mips8000              8000
524
     #define bfd_mach_mips10000             10000
525
     #define bfd_mach_mips16                16
526
       bfd_arch_i386,       /* Intel 386 */
527
     #define bfd_mach_i386_i386 0
528
     #define bfd_mach_i386_i8086 1
529
     #define bfd_mach_i386_i386_intel_syntax 2
530
       bfd_arch_we32k,      /* AT&T WE32xxx */
531
       bfd_arch_tahoe,      /* CCI/Harris Tahoe */
532
       bfd_arch_i860,       /* Intel 860 */
533
       bfd_arch_i370,       /* IBM 360/370 Mainframes */
534
       bfd_arch_romp,       /* IBM ROMP PC/RT */
535
       bfd_arch_alliant,    /* Alliant */
536
       bfd_arch_convex,     /* Convex */
537
       bfd_arch_m88k,       /* Motorola 88xxx */
538
       bfd_arch_pyramid,    /* Pyramid Technology */
539
       bfd_arch_h8300,      /* Hitachi H8/300 */
540
     #define bfd_mach_h8300   1
541
     #define bfd_mach_h8300h  2
542
     #define bfd_mach_h8300s  3
543
       bfd_arch_powerpc,    /* PowerPC */
544
       bfd_arch_rs6000,     /* IBM RS/6000 */
545
       bfd_arch_hppa,       /* HP PA RISC */
546
       bfd_arch_d10v,       /* Mitsubishi D10V */
547
     #define bfd_mach_d10v          0
548
     #define bfd_mach_d10v_ts2      2
549
     #define bfd_mach_d10v_ts3      3
550
       bfd_arch_d30v,       /* Mitsubishi D30V */
551
       bfd_arch_z8k,        /* Zilog Z8000 */
552
     #define bfd_mach_z8001         1
553
     #define bfd_mach_z8002         2
554
       bfd_arch_h8500,      /* Hitachi H8/500 */
555
       bfd_arch_sh,         /* Hitachi SH */
556
     #define bfd_mach_sh            0
557
     #define bfd_mach_sh2        0x20
558
     #define bfd_mach_sh_dsp     0x2d
559
     #define bfd_mach_sh3        0x30
560
     #define bfd_mach_sh3_dsp    0x3d
561
     #define bfd_mach_sh3e       0x3e
562
     #define bfd_mach_sh4        0x40
563
       bfd_arch_alpha,      /* Dec Alpha */
564
     #define bfd_mach_alpha_ev4  0x10
565
     #define bfd_mach_alpha_ev5  0x20
566
     #define bfd_mach_alpha_ev6  0x30
567
       bfd_arch_arm,        /* Advanced Risc Machines ARM */
568
     #define bfd_mach_arm_2         1
569
     #define bfd_mach_arm_2a        2
570
     #define bfd_mach_arm_3         3
571
     #define bfd_mach_arm_3M        4
572
     #define bfd_mach_arm_4         5
573
     #define bfd_mach_arm_4T        6
574
     #define bfd_mach_arm_5         7
575
     #define bfd_mach_arm_5T        8
576
       bfd_arch_ns32k,      /* National Semiconductors ns32000 */
577
       bfd_arch_w65,        /* WDC 65816 */
578
       bfd_arch_tic30,      /* Texas Instruments TMS320C30 */
579
       bfd_arch_tic54x,     /* Texas Instruments TMS320C54X */
580
       bfd_arch_tic80,      /* TI TMS320c80 (MVP) */
581
       bfd_arch_v850,       /* NEC V850 */
582
     #define bfd_mach_v850          0
583
     #define bfd_mach_v850e         'E'
584
     #define bfd_mach_v850ea        'A'
585
       bfd_arch_arc,        /* Argonaut RISC Core */
586
     #define bfd_mach_arc_base 0
587
       bfd_arch_m32r,       /* Mitsubishi M32R/D */
588
     #define bfd_mach_m32r          0  /* backwards compatibility */
589
     #define bfd_mach_m32rx         'x'
590
       bfd_arch_mn10200,    /* Matsushita MN10200 */
591
       bfd_arch_mn10300,    /* Matsushita MN10300 */
592
     #define bfd_mach_mn10300               300
593
     #define bfd_mach_am33          330
594
       bfd_arch_fr30,
595
     #define bfd_mach_fr30          0x46523330
596
       bfd_arch_mcore,
597
       bfd_arch_pj,
598
       bfd_arch_avr,        /* Atmel AVR microcontrollers */
599
     #define bfd_mach_avr1          1
600
     #define bfd_mach_avr2          2
601
     #define bfd_mach_avr3          3
602
     #define bfd_mach_avr4          4
603
       bfd_arch_last
604
       };
605
 
606
bfd_arch_info
607
-------------
608
 
609
   *Description*
610
This structure contains information on architectures for use within BFD.
611
 
612
     typedef struct bfd_arch_info
613
     {
614
       int bits_per_word;
615
       int bits_per_address;
616
       int bits_per_byte;
617
       enum bfd_architecture arch;
618
       unsigned long mach;
619
       const char *arch_name;
620
       const char *printable_name;
621
       unsigned int section_align_power;
622
       /* true if this is the default machine for the architecture */
623
       boolean the_default;
624
       const struct bfd_arch_info * (*compatible)
625
            PARAMS ((const struct bfd_arch_info *a,
626
                     const struct bfd_arch_info *b));
627
 
628
       boolean (*scan) PARAMS ((const struct bfd_arch_info *, const char *));
629
 
630
       const struct bfd_arch_info *next;
631
     } bfd_arch_info_type;
632
 
633
`bfd_printable_name'
634
....................
635
 
636
   *Synopsis*
637
     const char *bfd_printable_name(bfd *abfd);
638
   *Description*
639
Return a printable string representing the architecture and machine
640
from the pointer to the architecture info structure.
641
 
642
`bfd_scan_arch'
643
...............
644
 
645
   *Synopsis*
646
     const bfd_arch_info_type *bfd_scan_arch(const char *string);
647
   *Description*
648
Figure out if BFD supports any cpu which could be described with the
649
name STRING.  Return a pointer to an `arch_info' structure if a machine
650
is found, otherwise NULL.
651
 
652
`bfd_arch_list'
653
...............
654
 
655
   *Synopsis*
656
     const char **bfd_arch_list(void);
657
   *Description*
658
Return a freshly malloced NULL-terminated vector of the names of all
659
the valid BFD architectures.  Do not modify the names.
660
 
661
`bfd_arch_get_compatible'
662
.........................
663
 
664
   *Synopsis*
665
     const bfd_arch_info_type *bfd_arch_get_compatible(
666
         const bfd *abfd,
667
         const bfd *bbfd);
668
   *Description*
669
Determine whether two BFDs' architectures and machine types are
670
compatible.  Calculates the lowest common denominator between the two
671
architectures and machine types implied by the BFDs and returns a
672
pointer to an `arch_info' structure describing the compatible machine.
673
 
674
`bfd_default_arch_struct'
675
.........................
676
 
677
   *Description*
678
The `bfd_default_arch_struct' is an item of `bfd_arch_info_type' which
679
has been initialized to a fairly generic state.  A BFD starts life by
680
pointing to this structure, until the correct back end has determined
681
the real architecture of the file.
682
     extern const bfd_arch_info_type bfd_default_arch_struct;
683
 
684
`bfd_set_arch_info'
685
...................
686
 
687
   *Synopsis*
688
     void bfd_set_arch_info(bfd *abfd, const bfd_arch_info_type *arg);
689
   *Description*
690
Set the architecture info of ABFD to ARG.
691
 
692
`bfd_default_set_arch_mach'
693
...........................
694
 
695
   *Synopsis*
696
     boolean bfd_default_set_arch_mach(bfd *abfd,
697
         enum bfd_architecture arch,
698
         unsigned long mach);
699
   *Description*
700
Set the architecture and machine type in BFD ABFD to ARCH and MACH.
701
Find the correct pointer to a structure and insert it into the
702
`arch_info' pointer.
703
 
704
`bfd_get_arch'
705
..............
706
 
707
   *Synopsis*
708
     enum bfd_architecture bfd_get_arch(bfd *abfd);
709
   *Description*
710
Return the enumerated type which describes the BFD ABFD's architecture.
711
 
712
`bfd_get_mach'
713
..............
714
 
715
   *Synopsis*
716
     unsigned long bfd_get_mach(bfd *abfd);
717
   *Description*
718
Return the long type which describes the BFD ABFD's machine.
719
 
720
`bfd_arch_bits_per_byte'
721
........................
722
 
723
   *Synopsis*
724
     unsigned int bfd_arch_bits_per_byte(bfd *abfd);
725
   *Description*
726
Return the number of bits in one of the BFD ABFD's architecture's bytes.
727
 
728
`bfd_arch_bits_per_address'
729
...........................
730
 
731
   *Synopsis*
732
     unsigned int bfd_arch_bits_per_address(bfd *abfd);
733
   *Description*
734
Return the number of bits in one of the BFD ABFD's architecture's
735
addresses.
736
 
737
`bfd_default_compatible'
738
........................
739
 
740
   *Synopsis*
741
     const bfd_arch_info_type *bfd_default_compatible
742
        (const bfd_arch_info_type *a,
743
         const bfd_arch_info_type *b);
744
   *Description*
745
The default function for testing for compatibility.
746
 
747
`bfd_default_scan'
748
..................
749
 
750
   *Synopsis*
751
     boolean bfd_default_scan(const struct bfd_arch_info *info, const char *string);
752
   *Description*
753
The default function for working out whether this is an architecture
754
hit and a machine hit.
755
 
756
`bfd_get_arch_info'
757
...................
758
 
759
   *Synopsis*
760
     const bfd_arch_info_type * bfd_get_arch_info(bfd *abfd);
761
   *Description*
762
Return the architecture info struct in ABFD.
763
 
764
`bfd_lookup_arch'
765
.................
766
 
767
   *Synopsis*
768
     const bfd_arch_info_type *bfd_lookup_arch
769
        (enum bfd_architecture
770
         arch,
771
         unsigned long machine);
772
   *Description*
773
Look for the architecure info structure which matches the arguments
774
ARCH and MACHINE. A machine of 0 matches the machine/architecture
775
structure which marks itself as the default.
776
 
777
`bfd_printable_arch_mach'
778
.........................
779
 
780
   *Synopsis*
781
     const char *bfd_printable_arch_mach
782
        (enum bfd_architecture arch, unsigned long machine);
783
   *Description*
784
Return a printable string representing the architecture and machine
785
type.
786
 
787
   This routine is depreciated.
788
 
789
`bfd_octets_per_byte'
790
.....................
791
 
792
   *Synopsis*
793
     unsigned int bfd_octets_per_byte(bfd *abfd);
794
   *Description*
795
Return the number of octets (8-bit quantities) per target byte (minimum
796
addressable unit).  In most cases, this will be one, but some DSP
797
targets have 16, 32, or even 48 bits per byte.
798
 
799
`bfd_arch_mach_octets_per_byte'
800
...............................
801
 
802
   *Synopsis*
803
     unsigned int bfd_arch_mach_octets_per_byte(enum bfd_architecture arch,
804
         unsigned long machine);
805
   *Description*
806
See bfd_octets_per_byte.  This routine is provided for those cases
807
where a bfd * is not available
808
 
809

810
File: bfd.info,  Node: Opening and Closing,  Next: Internal,  Prev: Architectures,  Up: BFD front end
811
 
812
Opening and closing BFDs
813
========================
814
 
815
`bfd_openr'
816
...........
817
 
818
   *Synopsis*
819
     bfd *bfd_openr(CONST char *filename, CONST char *target);
820
   *Description*
821
Open the file FILENAME (using `fopen') with the target TARGET.  Return
822
a pointer to the created BFD.
823
 
824
   Calls `bfd_find_target', so TARGET is interpreted as by that
825
function.
826
 
827
   If `NULL' is returned then an error has occured.   Possible errors
828
are `bfd_error_no_memory', `bfd_error_invalid_target' or `system_call'
829
error.
830
 
831
`bfd_fdopenr'
832
.............
833
 
834
   *Synopsis*
835
     bfd *bfd_fdopenr(CONST char *filename, CONST char *target, int fd);
836
   *Description*
837
`bfd_fdopenr' is to `bfd_fopenr' much like `fdopen' is to `fopen'.  It
838
opens a BFD on a file already described by the FD supplied.
839
 
840
   When the file is later `bfd_close'd, the file descriptor will be
841
closed.
842
 
843
   If the caller desires that this file descriptor be cached by BFD
844
(opened as needed, closed as needed to free descriptors for other
845
opens), with the supplied FD used as an initial file descriptor (but
846
subject to closure at any time), call bfd_set_cacheable(bfd, 1) on the
847
returned BFD.  The default is to assume no cacheing; the file
848
descriptor will remain open until `bfd_close', and will not be affected
849
by BFD operations on other files.
850
 
851
   Possible errors are `bfd_error_no_memory',
852
`bfd_error_invalid_target' and `bfd_error_system_call'.
853
 
854
`bfd_openstreamr'
855
.................
856
 
857
   *Synopsis*
858
     bfd *bfd_openstreamr(const char *, const char *, PTR);
859
   *Description*
860
Open a BFD for read access on an existing stdio stream.  When the BFD
861
is passed to `bfd_close', the stream will be closed.
862
 
863
`bfd_openw'
864
...........
865
 
866
   *Synopsis*
867
     bfd *bfd_openw(CONST char *filename, CONST char *target);
868
   *Description*
869
Create a BFD, associated with file FILENAME, using the file format
870
TARGET, and return a pointer to it.
871
 
872
   Possible errors are `bfd_error_system_call', `bfd_error_no_memory',
873
`bfd_error_invalid_target'.
874
 
875
`bfd_close'
876
...........
877
 
878
   *Synopsis*
879
     boolean bfd_close(bfd *abfd);
880
   *Description*
881
Close a BFD. If the BFD was open for writing, then pending operations
882
are completed and the file written out and closed. If the created file
883
is executable, then `chmod' is called to mark it as such.
884
 
885
   All memory attached to the BFD is released.
886
 
887
   The file descriptor associated with the BFD is closed (even if it
888
was passed in to BFD by `bfd_fdopenr').
889
 
890
   *Returns*
891
`true' is returned if all is ok, otherwise `false'.
892
 
893
`bfd_close_all_done'
894
....................
895
 
896
   *Synopsis*
897
     boolean bfd_close_all_done(bfd *);
898
   *Description*
899
Close a BFD.  Differs from `bfd_close' since it does not complete any
900
pending operations.  This routine would be used if the application had
901
just used BFD for swapping and didn't want to use any of the writing
902
code.
903
 
904
   If the created file is executable, then `chmod' is called to mark it
905
as such.
906
 
907
   All memory attached to the BFD is released.
908
 
909
   *Returns*
910
`true' is returned if all is ok, otherwise `false'.
911
 
912
`bfd_create'
913
............
914
 
915
   *Synopsis*
916
     bfd *bfd_create(CONST char *filename, bfd *templ);
917
   *Description*
918
Create a new BFD in the manner of `bfd_openw', but without opening a
919
file. The new BFD takes the target from the target used by TEMPLATE. The
920
format is always set to `bfd_object'.
921
 
922
`bfd_make_writable'
923
...................
924
 
925
   *Synopsis*
926
     boolean bfd_make_writable(bfd *abfd);
927
   *Description*
928
Takes a BFD as created by `bfd_create' and converts it into one like as
929
returned by `bfd_openw'.  It does this by converting the BFD to
930
BFD_IN_MEMORY.  It's assumed that you will call `bfd_make_readable' on
931
this bfd later.
932
 
933
   *Returns*
934
`true' is returned if all is ok, otherwise `false'.
935
 
936
`bfd_make_readable'
937
...................
938
 
939
   *Synopsis*
940
     boolean bfd_make_readable(bfd *abfd);
941
   *Description*
942
Takes a BFD as created by `bfd_create' and `bfd_make_writable' and
943
converts it into one like as returned by `bfd_openr'.  It does this by
944
writing the contents out to the memory buffer, then reversing the
945
direction.
946
 
947
   *Returns*
948
`true' is returned if all is ok, otherwise `false'.
949
 
950
`bfd_alloc'
951
...........
952
 
953
   *Synopsis*
954
     PTR bfd_alloc (bfd *abfd, size_t wanted);
955
   *Description*
956
Allocate a block of WANTED bytes of memory attached to `abfd' and
957
return a pointer to it.
958
 
959

960
File: bfd.info,  Node: Internal,  Next: File Caching,  Prev: Opening and Closing,  Up: BFD front end
961
 
962
Internal functions
963
==================
964
 
965
   *Description*
966
These routines are used within BFD.  They are not intended for export,
967
but are documented here for completeness.
968
 
969
`bfd_write_bigendian_4byte_int'
970
...............................
971
 
972
   *Synopsis*
973
     void bfd_write_bigendian_4byte_int(bfd *abfd,  int i);
974
   *Description*
975
Write a 4 byte integer I to the output BFD ABFD, in big endian order
976
regardless of what else is going on.  This is useful in archives.
977
 
978
`bfd_put_size'
979
..............
980
 
981
`bfd_get_size'
982
..............
983
 
984
   *Description*
985
These macros as used for reading and writing raw data in sections; each
986
access (except for bytes) is vectored through the target format of the
987
BFD and mangled accordingly. The mangling performs any necessary endian
988
translations and removes alignment restrictions.  Note that types
989
accepted and returned by these macros are identical so they can be
990
swapped around in macros--for example, `libaout.h' defines `GET_WORD'
991
to either `bfd_get_32' or `bfd_get_64'.
992
 
993
   In the put routines, VAL must be a `bfd_vma'.  If we are on a system
994
without prototypes, the caller is responsible for making sure that is
995
true, with a cast if necessary.  We don't cast them in the macro
996
definitions because that would prevent `lint' or `gcc -Wall' from
997
detecting sins such as passing a pointer.  To detect calling these with
998
less than a `bfd_vma', use `gcc -Wconversion' on a host with 64 bit
999
`bfd_vma''s.
1000
 
1001
      /* Byte swapping macros for user section data.  */
1002
 
1003
     #define bfd_put_8(abfd, val, ptr) \
1004
                     ((void) (*((unsigned char *)(ptr)) = (unsigned char)(val)))
1005
     #define bfd_put_signed_8 \
1006
                    bfd_put_8
1007
     #define bfd_get_8(abfd, ptr) \
1008
                     (*(unsigned char *)(ptr))
1009
     #define bfd_get_signed_8(abfd, ptr) \
1010
                    ((*(unsigned char *)(ptr) ^ 0x80) - 0x80)
1011
 
1012
     #define bfd_put_16(abfd, val, ptr) \
1013
                     BFD_SEND(abfd, bfd_putx16, ((val),(ptr)))
1014
     #define bfd_put_signed_16 \
1015
                     bfd_put_16
1016
     #define bfd_get_16(abfd, ptr) \
1017
                     BFD_SEND(abfd, bfd_getx16, (ptr))
1018
     #define bfd_get_signed_16(abfd, ptr) \
1019
                     BFD_SEND (abfd, bfd_getx_signed_16, (ptr))
1020
 
1021
     #define bfd_put_32(abfd, val, ptr) \
1022
                     BFD_SEND(abfd, bfd_putx32, ((val),(ptr)))
1023
     #define bfd_put_signed_32 \
1024
                     bfd_put_32
1025
     #define bfd_get_32(abfd, ptr) \
1026
                     BFD_SEND(abfd, bfd_getx32, (ptr))
1027
     #define bfd_get_signed_32(abfd, ptr) \
1028
                     BFD_SEND(abfd, bfd_getx_signed_32, (ptr))
1029
 
1030
     #define bfd_put_64(abfd, val, ptr) \
1031
                     BFD_SEND(abfd, bfd_putx64, ((val), (ptr)))
1032
     #define bfd_put_signed_64 \
1033
                     bfd_put_64
1034
     #define bfd_get_64(abfd, ptr) \
1035
                     BFD_SEND(abfd, bfd_getx64, (ptr))
1036
     #define bfd_get_signed_64(abfd, ptr) \
1037
                     BFD_SEND(abfd, bfd_getx_signed_64, (ptr))
1038
 
1039
     #define bfd_get(bits, abfd, ptr)                               \
1040
                     ((bits) == 8 ? bfd_get_8 (abfd, ptr)           \
1041
                     : (bits) == 16 ? bfd_get_16 (abfd, ptr)        \
1042
                     : (bits) == 32 ? bfd_get_32 (abfd, ptr)        \
1043
                     : (bits) == 64 ? bfd_get_64 (abfd, ptr)        \
1044
                     : (abort (), (bfd_vma) - 1))
1045
 
1046
     #define bfd_put(bits, abfd, val, ptr)                          \
1047
                     ((bits) == 8 ? bfd_put_8 (abfd, val, ptr)      \
1048
                     : (bits) == 16 ? bfd_put_16 (abfd, val, ptr)   \
1049
                     : (bits) == 32 ? bfd_put_32 (abfd, val, ptr)   \
1050
                     : (bits) == 64 ? bfd_put_64 (abfd, val, ptr)   \
1051
                     : (abort (), (void) 0))
1052
 
1053
`bfd_h_put_size'
1054
................
1055
 
1056
   *Description*
1057
These macros have the same function as their `bfd_get_x' bretheren,
1058
except that they are used for removing information for the header
1059
records of object files. Believe it or not, some object files keep
1060
their header records in big endian order and their data in little
1061
endian order.
1062
 
1063
      /* Byte swapping macros for file header data.  */
1064
 
1065
     #define bfd_h_put_8(abfd, val, ptr) \
1066
                    bfd_put_8 (abfd, val, ptr)
1067
     #define bfd_h_put_signed_8(abfd, val, ptr) \
1068
                    bfd_put_8 (abfd, val, ptr)
1069
     #define bfd_h_get_8(abfd, ptr) \
1070
                    bfd_get_8 (abfd, ptr)
1071
     #define bfd_h_get_signed_8(abfd, ptr) \
1072
                    bfd_get_signed_8 (abfd, ptr)
1073
 
1074
     #define bfd_h_put_16(abfd, val, ptr) \
1075
                     BFD_SEND(abfd, bfd_h_putx16,(val,ptr))
1076
     #define bfd_h_put_signed_16 \
1077
                     bfd_h_put_16
1078
     #define bfd_h_get_16(abfd, ptr) \
1079
                     BFD_SEND(abfd, bfd_h_getx16,(ptr))
1080
     #define bfd_h_get_signed_16(abfd, ptr) \
1081
                     BFD_SEND(abfd, bfd_h_getx_signed_16, (ptr))
1082
 
1083
     #define bfd_h_put_32(abfd, val, ptr) \
1084
                     BFD_SEND(abfd, bfd_h_putx32,(val,ptr))
1085
     #define bfd_h_put_signed_32 \
1086
                     bfd_h_put_32
1087
     #define bfd_h_get_32(abfd, ptr) \
1088
                     BFD_SEND(abfd, bfd_h_getx32,(ptr))
1089
     #define bfd_h_get_signed_32(abfd, ptr) \
1090
                     BFD_SEND(abfd, bfd_h_getx_signed_32, (ptr))
1091
 
1092
     #define bfd_h_put_64(abfd, val, ptr) \
1093
                     BFD_SEND(abfd, bfd_h_putx64,(val, ptr))
1094
     #define bfd_h_put_signed_64 \
1095
                     bfd_h_put_64
1096
     #define bfd_h_get_64(abfd, ptr) \
1097
                     BFD_SEND(abfd, bfd_h_getx64,(ptr))
1098
     #define bfd_h_get_signed_64(abfd, ptr) \
1099
                     BFD_SEND(abfd, bfd_h_getx_signed_64, (ptr))
1100
 
1101
`bfd_log2'
1102
..........
1103
 
1104
   *Synopsis*
1105
     unsigned int bfd_log2(bfd_vma x);
1106
   *Description*
1107
Return the log base 2 of the value supplied, rounded up.  E.g., an X of
1108
1025 returns 11.
1109
 
1110

1111
File: bfd.info,  Node: File Caching,  Next: Linker Functions,  Prev: Internal,  Up: BFD front end
1112
 
1113
File caching
1114
============
1115
 
1116
   The file caching mechanism is embedded within BFD and allows the
1117
application to open as many BFDs as it wants without regard to the
1118
underlying operating system's file descriptor limit (often as low as 20
1119
open files).  The module in `cache.c' maintains a least recently used
1120
list of `BFD_CACHE_MAX_OPEN' files, and exports the name
1121
`bfd_cache_lookup', which runs around and makes sure that the required
1122
BFD is open. If not, then it chooses a file to close, closes it and
1123
opens the one wanted, returning its file handle.
1124
 
1125
`BFD_CACHE_MAX_OPEN macro'
1126
..........................
1127
 
1128
   *Description*
1129
The maximum number of files which the cache will keep open at one time.
1130
     #define BFD_CACHE_MAX_OPEN 10
1131
 
1132
`bfd_last_cache'
1133
................
1134
 
1135
   *Synopsis*
1136
     extern bfd *bfd_last_cache;
1137
   *Description*
1138
Zero, or a pointer to the topmost BFD on the chain.  This is used by
1139
the `bfd_cache_lookup' macro in `libbfd.h' to determine when it can
1140
avoid a function call.
1141
 
1142
`bfd_cache_lookup'
1143
..................
1144
 
1145
   *Description*
1146
Check to see if the required BFD is the same as the last one looked up.
1147
If so, then it can use the stream in the BFD with impunity, since it
1148
can't have changed since the last lookup; otherwise, it has to perform
1149
the complicated lookup function.
1150
     #define bfd_cache_lookup(x) \
1151
         ((x)==bfd_last_cache? \
1152
           (FILE*)(bfd_last_cache->iostream): \
1153
            bfd_cache_lookup_worker(x))
1154
 
1155
`bfd_cache_init'
1156
................
1157
 
1158
   *Synopsis*
1159
     boolean bfd_cache_init (bfd *abfd);
1160
   *Description*
1161
Add a newly opened BFD to the cache.
1162
 
1163
`bfd_cache_close'
1164
.................
1165
 
1166
   *Synopsis*
1167
     boolean bfd_cache_close (bfd *abfd);
1168
   *Description*
1169
Remove the BFD ABFD from the cache. If the attached file is open, then
1170
close it too.
1171
 
1172
   *Returns*
1173
`false' is returned if closing the file fails, `true' is returned if
1174
all is well.
1175
 
1176
`bfd_open_file'
1177
...............
1178
 
1179
   *Synopsis*
1180
     FILE* bfd_open_file(bfd *abfd);
1181
   *Description*
1182
Call the OS to open a file for ABFD.  Return the `FILE *' (possibly
1183
`NULL') that results from this operation.  Set up the BFD so that
1184
future accesses know the file is open. If the `FILE *' returned is
1185
`NULL', then it won't have been put in the cache, so it won't have to
1186
be removed from it.
1187
 
1188
`bfd_cache_lookup_worker'
1189
.........................
1190
 
1191
   *Synopsis*
1192
     FILE *bfd_cache_lookup_worker(bfd *abfd);
1193
   *Description*
1194
Called when the macro `bfd_cache_lookup' fails to find a quick answer.
1195
Find a file descriptor for ABFD.  If necessary, it open it.  If there
1196
are already more than `BFD_CACHE_MAX_OPEN' files open, it tries to
1197
close one first, to avoid running out of file descriptors.
1198
 
1199

1200
File: bfd.info,  Node: Linker Functions,  Next: Hash Tables,  Prev: File Caching,  Up: BFD front end
1201
 
1202
Linker Functions
1203
================
1204
 
1205
   The linker uses three special entry points in the BFD target vector.
1206
It is not necessary to write special routines for these entry points
1207
when creating a new BFD back end, since generic versions are provided.
1208
However, writing them can speed up linking and make it use
1209
significantly less runtime memory.
1210
 
1211
   The first routine creates a hash table used by the other routines.
1212
The second routine adds the symbols from an object file to the hash
1213
table.  The third routine takes all the object files and links them
1214
together to create the output file.  These routines are designed so
1215
that the linker proper does not need to know anything about the symbols
1216
in the object files that it is linking.  The linker merely arranges the
1217
sections as directed by the linker script and lets BFD handle the
1218
details of symbols and relocs.
1219
 
1220
   The second routine and third routines are passed a pointer to a
1221
`struct bfd_link_info' structure (defined in `bfdlink.h') which holds
1222
information relevant to the link, including the linker hash table
1223
(which was created by the first routine) and a set of callback
1224
functions to the linker proper.
1225
 
1226
   The generic linker routines are in `linker.c', and use the header
1227
file `genlink.h'.  As of this writing, the only back ends which have
1228
implemented versions of these routines are a.out (in `aoutx.h') and
1229
ECOFF (in `ecoff.c').  The a.out routines are used as examples
1230
throughout this section.
1231
 
1232
* Menu:
1233
 
1234
* Creating a Linker Hash Table::
1235
* Adding Symbols to the Hash Table::
1236
* Performing the Final Link::
1237
 
1238

1239
File: bfd.info,  Node: Creating a Linker Hash Table,  Next: Adding Symbols to the Hash Table,  Prev: Linker Functions,  Up: Linker Functions
1240
 
1241
Creating a linker hash table
1242
----------------------------
1243
 
1244
   The linker routines must create a hash table, which must be derived
1245
from `struct bfd_link_hash_table' described in `bfdlink.c'.  *Note Hash
1246
Tables::, for information on how to create a derived hash table.  This
1247
entry point is called using the target vector of the linker output file.
1248
 
1249
   The `_bfd_link_hash_table_create' entry point must allocate and
1250
initialize an instance of the desired hash table.  If the back end does
1251
not require any additional information to be stored with the entries in
1252
the hash table, the entry point may simply create a `struct
1253
bfd_link_hash_table'.  Most likely, however, some additional
1254
information will be needed.
1255
 
1256
   For example, with each entry in the hash table the a.out linker
1257
keeps the index the symbol has in the final output file (this index
1258
number is used so that when doing a relocateable link the symbol index
1259
used in the output file can be quickly filled in when copying over a
1260
reloc).  The a.out linker code defines the required structures and
1261
functions for a hash table derived from `struct bfd_link_hash_table'.
1262
The a.out linker hash table is created by the function
1263
`NAME(aout,link_hash_table_create)'; it simply allocates space for the
1264
hash table, initializes it, and returns a pointer to it.
1265
 
1266
   When writing the linker routines for a new back end, you will
1267
generally not know exactly which fields will be required until you have
1268
finished.  You should simply create a new hash table which defines no
1269
additional fields, and then simply add fields as they become necessary.
1270
 
1271

1272
File: bfd.info,  Node: Adding Symbols to the Hash Table,  Next: Performing the Final Link,  Prev: Creating a Linker Hash Table,  Up: Linker Functions
1273
 
1274
Adding symbols to the hash table
1275
--------------------------------
1276
 
1277
   The linker proper will call the `_bfd_link_add_symbols' entry point
1278
for each object file or archive which is to be linked (typically these
1279
are the files named on the command line, but some may also come from
1280
the linker script).  The entry point is responsible for examining the
1281
file.  For an object file, BFD must add any relevant symbol information
1282
to the hash table.  For an archive, BFD must determine which elements
1283
of the archive should be used and adding them to the link.
1284
 
1285
   The a.out version of this entry point is
1286
`NAME(aout,link_add_symbols)'.
1287
 
1288
* Menu:
1289
 
1290
* Differing file formats::
1291
* Adding symbols from an object file::
1292
* Adding symbols from an archive::
1293
 

powered by: WebSVN 2.1.0

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