1 @section @code{typedef bfd}
2 A BFD has type @code{bfd}; objects of this type are the
3 cornerstone of any application using BFD. Using BFD
4 consists of making references though the BFD and to data in the BFD.
6 Here is the structure that defines the type @code{bfd}. It
7 contains the major data about the file and pointers
8 to the rest of the data.
15 /* A unique identifier of the BFD */
18 /* The filename the application opened the BFD with. */
21 /* A pointer to the target jump table. */
22 const struct bfd_target *xvec;
24 /* To avoid dragging too many header files into every file that
25 includes `@code{bfd.h}', IOSTREAM has been declared as a "char *",
26 and MTIME as a "long". Their correct types, to which they
27 are cast when used, are "FILE *" and "time_t". The iostream
28 is the result of an fopen on the filename. However, if the
29 BFD_IN_MEMORY flag is set, then iostream is actually a pointer
30 to a bfd_in_memory struct. */
33 /* Is the file descriptor being cached? That is, can it be closed as
34 needed, and re-opened when accessed later? */
35 bfd_boolean cacheable;
37 /* Marks whether there was a default target specified when the
38 BFD was opened. This is used to select which matching algorithm
39 to use to choose the back end. */
40 bfd_boolean target_defaulted;
42 /* The caching routines use these to maintain a
43 least-recently-used list of BFDs. */
44 struct bfd *lru_prev, *lru_next;
46 /* When a file is closed by the caching routines, BFD retains
47 state information on the file here... */
50 /* ... and here: (``once'' means at least once). */
51 bfd_boolean opened_once;
53 /* Set if we have a locally maintained mtime value, rather than
54 getting it from the file each time. */
55 bfd_boolean mtime_set;
57 /* File modified time, if mtime_set is TRUE. */
60 /* Reserved for an unimplemented file locking extension. */
63 /* The format which belongs to the BFD. (object, core, etc.) */
66 /* The direction with which the BFD was opened. */
76 /* Format_specific flags. */
79 /* Currently my_archive is tested before adding origin to
80 anything. I believe that this can become always an add of
81 origin, with origin set to 0 for non archive files. */
84 /* Remember when output has begun, to stop strange things
86 bfd_boolean output_has_begun;
88 /* A hash table for section names. */
89 struct bfd_hash_table section_htab;
91 /* Pointer to linked list of sections. */
92 struct bfd_section *sections;
94 /* The place where we add to the section list. */
95 struct bfd_section **section_tail;
97 /* The number of sections. */
98 unsigned int section_count;
100 /* Stuff only useful for object files:
101 The start address. */
102 bfd_vma start_address;
104 /* Used for input and output. */
105 unsigned int symcount;
107 /* Symbol table for output BFD (with symcount entries). */
108 struct bfd_symbol **outsymbols;
110 /* Used for slurped dynamic symbol tables. */
111 unsigned int dynsymcount;
113 /* Pointer to structure which contains architecture information. */
114 const struct bfd_arch_info *arch_info;
116 /* Stuff only useful for archives. */
118 struct bfd *my_archive; /* The containing archive BFD. */
119 struct bfd *next; /* The next BFD in the archive. */
120 struct bfd *archive_head; /* The first BFD in the archive. */
121 bfd_boolean has_armap;
123 /* A chain of BFD structures involved in a link. */
124 struct bfd *link_next;
126 /* A field used by _bfd_generic_link_add_archive_symbols. This will
127 be used only for archive elements. */
130 /* Used by the back end to hold private data. */
133 struct aout_data_struct *aout_data;
134 struct artdata *aout_ar_data;
135 struct _oasys_data *oasys_obj_data;
136 struct _oasys_ar_data *oasys_ar_data;
137 struct coff_tdata *coff_obj_data;
138 struct pe_tdata *pe_obj_data;
139 struct xcoff_tdata *xcoff_obj_data;
140 struct ecoff_tdata *ecoff_obj_data;
141 struct ieee_data_struct *ieee_data;
142 struct ieee_ar_data_struct *ieee_ar_data;
143 struct srec_data_struct *srec_data;
144 struct ihex_data_struct *ihex_data;
145 struct tekhex_data_struct *tekhex_data;
146 struct elf_obj_tdata *elf_obj_data;
147 struct nlm_obj_tdata *nlm_obj_data;
148 struct bout_data_struct *bout_data;
149 struct mmo_data_struct *mmo_data;
150 struct sun_core_struct *sun_core_data;
151 struct sco5_core_struct *sco5_core_data;
152 struct trad_core_struct *trad_core_data;
153 struct som_data_struct *som_data;
154 struct hpux_core_struct *hpux_core_data;
155 struct hppabsd_core_struct *hppabsd_core_data;
156 struct sgi_core_struct *sgi_core_data;
157 struct lynx_core_struct *lynx_core_data;
158 struct osf_core_struct *osf_core_data;
159 struct cisco_core_struct *cisco_core_data;
160 struct versados_data_struct *versados_data;
161 struct netbsd_core_struct *netbsd_core_data;
162 struct mach_o_data_struct *mach_o_data;
163 struct mach_o_fat_data_struct *mach_o_fat_data;
164 struct bfd_pef_data_struct *pef_data;
165 struct bfd_pef_xlib_data_struct *pef_xlib_data;
166 struct bfd_sym_data_struct *sym_data;
171 /* Used by the application to hold private data. */
174 /* Where all the allocated stuff under this BFD goes. This is a
175 struct objalloc *, but we use void * to avoid requiring the inclusion
181 @section Error reporting
182 Most BFD functions return nonzero on success (check their
183 individual documentation for precise semantics). On an error,
184 they call @code{bfd_set_error} to set an error condition that callers
185 can check by calling @code{bfd_get_error}.
186 If that returns @code{bfd_error_system_call}, then check
189 The easiest way to report a BFD error to the user is to
190 use @code{bfd_perror}.
192 @subsection Type @code{bfd_error_type}
193 The values returned by @code{bfd_get_error} are defined by the
194 enumerated type @code{bfd_error_type}.
199 typedef enum bfd_error
201 bfd_error_no_error = 0,
202 bfd_error_system_call,
203 bfd_error_invalid_target,
204 bfd_error_wrong_format,
205 bfd_error_wrong_object_format,
206 bfd_error_invalid_operation,
208 bfd_error_no_symbols,
210 bfd_error_no_more_archived_files,
211 bfd_error_malformed_archive,
212 bfd_error_file_not_recognized,
213 bfd_error_file_ambiguously_recognized,
214 bfd_error_no_contents,
215 bfd_error_nonrepresentable_section,
216 bfd_error_no_debug_section,
218 bfd_error_file_truncated,
219 bfd_error_file_too_big,
220 bfd_error_invalid_error_code
225 @findex bfd_get_error
226 @subsubsection @code{bfd_get_error}
229 bfd_error_type bfd_get_error (void);
231 @strong{Description}@*
232 Return the current BFD error condition.
234 @findex bfd_set_error
235 @subsubsection @code{bfd_set_error}
238 void bfd_set_error (bfd_error_type error_tag);
240 @strong{Description}@*
241 Set the BFD error condition to be @var{error_tag}.
244 @subsubsection @code{bfd_errmsg}
247 const char *bfd_errmsg (bfd_error_type error_tag);
249 @strong{Description}@*
250 Return a string describing the error @var{error_tag}, or
251 the system error if @var{error_tag} is @code{bfd_error_system_call}.
254 @subsubsection @code{bfd_perror}
257 void bfd_perror (const char *message);
259 @strong{Description}@*
260 Print to the standard error stream a string describing the
261 last BFD error that occurred, or the last system error if
262 the last BFD error was a system call failure. If @var{message}
263 is non-NULL and non-empty, the error string printed is preceded
264 by @var{message}, a colon, and a space. It is followed by a newline.
266 @subsection BFD error handler
267 Some BFD functions want to print messages describing the
268 problem. They call a BFD error handler function. This
269 function may be overridden by the program.
271 The BFD error handler acts like printf.
276 typedef void (*bfd_error_handler_type) (const char *, ...);
279 @findex bfd_set_error_handler
280 @subsubsection @code{bfd_set_error_handler}
283 bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
285 @strong{Description}@*
286 Set the BFD error handler function. Returns the previous
289 @findex bfd_set_error_program_name
290 @subsubsection @code{bfd_set_error_program_name}
293 void bfd_set_error_program_name (const char *);
295 @strong{Description}@*
296 Set the program name to use when printing a BFD error. This
297 is printed before the error message followed by a colon and
298 space. The string must not be changed after it is passed to
301 @findex bfd_get_error_handler
302 @subsubsection @code{bfd_get_error_handler}
305 bfd_error_handler_type bfd_get_error_handler (void);
307 @strong{Description}@*
308 Return the BFD error handler function.
310 @findex bfd_archive_filename
311 @subsubsection @code{bfd_archive_filename}
314 const char *bfd_archive_filename (bfd *);
316 @strong{Description}@*
317 For a BFD that is a component of an archive, returns a string
318 with both the archive name and file name. For other BFDs, just
319 returns the file name.
324 @findex bfd_get_reloc_upper_bound
325 @subsubsection @code{bfd_get_reloc_upper_bound}
328 long bfd_get_reloc_upper_bound (bfd *abfd, asection *sect);
330 @strong{Description}@*
331 Return the number of bytes required to store the
332 relocation information associated with section @var{sect}
333 attached to bfd @var{abfd}. If an error occurs, return -1.
335 @findex bfd_canonicalize_reloc
336 @subsubsection @code{bfd_canonicalize_reloc}
339 long bfd_canonicalize_reloc
340 (bfd *abfd, asection *sec, arelent **loc, asymbol **syms);
342 @strong{Description}@*
343 Call the back end associated with the open BFD
344 @var{abfd} and translate the external form of the relocation
345 information attached to @var{sec} into the internal canonical
346 form. Place the table into memory at @var{loc}, which has
347 been preallocated, usually by a call to
348 @code{bfd_get_reloc_upper_bound}. Returns the number of relocs, or
351 The @var{syms} table is also needed for horrible internal magic
354 @findex bfd_set_reloc
355 @subsubsection @code{bfd_set_reloc}
359 (bfd *abfd, asection *sec, arelent **rel, unsigned int count);
361 @strong{Description}@*
362 Set the relocation pointer and count within
363 section @var{sec} to the values @var{rel} and @var{count}.
364 The argument @var{abfd} is ignored.
366 @findex bfd_set_file_flags
367 @subsubsection @code{bfd_set_file_flags}
370 bfd_boolean bfd_set_file_flags (bfd *abfd, flagword flags);
372 @strong{Description}@*
373 Set the flag word in the BFD @var{abfd} to the value @var{flags}.
379 @code{bfd_error_wrong_format} - The target bfd was not of object format.
381 @code{bfd_error_invalid_operation} - The target bfd was open for reading.
383 @code{bfd_error_invalid_operation} -
384 The flag word contained a bit which was not applicable to the
385 type of file. E.g., an attempt was made to set the @code{D_PAGED} bit
386 on a BFD format which does not support demand paging.
389 @findex bfd_get_arch_size
390 @subsubsection @code{bfd_get_arch_size}
393 int bfd_get_arch_size (bfd *abfd);
395 @strong{Description}@*
396 Returns the architecture address size, in bits, as determined
397 by the object file's format. For ELF, this information is
398 included in the header.
401 Returns the arch size in bits if known, @code{-1} otherwise.
403 @findex bfd_get_sign_extend_vma
404 @subsubsection @code{bfd_get_sign_extend_vma}
407 int bfd_get_sign_extend_vma (bfd *abfd);
409 @strong{Description}@*
410 Indicates if the target architecture "naturally" sign extends
411 an address. Some architectures implicitly sign extend address
412 values when they are converted to types larger than the size
413 of an address. For instance, bfd_get_start_address() will
414 return an address sign extended to fill a bfd_vma when this is
418 Returns @code{1} if the target architecture is known to sign
419 extend addresses, @code{0} if the target architecture is known to
420 not sign extend addresses, and @code{-1} otherwise.
422 @findex bfd_set_start_address
423 @subsubsection @code{bfd_set_start_address}
426 bfd_boolean bfd_set_start_address (bfd *abfd, bfd_vma vma);
428 @strong{Description}@*
429 Make @var{vma} the entry point of output BFD @var{abfd}.
432 Returns @code{TRUE} on success, @code{FALSE} otherwise.
434 @findex bfd_get_gp_size
435 @subsubsection @code{bfd_get_gp_size}
438 unsigned int bfd_get_gp_size (bfd *abfd);
440 @strong{Description}@*
441 Return the maximum size of objects to be optimized using the GP
442 register under MIPS ECOFF. This is typically set by the @code{-G}
443 argument to the compiler, assembler or linker.
445 @findex bfd_set_gp_size
446 @subsubsection @code{bfd_set_gp_size}
449 void bfd_set_gp_size (bfd *abfd, unsigned int i);
451 @strong{Description}@*
452 Set the maximum size of objects to be optimized using the GP
453 register under ECOFF or MIPS ELF. This is typically set by
454 the @code{-G} argument to the compiler, assembler or linker.
457 @subsubsection @code{bfd_scan_vma}
460 bfd_vma bfd_scan_vma (const char *string, const char **end, int base);
462 @strong{Description}@*
463 Convert, like @code{strtoul}, a numerical expression
464 @var{string} into a @code{bfd_vma} integer, and return that integer.
465 (Though without as many bells and whistles as @code{strtoul}.)
466 The expression is assumed to be unsigned (i.e., positive).
467 If given a @var{base}, it is used as the base for conversion.
468 A base of 0 causes the function to interpret the string
469 in hex if a leading "0x" or "0X" is found, otherwise
470 in octal if a leading zero is found, otherwise in decimal.
472 If the value would overflow, the maximum @code{bfd_vma} value is
475 @findex bfd_copy_private_bfd_data
476 @subsubsection @code{bfd_copy_private_bfd_data}
479 bfd_boolean bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd);
481 @strong{Description}@*
482 Copy private BFD information from the BFD @var{ibfd} to the
483 the BFD @var{obfd}. Return @code{TRUE} on success, @code{FALSE} on error.
484 Possible error returns are:
489 @code{bfd_error_no_memory} -
490 Not enough memory exists to create private data for @var{obfd}.
493 #define bfd_copy_private_bfd_data(ibfd, obfd) \
494 BFD_SEND (obfd, _bfd_copy_private_bfd_data, \
498 @findex bfd_merge_private_bfd_data
499 @subsubsection @code{bfd_merge_private_bfd_data}
502 bfd_boolean bfd_merge_private_bfd_data (bfd *ibfd, bfd *obfd);
504 @strong{Description}@*
505 Merge private BFD information from the BFD @var{ibfd} to the
506 the output file BFD @var{obfd} when linking. Return @code{TRUE}
507 on success, @code{FALSE} on error. Possible error returns are:
512 @code{bfd_error_no_memory} -
513 Not enough memory exists to create private data for @var{obfd}.
516 #define bfd_merge_private_bfd_data(ibfd, obfd) \
517 BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
521 @findex bfd_set_private_flags
522 @subsubsection @code{bfd_set_private_flags}
525 bfd_boolean bfd_set_private_flags (bfd *abfd, flagword flags);
527 @strong{Description}@*
528 Set private BFD flag information in the BFD @var{abfd}.
529 Return @code{TRUE} on success, @code{FALSE} on error. Possible error
535 @code{bfd_error_no_memory} -
536 Not enough memory exists to create private data for @var{obfd}.
539 #define bfd_set_private_flags(abfd, flags) \
540 BFD_SEND (abfd, _bfd_set_private_flags, (abfd, flags))
543 @findex Other functions
544 @subsubsection @code{Other functions}
545 @strong{Description}@*
546 The following functions exist but have not yet been documented.
548 #define bfd_sizeof_headers(abfd, reloc) \
549 BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
551 #define bfd_find_nearest_line(abfd, sec, syms, off, file, func, line) \
552 BFD_SEND (abfd, _bfd_find_nearest_line, \
553 (abfd, sec, syms, off, file, func, line))
555 #define bfd_debug_info_start(abfd) \
556 BFD_SEND (abfd, _bfd_debug_info_start, (abfd))
558 #define bfd_debug_info_end(abfd) \
559 BFD_SEND (abfd, _bfd_debug_info_end, (abfd))
561 #define bfd_debug_info_accumulate(abfd, section) \
562 BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
564 #define bfd_stat_arch_elt(abfd, stat) \
565 BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
567 #define bfd_update_armap_timestamp(abfd) \
568 BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))
570 #define bfd_set_arch_mach(abfd, arch, mach)\
571 BFD_SEND ( abfd, _bfd_set_arch_mach, (abfd, arch, mach))
573 #define bfd_relax_section(abfd, section, link_info, again) \
574 BFD_SEND (abfd, _bfd_relax_section, (abfd, section, link_info, again))
576 #define bfd_gc_sections(abfd, link_info) \
577 BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
579 #define bfd_merge_sections(abfd, link_info) \
580 BFD_SEND (abfd, _bfd_merge_sections, (abfd, link_info))
582 #define bfd_discard_group(abfd, sec) \
583 BFD_SEND (abfd, _bfd_discard_group, (abfd, sec))
585 #define bfd_link_hash_table_create(abfd) \
586 BFD_SEND (abfd, _bfd_link_hash_table_create, (abfd))
588 #define bfd_link_hash_table_free(abfd, hash) \
589 BFD_SEND (abfd, _bfd_link_hash_table_free, (hash))
591 #define bfd_link_add_symbols(abfd, info) \
592 BFD_SEND (abfd, _bfd_link_add_symbols, (abfd, info))
594 #define bfd_link_just_syms(sec, info) \
595 BFD_SEND (abfd, _bfd_link_just_syms, (sec, info))
597 #define bfd_final_link(abfd, info) \
598 BFD_SEND (abfd, _bfd_final_link, (abfd, info))
600 #define bfd_free_cached_info(abfd) \
601 BFD_SEND (abfd, _bfd_free_cached_info, (abfd))
603 #define bfd_get_dynamic_symtab_upper_bound(abfd) \
604 BFD_SEND (abfd, _bfd_get_dynamic_symtab_upper_bound, (abfd))
606 #define bfd_print_private_bfd_data(abfd, file)\
607 BFD_SEND (abfd, _bfd_print_private_bfd_data, (abfd, file))
609 #define bfd_canonicalize_dynamic_symtab(abfd, asymbols) \
610 BFD_SEND (abfd, _bfd_canonicalize_dynamic_symtab, (abfd, asymbols))
612 #define bfd_get_dynamic_reloc_upper_bound(abfd) \
613 BFD_SEND (abfd, _bfd_get_dynamic_reloc_upper_bound, (abfd))
615 #define bfd_canonicalize_dynamic_reloc(abfd, arels, asyms) \
616 BFD_SEND (abfd, _bfd_canonicalize_dynamic_reloc, (abfd, arels, asyms))
618 extern bfd_byte *bfd_get_relocated_section_contents
619 (bfd *, struct bfd_link_info *, struct bfd_link_order *, bfd_byte *,
620 bfd_boolean, asymbol **);
624 @findex bfd_alt_mach_code
625 @subsubsection @code{bfd_alt_mach_code}
628 bfd_boolean bfd_alt_mach_code (bfd *abfd, int alternative);
630 @strong{Description}@*
631 When more than one machine code number is available for the
632 same machine type, this function can be used to switch between
633 the preferred one (alternative == 0) and any others. Currently,
634 only ELF supports this feature, with up to two alternate
644 const struct bfd_arch_info *arch_info;
645 struct bfd_section *sections;
646 struct bfd_section **section_tail;
647 unsigned int section_count;
648 struct bfd_hash_table section_htab;
652 @findex bfd_preserve_save
653 @subsubsection @code{bfd_preserve_save}
656 bfd_boolean bfd_preserve_save (bfd *, struct bfd_preserve *);
658 @strong{Description}@*
659 When testing an object for compatibility with a particular
660 target back-end, the back-end object_p function needs to set
661 up certain fields in the bfd on successfully recognizing the
662 object. This typically happens in a piecemeal fashion, with
663 failures possible at many points. On failure, the bfd is
664 supposed to be restored to its initial state, which is
665 virtually impossible. However, restoring a subset of the bfd
666 state works in practice. This function stores the subset and
667 reinitializes the bfd.
669 @findex bfd_preserve_restore
670 @subsubsection @code{bfd_preserve_restore}
673 void bfd_preserve_restore (bfd *, struct bfd_preserve *);
675 @strong{Description}@*
676 This function restores bfd state saved by bfd_preserve_save.
677 If MARKER is non-NULL in struct bfd_preserve then that block
678 and all subsequently bfd_alloc'd memory is freed.
680 @findex bfd_preserve_finish
681 @subsubsection @code{bfd_preserve_finish}
684 void bfd_preserve_finish (bfd *, struct bfd_preserve *);
686 @strong{Description}@*
687 This function should be called when the bfd state saved by
688 bfd_preserve_save is no longer needed. ie. when the back-end
689 object_p function returns with success.