| 1 | This is bfd.info, produced by makeinfo version 4.3 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, 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
 | 
|---|
| 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 |        /* 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 | 
 | 
|---|
| 471 | Error reporting
 | 
|---|
| 472 | ===============
 | 
|---|
| 473 | 
 | 
|---|
| 474 |    Most BFD functions return nonzero on success (check their individual
 | 
|---|
| 475 | documentation for precise semantics).  On an error, they call
 | 
|---|
| 476 | `bfd_set_error' to set an error condition that callers can check by
 | 
|---|
| 477 | calling `bfd_get_error'.  If that returns `bfd_error_system_call', then
 | 
|---|
| 478 | check `errno'.
 | 
|---|
| 479 | 
 | 
|---|
| 480 |    The easiest way to report a BFD error to the user is to use
 | 
|---|
| 481 | `bfd_perror'.
 | 
|---|
| 482 | 
 | 
|---|
| 483 | Type `bfd_error_type'
 | 
|---|
| 484 | ---------------------
 | 
|---|
| 485 | 
 | 
|---|
| 486 |    The values returned by `bfd_get_error' are defined by the enumerated
 | 
|---|
| 487 | type `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*
 | 
|---|
| 521 | Return 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*
 | 
|---|
| 529 | Set 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*
 | 
|---|
| 537 | Return a string describing the error ERROR_TAG, or the system error if
 | 
|---|
| 538 | ERROR_TAG is `bfd_error_system_call'.
 | 
|---|
| 539 | 
 | 
|---|
| 540 | `bfd_perror'
 | 
|---|
| 541 | ............
 | 
|---|
| 542 | 
 | 
|---|
| 543 |    *Synopsis*
 | 
|---|
| 544 |      void bfd_perror (const char *message);
 | 
|---|
| 545 |    *Description*
 | 
|---|
| 546 | Print to the standard error stream a string describing the last BFD
 | 
|---|
| 547 | error that occurred, or the last system error if the last BFD error was
 | 
|---|
| 548 | a system call failure.  If MESSAGE is non-NULL and non-empty, the error
 | 
|---|
| 549 | string printed is preceded by MESSAGE, a colon, and a space.  It is
 | 
|---|
| 550 | followed by a newline.
 | 
|---|
| 551 | 
 | 
|---|
| 552 | BFD error handler
 | 
|---|
| 553 | -----------------
 | 
|---|
| 554 | 
 | 
|---|
| 555 |    Some BFD functions want to print messages describing the problem.
 | 
|---|
| 556 | They call a BFD error handler function.  This function may be overriden
 | 
|---|
| 557 | by 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*
 | 
|---|
| 570 | Set 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*
 | 
|---|
| 578 | Set the program name to use when printing a BFD error.  This is printed
 | 
|---|
| 579 | before the error message followed by a colon and space.  The string
 | 
|---|
| 580 | must 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*
 | 
|---|
| 588 | Return the BFD error handler function.
 | 
|---|
| 589 | 
 | 
|---|
| 590 | `bfd_archive_filename'
 | 
|---|
| 591 | ......................
 | 
|---|
| 592 | 
 | 
|---|
| 593 |    *Synopsis*
 | 
|---|
| 594 |      const char *bfd_archive_filename (bfd *);
 | 
|---|
| 595 |    *Description*
 | 
|---|
| 596 | For a BFD that is a component of an archive, returns a string with both
 | 
|---|
| 597 | the archive name and file name.  For other BFDs, just returns the file
 | 
|---|
| 598 | name.
 | 
|---|
| 599 | 
 | 
|---|
| 600 | Symbols
 | 
|---|
| 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*
 | 
|---|
| 609 | Return the number of bytes required to store the relocation information
 | 
|---|
| 610 | associated with section SECT attached to bfd ABFD.  If an error occurs,
 | 
|---|
| 611 | return -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*
 | 
|---|
| 623 | Call the back end associated with the open BFD ABFD and translate the
 | 
|---|
| 624 | external form of the relocation information attached to SEC into the
 | 
|---|
| 625 | internal canonical form.  Place the table into memory at LOC, which has
 | 
|---|
| 626 | been preallocated, usually by a call to `bfd_get_reloc_upper_bound'.
 | 
|---|
| 627 | Returns 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*
 | 
|---|
| 638 | Set the relocation pointer and count within section SEC to the values
 | 
|---|
| 639 | REL 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*
 | 
|---|
| 647 | Set 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*
 | 
|---|
| 666 | Returns the architecture address size, in bits, as determined by the
 | 
|---|
| 667 | object file's format.  For ELF, this information is included in the
 | 
|---|
| 668 | header.
 | 
|---|
| 669 | 
 | 
|---|
| 670 |    *Returns*
 | 
|---|
| 671 | Returns 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*
 | 
|---|
| 679 | Indicates if the target architecture "naturally" sign extends an
 | 
|---|
| 680 | address.  Some architectures implicitly sign extend address values when
 | 
|---|
| 681 | they are converted to types larger than the size of an address.  For
 | 
|---|
| 682 | instance, bfd_get_start_address() will return an address sign extended
 | 
|---|
| 683 | to fill a bfd_vma when this is the case.
 | 
|---|
| 684 | 
 | 
|---|
| 685 |    *Returns*
 | 
|---|
| 686 | Returns `1' if the target architecture is known to sign extend
 | 
|---|
| 687 | addresses, `0' if the target architecture is known to not sign extend
 | 
|---|
| 688 | addresses, 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*
 | 
|---|
| 696 | Make VMA the entry point of output BFD ABFD.
 | 
|---|
| 697 | 
 | 
|---|
| 698 |    *Returns*
 | 
|---|
| 699 | Returns `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*
 | 
|---|
| 707 | Return the maximum size of objects to be optimized using the GP
 | 
|---|
| 708 | register under MIPS ECOFF.  This is typically set by the `-G' argument
 | 
|---|
| 709 | to 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*
 | 
|---|
| 717 | Set the maximum size of objects to be optimized using the GP register
 | 
|---|
| 718 | under ECOFF or MIPS ELF.  This is typically set by the `-G' argument to
 | 
|---|
| 719 | the 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*
 | 
|---|
| 727 | Convert, like `strtoul', a numerical expression STRING into a `bfd_vma'
 | 
|---|
| 728 | integer, and return that integer.  (Though without as many bells and
 | 
|---|
| 729 | whistles as `strtoul'.)  The expression is assumed to be unsigned
 | 
|---|
| 730 | (i.e., positive).  If given a BASE, it is used as the base for
 | 
|---|
| 731 | conversion.  A base of 0 causes the function to interpret the string in
 | 
|---|
| 732 | hex if a leading "0x" or "0X" is found, otherwise in octal if a leading
 | 
|---|
| 733 | zero 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*
 | 
|---|
| 743 | Copy private BFD information from the BFD IBFD to the the BFD OBFD.
 | 
|---|
| 744 | Return `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*
 | 
|---|
| 759 | Merge private BFD information from the BFD IBFD to the the output file
 | 
|---|
| 760 | BFD OBFD when linking.  Return `TRUE' on success, `FALSE' on error.
 | 
|---|
| 761 | Possible 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*
 | 
|---|
| 776 | Set private BFD flag information in the BFD ABFD.  Return `TRUE' on
 | 
|---|
| 777 | success, `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*
 | 
|---|
| 789 | The 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*
 | 
|---|
| 871 | When more than one machine code number is available for the same
 | 
|---|
| 872 | machine type, this function can be used to switch between the preferred
 | 
|---|
| 873 | one (alternative == 0) and any others.  Currently, only ELF supports
 | 
|---|
| 874 | this 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*
 | 
|---|
| 894 | When testing an object for compatibility with a particular target
 | 
|---|
| 895 | back-end, the back-end object_p function needs to set up certain fields
 | 
|---|
| 896 | in the bfd on successfully recognizing the object.  This typically
 | 
|---|
| 897 | happens in a piecemeal fashion, with failures possible at many points.
 | 
|---|
| 898 | On failure, the bfd is supposed to be restored to its initial state,
 | 
|---|
| 899 | which is virtually impossible.  However, restoring a subset of the bfd
 | 
|---|
| 900 | state works in practice.  This function stores the subset and
 | 
|---|
| 901 | reinitializes the bfd.
 | 
|---|
| 902 | 
 | 
|---|
| 903 | `bfd_preserve_restore'
 | 
|---|
| 904 | ......................
 | 
|---|
| 905 | 
 | 
|---|
| 906 |    *Synopsis*
 | 
|---|
| 907 |      void bfd_preserve_restore (bfd *, struct bfd_preserve *);
 | 
|---|
| 908 |    *Description*
 | 
|---|
| 909 | This function restores bfd state saved by bfd_preserve_save.  If MARKER
 | 
|---|
| 910 | is non-NULL in struct bfd_preserve then that block and all subsequently
 | 
|---|
| 911 | bfd_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*
 | 
|---|
| 919 | This function should be called when the bfd state saved by
 | 
|---|
| 920 | bfd_preserve_save is no longer needed.  ie. when the back-end object_p
 | 
|---|
| 921 | function returns with success.
 | 
|---|
| 922 | 
 | 
|---|
| 923 | `bfd_get_mtime'
 | 
|---|
| 924 | ...............
 | 
|---|
| 925 | 
 | 
|---|
| 926 |    *Synopsis*
 | 
|---|
| 927 |      long bfd_get_mtime(bfd *abfd);
 | 
|---|
| 928 |    *Description*
 | 
|---|
| 929 | Return the file modification time (as read from the file system, or
 | 
|---|
| 930 | from the archive header for archive members).
 | 
|---|
| 931 | 
 | 
|---|
| 932 | `bfd_get_size'
 | 
|---|
| 933 | ..............
 | 
|---|
| 934 | 
 | 
|---|
| 935 |    *Synopsis*
 | 
|---|
| 936 |      long bfd_get_size(bfd *abfd);
 | 
|---|
| 937 |    *Description*
 | 
|---|
| 938 | Return the file size (as read from file system) for the file associated
 | 
|---|
| 939 | with BFD ABFD.
 | 
|---|
| 940 | 
 | 
|---|
| 941 |    The initial motivation for, and use of, this routine is not so we
 | 
|---|
| 942 | can get the exact size of the object the BFD applies to, since that
 | 
|---|
| 943 | might not be generally possible (archive members for example).  It
 | 
|---|
| 944 | would be ideal if someone could eventually modify it so that such
 | 
|---|
| 945 | results were guaranteed.
 | 
|---|
| 946 | 
 | 
|---|
| 947 |    Instead, we want to ask questions like "is this NNN byte sized
 | 
|---|
| 948 | object I'm about to try read from file offset YYY reasonable?"  As as
 | 
|---|
| 949 | example of where we might do this, some object formats use string
 | 
|---|
| 950 | tables for which the first `sizeof (long)' bytes of the table contain
 | 
|---|
| 951 | the size of the table itself, including the size bytes.  If an
 | 
|---|
| 952 | application tries to read what it thinks is one of these string tables,
 | 
|---|
| 953 | without some way to validate the size, and for some reason the size is
 | 
|---|
| 954 | wrong (byte swapping error, wrong location for the string table, etc.),
 | 
|---|
| 955 | the only clue is likely to be a read error when it tries to read the
 | 
|---|
| 956 | table, or a "virtual memory exhausted" error when it tries to allocate
 | 
|---|
| 957 | 15 bazillon bytes of space for the 15 bazillon byte table it is about
 | 
|---|
| 958 | to read.  This function at least allows us to answer the quesion, "is
 | 
|---|
| 959 | the 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 | 
 | 
|---|
| 980 | File: bfd.info,  Node: Memory Usage,  Next: Initialization,  Prev: BFD front end,  Up: BFD front end
 | 
|---|
| 981 | 
 | 
|---|
| 982 | Memory Usage
 | 
|---|
| 983 | ============
 | 
|---|
| 984 | 
 | 
|---|
| 985 |    BFD keeps all of its internal structures in obstacks. There is one
 | 
|---|
| 986 | obstack per open BFD file, into which the current state is stored. When
 | 
|---|
| 987 | a BFD is closed, the obstack is deleted, and so everything which has
 | 
|---|
| 988 | been allocated by BFD for the closing file is thrown away.
 | 
|---|
| 989 | 
 | 
|---|
| 990 |    BFD does not free anything created by an application, but pointers
 | 
|---|
| 991 | into `bfd' structures become invalid on a `bfd_close'; for example,
 | 
|---|
| 992 | after a `bfd_close' the vector passed to `bfd_canonicalize_symtab' is
 | 
|---|
| 993 | still around, since it has been allocated by the application, but the
 | 
|---|
| 994 | data that it pointed to are lost.
 | 
|---|
| 995 | 
 | 
|---|
| 996 |    The general rule is to not close a BFD until all operations dependent
 | 
|---|
| 997 | upon data from the BFD have been completed, or all the data from within
 | 
|---|
| 998 | the file has been copied. To help with the management of memory, there
 | 
|---|
| 999 | is a function (`bfd_alloc_size') which returns the number of bytes in
 | 
|---|
| 1000 | obstacks associated with the supplied BFD. This could be used to select
 | 
|---|
| 1001 | the greediest open BFD, close it to reclaim the memory, perform some
 | 
|---|
| 1002 | operation and reopen the BFD again, to get a fresh copy of the data
 | 
|---|
| 1003 | structures.
 | 
|---|
| 1004 | 
 | 
|---|
| 1005 | 
 | 
|---|
| 1006 | File: bfd.info,  Node: Initialization,  Next: Sections,  Prev: Memory Usage,  Up: BFD front end
 | 
|---|
| 1007 | 
 | 
|---|
| 1008 | Initialization
 | 
|---|
| 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*
 | 
|---|
| 1019 | This routine must be called before any other BFD function to initialize
 | 
|---|
| 1020 | magical internal data structures.
 | 
|---|
| 1021 | 
 | 
|---|
| 1022 | 
 | 
|---|
| 1023 | File: bfd.info,  Node: Sections,  Next: Symbols,  Prev: Initialization,  Up: BFD front end
 | 
|---|
| 1024 | 
 | 
|---|
| 1025 | Sections
 | 
|---|
| 1026 | ========
 | 
|---|
| 1027 | 
 | 
|---|
| 1028 |    The raw data contained within a BFD is maintained through the
 | 
|---|
| 1029 | section abstraction.  A single BFD may have any number of sections.  It
 | 
|---|
| 1030 | keeps hold of them by pointing to the first; each one points to the
 | 
|---|
| 1031 | next 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 | 
 | 
|---|
| 1043 | File: bfd.info,  Node: Section Input,  Next: Section Output,  Prev: Sections,  Up: Sections
 | 
|---|
| 1044 | 
 | 
|---|
| 1045 | Section input
 | 
|---|
| 1046 | -------------
 | 
|---|
| 1047 | 
 | 
|---|
| 1048 |    When a BFD is opened for reading, the section structures are created
 | 
|---|
| 1049 | and attached to the BFD.
 | 
|---|
| 1050 | 
 | 
|---|
| 1051 |    Each section has a name which describes the section in the outside
 | 
|---|
| 1052 | world--for example, `a.out' would contain at least three sections,
 | 
|---|
| 1053 | called `.text', `.data' and `.bss'.
 | 
|---|
| 1054 | 
 | 
|---|
| 1055 |    Names need not be unique; for example a COFF file may have several
 | 
|---|
| 1056 | sections named `.data'.
 | 
|---|
| 1057 | 
 | 
|---|
| 1058 |    Sometimes a BFD will contain more than the "natural" number of
 | 
|---|
| 1059 | sections. A back end may attach other sections containing constructor
 | 
|---|
| 1060 | data, or an application may add a section (using `bfd_make_section') to
 | 
|---|
| 1061 | the sections attached to an already open BFD. For example, the linker
 | 
|---|
| 1062 | creates an extra section `COMMON' for each input file's BFD to hold
 | 
|---|
| 1063 | information about common storage.
 | 
|---|
| 1064 | 
 | 
|---|
| 1065 |    The raw data is not necessarily read in when the section descriptor
 | 
|---|
| 1066 | is 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
 | 
|---|
| 1068 | all the data at once.  For example, an S-record file has to be read
 | 
|---|
| 1069 | once to determine the size of the data. An IEEE-695 file doesn't
 | 
|---|
| 1070 | contain raw data in sections, but data and relocation expressions
 | 
|---|
| 1071 | intermixed, so the data area has to be parsed to get out the data and
 | 
|---|
| 1072 | relocations.
 | 
|---|
| 1073 | 
 | 
|---|
| 1074 | 
 | 
|---|
| 1075 | File: bfd.info,  Node: Section Output,  Next: typedef asection,  Prev: Section Input,  Up: Sections
 | 
|---|
| 1076 | 
 | 
|---|
| 1077 | Section output
 | 
|---|
| 1078 | --------------
 | 
|---|
| 1079 | 
 | 
|---|
| 1080 |    To write a new object style BFD, the various sections to be written
 | 
|---|
| 1081 | have to be created. They are attached to the BFD in the same way as
 | 
|---|
| 1082 | input 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
 | 
|---|
| 1086 | and linker) must use the `asection' fields `output_section' and
 | 
|---|
| 1087 | `output_offset' to indicate the file sections to which each section
 | 
|---|
| 1088 | must 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
 | 
|---|
| 1094 | structure can be considered a filter for the input section: the output
 | 
|---|
| 1095 | section determines the vma of the output data and the name, but the
 | 
|---|
| 1096 | input section determines the offset into the output section of the data
 | 
|---|
| 1097 | to be written.
 | 
|---|
| 1098 | 
 | 
|---|
| 1099 |    E.g., to create a section "O", starting at 0x100, 0x123 long,
 | 
|---|
| 1100 | containing 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
 | 
|---|
| 1102 | look 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 | 
 | 
|---|
| 1114 | Link orders
 | 
|---|
| 1115 | -----------
 | 
|---|
| 1116 | 
 | 
|---|
| 1117 |    The data within a section is stored in a "link_order".  These are
 | 
|---|
| 1118 | much like the fixups in `gas'.  The link_order abstraction allows a
 | 
|---|
| 1119 | section to grow and shrink within itself.
 | 
|---|
| 1120 | 
 | 
|---|
| 1121 |    A link_order knows how big it is, and which is the next link_order
 | 
|---|
| 1122 | and where the raw data for it is; it also points to a list of
 | 
|---|
| 1123 | relocations which apply to it.
 | 
|---|
| 1124 | 
 | 
|---|
| 1125 |    The link_order is used by the linker to perform relaxing on final
 | 
|---|
| 1126 | code.  The compiler creates code which is as big as necessary to make
 | 
|---|
| 1127 | it work without relaxing, and the user can select whether to relax.
 | 
|---|
| 1128 | Sometimes relaxing takes a lot of time.  The linker runs around the
 | 
|---|
| 1129 | relocations to see if any are attached to data which can be shrunk, if
 | 
|---|
| 1130 | so it does it on a link_order by link_order basis.
 | 
|---|
| 1131 | 
 | 
|---|