source: trunk/binutils/bfd/doc/bfd.info-1@ 3232

Last change on this file since 3232 was 610, checked in by bird, 22 years ago

This commit was generated by cvs2svn to compensate for changes in r609,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 40.8 KB
Line 
1This is bfd.info, produced by makeinfo version 4.3 from bfd.texinfo.
2
3START-INFO-DIR-ENTRY
4* Bfd: (bfd). The Binary File Descriptor library.
5END-INFO-DIR-ENTRY
6
7 This file documents the BFD library.
8
9 Copyright (C) 1991, 2000, 2001, 2003 Free Software Foundation, Inc.
10
11 Permission is granted to copy, distribute and/or modify this document
12 under the terms of the GNU Free Documentation License, Version 1.1
13 or any later version published by the Free Software Foundation;
14 with no Invariant Sections, with no Front-Cover Texts, and with no
15 Back-Cover Texts. A copy of the license is included in the
16section entitled "GNU Free Documentation License".
17
18
19File: bfd.info, Node: Top, Next: Overview, Prev: (dir), Up: (dir)
20
21 This file documents the binary file descriptor library libbfd.
22
23* Menu:
24
25* Overview:: Overview of BFD
26* BFD front end:: BFD front end
27* BFD back ends:: BFD back ends
28* GNU Free Documentation License:: GNU Free Documentation License
29* Index:: Index
30
31
32File: bfd.info, Node: Overview, Next: BFD front end, Prev: Top, Up: Top
33
34Introduction
35************
36
37 BFD is a package which allows applications to use the same routines
38to operate on object files whatever the object file format. A new
39object file format can be supported simply by creating a new BFD back
40end and adding it to the library.
41
42 BFD is split into two parts: the front end, and the back ends (one
43for each object file format).
44 * The front end of BFD provides the interface to the user. It manages
45 memory and various canonical data structures. The front end also
46 decides which back end to use and when to call back end routines.
47
48 * The back ends provide BFD its view of the real world. Each back
49 end provides a set of calls which the BFD front end can use to
50 maintain its canonical form. The back ends also may keep around
51 information for their own use, for greater efficiency.
52
53* Menu:
54
55* History:: History
56* How It Works:: How It Works
57* What BFD Version 2 Can Do:: What BFD Version 2 Can Do
58
59
60File: bfd.info, Node: History, Next: How It Works, Prev: Overview, Up: Overview
61
62History
63=======
64
65 One spur behind BFD was the desire, on the part of the GNU 960 team
66at Intel Oregon, for interoperability of applications on their COFF and
67b.out file formats. Cygnus was providing GNU support for the team, and
68was contracted to provide the required functionality.
69
70 The name came from a conversation David Wallace was having with
71Richard Stallman about the library: RMS said that it would be quite
72hard--David said "BFD". Stallman was right, but the name stuck.
73
74 At the same time, Ready Systems wanted much the same thing, but for
75different object file formats: IEEE-695, Oasys, Srecords, a.out and 68k
76coff.
77
78 BFD was first implemented by members of Cygnus Support; Steve
79Chamberlain (`sac@cygnus.com'), John Gilmore (`gnu@cygnus.com'), K.
80Richard Pixley (`rich@cygnus.com') and David Henkel-Wallace
81(`gumby@cygnus.com').
82
83
84File: bfd.info, Node: How It Works, Next: What BFD Version 2 Can Do, Prev: History, Up: Overview
85
86How To Use BFD
87==============
88
89 To use the library, include `bfd.h' and link with `libbfd.a'.
90
91 BFD provides a common interface to the parts of an object file for a
92calling application.
93
94 When an application sucessfully opens a target file (object,
95archive, or whatever), a pointer to an internal structure is returned.
96This pointer points to a structure called `bfd', described in `bfd.h'.
97Our convention is to call this pointer a BFD, and instances of it
98within code `abfd'. All operations on the target object file are
99applied as methods to the BFD. The mapping is defined within `bfd.h'
100in a set of macros, all beginning with `bfd_' to reduce namespace
101pollution.
102
103 For example, this sequence does what you would probably expect:
104return the number of sections in an object file attached to a BFD
105`abfd'.
106
107 #include "bfd.h"
108
109 unsigned int number_of_sections (abfd)
110 bfd *abfd;
111 {
112 return bfd_count_sections (abfd);
113 }
114
115 The abstraction used within BFD is that an object file has:
116
117 * a header,
118
119 * a number of sections containing raw data (*note Sections::),
120
121 * a set of relocations (*note Relocations::), and
122
123 * some symbol information (*note Symbols::).
124
125Also, BFDs opened for archives have the additional attribute of an index
126and contain subordinate BFDs. This approach is fine for a.out and coff,
127but loses efficiency when applied to formats such as S-records and
128IEEE-695.
129
130
131File: bfd.info, Node: What BFD Version 2 Can Do, Prev: How It Works, Up: Overview
132
133What BFD Version 2 Can Do
134=========================
135
136 When an object file is opened, BFD subroutines automatically
137determine the format of the input object file. They then build a
138descriptor in memory with pointers to routines that will be used to
139access elements of the object file's data structures.
140
141 As different information from the object files is required, BFD
142reads from different sections of the file and processes them. For
143example, a very common operation for the linker is processing symbol
144tables. Each BFD back end provides a routine for converting between
145the object file's representation of symbols and an internal canonical
146format. When the linker asks for the symbol table of an object file, it
147calls through a memory pointer to the routine from the relevant BFD
148back end which reads and converts the table into a canonical form. The
149linker then operates upon the canonical form. When the link is finished
150and the linker writes the output file's symbol table, another BFD back
151end routine is called to take the newly created symbol table and
152convert it into the chosen output format.
153
154* Menu:
155
156* BFD information loss:: Information Loss
157* Canonical format:: The BFD canonical object-file format
158
159
160File: bfd.info, Node: BFD information loss, Next: Canonical format, Up: What BFD Version 2 Can Do
161
162Information Loss
163----------------
164
165 _Information can be lost during output._ The output formats
166supported by BFD do not provide identical facilities, and information
167which can be described in one form has nowhere to go in another format.
168One example of this is alignment information in `b.out'. There is
169nowhere in an `a.out' format file to store alignment information on the
170contained data, so when a file is linked from `b.out' and an `a.out'
171image is produced, alignment information will not propagate to the
172output file. (The linker will still use the alignment information
173internally, so the link is performed correctly).
174
175 Another example is COFF section names. COFF files may contain an
176unlimited number of sections, each one with a textual section name. If
177the target of the link is a format which does not have many sections
178(e.g., `a.out') or has sections without names (e.g., the Oasys format),
179the link cannot be done simply. You can circumvent this problem by
180describing the desired input-to-output section mapping with the linker
181command language.
182
183 _Information can be lost during canonicalization._ The BFD internal
184canonical form of the external formats is not exhaustive; there are
185structures in input formats for which there is no direct representation
186internally. This means that the BFD back ends cannot maintain all
187possible data richness through the transformation between external to
188internal and back to external formats.
189
190 This limitation is only a problem when an application reads one
191format and writes another. Each BFD back end is responsible for
192maintaining as much data as possible, and the internal BFD canonical
193form has structures which are opaque to the BFD core, and exported only
194to the back ends. When a file is read in one format, the canonical form
195is generated for BFD and the application. At the same time, the back
196end saves away any information which may otherwise be lost. If the data
197is then written back in the same format, the back end routine will be
198able to use the canonical form provided by the BFD core as well as the
199information it prepared earlier. Since there is a great deal of
200commonality between back ends, there is no information lost when
201linking or copying big endian COFF to little endian COFF, or `a.out' to
202`b.out'. When a mixture of formats is linked, the information is only
203lost from the files whose format differs from the destination.
204
205
206File: bfd.info, Node: Canonical format, Prev: BFD information loss, Up: What BFD Version 2 Can Do
207
208The BFD canonical object-file format
209------------------------------------
210
211 The greatest potential for loss of information occurs when there is
212the least overlap between the information provided by the source
213format, that stored by the canonical format, and that needed by the
214destination format. A brief description of the canonical form may help
215you understand which kinds of data you can count on preserving across
216conversions.
217
218_files_
219 Information stored on a per-file basis includes target machine
220 architecture, particular implementation format type, a demand
221 pageable bit, and a write protected bit. Information like Unix
222 magic numbers is not stored here--only the magic numbers' meaning,
223 so a `ZMAGIC' file would have both the demand pageable bit and the
224 write protected text bit set. The byte order of the target is
225 stored on a per-file basis, so that big- and little-endian object
226 files may be used with one another.
227
228_sections_
229 Each section in the input file contains the name of the section,
230 the section's original address in the object file, size and
231 alignment information, various flags, and pointers into other BFD
232 data structures.
233
234_symbols_
235 Each symbol contains a pointer to the information for the object
236 file which originally defined it, its name, its value, and various
237 flag bits. When a BFD back end reads in a symbol table, it
238 relocates all symbols to make them relative to the base of the
239 section where they were defined. Doing this ensures that each
240 symbol points to its containing section. Each symbol also has a
241 varying amount of hidden private data for the BFD back end. Since
242 the symbol points to the original file, the private data format
243 for that symbol is accessible. `ld' can operate on a collection
244 of symbols of wildly different formats without problems.
245
246 Normal global and simple local symbols are maintained on output,
247 so an output file (no matter its format) will retain symbols
248 pointing to functions and to global, static, and common variables.
249 Some symbol information is not worth retaining; in `a.out', type
250 information is stored in the symbol table as long symbol names.
251 This information would be useless to most COFF debuggers; the
252 linker has command line switches to allow users to throw it away.
253
254 There is one word of type information within the symbol, so if the
255 format supports symbol type information within symbols (for
256 example, COFF, IEEE, Oasys) and the type is simple enough to fit
257 within one word (nearly everything but aggregates), the
258 information will be preserved.
259
260_relocation level_
261 Each canonical BFD relocation record contains a pointer to the
262 symbol to relocate to, the offset of the data to relocate, the
263 section the data is in, and a pointer to a relocation type
264 descriptor. Relocation is performed by passing messages through
265 the relocation type descriptor and the symbol pointer. Therefore,
266 relocations can be performed on output data using a relocation
267 method that is only available in one of the input formats. For
268 instance, Oasys provides a byte relocation format. A relocation
269 record requesting this relocation type would point indirectly to a
270 routine to perform this, so the relocation may be performed on a
271 byte being written to a 68k COFF file, even though 68k COFF has no
272 such relocation type.
273
274_line numbers_
275 Object formats can contain, for debugging purposes, some form of
276 mapping between symbols, source line numbers, and addresses in the
277 output file. These addresses have to be relocated along with the
278 symbol information. Each symbol with an associated list of line
279 number records points to the first record of the list. The head
280 of a line number list consists of a pointer to the symbol, which
281 allows finding out the address of the function whose line number
282 is being described. The rest of the list is made up of pairs:
283 offsets into the section and line numbers. Any format which can
284 simply derive this information can pass it successfully between
285 formats (COFF, IEEE and Oasys).
286
287
288File: bfd.info, Node: BFD front end, Next: BFD back ends, Prev: Overview, Up: Top
289
290BFD Front End
291*************
292
293`typedef bfd'
294=============
295
296 A BFD has type `bfd'; objects of this type are the cornerstone of
297any application using BFD. Using BFD consists of making references
298though the BFD and to data in the BFD.
299
300 Here is the structure that defines the type `bfd'. It contains the
301major data about the file and pointers to the rest of the data.
302
303
304 struct bfd
305 {
306 /* A unique identifier of the BFD */
307 unsigned int id;
308
309 /* The filename the application opened the BFD with. */
310 const char *filename;
311
312 /* A pointer to the target jump table. */
313 const struct bfd_target *xvec;
314
315 /* To avoid dragging too many header files into every file that
316 includes ``bfd.h'', IOSTREAM has been declared as a "char *",
317 and MTIME as a "long". Their correct types, to which they
318 are cast when used, are "FILE *" and "time_t". The iostream
319 is the result of an fopen on the filename. However, if the
320 BFD_IN_MEMORY flag is set, then iostream is actually a pointer
321 to a bfd_in_memory struct. */
322 PTR iostream;
323
324 /* Is the file descriptor being cached? That is, can it be closed as
325 needed, and re-opened when accessed later? */
326 bfd_boolean cacheable;
327
328 /* Marks whether there was a default target specified when the
329 BFD was opened. This is used to select which matching algorithm
330 to use to choose the back end. */
331 bfd_boolean target_defaulted;
332
333 /* The caching routines use these to maintain a
334 least-recently-used list of BFDs. */
335 struct bfd *lru_prev, *lru_next;
336
337 /* When a file is closed by the caching routines, BFD retains
338 state information on the file here... */
339 ufile_ptr where;
340
341 /* ... and here: (``once'' means at least once). */
342 bfd_boolean opened_once;
343
344 /* Set if we have a locally maintained mtime value, rather than
345 getting it from the file each time. */
346 bfd_boolean mtime_set;
347
348 /* File modified time, if mtime_set is TRUE. */
349 long mtime;
350
351 /* Reserved for an unimplemented file locking extension. */
352 int ifd;
353
354 /* The format which belongs to the BFD. (object, core, etc.) */
355 bfd_format format;
356
357 /* The direction with which the BFD was opened. */
358 enum bfd_direction
359 {
360 no_direction = 0,
361 read_direction = 1,
362 write_direction = 2,
363 both_direction = 3
364 }
365 direction;
366
367 /* Format_specific flags. */
368 flagword flags;
369
370 /* Currently my_archive is tested before adding origin to
371 anything. I believe that this can become always an add of
372 origin, with origin set to 0 for non archive files. */
373 ufile_ptr origin;
374
375 /* Remember when output has begun, to stop strange things
376 from happening. */
377 bfd_boolean output_has_begun;
378
379 /* A hash table for section names. */
380 struct bfd_hash_table section_htab;
381
382 /* Pointer to linked list of sections. */
383 struct sec *sections;
384
385 /* The place where we add to the section list. */
386 struct sec **section_tail;
387
388 /* The number of sections. */
389 unsigned int section_count;
390
391 /* Stuff only useful for object files:
392 The start address. */
393 bfd_vma start_address;
394
395 /* Used for input and output. */
396 unsigned int symcount;
397
398 /* Symbol table for output BFD (with symcount entries). */
399 struct symbol_cache_entry **outsymbols;
400
401 /* Used for slurped dynamic symbol tables. */
402 unsigned int dynsymcount;
403
404 /* Pointer to structure which contains architecture information. */
405 const struct bfd_arch_info *arch_info;
406
407 /* Stuff only useful for archives. */
408 PTR arelt_data;
409 struct bfd *my_archive; /* The containing archive BFD. */
410 struct bfd *next; /* The next BFD in the archive. */
411 struct bfd *archive_head; /* The first BFD in the archive. */
412 bfd_boolean has_armap;
413
414 /* A chain of BFD structures involved in a link. */
415 struct bfd *link_next;
416
417 /* A field used by _bfd_generic_link_add_archive_symbols. This will
418 be used only for archive elements. */
419 int archive_pass;
420
421 /* Used by the back end to hold private data. */
422 union
423 {
424 struct aout_data_struct *aout_data;
425 struct artdata *aout_ar_data;
426 struct _oasys_data *oasys_obj_data;
427 struct _oasys_ar_data *oasys_ar_data;
428 struct coff_tdata *coff_obj_data;
429 struct pe_tdata *pe_obj_data;
430 struct xcoff_tdata *xcoff_obj_data;
431 struct ecoff_tdata *ecoff_obj_data;
432 struct ieee_data_struct *ieee_data;
433 struct ieee_ar_data_struct *ieee_ar_data;
434 struct srec_data_struct *srec_data;
435 struct ihex_data_struct *ihex_data;
436 struct tekhex_data_struct *tekhex_data;
437 struct elf_obj_tdata *elf_obj_data;
438 struct nlm_obj_tdata *nlm_obj_data;
439 struct bout_data_struct *bout_data;
440 struct mmo_data_struct *mmo_data;
441 struct sun_core_struct *sun_core_data;
442 struct sco5_core_struct *sco5_core_data;
443 struct trad_core_struct *trad_core_data;
444 struct som_data_struct *som_data;
445 struct hpux_core_struct *hpux_core_data;
446 struct hppabsd_core_struct *hppabsd_core_data;
447 struct sgi_core_struct *sgi_core_data;
448 struct lynx_core_struct *lynx_core_data;
449 struct osf_core_struct *osf_core_data;
450 struct cisco_core_struct *cisco_core_data;
451 struct versados_data_struct *versados_data;
452 struct netbsd_core_struct *netbsd_core_data;
453 struct mach_o_data_struct *mach_o_data;
454 struct mach_o_fat_data_struct *mach_o_fat_data;
455 struct bfd_pef_data_struct *pef_data;
456 struct bfd_pef_xlib_data_struct *pef_xlib_data;
457 struct bfd_sym_data_struct *sym_data;
458 PTR any;
459 }
460 tdata;
461
462 /* Used by the application to hold private data. */
463 PTR usrdata;
464
465 /* Where all the allocated stuff under this BFD goes. This is a
466 struct objalloc *, but we use PTR to avoid requiring the inclusion of
467 objalloc.h. */
468 PTR memory;
469 };
470
471Error reporting
472===============
473
474 Most BFD functions return nonzero on success (check their individual
475documentation for precise semantics). On an error, they call
476`bfd_set_error' to set an error condition that callers can check by
477calling `bfd_get_error'. If that returns `bfd_error_system_call', then
478check `errno'.
479
480 The easiest way to report a BFD error to the user is to use
481`bfd_perror'.
482
483Type `bfd_error_type'
484---------------------
485
486 The values returned by `bfd_get_error' are defined by the enumerated
487type `bfd_error_type'.
488
489
490 typedef enum bfd_error
491 {
492 bfd_error_no_error = 0,
493 bfd_error_system_call,
494 bfd_error_invalid_target,
495 bfd_error_wrong_format,
496 bfd_error_wrong_object_format,
497 bfd_error_invalid_operation,
498 bfd_error_no_memory,
499 bfd_error_no_symbols,
500 bfd_error_no_armap,
501 bfd_error_no_more_archived_files,
502 bfd_error_malformed_archive,
503 bfd_error_file_not_recognized,
504 bfd_error_file_ambiguously_recognized,
505 bfd_error_no_contents,
506 bfd_error_nonrepresentable_section,
507 bfd_error_no_debug_section,
508 bfd_error_bad_value,
509 bfd_error_file_truncated,
510 bfd_error_file_too_big,
511 bfd_error_invalid_error_code
512 }
513 bfd_error_type;
514
515`bfd_get_error'
516...............
517
518 *Synopsis*
519 bfd_error_type bfd_get_error (void);
520 *Description*
521Return the current BFD error condition.
522
523`bfd_set_error'
524...............
525
526 *Synopsis*
527 void bfd_set_error (bfd_error_type error_tag);
528 *Description*
529Set the BFD error condition to be ERROR_TAG.
530
531`bfd_errmsg'
532............
533
534 *Synopsis*
535 const char *bfd_errmsg (bfd_error_type error_tag);
536 *Description*
537Return a string describing the error ERROR_TAG, or the system error if
538ERROR_TAG is `bfd_error_system_call'.
539
540`bfd_perror'
541............
542
543 *Synopsis*
544 void bfd_perror (const char *message);
545 *Description*
546Print to the standard error stream a string describing the last BFD
547error that occurred, or the last system error if the last BFD error was
548a system call failure. If MESSAGE is non-NULL and non-empty, the error
549string printed is preceded by MESSAGE, a colon, and a space. It is
550followed by a newline.
551
552BFD error handler
553-----------------
554
555 Some BFD functions want to print messages describing the problem.
556They call a BFD error handler function. This function may be overriden
557by the program.
558
559 The BFD error handler acts like printf.
560
561
562 typedef void (*bfd_error_handler_type) PARAMS ((const char *, ...));
563
564`bfd_set_error_handler'
565.......................
566
567 *Synopsis*
568 bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
569 *Description*
570Set the BFD error handler function. Returns the previous function.
571
572`bfd_set_error_program_name'
573............................
574
575 *Synopsis*
576 void bfd_set_error_program_name (const char *);
577 *Description*
578Set the program name to use when printing a BFD error. This is printed
579before the error message followed by a colon and space. The string
580must not be changed after it is passed to this function.
581
582`bfd_get_error_handler'
583.......................
584
585 *Synopsis*
586 bfd_error_handler_type bfd_get_error_handler (void);
587 *Description*
588Return the BFD error handler function.
589
590`bfd_archive_filename'
591......................
592
593 *Synopsis*
594 const char *bfd_archive_filename (bfd *);
595 *Description*
596For a BFD that is a component of an archive, returns a string with both
597the archive name and file name. For other BFDs, just returns the file
598name.
599
600Symbols
601=======
602
603`bfd_get_reloc_upper_bound'
604...........................
605
606 *Synopsis*
607 long bfd_get_reloc_upper_bound (bfd *abfd, asection *sect);
608 *Description*
609Return the number of bytes required to store the relocation information
610associated with section SECT attached to bfd ABFD. If an error occurs,
611return -1.
612
613`bfd_canonicalize_reloc'
614........................
615
616 *Synopsis*
617 long bfd_canonicalize_reloc
618 (bfd *abfd,
619 asection *sec,
620 arelent **loc,
621 asymbol **syms);
622 *Description*
623Call the back end associated with the open BFD ABFD and translate the
624external form of the relocation information attached to SEC into the
625internal canonical form. Place the table into memory at LOC, which has
626been preallocated, usually by a call to `bfd_get_reloc_upper_bound'.
627Returns the number of relocs, or -1 on error.
628
629 The SYMS table is also needed for horrible internal magic reasons.
630
631`bfd_set_reloc'
632...............
633
634 *Synopsis*
635 void bfd_set_reloc
636 (bfd *abfd, asection *sec, arelent **rel, unsigned int count);
637 *Description*
638Set the relocation pointer and count within section SEC to the values
639REL and COUNT. The argument ABFD is ignored.
640
641`bfd_set_file_flags'
642....................
643
644 *Synopsis*
645 bfd_boolean bfd_set_file_flags (bfd *abfd, flagword flags);
646 *Description*
647Set the flag word in the BFD ABFD to the value FLAGS.
648
649 Possible errors are:
650 * `bfd_error_wrong_format' - The target bfd was not of object format.
651
652 * `bfd_error_invalid_operation' - The target bfd was open for
653 reading.
654
655 * `bfd_error_invalid_operation' - The flag word contained a bit
656 which was not applicable to the type of file. E.g., an attempt
657 was made to set the `D_PAGED' bit on a BFD format which does not
658 support demand paging.
659
660`bfd_get_arch_size'
661...................
662
663 *Synopsis*
664 int bfd_get_arch_size (bfd *abfd);
665 *Description*
666Returns the architecture address size, in bits, as determined by the
667object file's format. For ELF, this information is included in the
668header.
669
670 *Returns*
671Returns the arch size in bits if known, `-1' otherwise.
672
673`bfd_get_sign_extend_vma'
674.........................
675
676 *Synopsis*
677 int bfd_get_sign_extend_vma (bfd *abfd);
678 *Description*
679Indicates if the target architecture "naturally" sign extends an
680address. Some architectures implicitly sign extend address values when
681they are converted to types larger than the size of an address. For
682instance, bfd_get_start_address() will return an address sign extended
683to fill a bfd_vma when this is the case.
684
685 *Returns*
686Returns `1' if the target architecture is known to sign extend
687addresses, `0' if the target architecture is known to not sign extend
688addresses, and `-1' otherwise.
689
690`bfd_set_start_address'
691.......................
692
693 *Synopsis*
694 bfd_boolean bfd_set_start_address (bfd *abfd, bfd_vma vma);
695 *Description*
696Make VMA the entry point of output BFD ABFD.
697
698 *Returns*
699Returns `TRUE' on success, `FALSE' otherwise.
700
701`bfd_get_gp_size'
702.................
703
704 *Synopsis*
705 unsigned int bfd_get_gp_size (bfd *abfd);
706 *Description*
707Return the maximum size of objects to be optimized using the GP
708register under MIPS ECOFF. This is typically set by the `-G' argument
709to the compiler, assembler or linker.
710
711`bfd_set_gp_size'
712.................
713
714 *Synopsis*
715 void bfd_set_gp_size (bfd *abfd, unsigned int i);
716 *Description*
717Set the maximum size of objects to be optimized using the GP register
718under ECOFF or MIPS ELF. This is typically set by the `-G' argument to
719the compiler, assembler or linker.
720
721`bfd_scan_vma'
722..............
723
724 *Synopsis*
725 bfd_vma bfd_scan_vma (const char *string, const char **end, int base);
726 *Description*
727Convert, like `strtoul', a numerical expression STRING into a `bfd_vma'
728integer, and return that integer. (Though without as many bells and
729whistles as `strtoul'.) The expression is assumed to be unsigned
730(i.e., positive). If given a BASE, it is used as the base for
731conversion. A base of 0 causes the function to interpret the string in
732hex if a leading "0x" or "0X" is found, otherwise in octal if a leading
733zero is found, otherwise in decimal.
734
735 If the value would overflow, the maximum `bfd_vma' value is returned.
736
737`bfd_copy_private_bfd_data'
738...........................
739
740 *Synopsis*
741 bfd_boolean bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd);
742 *Description*
743Copy private BFD information from the BFD IBFD to the the BFD OBFD.
744Return `TRUE' on success, `FALSE' on error. Possible error returns are:
745
746 * `bfd_error_no_memory' - Not enough memory exists to create private
747 data for OBFD.
748
749 #define bfd_copy_private_bfd_data(ibfd, obfd) \
750 BFD_SEND (obfd, _bfd_copy_private_bfd_data, \
751 (ibfd, obfd))
752
753`bfd_merge_private_bfd_data'
754............................
755
756 *Synopsis*
757 bfd_boolean bfd_merge_private_bfd_data (bfd *ibfd, bfd *obfd);
758 *Description*
759Merge private BFD information from the BFD IBFD to the the output file
760BFD OBFD when linking. Return `TRUE' on success, `FALSE' on error.
761Possible error returns are:
762
763 * `bfd_error_no_memory' - Not enough memory exists to create private
764 data for OBFD.
765
766 #define bfd_merge_private_bfd_data(ibfd, obfd) \
767 BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
768 (ibfd, obfd))
769
770`bfd_set_private_flags'
771.......................
772
773 *Synopsis*
774 bfd_boolean bfd_set_private_flags (bfd *abfd, flagword flags);
775 *Description*
776Set private BFD flag information in the BFD ABFD. Return `TRUE' on
777success, `FALSE' on error. Possible error returns are:
778
779 * `bfd_error_no_memory' - Not enough memory exists to create private
780 data for OBFD.
781
782 #define bfd_set_private_flags(abfd, flags) \
783 BFD_SEND (abfd, _bfd_set_private_flags, (abfd, flags))
784
785`Other functions'
786.................
787
788 *Description*
789The following functions exist but have not yet been documented.
790 #define bfd_sizeof_headers(abfd, reloc) \
791 BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
792
793 #define bfd_find_nearest_line(abfd, sec, syms, off, file, func, line) \
794 BFD_SEND (abfd, _bfd_find_nearest_line, \
795 (abfd, sec, syms, off, file, func, line))
796
797 #define bfd_debug_info_start(abfd) \
798 BFD_SEND (abfd, _bfd_debug_info_start, (abfd))
799
800 #define bfd_debug_info_end(abfd) \
801 BFD_SEND (abfd, _bfd_debug_info_end, (abfd))
802
803 #define bfd_debug_info_accumulate(abfd, section) \
804 BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
805
806 #define bfd_stat_arch_elt(abfd, stat) \
807 BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
808
809 #define bfd_update_armap_timestamp(abfd) \
810 BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))
811
812 #define bfd_set_arch_mach(abfd, arch, mach)\
813 BFD_SEND ( abfd, _bfd_set_arch_mach, (abfd, arch, mach))
814
815 #define bfd_relax_section(abfd, section, link_info, again) \
816 BFD_SEND (abfd, _bfd_relax_section, (abfd, section, link_info, again))
817
818 #define bfd_gc_sections(abfd, link_info) \
819 BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
820
821 #define bfd_merge_sections(abfd, link_info) \
822 BFD_SEND (abfd, _bfd_merge_sections, (abfd, link_info))
823
824 #define bfd_discard_group(abfd, sec) \
825 BFD_SEND (abfd, _bfd_discard_group, (abfd, sec))
826
827 #define bfd_link_hash_table_create(abfd) \
828 BFD_SEND (abfd, _bfd_link_hash_table_create, (abfd))
829
830 #define bfd_link_hash_table_free(abfd, hash) \
831 BFD_SEND (abfd, _bfd_link_hash_table_free, (hash))
832
833 #define bfd_link_add_symbols(abfd, info) \
834 BFD_SEND (abfd, _bfd_link_add_symbols, (abfd, info))
835
836 #define bfd_link_just_syms(sec, info) \
837 BFD_SEND (abfd, _bfd_link_just_syms, (sec, info))
838
839 #define bfd_final_link(abfd, info) \
840 BFD_SEND (abfd, _bfd_final_link, (abfd, info))
841
842 #define bfd_free_cached_info(abfd) \
843 BFD_SEND (abfd, _bfd_free_cached_info, (abfd))
844
845 #define bfd_get_dynamic_symtab_upper_bound(abfd) \
846 BFD_SEND (abfd, _bfd_get_dynamic_symtab_upper_bound, (abfd))
847
848 #define bfd_print_private_bfd_data(abfd, file)\
849 BFD_SEND (abfd, _bfd_print_private_bfd_data, (abfd, file))
850
851 #define bfd_canonicalize_dynamic_symtab(abfd, asymbols) \
852 BFD_SEND (abfd, _bfd_canonicalize_dynamic_symtab, (abfd, asymbols))
853
854 #define bfd_get_dynamic_reloc_upper_bound(abfd) \
855 BFD_SEND (abfd, _bfd_get_dynamic_reloc_upper_bound, (abfd))
856
857 #define bfd_canonicalize_dynamic_reloc(abfd, arels, asyms) \
858 BFD_SEND (abfd, _bfd_canonicalize_dynamic_reloc, (abfd, arels, asyms))
859
860 extern bfd_byte *bfd_get_relocated_section_contents
861 PARAMS ((bfd *, struct bfd_link_info *,
862 struct bfd_link_order *, bfd_byte *,
863 bfd_boolean, asymbol **));
864
865`bfd_alt_mach_code'
866...................
867
868 *Synopsis*
869 bfd_boolean bfd_alt_mach_code (bfd *abfd, int alternative);
870 *Description*
871When more than one machine code number is available for the same
872machine type, this function can be used to switch between the preferred
873one (alternative == 0) and any others. Currently, only ELF supports
874this feature, with up to two alternate machine codes.
875
876 struct bfd_preserve
877 {
878 PTR marker;
879 PTR tdata;
880 flagword flags;
881 const struct bfd_arch_info *arch_info;
882 struct sec *sections;
883 struct sec **section_tail;
884 unsigned int section_count;
885 struct bfd_hash_table section_htab;
886 };
887
888`bfd_preserve_save'
889...................
890
891 *Synopsis*
892 bfd_boolean bfd_preserve_save (bfd *, struct bfd_preserve *);
893 *Description*
894When testing an object for compatibility with a particular target
895back-end, the back-end object_p function needs to set up certain fields
896in the bfd on successfully recognizing the object. This typically
897happens in a piecemeal fashion, with failures possible at many points.
898On failure, the bfd is supposed to be restored to its initial state,
899which is virtually impossible. However, restoring a subset of the bfd
900state works in practice. This function stores the subset and
901reinitializes the bfd.
902
903`bfd_preserve_restore'
904......................
905
906 *Synopsis*
907 void bfd_preserve_restore (bfd *, struct bfd_preserve *);
908 *Description*
909This function restores bfd state saved by bfd_preserve_save. If MARKER
910is non-NULL in struct bfd_preserve then that block and all subsequently
911bfd_alloc'd memory is freed.
912
913`bfd_preserve_finish'
914.....................
915
916 *Synopsis*
917 void bfd_preserve_finish (bfd *, struct bfd_preserve *);
918 *Description*
919This function should be called when the bfd state saved by
920bfd_preserve_save is no longer needed. ie. when the back-end object_p
921function returns with success.
922
923`bfd_get_mtime'
924...............
925
926 *Synopsis*
927 long bfd_get_mtime(bfd *abfd);
928 *Description*
929Return the file modification time (as read from the file system, or
930from the archive header for archive members).
931
932`bfd_get_size'
933..............
934
935 *Synopsis*
936 long bfd_get_size(bfd *abfd);
937 *Description*
938Return the file size (as read from file system) for the file associated
939with BFD ABFD.
940
941 The initial motivation for, and use of, this routine is not so we
942can get the exact size of the object the BFD applies to, since that
943might not be generally possible (archive members for example). It
944would be ideal if someone could eventually modify it so that such
945results were guaranteed.
946
947 Instead, we want to ask questions like "is this NNN byte sized
948object I'm about to try read from file offset YYY reasonable?" As as
949example of where we might do this, some object formats use string
950tables for which the first `sizeof (long)' bytes of the table contain
951the size of the table itself, including the size bytes. If an
952application tries to read what it thinks is one of these string tables,
953without some way to validate the size, and for some reason the size is
954wrong (byte swapping error, wrong location for the string table, etc.),
955the only clue is likely to be a read error when it tries to read the
956table, or a "virtual memory exhausted" error when it tries to allocate
95715 bazillon bytes of space for the 15 bazillon byte table it is about
958to read. This function at least allows us to answer the quesion, "is
959the size reasonable?".
960
961* Menu:
962
963* Memory Usage::
964* Initialization::
965* Sections::
966* Symbols::
967* Archives::
968* Formats::
969* Relocations::
970* Core Files::
971* Targets::
972* Architectures::
973* Opening and Closing::
974* Internal::
975* File Caching::
976* Linker Functions::
977* Hash Tables::
978
979
980File: bfd.info, Node: Memory Usage, Next: Initialization, Prev: BFD front end, Up: BFD front end
981
982Memory Usage
983============
984
985 BFD keeps all of its internal structures in obstacks. There is one
986obstack per open BFD file, into which the current state is stored. When
987a BFD is closed, the obstack is deleted, and so everything which has
988been allocated by BFD for the closing file is thrown away.
989
990 BFD does not free anything created by an application, but pointers
991into `bfd' structures become invalid on a `bfd_close'; for example,
992after a `bfd_close' the vector passed to `bfd_canonicalize_symtab' is
993still around, since it has been allocated by the application, but the
994data that it pointed to are lost.
995
996 The general rule is to not close a BFD until all operations dependent
997upon data from the BFD have been completed, or all the data from within
998the file has been copied. To help with the management of memory, there
999is a function (`bfd_alloc_size') which returns the number of bytes in
1000obstacks associated with the supplied BFD. This could be used to select
1001the greediest open BFD, close it to reclaim the memory, perform some
1002operation and reopen the BFD again, to get a fresh copy of the data
1003structures.
1004
1005
1006File: bfd.info, Node: Initialization, Next: Sections, Prev: Memory Usage, Up: BFD front end
1007
1008Initialization
1009==============
1010
1011 These are the functions that handle initializing a BFD.
1012
1013`bfd_init'
1014..........
1015
1016 *Synopsis*
1017 void bfd_init(void);
1018 *Description*
1019This routine must be called before any other BFD function to initialize
1020magical internal data structures.
1021
1022
1023File: bfd.info, Node: Sections, Next: Symbols, Prev: Initialization, Up: BFD front end
1024
1025Sections
1026========
1027
1028 The raw data contained within a BFD is maintained through the
1029section abstraction. A single BFD may have any number of sections. It
1030keeps hold of them by pointing to the first; each one points to the
1031next in the list.
1032
1033 Sections are supported in BFD in `section.c'.
1034
1035* Menu:
1036
1037* Section Input::
1038* Section Output::
1039* typedef asection::
1040* section prototypes::
1041
1042
1043File: bfd.info, Node: Section Input, Next: Section Output, Prev: Sections, Up: Sections
1044
1045Section input
1046-------------
1047
1048 When a BFD is opened for reading, the section structures are created
1049and attached to the BFD.
1050
1051 Each section has a name which describes the section in the outside
1052world--for example, `a.out' would contain at least three sections,
1053called `.text', `.data' and `.bss'.
1054
1055 Names need not be unique; for example a COFF file may have several
1056sections named `.data'.
1057
1058 Sometimes a BFD will contain more than the "natural" number of
1059sections. A back end may attach other sections containing constructor
1060data, or an application may add a section (using `bfd_make_section') to
1061the sections attached to an already open BFD. For example, the linker
1062creates an extra section `COMMON' for each input file's BFD to hold
1063information about common storage.
1064
1065 The raw data is not necessarily read in when the section descriptor
1066is created. Some targets may leave the data in place until a
1067`bfd_get_section_contents' call is made. Other back ends may read in
1068all the data at once. For example, an S-record file has to be read
1069once to determine the size of the data. An IEEE-695 file doesn't
1070contain raw data in sections, but data and relocation expressions
1071intermixed, so the data area has to be parsed to get out the data and
1072relocations.
1073
1074
1075File: bfd.info, Node: Section Output, Next: typedef asection, Prev: Section Input, Up: Sections
1076
1077Section output
1078--------------
1079
1080 To write a new object style BFD, the various sections to be written
1081have to be created. They are attached to the BFD in the same way as
1082input sections; data is written to the sections using
1083`bfd_set_section_contents'.
1084
1085 Any program that creates or combines sections (e.g., the assembler
1086and linker) must use the `asection' fields `output_section' and
1087`output_offset' to indicate the file sections to which each section
1088must be written. (If the section is being created from scratch,
1089`output_section' should probably point to the section itself and
1090`output_offset' should probably be zero.)
1091
1092 The data to be written comes from input sections attached (via
1093`output_section' pointers) to the output sections. The output section
1094structure can be considered a filter for the input section: the output
1095section determines the vma of the output data and the name, but the
1096input section determines the offset into the output section of the data
1097to be written.
1098
1099 E.g., to create a section "O", starting at 0x100, 0x123 long,
1100containing two subsections, "A" at offset 0x0 (i.e., at vma 0x100) and
1101"B" at offset 0x20 (i.e., at vma 0x120) the `asection' structures would
1102look like:
1103
1104 section name "A"
1105 output_offset 0x00
1106 size 0x20
1107 output_section -----------> section name "O"
1108 | vma 0x100
1109 section name "B" | size 0x123
1110 output_offset 0x20 |
1111 size 0x103 |
1112 output_section --------|
1113
1114Link orders
1115-----------
1116
1117 The data within a section is stored in a "link_order". These are
1118much like the fixups in `gas'. The link_order abstraction allows a
1119section to grow and shrink within itself.
1120
1121 A link_order knows how big it is, and which is the next link_order
1122and where the raw data for it is; it also points to a list of
1123relocations which apply to it.
1124
1125 The link_order is used by the linker to perform relaxing on final
1126code. The compiler creates code which is as big as necessary to make
1127it work without relaxing, and the user can select whether to relax.
1128Sometimes relaxing takes a lot of time. The linker runs around the
1129relocations to see if any are attached to data which can be shrunk, if
1130so it does it on a link_order by link_order basis.
1131
Note: See TracBrowser for help on using the repository browser.