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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.3/] [bfd/] [doc/] [bfd.info-1] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

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

924
File: bfd.info,  Node: Memory Usage,  Next: Initialization,  Prev: BFD front end,  Up: BFD front end
925
 
926
Memory usage
927
============
928
 
929
   BFD keeps all of its internal structures in obstacks. There is one
930
obstack per open BFD file, into which the current state is stored. When
931
a BFD is closed, the obstack is deleted, and so everything which has
932
been allocated by BFD for the closing file is thrown away.
933
 
934
   BFD does not free anything created by an application, but pointers
935
into `bfd' structures become invalid on a `bfd_close'; for example,
936
after a `bfd_close' the vector passed to `bfd_canonicalize_symtab' is
937
still around, since it has been allocated by the application, but the
938
data that it pointed to are lost.
939
 
940
   The general rule is to not close a BFD until all operations dependent
941
upon data from the BFD have been completed, or all the data from within
942
the file has been copied. To help with the management of memory, there
943
is a function (`bfd_alloc_size') which returns the number of bytes in
944
obstacks associated with the supplied BFD. This could be used to select
945
the greediest open BFD, close it to reclaim the memory, perform some
946
operation and reopen the BFD again, to get a fresh copy of the data
947
structures.
948
 
949

950
File: bfd.info,  Node: Initialization,  Next: Sections,  Prev: Memory Usage,  Up: BFD front end
951
 
952
Initialization
953
==============
954
 
955
   These are the functions that handle initializing a BFD.
956
 
957
`bfd_init'
958
..........
959
 
960
   *Synopsis*
961
     void bfd_init(void);
962
   *Description*
963
This routine must be called before any other BFD function to initialize
964
magical internal data structures.
965
 
966

967
File: bfd.info,  Node: Sections,  Next: Symbols,  Prev: Initialization,  Up: BFD front end
968
 
969
Sections
970
========
971
 
972
   The raw data contained within a BFD is maintained through the
973
section abstraction.  A single BFD may have any number of sections.  It
974
keeps hold of them by pointing to the first; each one points to the
975
next in the list.
976
 
977
   Sections are supported in BFD in `section.c'.
978
 
979
* Menu:
980
 
981
* Section Input::
982
* Section Output::
983
* typedef asection::
984
* section prototypes::
985
 
986

987
File: bfd.info,  Node: Section Input,  Next: Section Output,  Prev: Sections,  Up: Sections
988
 
989
Section input
990
-------------
991
 
992
   When a BFD is opened for reading, the section structures are created
993
and attached to the BFD.
994
 
995
   Each section has a name which describes the section in the outside
996
world--for example, `a.out' would contain at least three sections,
997
called `.text', `.data' and `.bss'.
998
 
999
   Names need not be unique; for example a COFF file may have several
1000
sections named `.data'.
1001
 
1002
   Sometimes a BFD will contain more than the "natural" number of
1003
sections. A back end may attach other sections containing constructor
1004
data, or an application may add a section (using `bfd_make_section') to
1005
the sections attached to an already open BFD. For example, the linker
1006
creates an extra section `COMMON' for each input file's BFD to hold
1007
information about common storage.
1008
 
1009
   The raw data is not necessarily read in when the section descriptor
1010
is created. Some targets may leave the data in place until a
1011
`bfd_get_section_contents' call is made. Other back ends may read in
1012
all the data at once.  For example, an S-record file has to be read
1013
once to determine the size of the data. An IEEE-695 file doesn't
1014
contain raw data in sections, but data and relocation expressions
1015
intermixed, so the data area has to be parsed to get out the data and
1016
relocations.
1017
 
1018

1019
File: bfd.info,  Node: Section Output,  Next: typedef asection,  Prev: Section Input,  Up: Sections
1020
 
1021
Section output
1022
--------------
1023
 
1024
   To write a new object style BFD, the various sections to be written
1025
have to be created. They are attached to the BFD in the same way as
1026
input sections; data is written to the sections using
1027
`bfd_set_section_contents'.
1028
 
1029
   Any program that creates or combines sections (e.g., the assembler
1030
and linker) must use the `asection' fields `output_section' and
1031
`output_offset' to indicate the file sections to which each section
1032
must be written.  (If the section is being created from scratch,
1033
`output_section' should probably point to the section itself and
1034
`output_offset' should probably be zero.)
1035
 
1036
   The data to be written comes from input sections attached (via
1037
`output_section' pointers) to the output sections.  The output section
1038
structure can be considered a filter for the input section: the output
1039
section determines the vma of the output data and the name, but the
1040
input section determines the offset into the output section of the data
1041
to be written.
1042
 
1043
   E.g., to create a section "O", starting at 0x100, 0x123 long,
1044
containing two subsections, "A" at offset 0x0 (i.e., at vma 0x100) and
1045
"B" at offset 0x20 (i.e., at vma 0x120) the `asection' structures would
1046
look like:
1047
 
1048
        section name          "A"
1049
          output_offset   0x00
1050
          size            0x20
1051
          output_section ----------->  section name    "O"
1052
                                  |    vma             0x100
1053
        section name          "B" |    size            0x123
1054
          output_offset   0x20    |
1055
          size            0x103   |
1056
          output_section  --------|
1057
 
1058
Link orders
1059
-----------
1060
 
1061
   The data within a section is stored in a "link_order".  These are
1062
much like the fixups in `gas'.  The link_order abstraction allows a
1063
section to grow and shrink within itself.
1064
 
1065
   A link_order knows how big it is, and which is the next link_order
1066
and where the raw data for it is; it also points to a list of
1067
relocations which apply to it.
1068
 
1069
   The link_order is used by the linker to perform relaxing on final
1070
code.  The compiler creates code which is as big as necessary to make
1071
it work without relaxing, and the user can select whether to relax.
1072
Sometimes relaxing takes a lot of time.  The linker runs around the
1073
relocations to see if any are attached to data which can be shrunk, if
1074
so it does it on a link_order by link_order basis.
1075
 

powered by: WebSVN 2.1.0

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