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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [bfd/] [doc/] [bfdt.texi] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
@section @code{typedef bfd}
2
A BFD has type @code{bfd}; objects of this type are the
3
cornerstone of any application using BFD. Using BFD
4
consists of making references though the BFD and to data in the BFD.
5
 
6
Here is the structure that defines the type @code{bfd}.  It
7
contains the major data about the file and pointers
8
to the rest of the data.
9
 
10
 
11
@example
12
 
13
struct _bfd
14
@{
15
    /* The filename the application opened the BFD with.  */
16
    CONST char *filename;
17
 
18
    /* A pointer to the target jump table.             */
19
    const struct bfd_target *xvec;
20
 
21
    /* To avoid dragging too many header files into every file that
22
       includes `@code{bfd.h}', IOSTREAM has been declared as a "char
23
       *", and MTIME as a "long".  Their correct types, to which they
24
       are cast when used, are "FILE *" and "time_t".    The iostream
25
       is the result of an fopen on the filename.  However, if the
26
       BFD_IN_MEMORY flag is set, then iostream is actually a pointer
27
       to a bfd_in_memory struct.  */
28
    PTR iostream;
29
 
30
    /* Is the file descriptor being cached?  That is, can it be closed as
31
       needed, and re-opened when accessed later?  */
32
 
33
    boolean cacheable;
34
 
35
    /* Marks whether there was a default target specified when the
36
       BFD was opened. This is used to select which matching algorithm
37
       to use to choose the back end. */
38
 
39
    boolean target_defaulted;
40
 
41
    /* The caching routines use these to maintain a
42
       least-recently-used list of BFDs */
43
 
44
    struct _bfd *lru_prev, *lru_next;
45
 
46
    /* When a file is closed by the caching routines, BFD retains
47
       state information on the file here: */
48
 
49
    file_ptr where;
50
 
51
    /* and here: (``once'' means at least once) */
52
 
53
    boolean opened_once;
54
 
55
    /* Set if we have a locally maintained mtime value, rather than
56
       getting it from the file each time: */
57
 
58
    boolean mtime_set;
59
 
60
    /* File modified time, if mtime_set is true: */
61
 
62
    long mtime;
63
 
64
    /* Reserved for an unimplemented file locking extension.*/
65
 
66
    int ifd;
67
 
68
    /* The format which belongs to the BFD. (object, core, etc.) */
69
 
70
    bfd_format format;
71
 
72
    /* The direction the BFD was opened with*/
73
 
74
    enum bfd_direction @{no_direction = 0,
75
                        read_direction = 1,
76
                        write_direction = 2,
77
                        both_direction = 3@} direction;
78
 
79
    /* Format_specific flags*/
80
 
81
    flagword flags;
82
 
83
    /* Currently my_archive is tested before adding origin to
84
       anything. I believe that this can become always an add of
85
       origin, with origin set to 0 for non archive files.   */
86
 
87
    file_ptr origin;
88
 
89
    /* Remember when output has begun, to stop strange things
90
       from happening. */
91
    boolean output_has_begun;
92
 
93
    /* Pointer to linked list of sections*/
94
    struct sec  *sections;
95
 
96
    /* The number of sections */
97
    unsigned int section_count;
98
 
99
    /* Stuff only useful for object files:
100
       The start address. */
101
    bfd_vma start_address;
102
 
103
    /* Used for input and output*/
104
    unsigned int symcount;
105
 
106
    /* Symbol table for output BFD (with symcount entries) */
107
    struct symbol_cache_entry  **outsymbols;
108
 
109
    /* Pointer to structure which contains architecture information*/
110
    const struct bfd_arch_info *arch_info;
111
 
112
    /* Stuff only useful for archives:*/
113
    PTR arelt_data;
114
    struct _bfd *my_archive;     /* The containing archive BFD.  */
115
    struct _bfd *next;           /* The next BFD in the archive.  */
116
    struct _bfd *archive_head;   /* The first BFD in the archive.  */
117
    boolean has_armap;
118
 
119
    /* A chain of BFD structures involved in a link.  */
120
    struct _bfd *link_next;
121
 
122
    /* A field used by _bfd_generic_link_add_archive_symbols.  This will
123
       be used only for archive elements.  */
124
    int archive_pass;
125
 
126
    /* Used by the back end to hold private data. */
127
 
128
    union
129
      @{
130
      struct aout_data_struct *aout_data;
131
      struct artdata *aout_ar_data;
132
      struct _oasys_data *oasys_obj_data;
133
      struct _oasys_ar_data *oasys_ar_data;
134
      struct coff_tdata *coff_obj_data;
135
      struct pe_tdata *pe_obj_data;
136
      struct xcoff_tdata *xcoff_obj_data;
137
      struct ecoff_tdata *ecoff_obj_data;
138
      struct ieee_data_struct *ieee_data;
139
      struct ieee_ar_data_struct *ieee_ar_data;
140
      struct srec_data_struct *srec_data;
141
      struct ihex_data_struct *ihex_data;
142
      struct tekhex_data_struct *tekhex_data;
143
      struct elf_obj_tdata *elf_obj_data;
144
      struct nlm_obj_tdata *nlm_obj_data;
145
      struct bout_data_struct *bout_data;
146
      struct sun_core_struct *sun_core_data;
147
      struct sco5_core_struct *sco5_core_data;
148
      struct trad_core_struct *trad_core_data;
149
      struct som_data_struct *som_data;
150
      struct hpux_core_struct *hpux_core_data;
151
      struct hppabsd_core_struct *hppabsd_core_data;
152
      struct sgi_core_struct *sgi_core_data;
153
      struct lynx_core_struct *lynx_core_data;
154
      struct osf_core_struct *osf_core_data;
155
      struct cisco_core_struct *cisco_core_data;
156
      struct versados_data_struct *versados_data;
157
      struct netbsd_core_struct *netbsd_core_data;
158
      PTR any;
159
      @} tdata;
160
 
161
    /* Used by the application to hold private data*/
162
    PTR usrdata;
163
 
164
  /* Where all the allocated stuff under this BFD goes.  This is a
165
     struct objalloc *, but we use PTR to avoid requiring the inclusion of
166
     objalloc.h.  */
167
    PTR memory;
168
@};
169
 
170
@end example
171
@section Error reporting
172
Most BFD functions return nonzero on success (check their
173
individual documentation for precise semantics).  On an error,
174
they call @code{bfd_set_error} to set an error condition that callers
175
can check by calling @code{bfd_get_error}.
176
If that returns @code{bfd_error_system_call}, then check
177
@code{errno}.
178
 
179
The easiest way to report a BFD error to the user is to
180
use @code{bfd_perror}.
181
 
182
@subsection Type @code{bfd_error_type}
183
The values returned by @code{bfd_get_error} are defined by the
184
enumerated type @code{bfd_error_type}.
185
 
186
 
187
@example
188
 
189
typedef enum bfd_error
190
@{
191
  bfd_error_no_error = 0,
192
  bfd_error_system_call,
193
  bfd_error_invalid_target,
194
  bfd_error_wrong_format,
195
  bfd_error_invalid_operation,
196
  bfd_error_no_memory,
197
  bfd_error_no_symbols,
198
  bfd_error_no_armap,
199
  bfd_error_no_more_archived_files,
200
  bfd_error_malformed_archive,
201
  bfd_error_file_not_recognized,
202
  bfd_error_file_ambiguously_recognized,
203
  bfd_error_no_contents,
204
  bfd_error_nonrepresentable_section,
205
  bfd_error_no_debug_section,
206
  bfd_error_bad_value,
207
  bfd_error_file_truncated,
208
  bfd_error_file_too_big,
209
  bfd_error_invalid_error_code
210
@} bfd_error_type;
211
 
212
@end example
213
@findex bfd_get_error
214
@subsubsection @code{bfd_get_error}
215
@strong{Synopsis}
216
@example
217
bfd_error_type bfd_get_error (void);
218
@end example
219
@strong{Description}@*
220
Return the current BFD error condition.
221
 
222
@findex bfd_set_error
223
@subsubsection @code{bfd_set_error}
224
@strong{Synopsis}
225
@example
226
void bfd_set_error (bfd_error_type error_tag);
227
@end example
228
@strong{Description}@*
229
Set the BFD error condition to be @var{error_tag}.
230
 
231
@findex bfd_errmsg
232
@subsubsection @code{bfd_errmsg}
233
@strong{Synopsis}
234
@example
235
CONST char *bfd_errmsg (bfd_error_type error_tag);
236
@end example
237
@strong{Description}@*
238
Return a string describing the error @var{error_tag}, or
239
the system error if @var{error_tag} is @code{bfd_error_system_call}.
240
 
241
@findex bfd_perror
242
@subsubsection @code{bfd_perror}
243
@strong{Synopsis}
244
@example
245
void bfd_perror (CONST char *message);
246
@end example
247
@strong{Description}@*
248
Print to the standard error stream a string describing the
249
last BFD error that occurred, or the last system error if
250
the last BFD error was a system call failure.  If @var{message}
251
is non-NULL and non-empty, the error string printed is preceded
252
by @var{message}, a colon, and a space.  It is followed by a newline.
253
 
254
@subsection BFD error handler
255
Some BFD functions want to print messages describing the
256
problem.  They call a BFD error handler function.  This
257
function may be overriden by the program.
258
 
259
The BFD error handler acts like printf.
260
 
261
 
262
@example
263
 
264
typedef void (*bfd_error_handler_type) PARAMS ((const char *, ...));
265
 
266
@end example
267
@findex bfd_set_error_handler
268
@subsubsection @code{bfd_set_error_handler}
269
@strong{Synopsis}
270
@example
271
bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
272
@end example
273
@strong{Description}@*
274
Set the BFD error handler function.  Returns the previous
275
function.
276
 
277
@findex bfd_set_error_program_name
278
@subsubsection @code{bfd_set_error_program_name}
279
@strong{Synopsis}
280
@example
281
void bfd_set_error_program_name (const char *);
282
@end example
283
@strong{Description}@*
284
Set the program name to use when printing a BFD error.  This
285
is printed before the error message followed by a colon and
286
space.  The string must not be changed after it is passed to
287
this function.
288
 
289
@findex bfd_get_error_handler
290
@subsubsection @code{bfd_get_error_handler}
291
@strong{Synopsis}
292
@example
293
bfd_error_handler_type bfd_get_error_handler (void);
294
@end example
295
@strong{Description}@*
296
Return the BFD error handler function.
297
 
298
@section Symbols
299
 
300
 
301
@findex bfd_get_reloc_upper_bound
302
@subsubsection @code{bfd_get_reloc_upper_bound}
303
@strong{Synopsis}
304
@example
305
long bfd_get_reloc_upper_bound(bfd *abfd, asection *sect);
306
@end example
307
@strong{Description}@*
308
Return the number of bytes required to store the
309
relocation information associated with section @var{sect}
310
attached to bfd @var{abfd}.  If an error occurs, return -1.
311
 
312
@findex bfd_canonicalize_reloc
313
@subsubsection @code{bfd_canonicalize_reloc}
314
@strong{Synopsis}
315
@example
316
long bfd_canonicalize_reloc
317
   (bfd *abfd,
318
    asection *sec,
319
    arelent **loc,
320
    asymbol **syms);
321
@end example
322
@strong{Description}@*
323
Call the back end associated with the open BFD
324
@var{abfd} and translate the external form of the relocation
325
information attached to @var{sec} into the internal canonical
326
form.  Place the table into memory at @var{loc}, which has
327
been preallocated, usually by a call to
328
@code{bfd_get_reloc_upper_bound}.  Returns the number of relocs, or
329
-1 on error.
330
 
331
The @var{syms} table is also needed for horrible internal magic
332
reasons.
333
 
334
@findex bfd_set_reloc
335
@subsubsection @code{bfd_set_reloc}
336
@strong{Synopsis}
337
@example
338
void bfd_set_reloc
339
   (bfd *abfd, asection *sec, arelent **rel, unsigned int count)
340
@end example
341
@strong{Description}@*
342
Set the relocation pointer and count within
343
section @var{sec} to the values @var{rel} and @var{count}.
344
The argument @var{abfd} is ignored.
345
 
346
@findex bfd_set_file_flags
347
@subsubsection @code{bfd_set_file_flags}
348
@strong{Synopsis}
349
@example
350
boolean bfd_set_file_flags(bfd *abfd, flagword flags);
351
@end example
352
@strong{Description}@*
353
Set the flag word in the BFD @var{abfd} to the value @var{flags}.
354
 
355
Possible errors are:
356
@itemize @bullet
357
 
358
@item
359
@code{bfd_error_wrong_format} - The target bfd was not of object format.
360
@item
361
@code{bfd_error_invalid_operation} - The target bfd was open for reading.
362
@item
363
@code{bfd_error_invalid_operation} -
364
The flag word contained a bit which was not applicable to the
365
type of file.  E.g., an attempt was made to set the @code{D_PAGED} bit
366
on a BFD format which does not support demand paging.
367
@end itemize
368
 
369
@findex bfd_get_arch_size
370
@subsubsection @code{bfd_get_arch_size}
371
@strong{Synopsis}
372
@example
373
int bfd_get_arch_size (bfd *abfd);
374
@end example
375
@strong{Description}@*
376
Returns the architecture address size, in bits, as determined
377
by the object file's format.  For ELF, this information is
378
included in the header.
379
 
380
@strong{Returns}@*
381
Returns the arch size in bits if known, @code{-1} otherwise.
382
 
383
@findex bfd_get_sign_extend_vma
384
@subsubsection @code{bfd_get_sign_extend_vma}
385
@strong{Synopsis}
386
@example
387
int bfd_get_sign_extend_vma (bfd *abfd);
388
@end example
389
@strong{Description}@*
390
Indicates if the target architecture "naturally" sign extends
391
an address.  Some architectures implicitly sign extend address
392
values when they are converted to types larger than the size
393
of an address.  For instance, bfd_get_start_address() will
394
return an address sign extended to fill a bfd_vma when this is
395
the case.
396
 
397
@strong{Returns}@*
398
Returns @code{1} if the target architecture is known to sign
399
extend addresses, @code{0} if the target architecture is known to
400
not sign extend addresses, and @code{-1} otherwise.
401
 
402
@findex bfd_set_start_address
403
@subsubsection @code{bfd_set_start_address}
404
@strong{Synopsis}
405
@example
406
boolean bfd_set_start_address(bfd *abfd, bfd_vma vma);
407
@end example
408
@strong{Description}@*
409
Make @var{vma} the entry point of output BFD @var{abfd}.
410
 
411
@strong{Returns}@*
412
Returns @code{true} on success, @code{false} otherwise.
413
 
414
@findex bfd_get_mtime
415
@subsubsection @code{bfd_get_mtime}
416
@strong{Synopsis}
417
@example
418
long bfd_get_mtime(bfd *abfd);
419
@end example
420
@strong{Description}@*
421
Return the file modification time (as read from the file system, or
422
from the archive header for archive members).
423
 
424
@findex bfd_get_size
425
@subsubsection @code{bfd_get_size}
426
@strong{Synopsis}
427
@example
428
long bfd_get_size(bfd *abfd);
429
@end example
430
@strong{Description}@*
431
Return the file size (as read from file system) for the file
432
associated with BFD @var{abfd}.
433
 
434
The initial motivation for, and use of, this routine is not
435
so we can get the exact size of the object the BFD applies to, since
436
that might not be generally possible (archive members for example).
437
It would be ideal if someone could eventually modify
438
it so that such results were guaranteed.
439
 
440
Instead, we want to ask questions like "is this NNN byte sized
441
object I'm about to try read from file offset YYY reasonable?"
442
As as example of where we might do this, some object formats
443
use string tables for which the first @code{sizeof (long)} bytes of the
444
table contain the size of the table itself, including the size bytes.
445
If an application tries to read what it thinks is one of these
446
string tables, without some way to validate the size, and for
447
some reason the size is wrong (byte swapping error, wrong location
448
for the string table, etc.), the only clue is likely to be a read
449
error when it tries to read the table, or a "virtual memory
450
exhausted" error when it tries to allocate 15 bazillon bytes
451
of space for the 15 bazillon byte table it is about to read.
452
This function at least allows us to answer the quesion, "is the
453
size reasonable?".
454
 
455
@findex bfd_get_gp_size
456
@subsubsection @code{bfd_get_gp_size}
457
@strong{Synopsis}
458
@example
459
int bfd_get_gp_size(bfd *abfd);
460
@end example
461
@strong{Description}@*
462
Return the maximum size of objects to be optimized using the GP
463
register under MIPS ECOFF.  This is typically set by the @code{-G}
464
argument to the compiler, assembler or linker.
465
 
466
@findex bfd_set_gp_size
467
@subsubsection @code{bfd_set_gp_size}
468
@strong{Synopsis}
469
@example
470
void bfd_set_gp_size(bfd *abfd, int i);
471
@end example
472
@strong{Description}@*
473
Set the maximum size of objects to be optimized using the GP
474
register under ECOFF or MIPS ELF.  This is typically set by
475
the @code{-G} argument to the compiler, assembler or linker.
476
 
477
@findex bfd_scan_vma
478
@subsubsection @code{bfd_scan_vma}
479
@strong{Synopsis}
480
@example
481
bfd_vma bfd_scan_vma(CONST char *string, CONST char **end, int base);
482
@end example
483
@strong{Description}@*
484
Convert, like @code{strtoul}, a numerical expression
485
@var{string} into a @code{bfd_vma} integer, and return that integer.
486
(Though without as many bells and whistles as @code{strtoul}.)
487
The expression is assumed to be unsigned (i.e., positive).
488
If given a @var{base}, it is used as the base for conversion.
489
A base of 0 causes the function to interpret the string
490
in hex if a leading "0x" or "0X" is found, otherwise
491
in octal if a leading zero is found, otherwise in decimal.
492
 
493
Overflow is not detected.
494
 
495
@findex bfd_copy_private_bfd_data
496
@subsubsection @code{bfd_copy_private_bfd_data}
497
@strong{Synopsis}
498
@example
499
boolean bfd_copy_private_bfd_data(bfd *ibfd, bfd *obfd);
500
@end example
501
@strong{Description}@*
502
Copy private BFD information from the BFD @var{ibfd} to the
503
the BFD @var{obfd}.  Return @code{true} on success, @code{false} on error.
504
Possible error returns are:
505
 
506
@itemize @bullet
507
 
508
@item
509
@code{bfd_error_no_memory} -
510
Not enough memory exists to create private data for @var{obfd}.
511
@end itemize
512
@example
513
#define bfd_copy_private_bfd_data(ibfd, obfd) \
514
     BFD_SEND (obfd, _bfd_copy_private_bfd_data, \
515
               (ibfd, obfd))
516
@end example
517
 
518
@findex bfd_merge_private_bfd_data
519
@subsubsection @code{bfd_merge_private_bfd_data}
520
@strong{Synopsis}
521
@example
522
boolean bfd_merge_private_bfd_data(bfd *ibfd, bfd *obfd);
523
@end example
524
@strong{Description}@*
525
Merge private BFD information from the BFD @var{ibfd} to the
526
the output file BFD @var{obfd} when linking.  Return @code{true}
527
on success, @code{false} on error.  Possible error returns are:
528
 
529
@itemize @bullet
530
 
531
@item
532
@code{bfd_error_no_memory} -
533
Not enough memory exists to create private data for @var{obfd}.
534
@end itemize
535
@example
536
#define bfd_merge_private_bfd_data(ibfd, obfd) \
537
     BFD_SEND (obfd, _bfd_merge_private_bfd_data, \
538
               (ibfd, obfd))
539
@end example
540
 
541
@findex bfd_set_private_flags
542
@subsubsection @code{bfd_set_private_flags}
543
@strong{Synopsis}
544
@example
545
boolean bfd_set_private_flags(bfd *abfd, flagword flags);
546
@end example
547
@strong{Description}@*
548
Set private BFD flag information in the BFD @var{abfd}.
549
Return @code{true} on success, @code{false} on error.  Possible error
550
returns are:
551
 
552
@itemize @bullet
553
 
554
@item
555
@code{bfd_error_no_memory} -
556
Not enough memory exists to create private data for @var{obfd}.
557
@end itemize
558
@example
559
#define bfd_set_private_flags(abfd, flags) \
560
     BFD_SEND (abfd, _bfd_set_private_flags, \
561
               (abfd, flags))
562
@end example
563
 
564
@findex stuff
565
@subsubsection @code{stuff}
566
@strong{Description}@*
567
Stuff which should be documented:
568
@example
569
#define bfd_sizeof_headers(abfd, reloc) \
570
     BFD_SEND (abfd, _bfd_sizeof_headers, (abfd, reloc))
571
 
572
#define bfd_find_nearest_line(abfd, sec, syms, off, file, func, line) \
573
     BFD_SEND (abfd, _bfd_find_nearest_line,  (abfd, sec, syms, off, file, func, line))
574
 
575
       /* Do these three do anything useful at all, for any back end?  */
576
#define bfd_debug_info_start(abfd) \
577
        BFD_SEND (abfd, _bfd_debug_info_start, (abfd))
578
 
579
#define bfd_debug_info_end(abfd) \
580
        BFD_SEND (abfd, _bfd_debug_info_end, (abfd))
581
 
582
#define bfd_debug_info_accumulate(abfd, section) \
583
        BFD_SEND (abfd, _bfd_debug_info_accumulate, (abfd, section))
584
 
585
 
586
#define bfd_stat_arch_elt(abfd, stat) \
587
        BFD_SEND (abfd, _bfd_stat_arch_elt,(abfd, stat))
588
 
589
#define bfd_update_armap_timestamp(abfd) \
590
        BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))
591
 
592
#define bfd_set_arch_mach(abfd, arch, mach)\
593
        BFD_SEND ( abfd, _bfd_set_arch_mach, (abfd, arch, mach))
594
 
595
#define bfd_relax_section(abfd, section, link_info, again) \
596
       BFD_SEND (abfd, _bfd_relax_section, (abfd, section, link_info, again))
597
 
598
#define bfd_gc_sections(abfd, link_info) \
599
       BFD_SEND (abfd, _bfd_gc_sections, (abfd, link_info))
600
 
601
#define bfd_merge_sections(abfd, link_info) \
602
       BFD_SEND (abfd, _bfd_merge_sections, (abfd, link_info))
603
 
604
#define bfd_link_hash_table_create(abfd) \
605
       BFD_SEND (abfd, _bfd_link_hash_table_create, (abfd))
606
 
607
#define bfd_link_add_symbols(abfd, info) \
608
       BFD_SEND (abfd, _bfd_link_add_symbols, (abfd, info))
609
 
610
#define bfd_final_link(abfd, info) \
611
       BFD_SEND (abfd, _bfd_final_link, (abfd, info))
612
 
613
#define bfd_free_cached_info(abfd) \
614
       BFD_SEND (abfd, _bfd_free_cached_info, (abfd))
615
 
616
#define bfd_get_dynamic_symtab_upper_bound(abfd) \
617
       BFD_SEND (abfd, _bfd_get_dynamic_symtab_upper_bound, (abfd))
618
 
619
#define bfd_print_private_bfd_data(abfd, file)\
620
       BFD_SEND (abfd, _bfd_print_private_bfd_data, (abfd, file))
621
 
622
#define bfd_canonicalize_dynamic_symtab(abfd, asymbols) \
623
       BFD_SEND (abfd, _bfd_canonicalize_dynamic_symtab, (abfd, asymbols))
624
 
625
#define bfd_get_dynamic_reloc_upper_bound(abfd) \
626
       BFD_SEND (abfd, _bfd_get_dynamic_reloc_upper_bound, (abfd))
627
 
628
#define bfd_canonicalize_dynamic_reloc(abfd, arels, asyms) \
629
       BFD_SEND (abfd, _bfd_canonicalize_dynamic_reloc, (abfd, arels, asyms))
630
 
631
extern bfd_byte *bfd_get_relocated_section_contents
632
       PARAMS ((bfd *, struct bfd_link_info *,
633
                 struct bfd_link_order *, bfd_byte *,
634
                 boolean, asymbol **));
635
 
636
@end example
637
 

powered by: WebSVN 2.1.0

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