OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [bfd/] [doc/] [bfd.info-1] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
This is bfd.info, produced by makeinfo version 4.0 from bfd.texinfo.
2
 
3
START-INFO-DIR-ENTRY
4
* Bfd: (bfd).                   The Binary File Descriptor library.
5
END-INFO-DIR-ENTRY
6
 
7
   This file documents the BFD library.
8
 
9
   Copyright (C) 1991, 2000 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
16
section entitled "GNU Free Documentation License".
17
 
18

19
File: 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

32
File: bfd.info,  Node: Overview,  Next: BFD front end,  Prev: Top,  Up: Top
33
 
34
Introduction
35
************
36
 
37
   BFD is a package which allows applications to use the same routines
38
to operate on object files whatever the object file format.  A new
39
object file format can be supported simply by creating a new BFD back
40
end and adding it to the library.
41
 
42
   BFD is split into two parts: the front end, and the back ends (one
43
for 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

60
File: bfd.info,  Node: History,  Next: How It Works,  Prev: Overview,  Up: Overview
61
 
62
History
63
=======
64
 
65
   One spur behind BFD was the desire, on the part of the GNU 960 team
66
at Intel Oregon, for interoperability of applications on their COFF and
67
b.out file formats.  Cygnus was providing GNU support for the team, and
68
was contracted to provide the required functionality.
69
 
70
   The name came from a conversation David Wallace was having with
71
Richard Stallman about the library: RMS said that it would be quite
72
hard--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
75
different object file formats: IEEE-695, Oasys, Srecords, a.out and 68k
76
coff.
77
 
78
   BFD was first implemented by members of Cygnus Support; Steve
79
Chamberlain (`sac@cygnus.com'), John Gilmore (`gnu@cygnus.com'), K.
80
Richard Pixley (`rich@cygnus.com') and David Henkel-Wallace
81
(`gumby@cygnus.com').
82
 
83

84
File: bfd.info,  Node: How It Works,  Next: What BFD Version 2 Can Do,  Prev: History,  Up: Overview
85
 
86
How 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
92
calling application.
93
 
94
   When an application sucessfully opens a target file (object,
95
archive, or whatever), a pointer to an internal structure is returned.
96
This pointer points to a structure called `bfd', described in `bfd.h'.
97
Our convention is to call this pointer a BFD, and instances of it
98
within code `abfd'.  All operations on the target object file are
99
applied as methods to the BFD.  The mapping is defined within `bfd.h'
100
in a set of macros, all beginning with `bfd_' to reduce namespace
101
pollution.
102
 
103
   For example, this sequence does what you would probably expect:
104
return 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
 
125
Also, BFDs opened for archives have the additional attribute of an index
126
and contain subordinate BFDs. This approach is fine for a.out and coff,
127
but loses efficiency when applied to formats such as S-records and
128
IEEE-695.
129
 
130

131
File: bfd.info,  Node: What BFD Version 2 Can Do,  Prev: How It Works,  Up: Overview
132
 
133
What BFD Version 2 Can Do
134
=========================
135
 
136
   When an object file is opened, BFD subroutines automatically
137
determine the format of the input object file.  They then build a
138
descriptor in memory with pointers to routines that will be used to
139
access elements of the object file's data structures.
140
 
141
   As different information from the the object files is required, BFD
142
reads from different sections of the file and processes them.  For
143
example, a very common operation for the linker is processing symbol
144
tables.  Each BFD back end provides a routine for converting between
145
the object file's representation of symbols and an internal canonical
146
format. When the linker asks for the symbol table of an object file, it
147
calls through a memory pointer to the routine from the relevant BFD
148
back end which reads and converts the table into a canonical form.  The
149
linker then operates upon the canonical form. When the link is finished
150
and the linker writes the output file's symbol table, another BFD back
151
end routine is called to take the newly created symbol table and
152
convert 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

160
File: bfd.info,  Node: BFD information loss,  Next: Canonical format,  Up: What BFD Version 2 Can Do
161
 
162
Information Loss
163
----------------
164
 
165
   _Information can be lost during output._ The output formats
166
supported by BFD do not provide identical facilities, and information
167
which can be described in one form has nowhere to go in another format.
168
One example of this is alignment information in `b.out'. There is
169
nowhere in an `a.out' format file to store alignment information on the
170
contained data, so when a file is linked from `b.out' and an `a.out'
171
image is produced, alignment information will not propagate to the
172
output file. (The linker will still use the alignment information
173
internally, so the link is performed correctly).
174
 
175
   Another example is COFF section names. COFF files may contain an
176
unlimited number of sections, each one with a textual section name. If
177
the 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),
179
the link cannot be done simply. You can circumvent this problem by
180
describing the desired input-to-output section mapping with the linker
181
command language.
182
 
183
   _Information can be lost during canonicalization._ The BFD internal
184
canonical form of the external formats is not exhaustive; there are
185
structures in input formats for which there is no direct representation
186
internally.  This means that the BFD back ends cannot maintain all
187
possible data richness through the transformation between external to
188
internal and back to external formats.
189
 
190
   This limitation is only a problem when an application reads one
191
format and writes another.  Each BFD back end is responsible for
192
maintaining as much data as possible, and the internal BFD canonical
193
form has structures which are opaque to the BFD core, and exported only
194
to the back ends. When a file is read in one format, the canonical form
195
is generated for BFD and the application. At the same time, the back
196
end saves away any information which may otherwise be lost. If the data
197
is then written back in the same format, the back end routine will be
198
able to use the canonical form provided by the BFD core as well as the
199
information it prepared earlier.  Since there is a great deal of
200
commonality between back ends, there is no information lost when
201
linking 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
203
lost from the files whose format differs from the destination.
204
 
205

206
File: bfd.info,  Node: Canonical format,  Prev: BFD information loss,  Up: What BFD Version 2 Can Do
207
 
208
The BFD canonical object-file format
209
------------------------------------
210
 
211
   The greatest potential for loss of information occurs when there is
212
the least overlap between the information provided by the source
213
format, that stored by the canonical format, and that needed by the
214
destination format. A brief description of the canonical form may help
215
you understand which kinds of data you can count on preserving across
216
conversions.
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

288
File: bfd.info,  Node: BFD front end,  Next: BFD back ends,  Prev: Overview,  Up: Top
289
 
290
BFD front end
291
*************
292
 
293
`typedef bfd'
294
=============
295
 
296
   A BFD has type `bfd'; objects of this type are the cornerstone of
297
any application using BFD. Using BFD consists of making references
298
though the BFD and to data in the BFD.
299
 
300
   Here is the structure that defines the type `bfd'.  It contains the
301
major data about the file and pointers to the rest of the data.
302
 
303
 
304
     struct _bfd
305
     {
306
         /* The filename the application opened the BFD with.  */
307
         CONST char *filename;
308
 
309
         /* A pointer to the target jump table.             */
310
         const struct bfd_target *xvec;
311
 
312
         /* To avoid dragging too many header files into every file that
313
            includes ``bfd.h'', IOSTREAM has been declared as a "char
314
            *", and MTIME as a "long".  Their correct types, to which they
315
            are cast when used, are "FILE *" and "time_t".    The iostream
316
            is the result of an fopen on the filename.  However, if the
317
            BFD_IN_MEMORY flag is set, then iostream is actually a pointer
318
            to a bfd_in_memory struct.  */
319
         PTR iostream;
320
 
321
         /* Is the file descriptor being cached?  That is, can it be closed as
322
            needed, and re-opened when accessed later?  */
323
 
324
         boolean cacheable;
325
 
326
         /* Marks whether there was a default target specified when the
327
            BFD was opened. This is used to select which matching algorithm
328
            to use to choose the back end. */
329
 
330
         boolean target_defaulted;
331
 
332
         /* The caching routines use these to maintain a
333
            least-recently-used list of BFDs */
334
 
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
 
340
         file_ptr where;
341
 
342
         /* and here: (``once'' means at least once) */
343
 
344
         boolean opened_once;
345
 
346
         /* Set if we have a locally maintained mtime value, rather than
347
            getting it from the file each time: */
348
 
349
         boolean mtime_set;
350
 
351
         /* File modified time, if mtime_set is true: */
352
 
353
         long mtime;
354
 
355
         /* Reserved for an unimplemented file locking extension.*/
356
 
357
         int ifd;
358
 
359
         /* The format which belongs to the BFD. (object, core, etc.) */
360
 
361
         bfd_format format;
362
 
363
         /* The direction the BFD was opened with*/
364
 
365
         enum bfd_direction {no_direction = 0,
366
                             read_direction = 1,
367
                             write_direction = 2,
368
                             both_direction = 3} direction;
369
 
370
         /* Format_specific flags*/
371
 
372
         flagword flags;
373
 
374
         /* Currently my_archive is tested before adding origin to
375
            anything. I believe that this can become always an add of
376
            origin, with origin set to 0 for non archive files.   */
377
 
378
         file_ptr origin;
379
 
380
         /* Remember when output has begun, to stop strange things
381
            from happening. */
382
         boolean output_has_begun;
383
 
384
         /* Pointer to linked list of sections*/
385
         struct sec  *sections;
386
 
387
         /* The number of sections */
388
         unsigned int section_count;
389
 
390
         /* Stuff only useful for object files:
391
            The start address. */
392
         bfd_vma start_address;
393
 
394
         /* Used for input and output*/
395
         unsigned int symcount;
396
 
397
         /* Symbol table for output BFD (with symcount entries) */
398
         struct symbol_cache_entry  **outsymbols;
399
 
400
         /* Pointer to structure which contains architecture information*/
401
         const struct bfd_arch_info *arch_info;
402
 
403
         /* Stuff only useful for archives:*/
404
         PTR arelt_data;
405
         struct _bfd *my_archive;     /* The containing archive BFD.  */
406
         struct _bfd *next;           /* The next BFD in the archive.  */
407
         struct _bfd *archive_head;   /* The first BFD in the archive.  */
408
         boolean has_armap;
409
 
410
         /* A chain of BFD structures involved in a link.  */
411
         struct _bfd *link_next;
412
 
413
         /* A field used by _bfd_generic_link_add_archive_symbols.  This will
414
            be used only for archive elements.  */
415
         int archive_pass;
416
 
417
         /* Used by the back end to hold private data. */
418
 
419
         union
420
           {
421
           struct aout_data_struct *aout_data;
422
           struct artdata *aout_ar_data;
423
           struct _oasys_data *oasys_obj_data;
424
           struct _oasys_ar_data *oasys_ar_data;
425
           struct coff_tdata *coff_obj_data;
426
           struct pe_tdata *pe_obj_data;
427
           struct xcoff_tdata *xcoff_obj_data;
428
           struct ecoff_tdata *ecoff_obj_data;
429
           struct ieee_data_struct *ieee_data;
430
           struct ieee_ar_data_struct *ieee_ar_data;
431
           struct srec_data_struct *srec_data;
432
           struct ihex_data_struct *ihex_data;
433
           struct tekhex_data_struct *tekhex_data;
434
           struct elf_obj_tdata *elf_obj_data;
435
           struct nlm_obj_tdata *nlm_obj_data;
436
           struct bout_data_struct *bout_data;
437
           struct sun_core_struct *sun_core_data;
438
           struct sco5_core_struct *sco5_core_data;
439
           struct trad_core_struct *trad_core_data;
440
           struct som_data_struct *som_data;
441
           struct hpux_core_struct *hpux_core_data;
442
           struct hppabsd_core_struct *hppabsd_core_data;
443
           struct sgi_core_struct *sgi_core_data;
444
           struct lynx_core_struct *lynx_core_data;
445
           struct osf_core_struct *osf_core_data;
446
           struct cisco_core_struct *cisco_core_data;
447
           struct versados_data_struct *versados_data;
448
           struct netbsd_core_struct *netbsd_core_data;
449
           PTR any;
450
           } tdata;
451
 
452
         /* Used by the application to hold private data*/
453
         PTR usrdata;
454
 
455
       /* Where all the allocated stuff under this BFD goes.  This is a
456
          struct objalloc *, but we use PTR to avoid requiring the inclusion of
457
          objalloc.h.  */
458
         PTR memory;
459
     };
460
 
461
Error reporting
462
===============
463
 
464
   Most BFD functions return nonzero on success (check their individual
465
documentation for precise semantics).  On an error, they call
466
`bfd_set_error' to set an error condition that callers can check by
467
calling `bfd_get_error'.  If that returns `bfd_error_system_call', then
468
check `errno'.
469
 
470
   The easiest way to report a BFD error to the user is to use
471
`bfd_perror'.
472
 
473
Type `bfd_error_type'
474
---------------------
475
 
476
   The values returned by `bfd_get_error' are defined by the enumerated
477
type `bfd_error_type'.
478
 
479
 
480
     typedef enum bfd_error
481
     {
482
       bfd_error_no_error = 0,
483
       bfd_error_system_call,
484
       bfd_error_invalid_target,
485
       bfd_error_wrong_format,
486
       bfd_error_invalid_operation,
487
       bfd_error_no_memory,
488
       bfd_error_no_symbols,
489
       bfd_error_no_armap,
490
       bfd_error_no_more_archived_files,
491
       bfd_error_malformed_archive,
492
       bfd_error_file_not_recognized,
493
       bfd_error_file_ambiguously_recognized,
494
       bfd_error_no_contents,
495
       bfd_error_nonrepresentable_section,
496
       bfd_error_no_debug_section,
497
       bfd_error_bad_value,
498
       bfd_error_file_truncated,
499
       bfd_error_file_too_big,
500
       bfd_error_invalid_error_code
501
     } bfd_error_type;
502
 
503
`bfd_get_error'
504
...............
505
 
506
   *Synopsis*
507
     bfd_error_type bfd_get_error (void);
508
   *Description*
509
Return the current BFD error condition.
510
 
511
`bfd_set_error'
512
...............
513
 
514
   *Synopsis*
515
     void bfd_set_error (bfd_error_type error_tag);
516
   *Description*
517
Set the BFD error condition to be ERROR_TAG.
518
 
519
`bfd_errmsg'
520
............
521
 
522
   *Synopsis*
523
     CONST char *bfd_errmsg (bfd_error_type error_tag);
524
   *Description*
525
Return a string describing the error ERROR_TAG, or the system error if
526
ERROR_TAG is `bfd_error_system_call'.
527
 
528
`bfd_perror'
529
............
530
 
531
   *Synopsis*
532
     void bfd_perror (CONST char *message);
533
   *Description*
534
Print to the standard error stream a string describing the last BFD
535
error that occurred, or the last system error if the last BFD error was
536
a system call failure.  If MESSAGE is non-NULL and non-empty, the error
537
string printed is preceded by MESSAGE, a colon, and a space.  It is
538
followed by a newline.
539
 
540
BFD error handler
541
-----------------
542
 
543
   Some BFD functions want to print messages describing the problem.
544
They call a BFD error handler function.  This function may be overriden
545
by the program.
546
 
547
   The BFD error handler acts like printf.
548
 
549
 
550
     typedef void (*bfd_error_handler_type) PARAMS ((const char *, ...));
551
 
552
`bfd_set_error_handler'
553
.......................
554
 
555
   *Synopsis*
556
     bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
557
   *Description*
558
Set the BFD error handler function.  Returns the previous function.
559
 
560
`bfd_set_error_program_name'
561
............................
562
 
563
   *Synopsis*
564
     void bfd_set_error_program_name (const char *);
565
   *Description*
566
Set the program name to use when printing a BFD error.  This is printed
567
before the error message followed by a colon and space.  The string
568
must not be changed after it is passed to this function.
569
 
570
`bfd_get_error_handler'
571
.......................
572
 
573
   *Synopsis*
574
     bfd_error_handler_type bfd_get_error_handler (void);
575
   *Description*
576
Return the BFD error handler function.
577
 
578
Symbols
579
=======
580
 
581
`bfd_get_reloc_upper_bound'
582
...........................
583
 
584
   *Synopsis*
585
     long bfd_get_reloc_upper_bound(bfd *abfd, asection *sect);
586
   *Description*
587
Return the number of bytes required to store the relocation information
588
associated with section SECT attached to bfd ABFD.  If an error occurs,
589
return -1.
590
 
591
`bfd_canonicalize_reloc'
592
........................
593
 
594
   *Synopsis*
595
     long bfd_canonicalize_reloc
596
        (bfd *abfd,
597
         asection *sec,
598
         arelent **loc,
599
         asymbol **syms);
600
   *Description*
601
Call the back end associated with the open BFD ABFD and translate the
602
external form of the relocation information attached to SEC into the
603
internal canonical form.  Place the table into memory at LOC, which has
604
been preallocated, usually by a call to `bfd_get_reloc_upper_bound'.
605
Returns the number of relocs, or -1 on error.
606
 
607
   The SYMS table is also needed for horrible internal magic reasons.
608
 
609
`bfd_set_reloc'
610
...............
611
 
612
   *Synopsis*
613
     void bfd_set_reloc
614
        (bfd *abfd, asection *sec, arelent **rel, unsigned int count)
615
   *Description*
616
Set the relocation pointer and count within section SEC to the values
617
REL and COUNT.  The argument ABFD is ignored.
618
 
619
`bfd_set_file_flags'
620
....................
621
 
622
   *Synopsis*
623
     boolean bfd_set_file_flags(bfd *abfd, flagword flags);
624
   *Description*
625
Set the flag word in the BFD ABFD to the value FLAGS.
626
 
627
   Possible errors are:
628
   * `bfd_error_wrong_format' - The target bfd was not of object format.
629
 
630
   * `bfd_error_invalid_operation' - The target bfd was open for
631
     reading.
632
 
633
   * `bfd_error_invalid_operation' - The flag word contained a bit
634
     which was not applicable to the type of file.  E.g., an attempt
635
     was made to set the `D_PAGED' bit on a BFD format which does not
636
     support demand paging.
637
 
638
`bfd_get_arch_size'
639
...................
640
 
641
   *Synopsis*
642
     int bfd_get_arch_size (bfd *abfd);
643
   *Description*
644
Returns the architecture address size, in bits, as determined by the
645
object file's format.  For ELF, this information is included in the
646
header.
647
 
648
   *Returns*
649
Returns the arch size in bits if known, `-1' otherwise.
650
 
651
`bfd_get_sign_extend_vma'
652
.........................
653
 
654
   *Synopsis*
655
     int bfd_get_sign_extend_vma (bfd *abfd);
656
   *Description*
657
Indicates if the target architecture "naturally" sign extends an
658
address.  Some architectures implicitly sign extend address values when
659
they are converted to types larger than the size of an address.  For
660
instance, bfd_get_start_address() will return an address sign extended
661
to fill a bfd_vma when this is the case.
662
 
663
   *Returns*
664
Returns `1' if the target architecture is known to sign extend
665
addresses, `0' if the target architecture is known to not sign extend
666
addresses, and `-1' otherwise.
667
 
668
`bfd_set_start_address'
669
.......................
670
 
671
   *Synopsis*
672
     boolean bfd_set_start_address(bfd *abfd, bfd_vma vma);
673
   *Description*
674
Make VMA the entry point of output BFD ABFD.
675
 
676
   *Returns*
677
Returns `true' on success, `false' otherwise.
678
 
679
`bfd_get_mtime'
680
...............
681
 
682
   *Synopsis*
683
     long bfd_get_mtime(bfd *abfd);
684
   *Description*
685
Return the file modification time (as read from the file system, or
686
from the archive header for archive members).
687
 
688
`bfd_get_size'
689
..............
690
 
691
   *Synopsis*
692
     long bfd_get_size(bfd *abfd);
693
   *Description*
694
Return the file size (as read from file system) for the file associated
695
with BFD ABFD.
696
 
697
   The initial motivation for, and use of, this routine is not so we
698
can get the exact size of the object the BFD applies to, since that
699
might not be generally possible (archive members for example).  It
700
would be ideal if someone could eventually modify it so that such
701
results were guaranteed.
702
 
703
   Instead, we want to ask questions like "is this NNN byte sized
704
object I'm about to try read from file offset YYY reasonable?"  As as
705
example of where we might do this, some object formats use string
706
tables for which the first `sizeof (long)' bytes of the table contain
707
the size of the table itself, including the size bytes.  If an
708
application tries to read what it thinks is one of these string tables,
709
without some way to validate the size, and for some reason the size is
710
wrong (byte swapping error, wrong location for the string table, etc.),
711
the only clue is likely to be a read error when it tries to read the
712
table, or a "virtual memory exhausted" error when it tries to allocate
713
15 bazillon bytes of space for the 15 bazillon byte table it is about
714
to read.  This function at least allows us to answer the quesion, "is
715
the size reasonable?".
716
 
717
`bfd_get_gp_size'
718
.................
719
 
720
   *Synopsis*
721
     int bfd_get_gp_size(bfd *abfd);
722
   *Description*
723
Return the maximum size of objects to be optimized using the GP
724
register under MIPS ECOFF.  This is typically set by the `-G' argument
725
to the compiler, assembler or linker.
726
 
727
`bfd_set_gp_size'
728
.................
729
 
730
   *Synopsis*
731
     void bfd_set_gp_size(bfd *abfd, int i);
732
   *Description*
733
Set the maximum size of objects to be optimized using the GP register
734
under ECOFF or MIPS ELF.  This is typically set by the `-G' argument to
735
the compiler, assembler or linker.
736
 
737
`bfd_scan_vma'
738
..............
739
 
740
   *Synopsis*
741
     bfd_vma bfd_scan_vma(CONST char *string, CONST char **end, int base);
742
   *Description*
743
Convert, like `strtoul', a numerical expression STRING into a `bfd_vma'
744
integer, and return that integer.  (Though without as many bells and
745
whistles as `strtoul'.)  The expression is assumed to be unsigned
746
(i.e., positive).  If given a BASE, it is used as the base for
747
conversion.  A base of 0 causes the function to interpret the string in
748
hex if a leading "0x" or "0X" is found, otherwise in octal if a leading
749
zero is found, otherwise in decimal.
750
 
751
   Overflow is not detected.
752
 
753
`bfd_copy_private_bfd_data'
754
...........................
755
 
756
   *Synopsis*
757
     boolean bfd_copy_private_bfd_data(bfd *ibfd, bfd *obfd);
758
   *Description*
759
Copy private BFD information from the BFD IBFD to the the BFD OBFD.
760
Return `true' on success, `false' on error.  Possible error returns are:
761
 
762
   * `bfd_error_no_memory' - Not enough memory exists to create private
763
     data for OBFD.
764
 
765
     #define bfd_copy_private_bfd_data(ibfd, obfd) \
766
          BFD_SEND (obfd, _bfd_copy_private_bfd_data, \
767
                    (ibfd, obfd))
768
 
769
`bfd_merge_private_bfd_data'
770
............................
771
 
772
   *Synopsis*
773
     boolean bfd_merge_private_bfd_data(bfd *ibfd, bfd *obfd);
774
   *Description*
775
Merge private BFD information from the BFD IBFD to the the output file
776
BFD OBFD when linking.  Return `true' on success, `false' on error.
777
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_merge_private_bfd_data(ibfd, obfd) \
783
          BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
784
                    (ibfd, obfd))
785
 
786
`bfd_set_private_flags'
787
.......................
788
 
789
   *Synopsis*
790
     boolean bfd_set_private_flags(bfd *abfd, flagword flags);
791
   *Description*
792
Set private BFD flag information in the BFD ABFD.  Return `true' on
793
success, `false' on error.  Possible error returns are:
794
 
795
   * `bfd_error_no_memory' - Not enough memory exists to create private
796
     data for OBFD.
797
 
798
     #define bfd_set_private_flags(abfd, flags) \
799
          BFD_SEND (abfd, _bfd_set_private_flags, \
800
                    (abfd, flags))
801
 
802
`stuff'
803
.......
804
 
805
   *Description*
806
Stuff which should be documented:
807
     #define bfd_sizeof_headers(abfd, reloc) \
808
          BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
809
 
810
     #define bfd_find_nearest_line(abfd, sec, syms, off, file, func, line) \
811
          BFD_SEND (abfd, _bfd_find_nearest_line,  (abfd, sec, syms, off, file, func, line))
812
 
813
            /* Do these three do anything useful at all, for any back end?  */
814
     #define bfd_debug_info_start(abfd) \
815
             BFD_SEND (abfd, _bfd_debug_info_start, (abfd))
816
 
817
     #define bfd_debug_info_end(abfd) \
818
             BFD_SEND (abfd, _bfd_debug_info_end, (abfd))
819
 
820
     #define bfd_debug_info_accumulate(abfd, section) \
821
             BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
822
 
823
 
824
     #define bfd_stat_arch_elt(abfd, stat) \
825
             BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
826
 
827
     #define bfd_update_armap_timestamp(abfd) \
828
             BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))
829
 
830
     #define bfd_set_arch_mach(abfd, arch, mach)\
831
             BFD_SEND ( abfd, _bfd_set_arch_mach, (abfd, arch, mach))
832
 
833
     #define bfd_relax_section(abfd, section, link_info, again) \
834
            BFD_SEND (abfd, _bfd_relax_section, (abfd, section, link_info, again))
835
 
836
     #define bfd_gc_sections(abfd, link_info) \
837
            BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
838
 
839
     #define bfd_merge_sections(abfd, link_info) \
840
            BFD_SEND (abfd, _bfd_merge_sections, (abfd, link_info))
841
 
842
     #define bfd_link_hash_table_create(abfd) \
843
            BFD_SEND (abfd, _bfd_link_hash_table_create, (abfd))
844
 
845
     #define bfd_link_add_symbols(abfd, info) \
846
            BFD_SEND (abfd, _bfd_link_add_symbols, (abfd, info))
847
 
848
     #define bfd_final_link(abfd, info) \
849
            BFD_SEND (abfd, _bfd_final_link, (abfd, info))
850
 
851
     #define bfd_free_cached_info(abfd) \
852
            BFD_SEND (abfd, _bfd_free_cached_info, (abfd))
853
 
854
     #define bfd_get_dynamic_symtab_upper_bound(abfd) \
855
            BFD_SEND (abfd, _bfd_get_dynamic_symtab_upper_bound, (abfd))
856
 
857
     #define bfd_print_private_bfd_data(abfd, file)\
858
            BFD_SEND (abfd, _bfd_print_private_bfd_data, (abfd, file))
859
 
860
     #define bfd_canonicalize_dynamic_symtab(abfd, asymbols) \
861
            BFD_SEND (abfd, _bfd_canonicalize_dynamic_symtab, (abfd, asymbols))
862
 
863
     #define bfd_get_dynamic_reloc_upper_bound(abfd) \
864
            BFD_SEND (abfd, _bfd_get_dynamic_reloc_upper_bound, (abfd))
865
 
866
     #define bfd_canonicalize_dynamic_reloc(abfd, arels, asyms) \
867
            BFD_SEND (abfd, _bfd_canonicalize_dynamic_reloc, (abfd, arels, asyms))
868
 
869
     extern bfd_byte *bfd_get_relocated_section_contents
870
            PARAMS ((bfd *, struct bfd_link_info *,
871
                      struct bfd_link_order *, bfd_byte *,
872
                      boolean, asymbol **));
873
 
874
* Menu:
875
 
876
* Memory Usage::
877
* Initialization::
878
* Sections::
879
* Symbols::
880
* Archives::
881
* Formats::
882
* Relocations::
883
* Core Files::
884
* Targets::
885
* Architectures::
886
* Opening and Closing::
887
* Internal::
888
* File Caching::
889
* Linker Functions::
890
* Hash Tables::
891
 
892

893
File: bfd.info,  Node: Memory Usage,  Next: Initialization,  Prev: BFD front end,  Up: BFD front end
894
 
895
Memory usage
896
============
897
 
898
   BFD keeps all of its internal structures in obstacks. There is one
899
obstack per open BFD file, into which the current state is stored. When
900
a BFD is closed, the obstack is deleted, and so everything which has
901
been allocated by BFD for the closing file is thrown away.
902
 
903
   BFD does not free anything created by an application, but pointers
904
into `bfd' structures become invalid on a `bfd_close'; for example,
905
after a `bfd_close' the vector passed to `bfd_canonicalize_symtab' is
906
still around, since it has been allocated by the application, but the
907
data that it pointed to are lost.
908
 
909
   The general rule is to not close a BFD until all operations dependent
910
upon data from the BFD have been completed, or all the data from within
911
the file has been copied. To help with the management of memory, there
912
is a function (`bfd_alloc_size') which returns the number of bytes in
913
obstacks associated with the supplied BFD. This could be used to select
914
the greediest open BFD, close it to reclaim the memory, perform some
915
operation and reopen the BFD again, to get a fresh copy of the data
916
structures.
917
 
918

919
File: bfd.info,  Node: Initialization,  Next: Sections,  Prev: Memory Usage,  Up: BFD front end
920
 
921
Initialization
922
==============
923
 
924
   These are the functions that handle initializing a BFD.
925
 
926
`bfd_init'
927
..........
928
 
929
   *Synopsis*
930
     void bfd_init(void);
931
   *Description*
932
This routine must be called before any other BFD function to initialize
933
magical internal data structures.
934
 
935

936
File: bfd.info,  Node: Sections,  Next: Symbols,  Prev: Initialization,  Up: BFD front end
937
 
938
Sections
939
========
940
 
941
   The raw data contained within a BFD is maintained through the
942
section abstraction.  A single BFD may have any number of sections.  It
943
keeps hold of them by pointing to the first; each one points to the
944
next in the list.
945
 
946
   Sections are supported in BFD in `section.c'.
947
 
948
* Menu:
949
 
950
* Section Input::
951
* Section Output::
952
* typedef asection::
953
* section prototypes::
954
 
955

956
File: bfd.info,  Node: Section Input,  Next: Section Output,  Prev: Sections,  Up: Sections
957
 
958
Section input
959
-------------
960
 
961
   When a BFD is opened for reading, the section structures are created
962
and attached to the BFD.
963
 
964
   Each section has a name which describes the section in the outside
965
world--for example, `a.out' would contain at least three sections,
966
called `.text', `.data' and `.bss'.
967
 
968
   Names need not be unique; for example a COFF file may have several
969
sections named `.data'.
970
 
971
   Sometimes a BFD will contain more than the "natural" number of
972
sections. A back end may attach other sections containing constructor
973
data, or an application may add a section (using `bfd_make_section') to
974
the sections attached to an already open BFD. For example, the linker
975
creates an extra section `COMMON' for each input file's BFD to hold
976
information about common storage.
977
 
978
   The raw data is not necessarily read in when the section descriptor
979
is created. Some targets may leave the data in place until a
980
`bfd_get_section_contents' call is made. Other back ends may read in
981
all the data at once.  For example, an S-record file has to be read
982
once to determine the size of the data. An IEEE-695 file doesn't
983
contain raw data in sections, but data and relocation expressions
984
intermixed, so the data area has to be parsed to get out the data and
985
relocations.
986
 
987

988
File: bfd.info,  Node: Section Output,  Next: typedef asection,  Prev: Section Input,  Up: Sections
989
 
990
Section output
991
--------------
992
 
993
   To write a new object style BFD, the various sections to be written
994
have to be created. They are attached to the BFD in the same way as
995
input sections; data is written to the sections using
996
`bfd_set_section_contents'.
997
 
998
   Any program that creates or combines sections (e.g., the assembler
999
and linker) must use the `asection' fields `output_section' and
1000
`output_offset' to indicate the file sections to which each section
1001
must be written.  (If the section is being created from scratch,
1002
`output_section' should probably point to the section itself and
1003
`output_offset' should probably be zero.)
1004
 
1005
   The data to be written comes from input sections attached (via
1006
`output_section' pointers) to the output sections.  The output section
1007
structure can be considered a filter for the input section: the output
1008
section determines the vma of the output data and the name, but the
1009
input section determines the offset into the output section of the data
1010
to be written.
1011
 
1012
   E.g., to create a section "O", starting at 0x100, 0x123 long,
1013
containing two subsections, "A" at offset 0x0 (i.e., at vma 0x100) and
1014
"B" at offset 0x20 (i.e., at vma 0x120) the `asection' structures would
1015
look like:
1016
 
1017
        section name          "A"
1018
          output_offset   0x00
1019
          size            0x20
1020
          output_section ----------->  section name    "O"
1021
                                  |    vma             0x100
1022
        section name          "B" |    size            0x123
1023
          output_offset   0x20    |
1024
          size            0x103   |
1025
          output_section  --------|
1026
 
1027
Link orders
1028
-----------
1029
 
1030
   The data within a section is stored in a "link_order".  These are
1031
much like the fixups in `gas'.  The link_order abstraction allows a
1032
section to grow and shrink within itself.
1033
 
1034
   A link_order knows how big it is, and which is the next link_order
1035
and where the raw data for it is; it also points to a list of
1036
relocations which apply to it.
1037
 
1038
   The link_order is used by the linker to perform relaxing on final
1039
code.  The compiler creates code which is as big as necessary to make
1040
it work without relaxing, and the user can select whether to relax.
1041
Sometimes relaxing takes a lot of time.  The linker runs around the
1042
relocations to see if any are attached to data which can be shrunk, if
1043
so it does it on a link_order by link_order basis.
1044
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.