]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - x/binutils/bfd/doc/bfd.texi
Flatten vendor/binutils/dist.
[FreeBSD/FreeBSD.git] / x / binutils / bfd / doc / bfd.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 struct _bfd 
13 @{
14     /* The filename the application opened the BFD with.  */
15     CONST char *filename;                
16
17     /* A pointer to the target jump table.             */
18     const struct bfd_target *xvec;
19
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.  */
27     PTR iostream;
28
29     /* Is the file descriptor being cached?  That is, can it be closed as
30        needed, and re-opened when accessed later?  */
31
32     boolean cacheable;
33
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. */
37
38     boolean target_defaulted;
39
40     /* The caching routines use these to maintain a
41        least-recently-used list of BFDs */
42
43     struct _bfd *lru_prev, *lru_next;
44
45     /* When a file is closed by the caching routines, BFD retains
46        state information on the file here: */
47
48     file_ptr where;              
49
50     /* and here: (``once'' means at least once) */
51
52     boolean opened_once;
53
54     /* Set if we have a locally maintained mtime value, rather than
55        getting it from the file each time: */
56
57     boolean mtime_set;
58
59     /* File modified time, if mtime_set is true: */
60
61     long mtime;          
62
63     /* Reserved for an unimplemented file locking extension.*/
64
65     int ifd;
66
67     /* The format which belongs to the BFD. (object, core, etc.) */
68
69     bfd_format format;
70
71     /* The direction the BFD was opened with*/
72
73     enum bfd_direction @{no_direction = 0,
74                         read_direction = 1,
75                         write_direction = 2,
76                         both_direction = 3@} direction;
77
78     /* Format_specific flags*/
79
80     flagword flags;              
81
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.   */
85
86     file_ptr origin;             
87
88     /* Remember when output has begun, to stop strange things
89        from happening. */
90     boolean output_has_begun;
91
92     /* Pointer to linked list of sections*/
93     struct sec  *sections;
94
95     /* The number of sections */
96     unsigned int section_count;
97
98     /* Stuff only useful for object files: 
99        The start address. */
100     bfd_vma start_address;
101
102     /* Used for input and output*/
103     unsigned int symcount;
104
105     /* Symbol table for output BFD (with symcount entries) */
106     struct symbol_cache_entry  **outsymbols;             
107
108     /* Pointer to structure which contains architecture information*/
109     const struct bfd_arch_info *arch_info;
110
111     /* Stuff only useful for archives:*/
112     PTR arelt_data;              
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.  */
116     boolean has_armap;           
117
118     /* A chain of BFD structures involved in a link.  */
119     struct _bfd *link_next;
120
121     /* A field used by _bfd_generic_link_add_archive_symbols.  This will
122        be used only for archive elements.  */
123     int archive_pass;
124
125     /* Used by the back end to hold private data. */
126
127     union 
128       @{
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;
156       PTR any;
157       @} tdata;
158   
159     /* Used by the application to hold private data*/
160     PTR usrdata;
161
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
164      objalloc.h.  */
165     PTR memory;
166 @};
167
168 @end example
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
175 @code{errno}.
176
177 The easiest way to report a BFD error to the user is to
178 use @code{bfd_perror}.
179 @*
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}.
183 @*
184 .
185 @example
186 typedef enum bfd_error
187 @{
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,
193   bfd_error_no_memory,
194   bfd_error_no_symbols,
195   bfd_error_no_armap,
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,
203   bfd_error_bad_value,
204   bfd_error_file_truncated,
205   bfd_error_file_too_big,
206   bfd_error_invalid_error_code
207 @} bfd_error_type;
208
209 @end example
210 @findex bfd_get_error
211 @subsubsection @code{bfd_get_error}
212 @strong{Synopsis}
213 @example
214 bfd_error_type bfd_get_error (void);
215 @end example
216 @strong{Description}@*
217 Return the current BFD error condition.
218 @*
219 @findex bfd_set_error
220 @subsubsection @code{bfd_set_error}
221 @strong{Synopsis}
222 @example
223 void bfd_set_error (bfd_error_type error_tag);
224 @end example
225 @strong{Description}@*
226 Set the BFD error condition to be @var{error_tag}.
227 @*
228 @findex bfd_errmsg
229 @subsubsection @code{bfd_errmsg}
230 @strong{Synopsis}
231 @example
232 CONST char *bfd_errmsg (bfd_error_type error_tag);
233 @end example
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}.
237 @*
238 @findex bfd_perror
239 @subsubsection @code{bfd_perror}
240 @strong{Synopsis}
241 @example
242 void bfd_perror (CONST char *message);
243 @end example
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.
250 @*
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.
255
256 The BFD error handler acts like printf.
257 @*
258 .
259 @example
260 typedef void (*bfd_error_handler_type) PARAMS ((const char *, ...));
261
262 @end example
263 @findex bfd_set_error_handler
264 @subsubsection @code{bfd_set_error_handler}
265 @strong{Synopsis}
266 @example
267 bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
268 @end example
269 @strong{Description}@*
270 Set the BFD error handler function.  Returns the previous
271 function.
272 @*
273 @findex bfd_set_error_program_name
274 @subsubsection @code{bfd_set_error_program_name}
275 @strong{Synopsis}
276 @example
277 void bfd_set_error_program_name (const char *);
278 @end example
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
283 this function.
284 @*
285 @section Symbols
286
287 @*
288 @findex bfd_get_reloc_upper_bound
289 @subsubsection @code{bfd_get_reloc_upper_bound}
290 @strong{Synopsis}
291 @example
292 long bfd_get_reloc_upper_bound(bfd *abfd, asection *sect);
293 @end example
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.
298 @*
299 @findex bfd_canonicalize_reloc
300 @subsubsection @code{bfd_canonicalize_reloc}
301 @strong{Synopsis}
302 @example
303 long bfd_canonicalize_reloc
304    (bfd *abfd,
305     asection *sec,
306     arelent **loc,
307     asymbol     **syms);
308 @end example
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
316 -1 on error.
317
318 The @var{syms} table is also needed for horrible internal magic
319 reasons.
320 @*
321 @findex bfd_set_reloc
322 @subsubsection @code{bfd_set_reloc}
323 @strong{Synopsis}
324 @example
325 void bfd_set_reloc
326    (bfd *abfd, asection *sec, arelent **rel, unsigned int count)
327 @end example
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.
332 @*
333 @findex bfd_set_file_flags
334 @subsubsection @code{bfd_set_file_flags}
335 @strong{Synopsis}
336 @example
337 boolean bfd_set_file_flags(bfd *abfd, flagword flags);
338 @end example
339 @strong{Description}@*
340 Set the flag word in the BFD @var{abfd} to the value @var{flags}.
341
342 Possible errors are:
343 @itemize @bullet
344
345 @item
346 @code{bfd_error_wrong_format} - The target bfd was not of object format.
347 @item
348 @code{bfd_error_invalid_operation} - The target bfd was open for reading.
349 @item
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.
354 @end itemize
355 @*
356 @findex bfd_set_start_address
357 @subsubsection @code{bfd_set_start_address}
358 @strong{Synopsis}
359 @example
360 boolean bfd_set_start_address(bfd *abfd, bfd_vma vma);
361 @end example
362 @strong{Description}@*
363 Make @var{vma} the entry point of output BFD @var{abfd}.
364 @*
365 @strong{Returns}@*
366 Returns @code{true} on success, @code{false} otherwise.
367 @*
368 @findex bfd_get_mtime
369 @subsubsection @code{bfd_get_mtime}
370 @strong{Synopsis}
371 @example
372 long bfd_get_mtime(bfd *abfd);
373 @end example
374 @strong{Description}@*
375 Return the file modification time (as read from the file system, or
376 from the archive header for archive members).
377 @*
378 @findex bfd_get_size
379 @subsubsection @code{bfd_get_size}
380 @strong{Synopsis}
381 @example
382 long bfd_get_size(bfd *abfd);
383 @end example
384 @strong{Description}@*
385 Return the file size (as read from file system) for the file
386 associated with BFD @var{abfd}.
387
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.
393
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
407 size reasonable?".
408 @*
409 @findex bfd_get_gp_size
410 @subsubsection @code{bfd_get_gp_size}
411 @strong{Synopsis}
412 @example
413 int bfd_get_gp_size(bfd *abfd);
414 @end example
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.
419 @*
420 @findex bfd_set_gp_size
421 @subsubsection @code{bfd_set_gp_size}
422 @strong{Synopsis}
423 @example
424 void bfd_set_gp_size(bfd *abfd, int i);
425 @end example
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.
430 @*
431 @findex bfd_scan_vma
432 @subsubsection @code{bfd_scan_vma}
433 @strong{Synopsis}
434 @example
435 bfd_vma bfd_scan_vma(CONST char *string, CONST char **end, int base);
436 @end example
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.
446
447 Overflow is not detected.
448 @*
449 @findex bfd_copy_private_bfd_data
450 @subsubsection @code{bfd_copy_private_bfd_data}
451 @strong{Synopsis}
452 @example
453 boolean bfd_copy_private_bfd_data(bfd *ibfd, bfd *obfd);
454 @end example
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:
459
460 @itemize @bullet
461
462 @item
463 @code{bfd_error_no_memory} -
464 Not enough memory exists to create private data for @var{obfd}.
465 @end itemize
466 @example
467 #define bfd_copy_private_bfd_data(ibfd, obfd) \
468      BFD_SEND (obfd, _bfd_copy_private_bfd_data, \
469                 (ibfd, obfd))
470 @end example
471 @*
472 @findex bfd_merge_private_bfd_data
473 @subsubsection @code{bfd_merge_private_bfd_data}
474 @strong{Synopsis}
475 @example
476 boolean bfd_merge_private_bfd_data(bfd *ibfd, bfd *obfd);
477 @end example
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:
482
483 @itemize @bullet
484
485 @item
486 @code{bfd_error_no_memory} -
487 Not enough memory exists to create private data for @var{obfd}.
488 @end itemize
489 @example
490 #define bfd_merge_private_bfd_data(ibfd, obfd) \
491      BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
492                 (ibfd, obfd))
493 @end example
494 @*
495 @findex bfd_set_private_flags
496 @subsubsection @code{bfd_set_private_flags}
497 @strong{Synopsis}
498 @example
499 boolean bfd_set_private_flags(bfd *abfd, flagword flags);
500 @end example
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
504 returns are:
505
506 @itemize @bullet
507
508 @item
509 @code{bfd_error_no_memory} -
510 Not enough memory exists to create private data for @var{obfd}.
511 @end itemize
512 @example
513 #define bfd_set_private_flags(abfd, flags) \
514      BFD_SEND (abfd, _bfd_set_private_flags, \
515                 (abfd, flags))
516 @end example
517 @*
518 @findex stuff
519 @subsubsection @code{stuff}
520 @strong{Description}@*
521 Stuff which should be documented:
522 @example
523 #define bfd_sizeof_headers(abfd, reloc) \
524      BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
525
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))
528
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))
532
533 #define bfd_debug_info_end(abfd) \
534         BFD_SEND (abfd, _bfd_debug_info_end, (abfd))
535
536 #define bfd_debug_info_accumulate(abfd, section) \
537         BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
538
539
540 #define bfd_stat_arch_elt(abfd, stat) \
541         BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
542
543 #define bfd_update_armap_timestamp(abfd) \
544         BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))
545
546 #define bfd_set_arch_mach(abfd, arch, mach)\
547         BFD_SEND ( abfd, _bfd_set_arch_mach, (abfd, arch, mach))
548
549 #define bfd_relax_section(abfd, section, link_info, again) \
550        BFD_SEND (abfd, _bfd_relax_section, (abfd, section, link_info, again))
551
552 #define bfd_link_hash_table_create(abfd) \
553         BFD_SEND (abfd, _bfd_link_hash_table_create, (abfd))
554
555 #define bfd_link_add_symbols(abfd, info) \
556         BFD_SEND (abfd, _bfd_link_add_symbols, (abfd, info))
557
558 #define bfd_final_link(abfd, info) \
559         BFD_SEND (abfd, _bfd_final_link, (abfd, info))
560
561 #define bfd_free_cached_info(abfd) \
562        BFD_SEND (abfd, _bfd_free_cached_info, (abfd))
563
564 #define bfd_get_dynamic_symtab_upper_bound(abfd) \
565         BFD_SEND (abfd, _bfd_get_dynamic_symtab_upper_bound, (abfd))
566
567 #define bfd_print_private_bfd_data(abfd, file)\
568         BFD_SEND (abfd, _bfd_print_private_bfd_data, (abfd, file))
569
570 #define bfd_canonicalize_dynamic_symtab(abfd, asymbols) \
571         BFD_SEND (abfd, _bfd_canonicalize_dynamic_symtab, (abfd, asymbols))
572
573 #define bfd_get_dynamic_reloc_upper_bound(abfd) \
574         BFD_SEND (abfd, _bfd_get_dynamic_reloc_upper_bound, (abfd))
575
576 #define bfd_canonicalize_dynamic_reloc(abfd, arels, asyms) \
577         BFD_SEND (abfd, _bfd_canonicalize_dynamic_reloc, (abfd, arels, asyms))
578
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 **));
583
584 @end example
585 @*