]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/binutils/bfd/doc/bfdt.texi
This commit was generated by cvs2svn to compensate for changes in r48743,
[FreeBSD/FreeBSD.git] / contrib / binutils / bfd / doc / bfdt.texi
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.
5
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.
9
10
11 @example
12
13 struct _bfd 
14 @{
15     /* The filename the application opened the BFD with.  */
16     CONST char *filename;                
17
18     /* A pointer to the target jump table.             */
19     const struct bfd_target *xvec;
20
21     /* To avoid dragging too many header files into every file that
22        includes `@code{bfd.h}', IOSTREAM has been declared as a "char
23        *", and MTIME as a "long".  Their correct types, to which they
24        are cast when used, are "FILE *" and "time_t".    The iostream
25        is the result of an fopen on the filename.  However, if the
26        BFD_IN_MEMORY flag is set, then iostream is actually a pointer
27        to a bfd_in_memory struct.  */
28     PTR iostream;
29
30     /* Is the file descriptor being cached?  That is, can it be closed as
31        needed, and re-opened when accessed later?  */
32
33     boolean cacheable;
34
35     /* Marks whether there was a default target specified when the
36        BFD was opened. This is used to select which matching algorithm
37        to use to choose the back end. */
38
39     boolean target_defaulted;
40
41     /* The caching routines use these to maintain a
42        least-recently-used list of BFDs */
43
44     struct _bfd *lru_prev, *lru_next;
45
46     /* When a file is closed by the caching routines, BFD retains
47        state information on the file here: */
48
49     file_ptr where;              
50
51     /* and here: (``once'' means at least once) */
52
53     boolean opened_once;
54
55     /* Set if we have a locally maintained mtime value, rather than
56        getting it from the file each time: */
57
58     boolean mtime_set;
59
60     /* File modified time, if mtime_set is true: */
61
62     long mtime;          
63
64     /* Reserved for an unimplemented file locking extension.*/
65
66     int ifd;
67
68     /* The format which belongs to the BFD. (object, core, etc.) */
69
70     bfd_format format;
71
72     /* The direction the BFD was opened with*/
73
74     enum bfd_direction @{no_direction = 0,
75                         read_direction = 1,
76                         write_direction = 2,
77                         both_direction = 3@} direction;
78
79     /* Format_specific flags*/
80
81     flagword flags;              
82
83     /* Currently my_archive is tested before adding origin to
84        anything. I believe that this can become always an add of
85        origin, with origin set to 0 for non archive files.   */
86
87     file_ptr origin;             
88
89     /* Remember when output has begun, to stop strange things
90        from happening. */
91     boolean output_has_begun;
92
93     /* Pointer to linked list of sections*/
94     struct sec  *sections;
95
96     /* The number of sections */
97     unsigned int section_count;
98
99     /* Stuff only useful for object files: 
100        The start address. */
101     bfd_vma start_address;
102
103     /* Used for input and output*/
104     unsigned int symcount;
105
106     /* Symbol table for output BFD (with symcount entries) */
107     struct symbol_cache_entry  **outsymbols;             
108
109     /* Pointer to structure which contains architecture information*/
110     const struct bfd_arch_info *arch_info;
111
112     /* Stuff only useful for archives:*/
113     PTR arelt_data;              
114     struct _bfd *my_archive;     /* The containing archive BFD.  */
115     struct _bfd *next;           /* The next BFD in the archive.  */
116     struct _bfd *archive_head;   /* The first BFD in the archive.  */
117     boolean has_armap;           
118
119     /* A chain of BFD structures involved in a link.  */
120     struct _bfd *link_next;
121
122     /* A field used by _bfd_generic_link_add_archive_symbols.  This will
123        be used only for archive elements.  */
124     int archive_pass;
125
126     /* Used by the back end to hold private data. */
127
128     union 
129       @{
130       struct aout_data_struct *aout_data;
131       struct artdata *aout_ar_data;
132       struct _oasys_data *oasys_obj_data;
133       struct _oasys_ar_data *oasys_ar_data;
134       struct coff_tdata *coff_obj_data;
135       struct pe_tdata *pe_obj_data;
136       struct xcoff_tdata *xcoff_obj_data;
137       struct ecoff_tdata *ecoff_obj_data;
138       struct ieee_data_struct *ieee_data;
139       struct ieee_ar_data_struct *ieee_ar_data;
140       struct srec_data_struct *srec_data;
141       struct ihex_data_struct *ihex_data;
142       struct tekhex_data_struct *tekhex_data;
143       struct elf_obj_tdata *elf_obj_data;
144       struct nlm_obj_tdata *nlm_obj_data;
145       struct bout_data_struct *bout_data;
146       struct sun_core_struct *sun_core_data;
147       struct trad_core_struct *trad_core_data;
148       struct som_data_struct *som_data;
149       struct hpux_core_struct *hpux_core_data;
150       struct hppabsd_core_struct *hppabsd_core_data;
151       struct sgi_core_struct *sgi_core_data;
152       struct lynx_core_struct *lynx_core_data;
153       struct osf_core_struct *osf_core_data;
154       struct cisco_core_struct *cisco_core_data;
155       struct versados_data_struct *versados_data;
156       struct netbsd_core_struct *netbsd_core_data;
157       PTR any;
158       @} tdata;
159   
160     /* Used by the application to hold private data*/
161     PTR usrdata;
162
163   /* Where all the allocated stuff under this BFD goes.  This is a
164      struct objalloc *, but we use PTR to avoid requiring the inclusion of
165      objalloc.h.  */
166     PTR memory;
167 @};
168
169 @end example
170 @section Error reporting
171 Most BFD functions return nonzero on success (check their
172 individual documentation for precise semantics).  On an error,
173 they call @code{bfd_set_error} to set an error condition that callers
174 can check by calling @code{bfd_get_error}.
175 If that returns @code{bfd_error_system_call}, then check
176 @code{errno}.
177
178 The easiest way to report a BFD error to the user is to
179 use @code{bfd_perror}.
180
181 @subsection Type @code{bfd_error_type}
182 The values returned by @code{bfd_get_error} are defined by the
183 enumerated type @code{bfd_error_type}.
184
185
186 @example
187
188 typedef enum bfd_error
189 @{
190   bfd_error_no_error = 0,
191   bfd_error_system_call,
192   bfd_error_invalid_target,
193   bfd_error_wrong_format,
194   bfd_error_invalid_operation,
195   bfd_error_no_memory,
196   bfd_error_no_symbols,
197   bfd_error_no_armap,
198   bfd_error_no_more_archived_files,
199   bfd_error_malformed_archive,
200   bfd_error_file_not_recognized,
201   bfd_error_file_ambiguously_recognized,
202   bfd_error_no_contents,
203   bfd_error_nonrepresentable_section,
204   bfd_error_no_debug_section,
205   bfd_error_bad_value,
206   bfd_error_file_truncated,
207   bfd_error_file_too_big,
208   bfd_error_invalid_error_code
209 @} bfd_error_type;
210
211 @end example
212 @findex bfd_get_error
213 @subsubsection @code{bfd_get_error}
214 @strong{Synopsis}
215 @example
216 bfd_error_type bfd_get_error (void);
217 @end example
218 @strong{Description}@*
219 Return the current BFD error condition.
220
221 @findex bfd_set_error
222 @subsubsection @code{bfd_set_error}
223 @strong{Synopsis}
224 @example
225 void bfd_set_error (bfd_error_type error_tag);
226 @end example
227 @strong{Description}@*
228 Set the BFD error condition to be @var{error_tag}.
229
230 @findex bfd_errmsg
231 @subsubsection @code{bfd_errmsg}
232 @strong{Synopsis}
233 @example
234 CONST char *bfd_errmsg (bfd_error_type error_tag);
235 @end example
236 @strong{Description}@*
237 Return a string describing the error @var{error_tag}, or
238 the system error if @var{error_tag} is @code{bfd_error_system_call}.
239
240 @findex bfd_perror
241 @subsubsection @code{bfd_perror}
242 @strong{Synopsis}
243 @example
244 void bfd_perror (CONST char *message);
245 @end example
246 @strong{Description}@*
247 Print to the standard error stream a string describing the
248 last BFD error that occurred, or the last system error if
249 the last BFD error was a system call failure.  If @var{message}
250 is non-NULL and non-empty, the error string printed is preceded
251 by @var{message}, a colon, and a space.  It is followed by a newline.
252
253 @subsection BFD error handler
254 Some BFD functions want to print messages describing the
255 problem.  They call a BFD error handler function.  This
256 function may be overriden by the program.
257
258 The BFD error handler acts like printf.
259
260
261 @example
262
263 typedef void (*bfd_error_handler_type) PARAMS ((const char *, ...));
264
265 @end example
266 @findex bfd_set_error_handler
267 @subsubsection @code{bfd_set_error_handler}
268 @strong{Synopsis}
269 @example
270 bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
271 @end example
272 @strong{Description}@*
273 Set the BFD error handler function.  Returns the previous
274 function.
275
276 @findex bfd_set_error_program_name
277 @subsubsection @code{bfd_set_error_program_name}
278 @strong{Synopsis}
279 @example
280 void bfd_set_error_program_name (const char *);
281 @end example
282 @strong{Description}@*
283 Set the program name to use when printing a BFD error.  This
284 is printed before the error message followed by a colon and
285 space.  The string must not be changed after it is passed to
286 this function.
287
288 @findex bfd_get_error_handler
289 @subsubsection @code{bfd_get_error_handler}
290 @strong{Synopsis}
291 @example
292 bfd_error_handler_type bfd_get_error_handler (void);
293 @end example
294 @strong{Description}@*
295 Return the BFD error handler function.
296
297 @section Symbols
298
299
300 @findex bfd_get_reloc_upper_bound
301 @subsubsection @code{bfd_get_reloc_upper_bound}
302 @strong{Synopsis}
303 @example
304 long bfd_get_reloc_upper_bound(bfd *abfd, asection *sect);
305 @end example
306 @strong{Description}@*
307 Return the number of bytes required to store the
308 relocation information associated with section @var{sect}
309 attached to bfd @var{abfd}.  If an error occurs, return -1.
310
311 @findex bfd_canonicalize_reloc
312 @subsubsection @code{bfd_canonicalize_reloc}
313 @strong{Synopsis}
314 @example
315 long bfd_canonicalize_reloc
316    (bfd *abfd,
317     asection *sec,
318     arelent **loc,
319     asymbol **syms);
320 @end example
321 @strong{Description}@*
322 Call the back end associated with the open BFD
323 @var{abfd} and translate the external form of the relocation
324 information attached to @var{sec} into the internal canonical
325 form.  Place the table into memory at @var{loc}, which has
326 been preallocated, usually by a call to
327 @code{bfd_get_reloc_upper_bound}.  Returns the number of relocs, or
328 -1 on error.
329
330 The @var{syms} table is also needed for horrible internal magic
331 reasons.
332
333 @findex bfd_set_reloc
334 @subsubsection @code{bfd_set_reloc}
335 @strong{Synopsis}
336 @example
337 void bfd_set_reloc
338    (bfd *abfd, asection *sec, arelent **rel, unsigned int count)
339 @end example
340 @strong{Description}@*
341 Set the relocation pointer and count within
342 section @var{sec} to the values @var{rel} and @var{count}.
343 The argument @var{abfd} is ignored.
344
345 @findex bfd_set_file_flags
346 @subsubsection @code{bfd_set_file_flags}
347 @strong{Synopsis}
348 @example
349 boolean bfd_set_file_flags(bfd *abfd, flagword flags);
350 @end example
351 @strong{Description}@*
352 Set the flag word in the BFD @var{abfd} to the value @var{flags}.
353
354 Possible errors are:
355 @itemize @bullet
356
357 @item
358 @code{bfd_error_wrong_format} - The target bfd was not of object format.
359 @item
360 @code{bfd_error_invalid_operation} - The target bfd was open for reading.
361 @item
362 @code{bfd_error_invalid_operation} -
363 The flag word contained a bit which was not applicable to the
364 type of file.  E.g., an attempt was made to set the @code{D_PAGED} bit
365 on a BFD format which does not support demand paging.
366 @end itemize
367
368 @findex bfd_set_start_address
369 @subsubsection @code{bfd_set_start_address}
370 @strong{Synopsis}
371 @example
372 boolean bfd_set_start_address(bfd *abfd, bfd_vma vma);
373 @end example
374 @strong{Description}@*
375 Make @var{vma} the entry point of output BFD @var{abfd}.
376
377 @strong{Returns}@*
378 Returns @code{true} on success, @code{false} otherwise.
379
380 @findex bfd_get_mtime
381 @subsubsection @code{bfd_get_mtime}
382 @strong{Synopsis}
383 @example
384 long bfd_get_mtime(bfd *abfd);
385 @end example
386 @strong{Description}@*
387 Return the file modification time (as read from the file system, or
388 from the archive header for archive members).
389
390 @findex bfd_get_size
391 @subsubsection @code{bfd_get_size}
392 @strong{Synopsis}
393 @example
394 long bfd_get_size(bfd *abfd);
395 @end example
396 @strong{Description}@*
397 Return the file size (as read from file system) for the file
398 associated with BFD @var{abfd}.
399
400 The initial motivation for, and use of, this routine is not
401 so we can get the exact size of the object the BFD applies to, since
402 that might not be generally possible (archive members for example).
403 It would be ideal if someone could eventually modify
404 it so that such results were guaranteed.
405
406 Instead, we want to ask questions like "is this NNN byte sized
407 object I'm about to try read from file offset YYY reasonable?"
408 As as example of where we might do this, some object formats
409 use string tables for which the first @code{sizeof(long)} bytes of the
410 table contain the size of the table itself, including the size bytes.
411 If an application tries to read what it thinks is one of these
412 string tables, without some way to validate the size, and for
413 some reason the size is wrong (byte swapping error, wrong location
414 for the string table, etc.), the only clue is likely to be a read
415 error when it tries to read the table, or a "virtual memory
416 exhausted" error when it tries to allocate 15 bazillon bytes
417 of space for the 15 bazillon byte table it is about to read.
418 This function at least allows us to answer the quesion, "is the
419 size reasonable?".
420
421 @findex bfd_get_gp_size
422 @subsubsection @code{bfd_get_gp_size}
423 @strong{Synopsis}
424 @example
425 int bfd_get_gp_size(bfd *abfd);
426 @end example
427 @strong{Description}@*
428 Return the maximum size of objects to be optimized using the GP
429 register under MIPS ECOFF.  This is typically set by the @code{-G}
430 argument to the compiler, assembler or linker.
431
432 @findex bfd_set_gp_size
433 @subsubsection @code{bfd_set_gp_size}
434 @strong{Synopsis}
435 @example
436 void bfd_set_gp_size(bfd *abfd, int i);
437 @end example
438 @strong{Description}@*
439 Set the maximum size of objects to be optimized using the GP
440 register under ECOFF or MIPS ELF.  This is typically set by
441 the @code{-G} argument to the compiler, assembler or linker.
442
443 @findex bfd_scan_vma
444 @subsubsection @code{bfd_scan_vma}
445 @strong{Synopsis}
446 @example
447 bfd_vma bfd_scan_vma(CONST char *string, CONST char **end, int base);
448 @end example
449 @strong{Description}@*
450 Convert, like @code{strtoul}, a numerical expression
451 @var{string} into a @code{bfd_vma} integer, and return that integer.
452 (Though without as many bells and whistles as @code{strtoul}.)
453 The expression is assumed to be unsigned (i.e., positive).
454 If given a @var{base}, it is used as the base for conversion.
455 A base of 0 causes the function to interpret the string
456 in hex if a leading "0x" or "0X" is found, otherwise
457 in octal if a leading zero is found, otherwise in decimal.
458
459 Overflow is not detected.
460
461 @findex bfd_copy_private_bfd_data
462 @subsubsection @code{bfd_copy_private_bfd_data}
463 @strong{Synopsis}
464 @example
465 boolean bfd_copy_private_bfd_data(bfd *ibfd, bfd *obfd);
466 @end example
467 @strong{Description}@*
468 Copy private BFD information from the BFD @var{ibfd} to the 
469 the BFD @var{obfd}.  Return @code{true} on success, @code{false} on error.
470 Possible error returns are:
471
472 @itemize @bullet
473
474 @item
475 @code{bfd_error_no_memory} -
476 Not enough memory exists to create private data for @var{obfd}.
477 @end itemize
478 @example
479 #define bfd_copy_private_bfd_data(ibfd, obfd) \
480      BFD_SEND (obfd, _bfd_copy_private_bfd_data, \
481                (ibfd, obfd))
482 @end example
483
484 @findex bfd_merge_private_bfd_data
485 @subsubsection @code{bfd_merge_private_bfd_data}
486 @strong{Synopsis}
487 @example
488 boolean bfd_merge_private_bfd_data(bfd *ibfd, bfd *obfd);
489 @end example
490 @strong{Description}@*
491 Merge private BFD information from the BFD @var{ibfd} to the 
492 the output file BFD @var{obfd} when linking.  Return @code{true}
493 on success, @code{false} on error.  Possible error returns are:
494
495 @itemize @bullet
496
497 @item
498 @code{bfd_error_no_memory} -
499 Not enough memory exists to create private data for @var{obfd}.
500 @end itemize
501 @example
502 #define bfd_merge_private_bfd_data(ibfd, obfd) \
503      BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
504                (ibfd, obfd))
505 @end example
506
507 @findex bfd_set_private_flags
508 @subsubsection @code{bfd_set_private_flags}
509 @strong{Synopsis}
510 @example
511 boolean bfd_set_private_flags(bfd *abfd, flagword flags);
512 @end example
513 @strong{Description}@*
514 Set private BFD flag information in the BFD @var{abfd}.
515 Return @code{true} on success, @code{false} on error.  Possible error
516 returns are:
517
518 @itemize @bullet
519
520 @item
521 @code{bfd_error_no_memory} -
522 Not enough memory exists to create private data for @var{obfd}.
523 @end itemize
524 @example
525 #define bfd_set_private_flags(abfd, flags) \
526      BFD_SEND (abfd, _bfd_set_private_flags, \
527                (abfd, flags))
528 @end example
529
530 @findex stuff
531 @subsubsection @code{stuff}
532 @strong{Description}@*
533 Stuff which should be documented:
534 @example
535 #define bfd_sizeof_headers(abfd, reloc) \
536      BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
537
538 #define bfd_find_nearest_line(abfd, sec, syms, off, file, func, line) \
539      BFD_SEND (abfd, _bfd_find_nearest_line,  (abfd, sec, syms, off, file, func, line))
540
541         /* Do these three do anything useful at all, for any back end?  */
542 #define bfd_debug_info_start(abfd) \
543         BFD_SEND (abfd, _bfd_debug_info_start, (abfd))
544
545 #define bfd_debug_info_end(abfd) \
546         BFD_SEND (abfd, _bfd_debug_info_end, (abfd))
547
548 #define bfd_debug_info_accumulate(abfd, section) \
549         BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
550
551
552 #define bfd_stat_arch_elt(abfd, stat) \
553         BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
554
555 #define bfd_update_armap_timestamp(abfd) \
556         BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))
557
558 #define bfd_set_arch_mach(abfd, arch, mach)\
559         BFD_SEND ( abfd, _bfd_set_arch_mach, (abfd, arch, mach))
560
561 #define bfd_relax_section(abfd, section, link_info, again) \
562        BFD_SEND (abfd, _bfd_relax_section, (abfd, section, link_info, again))
563
564 #define bfd_link_hash_table_create(abfd) \
565        BFD_SEND (abfd, _bfd_link_hash_table_create, (abfd))
566
567 #define bfd_link_add_symbols(abfd, info) \
568        BFD_SEND (abfd, _bfd_link_add_symbols, (abfd, info))
569
570 #define bfd_final_link(abfd, info) \
571        BFD_SEND (abfd, _bfd_final_link, (abfd, info))
572
573 #define bfd_free_cached_info(abfd) \
574        BFD_SEND (abfd, _bfd_free_cached_info, (abfd))
575
576 #define bfd_get_dynamic_symtab_upper_bound(abfd) \
577        BFD_SEND (abfd, _bfd_get_dynamic_symtab_upper_bound, (abfd))
578
579 #define bfd_print_private_bfd_data(abfd, file)\
580        BFD_SEND (abfd, _bfd_print_private_bfd_data, (abfd, file))
581
582 #define bfd_canonicalize_dynamic_symtab(abfd, asymbols) \
583        BFD_SEND (abfd, _bfd_canonicalize_dynamic_symtab, (abfd, asymbols))
584
585 #define bfd_get_dynamic_reloc_upper_bound(abfd) \
586        BFD_SEND (abfd, _bfd_get_dynamic_reloc_upper_bound, (abfd))
587
588 #define bfd_canonicalize_dynamic_reloc(abfd, arels, asyms) \
589        BFD_SEND (abfd, _bfd_canonicalize_dynamic_reloc, (abfd, arels, asyms))
590
591 extern bfd_byte *bfd_get_relocated_section_contents
592        PARAMS ((bfd *, struct bfd_link_info *,
593                  struct bfd_link_order *, bfd_byte *,
594                  boolean, asymbol **));
595
596 @end example
597