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.
14 /* The filename the application opened the BFD with. */
17 /* A pointer to the target jump table. */
18 const struct bfd_target *xvec;
20 /* To avoid dragging too many header files into every file that
21 includes `@code{bfd.h}', IOSTREAM has been declared as a "char
22 *", and MTIME as a "long". Their correct types, to which they
23 are cast when used, are "FILE *" and "time_t". The iostream
24 is the result of an fopen on the filename. However, if the
25 BFD_IN_MEMORY flag is set, then iostream is actually a pointer
26 to a bfd_in_memory struct. */
29 /* Is the file descriptor being cached? That is, can it be closed as
30 needed, and re-opened when accessed later? */
34 /* Marks whether there was a default target specified when the
35 BFD was opened. This is used to select which matching algorithm
36 to use to choose the back end. */
38 boolean target_defaulted;
40 /* The caching routines use these to maintain a
41 least-recently-used list of BFDs */
43 struct _bfd *lru_prev, *lru_next;
45 /* When a file is closed by the caching routines, BFD retains
46 state information on the file here: */
50 /* and here: (``once'' means at least once) */
54 /* Set if we have a locally maintained mtime value, rather than
55 getting it from the file each time: */
59 /* File modified time, if mtime_set is true: */
63 /* Reserved for an unimplemented file locking extension.*/
67 /* The format which belongs to the BFD. (object, core, etc.) */
71 /* The direction the BFD was opened with*/
73 enum bfd_direction @{no_direction = 0,
76 both_direction = 3@} direction;
78 /* Format_specific flags*/
82 /* Currently my_archive is tested before adding origin to
83 anything. I believe that this can become always an add of
84 origin, with origin set to 0 for non archive files. */
88 /* Remember when output has begun, to stop strange things
90 boolean output_has_begun;
92 /* Pointer to linked list of sections*/
95 /* The number of sections */
96 unsigned int section_count;
98 /* Stuff only useful for object files:
100 bfd_vma start_address;
102 /* Used for input and output*/
103 unsigned int symcount;
105 /* Symbol table for output BFD (with symcount entries) */
106 struct symbol_cache_entry **outsymbols;
108 /* Pointer to structure which contains architecture information*/
109 const struct bfd_arch_info *arch_info;
111 /* Stuff only useful for archives:*/
113 struct _bfd *my_archive; /* The containing archive BFD. */
114 struct _bfd *next; /* The next BFD in the archive. */
115 struct _bfd *archive_head; /* The first BFD in the archive. */
118 /* A chain of BFD structures involved in a link. */
119 struct _bfd *link_next;
121 /* A field used by _bfd_generic_link_add_archive_symbols. This will
122 be used only for archive elements. */
125 /* Used by the back end to hold private data. */
129 struct aout_data_struct *aout_data;
130 struct artdata *aout_ar_data;
131 struct _oasys_data *oasys_obj_data;
132 struct _oasys_ar_data *oasys_ar_data;
133 struct coff_tdata *coff_obj_data;
134 struct pe_tdata *pe_obj_data;
135 struct xcoff_tdata *xcoff_obj_data;
136 struct ecoff_tdata *ecoff_obj_data;
137 struct ieee_data_struct *ieee_data;
138 struct ieee_ar_data_struct *ieee_ar_data;
139 struct srec_data_struct *srec_data;
140 struct ihex_data_struct *ihex_data;
141 struct tekhex_data_struct *tekhex_data;
142 struct elf_obj_tdata *elf_obj_data;
143 struct nlm_obj_tdata *nlm_obj_data;
144 struct bout_data_struct *bout_data;
145 struct sun_core_struct *sun_core_data;
146 struct trad_core_struct *trad_core_data;
147 struct som_data_struct *som_data;
148 struct hpux_core_struct *hpux_core_data;
149 struct hppabsd_core_struct *hppabsd_core_data;
150 struct sgi_core_struct *sgi_core_data;
151 struct lynx_core_struct *lynx_core_data;
152 struct osf_core_struct *osf_core_data;
153 struct cisco_core_struct *cisco_core_data;
154 struct versados_data_struct *versados_data;
155 struct netbsd_core_struct *netbsd_core_data;
159 /* Used by the application to hold private data*/
162 /* Where all the allocated stuff under this BFD goes. This is a
163 struct objalloc *, but we use PTR to avoid requiring the inclusion of
169 @section Error reporting
170 Most BFD functions return nonzero on success (check their
171 individual documentation for precise semantics). On an error,
172 they call @code{bfd_set_error} to set an error condition that callers
173 can check by calling @code{bfd_get_error}.
174 If that returns @code{bfd_error_system_call}, then check
177 The easiest way to report a BFD error to the user is to
178 use @code{bfd_perror}.
180 @subsection Type @code{bfd_error_type}
181 The values returned by @code{bfd_get_error} are defined by the
182 enumerated type @code{bfd_error_type}.
186 typedef enum bfd_error
188 bfd_error_no_error = 0,
189 bfd_error_system_call,
190 bfd_error_invalid_target,
191 bfd_error_wrong_format,
192 bfd_error_invalid_operation,
194 bfd_error_no_symbols,
196 bfd_error_no_more_archived_files,
197 bfd_error_malformed_archive,
198 bfd_error_file_not_recognized,
199 bfd_error_file_ambiguously_recognized,
200 bfd_error_no_contents,
201 bfd_error_nonrepresentable_section,
202 bfd_error_no_debug_section,
204 bfd_error_file_truncated,
205 bfd_error_file_too_big,
206 bfd_error_invalid_error_code
210 @findex bfd_get_error
211 @subsubsection @code{bfd_get_error}
214 bfd_error_type bfd_get_error (void);
216 @strong{Description}@*
217 Return the current BFD error condition.
219 @findex bfd_set_error
220 @subsubsection @code{bfd_set_error}
223 void bfd_set_error (bfd_error_type error_tag);
225 @strong{Description}@*
226 Set the BFD error condition to be @var{error_tag}.
229 @subsubsection @code{bfd_errmsg}
232 CONST char *bfd_errmsg (bfd_error_type error_tag);
234 @strong{Description}@*
235 Return a string describing the error @var{error_tag}, or
236 the system error if @var{error_tag} is @code{bfd_error_system_call}.
239 @subsubsection @code{bfd_perror}
242 void bfd_perror (CONST char *message);
244 @strong{Description}@*
245 Print to the standard error stream a string describing the
246 last BFD error that occurred, or the last system error if
247 the last BFD error was a system call failure. If @var{message}
248 is non-NULL and non-empty, the error string printed is preceded
249 by @var{message}, a colon, and a space. It is followed by a newline.
251 @subsection BFD error handler
252 Some BFD functions want to print messages describing the
253 problem. They call a BFD error handler function. This
254 function may be overriden by the program.
256 The BFD error handler acts like printf.
260 typedef void (*bfd_error_handler_type) PARAMS ((const char *, ...));
263 @findex bfd_set_error_handler
264 @subsubsection @code{bfd_set_error_handler}
267 bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
269 @strong{Description}@*
270 Set the BFD error handler function. Returns the previous
273 @findex bfd_set_error_program_name
274 @subsubsection @code{bfd_set_error_program_name}
277 void bfd_set_error_program_name (const char *);
279 @strong{Description}@*
280 Set the program name to use when printing a BFD error. This
281 is printed before the error message followed by a colon and
282 space. The string must not be changed after it is passed to
288 @findex bfd_get_reloc_upper_bound
289 @subsubsection @code{bfd_get_reloc_upper_bound}
292 long bfd_get_reloc_upper_bound(bfd *abfd, asection *sect);
294 @strong{Description}@*
295 Return the number of bytes required to store the
296 relocation information associated with section @var{sect}
297 attached to bfd @var{abfd}. If an error occurs, return -1.
299 @findex bfd_canonicalize_reloc
300 @subsubsection @code{bfd_canonicalize_reloc}
303 long bfd_canonicalize_reloc
309 @strong{Description}@*
310 Call the back end associated with the open BFD
311 @var{abfd} and translate the external form of the relocation
312 information attached to @var{sec} into the internal canonical
313 form. Place the table into memory at @var{loc}, which has
314 been preallocated, usually by a call to
315 @code{bfd_get_reloc_upper_bound}. Returns the number of relocs, or
318 The @var{syms} table is also needed for horrible internal magic
321 @findex bfd_set_reloc
322 @subsubsection @code{bfd_set_reloc}
326 (bfd *abfd, asection *sec, arelent **rel, unsigned int count)
328 @strong{Description}@*
329 Set the relocation pointer and count within
330 section @var{sec} to the values @var{rel} and @var{count}.
331 The argument @var{abfd} is ignored.
333 @findex bfd_set_file_flags
334 @subsubsection @code{bfd_set_file_flags}
337 boolean bfd_set_file_flags(bfd *abfd, flagword flags);
339 @strong{Description}@*
340 Set the flag word in the BFD @var{abfd} to the value @var{flags}.
346 @code{bfd_error_wrong_format} - The target bfd was not of object format.
348 @code{bfd_error_invalid_operation} - The target bfd was open for reading.
350 @code{bfd_error_invalid_operation} -
351 The flag word contained a bit which was not applicable to the
352 type of file. E.g., an attempt was made to set the @code{D_PAGED} bit
353 on a BFD format which does not support demand paging.
356 @findex bfd_set_start_address
357 @subsubsection @code{bfd_set_start_address}
360 boolean bfd_set_start_address(bfd *abfd, bfd_vma vma);
362 @strong{Description}@*
363 Make @var{vma} the entry point of output BFD @var{abfd}.
366 Returns @code{true} on success, @code{false} otherwise.
368 @findex bfd_get_mtime
369 @subsubsection @code{bfd_get_mtime}
372 long bfd_get_mtime(bfd *abfd);
374 @strong{Description}@*
375 Return the file modification time (as read from the file system, or
376 from the archive header for archive members).
379 @subsubsection @code{bfd_get_size}
382 long bfd_get_size(bfd *abfd);
384 @strong{Description}@*
385 Return the file size (as read from file system) for the file
386 associated with BFD @var{abfd}.
388 The initial motivation for, and use of, this routine is not
389 so we can get the exact size of the object the BFD applies to, since
390 that might not be generally possible (archive members for example).
391 It would be ideal if someone could eventually modify
392 it so that such results were guaranteed.
394 Instead, we want to ask questions like "is this NNN byte sized
395 object I'm about to try read from file offset YYY reasonable?"
396 As as example of where we might do this, some object formats
397 use string tables for which the first @code{sizeof(long)} bytes of the
398 table contain the size of the table itself, including the size bytes.
399 If an application tries to read what it thinks is one of these
400 string tables, without some way to validate the size, and for
401 some reason the size is wrong (byte swapping error, wrong location
402 for the string table, etc.), the only clue is likely to be a read
403 error when it tries to read the table, or a "virtual memory
404 exhausted" error when it tries to allocate 15 bazillon bytes
405 of space for the 15 bazillon byte table it is about to read.
406 This function at least allows us to answer the quesion, "is the
409 @findex bfd_get_gp_size
410 @subsubsection @code{bfd_get_gp_size}
413 int bfd_get_gp_size(bfd *abfd);
415 @strong{Description}@*
416 Return the maximum size of objects to be optimized using the GP
417 register under MIPS ECOFF. This is typically set by the @code{-G}
418 argument to the compiler, assembler or linker.
420 @findex bfd_set_gp_size
421 @subsubsection @code{bfd_set_gp_size}
424 void bfd_set_gp_size(bfd *abfd, int i);
426 @strong{Description}@*
427 Set the maximum size of objects to be optimized using the GP
428 register under ECOFF or MIPS ELF. This is typically set by
429 the @code{-G} argument to the compiler, assembler or linker.
432 @subsubsection @code{bfd_scan_vma}
435 bfd_vma bfd_scan_vma(CONST char *string, CONST char **end, int base);
437 @strong{Description}@*
438 Convert, like @code{strtoul}, a numerical expression
439 @var{string} into a @code{bfd_vma} integer, and return that integer.
440 (Though without as many bells and whistles as @code{strtoul}.)
441 The expression is assumed to be unsigned (i.e., positive).
442 If given a @var{base}, it is used as the base for conversion.
443 A base of 0 causes the function to interpret the string
444 in hex if a leading "0x" or "0X" is found, otherwise
445 in octal if a leading zero is found, otherwise in decimal.
447 Overflow is not detected.
449 @findex bfd_copy_private_bfd_data
450 @subsubsection @code{bfd_copy_private_bfd_data}
453 boolean bfd_copy_private_bfd_data(bfd *ibfd, bfd *obfd);
455 @strong{Description}@*
456 Copy private BFD information from the BFD @var{ibfd} to the
457 the BFD @var{obfd}. Return @code{true} on success, @code{false} on error.
458 Possible error returns are:
463 @code{bfd_error_no_memory} -
464 Not enough memory exists to create private data for @var{obfd}.
467 #define bfd_copy_private_bfd_data(ibfd, obfd) \
468 BFD_SEND (obfd, _bfd_copy_private_bfd_data, \
472 @findex bfd_merge_private_bfd_data
473 @subsubsection @code{bfd_merge_private_bfd_data}
476 boolean bfd_merge_private_bfd_data(bfd *ibfd, bfd *obfd);
478 @strong{Description}@*
479 Merge private BFD information from the BFD @var{ibfd} to the
480 the output file BFD @var{obfd} when linking. Return @code{true}
481 on success, @code{false} on error. Possible error returns are:
486 @code{bfd_error_no_memory} -
487 Not enough memory exists to create private data for @var{obfd}.
490 #define bfd_merge_private_bfd_data(ibfd, obfd) \
491 BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
495 @findex bfd_set_private_flags
496 @subsubsection @code{bfd_set_private_flags}
499 boolean bfd_set_private_flags(bfd *abfd, flagword flags);
501 @strong{Description}@*
502 Set private BFD flag information in the BFD @var{abfd}.
503 Return @code{true} on success, @code{false} on error. Possible error
509 @code{bfd_error_no_memory} -
510 Not enough memory exists to create private data for @var{obfd}.
513 #define bfd_set_private_flags(abfd, flags) \
514 BFD_SEND (abfd, _bfd_set_private_flags, \
519 @subsubsection @code{stuff}
520 @strong{Description}@*
521 Stuff which should be documented:
523 #define bfd_sizeof_headers(abfd, reloc) \
524 BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
526 #define bfd_find_nearest_line(abfd, sec, syms, off, file, func, line) \
527 BFD_SEND (abfd, _bfd_find_nearest_line, (abfd, sec, syms, off, file, func, line))
529 /* Do these three do anything useful at all, for any back end? */
530 #define bfd_debug_info_start(abfd) \
531 BFD_SEND (abfd, _bfd_debug_info_start, (abfd))
533 #define bfd_debug_info_end(abfd) \
534 BFD_SEND (abfd, _bfd_debug_info_end, (abfd))
536 #define bfd_debug_info_accumulate(abfd, section) \
537 BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
540 #define bfd_stat_arch_elt(abfd, stat) \
541 BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
543 #define bfd_update_armap_timestamp(abfd) \
544 BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))
546 #define bfd_set_arch_mach(abfd, arch, mach)\
547 BFD_SEND ( abfd, _bfd_set_arch_mach, (abfd, arch, mach))
549 #define bfd_relax_section(abfd, section, link_info, again) \
550 BFD_SEND (abfd, _bfd_relax_section, (abfd, section, link_info, again))
552 #define bfd_link_hash_table_create(abfd) \
553 BFD_SEND (abfd, _bfd_link_hash_table_create, (abfd))
555 #define bfd_link_add_symbols(abfd, info) \
556 BFD_SEND (abfd, _bfd_link_add_symbols, (abfd, info))
558 #define bfd_final_link(abfd, info) \
559 BFD_SEND (abfd, _bfd_final_link, (abfd, info))
561 #define bfd_free_cached_info(abfd) \
562 BFD_SEND (abfd, _bfd_free_cached_info, (abfd))
564 #define bfd_get_dynamic_symtab_upper_bound(abfd) \
565 BFD_SEND (abfd, _bfd_get_dynamic_symtab_upper_bound, (abfd))
567 #define bfd_print_private_bfd_data(abfd, file)\
568 BFD_SEND (abfd, _bfd_print_private_bfd_data, (abfd, file))
570 #define bfd_canonicalize_dynamic_symtab(abfd, asymbols) \
571 BFD_SEND (abfd, _bfd_canonicalize_dynamic_symtab, (abfd, asymbols))
573 #define bfd_get_dynamic_reloc_upper_bound(abfd) \
574 BFD_SEND (abfd, _bfd_get_dynamic_reloc_upper_bound, (abfd))
576 #define bfd_canonicalize_dynamic_reloc(abfd, arels, asyms) \
577 BFD_SEND (abfd, _bfd_canonicalize_dynamic_reloc, (abfd, arels, asyms))
579 extern bfd_byte *bfd_get_relocated_section_contents
580 PARAMS ((bfd *, struct bfd_link_info *,
581 struct bfd_link_order *, bfd_byte *,
582 boolean, asymbol **));