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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
This is bfd.info, produced by makeinfo version 4.0 from bfd.texinfo.
2
 
3
START-INFO-DIR-ENTRY
4
* Bfd: (bfd).                   The Binary File Descriptor library.
5
END-INFO-DIR-ENTRY
6
 
7
   This file documents the BFD library.
8
 
9
   Copyright (C) 1991, 2000 Free Software Foundation, Inc.
10
 
11
   Permission is granted to copy, distribute and/or modify this document
12
     under the terms of the GNU Free Documentation License, Version 1.1
13
     or any later version published by the Free Software Foundation;
14
   with no Invariant Sections, with no Front-Cover Texts, and with no
15
    Back-Cover Texts.  A copy of the license is included in the
16
section entitled "GNU Free Documentation License".
17
 
18

19
File: bfd.info,  Node: typedef asection,  Next: section prototypes,  Prev: Section Output,  Up: Sections
20
 
21
typedef asection
22
----------------
23
 
24
   Here is the section structure:
25
 
26
 
27
     /* This structure is used for a comdat section, as in PE.  A comdat
28
        section is associated with a particular symbol.  When the linker
29
        sees a comdat section, it keeps only one of the sections with a
30
        given name and associated with a given symbol.  */
31
 
32
     struct bfd_comdat_info
33
     {
34
       /* The name of the symbol associated with a comdat section.  */
35
       const char *name;
36
 
37
       /* The local symbol table index of the symbol associated with a
38
          comdat section.  This is only meaningful to the object file format
39
          specific code; it is not an index into the list returned by
40
          bfd_canonicalize_symtab.  */
41
       long symbol;
42
     };
43
 
44
     typedef struct sec
45
     {
46
       /* The name of the section; the name isn't a copy, the pointer is
47
          the same as that passed to bfd_make_section.  */
48
 
49
       const char *name;
50
 
51
       /* A unique sequence number.  */
52
 
53
       int id;
54
 
55
       /* Which section is it; 0..nth.  */
56
 
57
       int index;
58
 
59
       /* The next section in the list belonging to the BFD, or NULL.  */
60
 
61
       struct sec *next;
62
 
63
       /* The field flags contains attributes of the section. Some
64
          flags are read in from the object file, and some are
65
          synthesized from other information.  */
66
 
67
       flagword flags;
68
 
69
     #define SEC_NO_FLAGS   0x000
70
 
71
       /* Tells the OS to allocate space for this section when loading.
72
          This is clear for a section containing debug information only.  */
73
     #define SEC_ALLOC      0x001
74
 
75
       /* Tells the OS to load the section from the file when loading.
76
          This is clear for a .bss section.  */
77
     #define SEC_LOAD       0x002
78
 
79
       /* The section contains data still to be relocated, so there is
80
          some relocation information too.  */
81
     #define SEC_RELOC      0x004
82
 
83
     #if 0   /* Obsolete ? */
84
     #define SEC_BALIGN     0x008
85
     #endif
86
 
87
       /* A signal to the OS that the section contains read only data.  */
88
     #define SEC_READONLY   0x010
89
 
90
       /* The section contains code only.  */
91
     #define SEC_CODE       0x020
92
 
93
       /* The section contains data only.  */
94
     #define SEC_DATA       0x040
95
 
96
       /* The section will reside in ROM.  */
97
     #define SEC_ROM        0x080
98
 
99
       /* The section contains constructor information. This section
100
          type is used by the linker to create lists of constructors and
101
          destructors used by `g++'. When a back end sees a symbol
102
          which should be used in a constructor list, it creates a new
103
          section for the type of name (e.g., `__CTOR_LIST__'), attaches
104
          the symbol to it, and builds a relocation. To build the lists
105
          of constructors, all the linker has to do is catenate all the
106
          sections called `__CTOR_LIST__' and relocate the data
107
          contained within - exactly the operations it would peform on
108
          standard data.  */
109
     #define SEC_CONSTRUCTOR 0x100
110
 
111
       /* The section is a constructor, and should be placed at the
112
          end of the text, data, or bss section(?).  */
113
     #define SEC_CONSTRUCTOR_TEXT 0x1100
114
     #define SEC_CONSTRUCTOR_DATA 0x2100
115
     #define SEC_CONSTRUCTOR_BSS  0x3100
116
 
117
       /* The section has contents - a data section could be
118
          `SEC_ALLOC' | `SEC_HAS_CONTENTS'; a debug section could be
119
          `SEC_HAS_CONTENTS'  */
120
     #define SEC_HAS_CONTENTS 0x200
121
 
122
       /* An instruction to the linker to not output the section
123
          even if it has information which would normally be written.  */
124
     #define SEC_NEVER_LOAD 0x400
125
 
126
       /* The section is a COFF shared library section.  This flag is
127
          only for the linker.  If this type of section appears in
128
          the input file, the linker must copy it to the output file
129
          without changing the vma or size.  FIXME: Although this
130
          was originally intended to be general, it really is COFF
131
          specific (and the flag was renamed to indicate this).  It
132
          might be cleaner to have some more general mechanism to
133
          allow the back end to control what the linker does with
134
          sections.  */
135
     #define SEC_COFF_SHARED_LIBRARY 0x800
136
 
137
       /* The section has GOT references.  This flag is only for the
138
          linker, and is currently only used by the elf32-hppa back end.
139
          It will be set if global offset table references were detected
140
          in this section, which indicate to the linker that the section
141
          contains PIC code, and must be handled specially when doing a
142
          static link.  */
143
     #define SEC_HAS_GOT_REF 0x4000
144
 
145
       /* The section contains common symbols (symbols may be defined
146
          multiple times, the value of a symbol is the amount of
147
          space it requires, and the largest symbol value is the one
148
          used).  Most targets have exactly one of these (which we
149
          translate to bfd_com_section_ptr), but ECOFF has two.  */
150
     #define SEC_IS_COMMON 0x8000
151
 
152
       /* The section contains only debugging information.  For
153
          example, this is set for ELF .debug and .stab sections.
154
          strip tests this flag to see if a section can be
155
          discarded.  */
156
     #define SEC_DEBUGGING 0x10000
157
 
158
       /* The contents of this section are held in memory pointed to
159
          by the contents field.  This is checked by bfd_get_section_contents,
160
          and the data is retrieved from memory if appropriate.  */
161
     #define SEC_IN_MEMORY 0x20000
162
 
163
       /* The contents of this section are to be excluded by the
164
          linker for executable and shared objects unless those
165
          objects are to be further relocated.  */
166
     #define SEC_EXCLUDE 0x40000
167
 
168
       /* The contents of this section are to be sorted by the
169
          based on the address specified in the associated symbol
170
          table.  */
171
     #define SEC_SORT_ENTRIES 0x80000
172
 
173
       /* When linking, duplicate sections of the same name should be
174
          discarded, rather than being combined into a single section as
175
          is usually done.  This is similar to how common symbols are
176
          handled.  See SEC_LINK_DUPLICATES below.  */
177
     #define SEC_LINK_ONCE 0x100000
178
 
179
       /* If SEC_LINK_ONCE is set, this bitfield describes how the linker
180
          should handle duplicate sections.  */
181
     #define SEC_LINK_DUPLICATES 0x600000
182
 
183
       /* This value for SEC_LINK_DUPLICATES means that duplicate
184
          sections with the same name should simply be discarded.  */
185
     #define SEC_LINK_DUPLICATES_DISCARD 0x0
186
 
187
       /* This value for SEC_LINK_DUPLICATES means that the linker
188
          should warn if there are any duplicate sections, although
189
          it should still only link one copy.  */
190
     #define SEC_LINK_DUPLICATES_ONE_ONLY 0x200000
191
 
192
       /* This value for SEC_LINK_DUPLICATES means that the linker
193
          should warn if any duplicate sections are a different size.  */
194
     #define SEC_LINK_DUPLICATES_SAME_SIZE 0x400000
195
 
196
       /* This value for SEC_LINK_DUPLICATES means that the linker
197
          should warn if any duplicate sections contain different
198
          contents.  */
199
     #define SEC_LINK_DUPLICATES_SAME_CONTENTS 0x600000
200
 
201
       /* This section was created by the linker as part of dynamic
202
          relocation or other arcane processing.  It is skipped when
203
          going through the first-pass output, trusting that someone
204
          else up the line will take care of it later.  */
205
     #define SEC_LINKER_CREATED 0x800000
206
 
207
       /* This section should not be subject to garbage collection.  */
208
     #define SEC_KEEP 0x1000000
209
 
210
       /* This section contains "short" data, and should be placed
211
          "near" the GP.  */
212
     #define SEC_SMALL_DATA 0x2000000
213
 
214
       /* This section contains data which may be shared with other
215
          executables or shared objects.  */
216
     #define SEC_SHARED 0x4000000
217
 
218
       /* When a section with this flag is being linked, then if the size of
219
          the input section is less than a page, it should not cross a page
220
          boundary.  If the size of the input section is one page or more, it
221
          should be aligned on a page boundary.  */
222
     #define SEC_BLOCK 0x8000000
223
 
224
       /* Conditionally link this section; do not link if there are no
225
          references found to any symbol in the section.  */
226
     #define SEC_CLINK 0x10000000
227
 
228
       /* Attempt to merge identical entities in the section.
229
          Entity size is given in the entsize field.  */
230
     #define SEC_MERGE 0x20000000
231
 
232
       /* If given with SEC_MERGE, entities to merge are zero terminated
233
          strings where entsize specifies character size instead of fixed
234
          size entries.  */
235
     #define SEC_STRINGS 0x40000000
236
 
237
       /*  End of section flags.  */
238
 
239
       /* Some internal packed boolean fields.  */
240
 
241
       /* See the vma field.  */
242
       unsigned int user_set_vma : 1;
243
 
244
       /* Whether relocations have been processed.  */
245
       unsigned int reloc_done : 1;
246
 
247
       /* A mark flag used by some of the linker backends.  */
248
       unsigned int linker_mark : 1;
249
 
250
       /* Another mark flag used by some of the linker backends.  Set for
251
          output sections that have a input section.  */
252
       unsigned int linker_has_input : 1;
253
 
254
       /* A mark flag used by some linker backends for garbage collection.  */
255
       unsigned int gc_mark : 1;
256
 
257
       /* Used by the ELF code to mark sections which have been allocated to segments.  */
258
       unsigned int segment_mark : 1;
259
 
260
       /* End of internal packed boolean fields.  */
261
 
262
       /*  The virtual memory address of the section - where it will be
263
           at run time.  The symbols are relocated against this.  The
264
           user_set_vma flag is maintained by bfd; if it's not set, the
265
           backend can assign addresses (for example, in `a.out', where
266
           the default address for `.data' is dependent on the specific
267
           target and various flags).  */
268
 
269
       bfd_vma vma;
270
 
271
       /*  The load address of the section - where it would be in a
272
           rom image; really only used for writing section header
273
           information. */
274
 
275
       bfd_vma lma;
276
 
277
       /* The size of the section in octets, as it will be output.
278
          Contains a value even if the section has no contents (e.g., the
279
          size of `.bss').  This will be filled in after relocation.  */
280
 
281
       bfd_size_type _cooked_size;
282
 
283
       /* The original size on disk of the section, in octets.  Normally this
284
          value is the same as the size, but if some relaxing has
285
          been done, then this value will be bigger.  */
286
 
287
       bfd_size_type _raw_size;
288
 
289
       /* If this section is going to be output, then this value is the
290
          offset in *bytes* into the output section of the first byte in the
291
          input section (byte ==> smallest addressable unit on the
292
          target).  In most cases, if this was going to start at the
293
          100th octet (8-bit quantity) in the output section, this value
294
          would be 100.  However, if the target byte size is 16 bits
295
          (bfd_octets_per_byte is "2"), this value would be 50.  */
296
 
297
       bfd_vma output_offset;
298
 
299
       /* The output section through which to map on output.  */
300
 
301
       struct sec *output_section;
302
 
303
       /* The alignment requirement of the section, as an exponent of 2 -
304
          e.g., 3 aligns to 2^3 (or 8).  */
305
 
306
       unsigned int alignment_power;
307
 
308
       /* If an input section, a pointer to a vector of relocation
309
          records for the data in this section.  */
310
 
311
       struct reloc_cache_entry *relocation;
312
 
313
       /* If an output section, a pointer to a vector of pointers to
314
          relocation records for the data in this section.  */
315
 
316
       struct reloc_cache_entry **orelocation;
317
 
318
       /* The number of relocation records in one of the above  */
319
 
320
       unsigned reloc_count;
321
 
322
       /* Information below is back end specific - and not always used
323
          or updated.  */
324
 
325
       /* File position of section data.  */
326
 
327
       file_ptr filepos;
328
 
329
       /* File position of relocation info.  */
330
 
331
       file_ptr rel_filepos;
332
 
333
       /* File position of line data.  */
334
 
335
       file_ptr line_filepos;
336
 
337
       /* Pointer to data for applications.  */
338
 
339
       PTR userdata;
340
 
341
       /* If the SEC_IN_MEMORY flag is set, this points to the actual
342
          contents.  */
343
       unsigned char *contents;
344
 
345
       /* Attached line number information.  */
346
 
347
       alent *lineno;
348
 
349
       /* Number of line number records.  */
350
 
351
       unsigned int lineno_count;
352
 
353
       /* Entity size for merging purposes.  */
354
 
355
       unsigned int entsize;
356
 
357
       /* Optional information about a COMDAT entry; NULL if not COMDAT.  */
358
 
359
       struct bfd_comdat_info *comdat;
360
 
361
       /* Points to the kept section if this section is a link-once section,
362
          and is discarded.  */
363
       struct sec *kept_section;
364
 
365
       /* When a section is being output, this value changes as more
366
          linenumbers are written out.  */
367
 
368
       file_ptr moving_line_filepos;
369
 
370
       /* What the section number is in the target world.  */
371
 
372
       int target_index;
373
 
374
       PTR used_by_bfd;
375
 
376
       /* If this is a constructor section then here is a list of the
377
          relocations created to relocate items within it.  */
378
 
379
       struct relent_chain *constructor_chain;
380
 
381
       /* The BFD which owns the section.  */
382
 
383
       bfd *owner;
384
 
385
       /* A symbol which points at this section only */
386
       struct symbol_cache_entry *symbol;
387
       struct symbol_cache_entry **symbol_ptr_ptr;
388
 
389
       struct bfd_link_order *link_order_head;
390
       struct bfd_link_order *link_order_tail;
391
     } asection ;
392
 
393
     /* These sections are global, and are managed by BFD.  The application
394
        and target back end are not permitted to change the values in
395
        these sections.  New code should use the section_ptr macros rather
396
        than referring directly to the const sections.  The const sections
397
        may eventually vanish.  */
398
     #define BFD_ABS_SECTION_NAME "*ABS*"
399
     #define BFD_UND_SECTION_NAME "*UND*"
400
     #define BFD_COM_SECTION_NAME "*COM*"
401
     #define BFD_IND_SECTION_NAME "*IND*"
402
 
403
     /* the absolute section */
404
     extern const asection bfd_abs_section;
405
     #define bfd_abs_section_ptr ((asection *) &bfd_abs_section)
406
     #define bfd_is_abs_section(sec) ((sec) == bfd_abs_section_ptr)
407
     /* Pointer to the undefined section */
408
     extern const asection bfd_und_section;
409
     #define bfd_und_section_ptr ((asection *) &bfd_und_section)
410
     #define bfd_is_und_section(sec) ((sec) == bfd_und_section_ptr)
411
     /* Pointer to the common section */
412
     extern const asection bfd_com_section;
413
     #define bfd_com_section_ptr ((asection *) &bfd_com_section)
414
     /* Pointer to the indirect section */
415
     extern const asection bfd_ind_section;
416
     #define bfd_ind_section_ptr ((asection *) &bfd_ind_section)
417
     #define bfd_is_ind_section(sec) ((sec) == bfd_ind_section_ptr)
418
 
419
     extern const struct symbol_cache_entry * const bfd_abs_symbol;
420
     extern const struct symbol_cache_entry * const bfd_com_symbol;
421
     extern const struct symbol_cache_entry * const bfd_und_symbol;
422
     extern const struct symbol_cache_entry * const bfd_ind_symbol;
423
     #define bfd_get_section_size_before_reloc(section) \
424
          ((section)->reloc_done ? (abort (), (bfd_size_type) 1) \
425
                                 : (section)->_raw_size)
426
     #define bfd_get_section_size_after_reloc(section) \
427
          ((section)->reloc_done ? (section)->_cooked_size \
428
                                 : (abort (), (bfd_size_type) 1))
429
 
430

431
File: bfd.info,  Node: section prototypes,  Prev: typedef asection,  Up: Sections
432
 
433
Section prototypes
434
------------------
435
 
436
   These are the functions exported by the section handling part of BFD.
437
 
438
`bfd_get_section_by_name'
439
.........................
440
 
441
   *Synopsis*
442
     asection *bfd_get_section_by_name(bfd *abfd, const char *name);
443
   *Description*
444
Run through ABFD and return the one of the `asection's whose name
445
matches NAME, otherwise `NULL'.  *Note Sections::, for more information.
446
 
447
   This should only be used in special cases; the normal way to process
448
all sections of a given name is to use `bfd_map_over_sections' and
449
`strcmp' on the name (or better yet, base it on the section flags or
450
something else) for each section.
451
 
452
`bfd_get_unique_section_name'
453
.............................
454
 
455
   *Synopsis*
456
     char *bfd_get_unique_section_name(bfd *abfd,
457
         const char *templat,
458
         int *count);
459
   *Description*
460
Invent a section name that is unique in ABFD by tacking a dot and a
461
digit suffix onto the original TEMPLAT.  If COUNT is non-NULL, then it
462
specifies the first number tried as a suffix to generate a unique name.
463
The value pointed to by COUNT will be incremented in this case.
464
 
465
`bfd_make_section_old_way'
466
..........................
467
 
468
   *Synopsis*
469
     asection *bfd_make_section_old_way(bfd *abfd, const char *name);
470
   *Description*
471
Create a new empty section called NAME and attach it to the end of the
472
chain of sections for the BFD ABFD. An attempt to create a section with
473
a name which is already in use returns its pointer without changing the
474
section chain.
475
 
476
   It has the funny name since this is the way it used to be before it
477
was rewritten....
478
 
479
   Possible errors are:
480
   * `bfd_error_invalid_operation' - If output has already started for
481
     this BFD.
482
 
483
   * `bfd_error_no_memory' - If memory allocation fails.
484
 
485
`bfd_make_section_anyway'
486
.........................
487
 
488
   *Synopsis*
489
     asection *bfd_make_section_anyway(bfd *abfd, const char *name);
490
   *Description*
491
Create a new empty section called NAME and attach it to the end of the
492
chain of sections for ABFD.  Create a new section even if there is
493
already a section with that name.
494
 
495
   Return `NULL' and set `bfd_error' on error; possible errors are:
496
   * `bfd_error_invalid_operation' - If output has already started for
497
     ABFD.
498
 
499
   * `bfd_error_no_memory' - If memory allocation fails.
500
 
501
`bfd_make_section'
502
..................
503
 
504
   *Synopsis*
505
     asection *bfd_make_section(bfd *, const char *name);
506
   *Description*
507
Like `bfd_make_section_anyway', but return `NULL' (without calling
508
bfd_set_error ()) without changing the section chain if there is
509
already a section named NAME.  If there is an error, return `NULL' and
510
set `bfd_error'.
511
 
512
`bfd_set_section_flags'
513
.......................
514
 
515
   *Synopsis*
516
     boolean bfd_set_section_flags(bfd *abfd, asection *sec, flagword flags);
517
   *Description*
518
Set the attributes of the section SEC in the BFD ABFD to the value
519
FLAGS. Return `true' on success, `false' on error. Possible error
520
returns are:
521
 
522
   * `bfd_error_invalid_operation' - The section cannot have one or
523
     more of the attributes requested. For example, a .bss section in
524
     `a.out' may not have the `SEC_HAS_CONTENTS' field set.
525
 
526
`bfd_map_over_sections'
527
.......................
528
 
529
   *Synopsis*
530
     void bfd_map_over_sections(bfd *abfd,
531
         void (*func) (bfd *abfd,
532
         asection *sect,
533
         PTR obj),
534
         PTR obj);
535
   *Description*
536
Call the provided function FUNC for each section attached to the BFD
537
ABFD, passing OBJ as an argument. The function will be called as if by
538
 
539
            func(abfd, the_section, obj);
540
 
541
   This is the prefered method for iterating over sections; an
542
alternative would be to use a loop:
543
 
544
               section *p;
545
               for (p = abfd->sections; p != NULL; p = p->next)
546
                  func(abfd, p, ...)
547
 
548
`bfd_set_section_size'
549
......................
550
 
551
   *Synopsis*
552
     boolean bfd_set_section_size(bfd *abfd, asection *sec, bfd_size_type val);
553
   *Description*
554
Set SEC to the size VAL. If the operation is ok, then `true' is
555
returned, else `false'.
556
 
557
   Possible error returns:
558
   * `bfd_error_invalid_operation' - Writing has started to the BFD, so
559
     setting the size is invalid.
560
 
561
`bfd_set_section_contents'
562
..........................
563
 
564
   *Synopsis*
565
     boolean bfd_set_section_contents
566
        (bfd *abfd,
567
         asection *section,
568
         PTR data,
569
         file_ptr offset,
570
         bfd_size_type count);
571
   *Description*
572
Sets the contents of the section SECTION in BFD ABFD to the data
573
starting in memory at DATA. The data is written to the output section
574
starting at offset OFFSET for COUNT octets.
575
 
576
   Normally `true' is returned, else `false'. Possible error returns
577
are:
578
   * `bfd_error_no_contents' - The output section does not have the
579
     `SEC_HAS_CONTENTS' attribute, so nothing can be written to it.
580
 
581
   * and some more too
582
   This routine is front end to the back end function
583
`_bfd_set_section_contents'.
584
 
585
`bfd_get_section_contents'
586
..........................
587
 
588
   *Synopsis*
589
     boolean bfd_get_section_contents
590
        (bfd *abfd, asection *section, PTR location,
591
         file_ptr offset, bfd_size_type count);
592
   *Description*
593
Read data from SECTION in BFD ABFD into memory starting at LOCATION.
594
The data is read at an offset of OFFSET from the start of the input
595
section, and is read for COUNT bytes.
596
 
597
   If the contents of a constructor with the `SEC_CONSTRUCTOR' flag set
598
are requested or if the section does not have the `SEC_HAS_CONTENTS'
599
flag set, then the LOCATION is filled with zeroes. If no errors occur,
600
`true' is returned, else `false'.
601
 
602
`bfd_copy_private_section_data'
603
...............................
604
 
605
   *Synopsis*
606
     boolean bfd_copy_private_section_data(bfd *ibfd, asection *isec, bfd *obfd, asection *osec);
607
   *Description*
608
Copy private section information from ISEC in the BFD IBFD to the
609
section OSEC in the BFD OBFD.  Return `true' on success, `false' on
610
error.  Possible error returns are:
611
 
612
   * `bfd_error_no_memory' - Not enough memory exists to create private
613
     data for OSEC.
614
 
615
     #define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \
616
          BFD_SEND (obfd, _bfd_copy_private_section_data, \
617
                    (ibfd, isection, obfd, osection))
618
 
619
`_bfd_strip_section_from_output'
620
................................
621
 
622
   *Synopsis*
623
     void _bfd_strip_section_from_output
624
        (struct bfd_link_info *info, asection *section);
625
   *Description*
626
Remove SECTION from the output.  If the output section becomes empty,
627
remove it from the output bfd.  INFO may be NULL; if it is not, it is
628
used to decide whether the output section is empty.
629
 
630

631
File: bfd.info,  Node: Symbols,  Next: Archives,  Prev: Sections,  Up: BFD front end
632
 
633
Symbols
634
=======
635
 
636
   BFD tries to maintain as much symbol information as it can when it
637
moves information from file to file. BFD passes information to
638
applications though the `asymbol' structure. When the application
639
requests the symbol table, BFD reads the table in the native form and
640
translates parts of it into the internal format. To maintain more than
641
the information passed to applications, some targets keep some
642
information "behind the scenes" in a structure only the particular back
643
end knows about. For example, the coff back end keeps the original
644
symbol table structure as well as the canonical structure when a BFD is
645
read in. On output, the coff back end can reconstruct the output symbol
646
table so that no information is lost, even information unique to coff
647
which BFD doesn't know or understand. If a coff symbol table were read,
648
but were written through an a.out back end, all the coff specific
649
information would be lost. The symbol table of a BFD is not necessarily
650
read in until a canonicalize request is made. Then the BFD back end
651
fills in a table provided by the application with pointers to the
652
canonical information.  To output symbols, the application provides BFD
653
with a table of pointers to pointers to `asymbol's. This allows
654
applications like the linker to output a symbol as it was read, since
655
the "behind the scenes" information will be still available.
656
 
657
* Menu:
658
 
659
* Reading Symbols::
660
* Writing Symbols::
661
* Mini Symbols::
662
* typedef asymbol::
663
* symbol handling functions::
664
 
665

666
File: bfd.info,  Node: Reading Symbols,  Next: Writing Symbols,  Prev: Symbols,  Up: Symbols
667
 
668
Reading symbols
669
---------------
670
 
671
   There are two stages to reading a symbol table from a BFD:
672
allocating storage, and the actual reading process. This is an excerpt
673
from an application which reads the symbol table:
674
 
675
              long storage_needed;
676
              asymbol **symbol_table;
677
              long number_of_symbols;
678
              long i;
679
 
680
              storage_needed = bfd_get_symtab_upper_bound (abfd);
681
 
682
              if (storage_needed < 0)
683
                FAIL
684
 
685
              if (storage_needed == 0) {
686
                 return ;
687
              }
688
              symbol_table = (asymbol **) xmalloc (storage_needed);
689
                ...
690
              number_of_symbols =
691
                 bfd_canonicalize_symtab (abfd, symbol_table);
692
 
693
              if (number_of_symbols < 0)
694
                FAIL
695
 
696
              for (i = 0; i < number_of_symbols; i++) {
697
                 process_symbol (symbol_table[i]);
698
              }
699
 
700
   All storage for the symbols themselves is in an objalloc connected
701
to the BFD; it is freed when the BFD is closed.
702
 
703

704
File: bfd.info,  Node: Writing Symbols,  Next: Mini Symbols,  Prev: Reading Symbols,  Up: Symbols
705
 
706
Writing symbols
707
---------------
708
 
709
   Writing of a symbol table is automatic when a BFD open for writing
710
is closed. The application attaches a vector of pointers to pointers to
711
symbols to the BFD being written, and fills in the symbol count. The
712
close and cleanup code reads through the table provided and performs
713
all the necessary operations. The BFD output code must always be
714
provided with an "owned" symbol: one which has come from another BFD,
715
or one which has been created using `bfd_make_empty_symbol'.  Here is an
716
example showing the creation of a symbol table with only one element:
717
 
718
            #include "bfd.h"
719
            main()
720
            {
721
              bfd *abfd;
722
              asymbol *ptrs[2];
723
              asymbol *new;
724
 
725
              abfd = bfd_openw("foo","a.out-sunos-big");
726
              bfd_set_format(abfd, bfd_object);
727
              new = bfd_make_empty_symbol(abfd);
728
              new->name = "dummy_symbol";
729
              new->section = bfd_make_section_old_way(abfd, ".text");
730
              new->flags = BSF_GLOBAL;
731
              new->value = 0x12345;
732
 
733
              ptrs[0] = new;
734
              ptrs[1] = (asymbol *)0;
735
 
736
              bfd_set_symtab(abfd, ptrs, 1);
737
              bfd_close(abfd);
738
            }
739
 
740
            ./makesym
741
            nm foo
742
            00012345 A dummy_symbol
743
 
744
   Many formats cannot represent arbitary symbol information; for
745
instance, the `a.out' object format does not allow an arbitary number
746
of sections. A symbol pointing to a section which is not one  of
747
`.text', `.data' or `.bss' cannot be described.
748
 
749

750
File: bfd.info,  Node: Mini Symbols,  Next: typedef asymbol,  Prev: Writing Symbols,  Up: Symbols
751
 
752
Mini Symbols
753
------------
754
 
755
   Mini symbols provide read-only access to the symbol table.  They use
756
less memory space, but require more time to access.  They can be useful
757
for tools like nm or objdump, which may have to handle symbol tables of
758
extremely large executables.
759
 
760
   The `bfd_read_minisymbols' function will read the symbols into
761
memory in an internal form.  It will return a `void *' pointer to a
762
block of memory, a symbol count, and the size of each symbol.  The
763
pointer is allocated using `malloc', and should be freed by the caller
764
when it is no longer needed.
765
 
766
   The function `bfd_minisymbol_to_symbol' will take a pointer to a
767
minisymbol, and a pointer to a structure returned by
768
`bfd_make_empty_symbol', and return a `asymbol' structure.  The return
769
value may or may not be the same as the value from
770
`bfd_make_empty_symbol' which was passed in.
771
 
772

773
File: bfd.info,  Node: typedef asymbol,  Next: symbol handling functions,  Prev: Mini Symbols,  Up: Symbols
774
 
775
typedef asymbol
776
---------------
777
 
778
   An `asymbol' has the form:
779
 
780
 
781
     typedef struct symbol_cache_entry
782
     {
783
            /* A pointer to the BFD which owns the symbol. This information
784
               is necessary so that a back end can work out what additional
785
               information (invisible to the application writer) is carried
786
               with the symbol.
787
 
788
               This field is *almost* redundant, since you can use section->owner
789
               instead, except that some symbols point to the global sections
790
               bfd_{abs,com,und}_section.  This could be fixed by making
791
               these globals be per-bfd (or per-target-flavor).  FIXME. */
792
 
793
       struct _bfd *the_bfd; /* Use bfd_asymbol_bfd(sym) to access this field. */
794
 
795
            /* The text of the symbol. The name is left alone, and not copied; the
796
               application may not alter it. */
797
       CONST char *name;
798
 
799
            /* The value of the symbol.  This really should be a union of a
800
               numeric value with a pointer, since some flags indicate that
801
               a pointer to another symbol is stored here.  */
802
       symvalue value;
803
 
804
            /* Attributes of a symbol: */
805
 
806
     #define BSF_NO_FLAGS    0x00
807
 
808
            /* The symbol has local scope; `static' in `C'. The value
809
               is the offset into the section of the data. */
810
     #define BSF_LOCAL      0x01
811
 
812
            /* The symbol has global scope; initialized data in `C'. The
813
               value is the offset into the section of the data. */
814
     #define BSF_GLOBAL     0x02
815
 
816
            /* The symbol has global scope and is exported. The value is
817
               the offset into the section of the data. */
818
     #define BSF_EXPORT     BSF_GLOBAL /* no real difference */
819
 
820
            /* A normal C symbol would be one of:
821
               `BSF_LOCAL', `BSF_FORT_COMM',  `BSF_UNDEFINED' or
822
               `BSF_GLOBAL' */
823
 
824
            /* The symbol is a debugging record. The value has an arbitary
825
               meaning, unless BSF_DEBUGGING_RELOC is also set.  */
826
     #define BSF_DEBUGGING  0x08
827
 
828
            /* The symbol denotes a function entry point.  Used in ELF,
829
               perhaps others someday.  */
830
     #define BSF_FUNCTION    0x10
831
 
832
            /* Used by the linker. */
833
     #define BSF_KEEP        0x20
834
     #define BSF_KEEP_G      0x40
835
 
836
            /* A weak global symbol, overridable without warnings by
837
               a regular global symbol of the same name.  */
838
     #define BSF_WEAK        0x80
839
 
840
            /* This symbol was created to point to a section, e.g. ELF's
841
               STT_SECTION symbols.  */
842
     #define BSF_SECTION_SYM 0x100
843
 
844
            /* The symbol used to be a common symbol, but now it is
845
               allocated. */
846
     #define BSF_OLD_COMMON  0x200
847
 
848
            /* The default value for common data. */
849
     #define BFD_FORT_COMM_DEFAULT_VALUE 0
850
 
851
            /* In some files the type of a symbol sometimes alters its
852
               location in an output file - ie in coff a `ISFCN' symbol
853
               which is also `C_EXT' symbol appears where it was
854
               declared and not at the end of a section.  This bit is set
855
               by the target BFD part to convey this information. */
856
 
857
     #define BSF_NOT_AT_END    0x400
858
 
859
            /* Signal that the symbol is the label of constructor section. */
860
     #define BSF_CONSTRUCTOR   0x800
861
 
862
            /* Signal that the symbol is a warning symbol.  The name is a
863
               warning.  The name of the next symbol is the one to warn about;
864
               if a reference is made to a symbol with the same name as the next
865
               symbol, a warning is issued by the linker. */
866
     #define BSF_WARNING       0x1000
867
 
868
            /* Signal that the symbol is indirect.  This symbol is an indirect
869
               pointer to the symbol with the same name as the next symbol. */
870
     #define BSF_INDIRECT      0x2000
871
 
872
            /* BSF_FILE marks symbols that contain a file name.  This is used
873
               for ELF STT_FILE symbols.  */
874
     #define BSF_FILE          0x4000
875
 
876
            /* Symbol is from dynamic linking information.  */
877
     #define BSF_DYNAMIC       0x8000
878
 
879
            /* The symbol denotes a data object.  Used in ELF, and perhaps
880
               others someday.  */
881
     #define BSF_OBJECT        0x10000
882
 
883
            /* This symbol is a debugging symbol.  The value is the offset
884
               into the section of the data.  BSF_DEBUGGING should be set
885
               as well.  */
886
     #define BSF_DEBUGGING_RELOC 0x20000
887
 
888
       flagword flags;
889
 
890
            /* A pointer to the section to which this symbol is
891
               relative.  This will always be non NULL, there are special
892
               sections for undefined and absolute symbols.  */
893
       struct sec *section;
894
 
895
            /* Back end special data.  */
896
       union
897
         {
898
           PTR p;
899
           bfd_vma i;
900
         } udata;
901
 
902
     } asymbol;
903
 
904

905
File: bfd.info,  Node: symbol handling functions,  Prev: typedef asymbol,  Up: Symbols
906
 
907
Symbol handling functions
908
-------------------------
909
 
910
`bfd_get_symtab_upper_bound'
911
............................
912
 
913
   *Description*
914
Return the number of bytes required to store a vector of pointers to
915
`asymbols' for all the symbols in the BFD ABFD, including a terminal
916
NULL pointer. If there are no symbols in the BFD, then return 0.  If an
917
error occurs, return -1.
918
     #define bfd_get_symtab_upper_bound(abfd) \
919
          BFD_SEND (abfd, _bfd_get_symtab_upper_bound, (abfd))
920
 
921
`bfd_is_local_label'
922
....................
923
 
924
   *Synopsis*
925
     boolean bfd_is_local_label(bfd *abfd, asymbol *sym);
926
   *Description*
927
Return true if the given symbol SYM in the BFD ABFD is a compiler
928
generated local label, else return false.
929
 
930
`bfd_is_local_label_name'
931
.........................
932
 
933
   *Synopsis*
934
     boolean bfd_is_local_label_name(bfd *abfd, const char *name);
935
   *Description*
936
Return true if a symbol with the name NAME in the BFD ABFD is a
937
compiler generated local label, else return false.  This just checks
938
whether the name has the form of a local label.
939
     #define bfd_is_local_label_name(abfd, name) \
940
          BFD_SEND (abfd, _bfd_is_local_label_name, (abfd, name))
941
 
942
`bfd_canonicalize_symtab'
943
.........................
944
 
945
   *Description*
946
Read the symbols from the BFD ABFD, and fills in the vector LOCATION
947
with pointers to the symbols and a trailing NULL.  Return the actual
948
number of symbol pointers, not including the NULL.
949
     #define bfd_canonicalize_symtab(abfd, location) \
950
          BFD_SEND (abfd, _bfd_canonicalize_symtab,\
951
                       (abfd, location))
952
 
953
`bfd_set_symtab'
954
................
955
 
956
   *Synopsis*
957
     boolean bfd_set_symtab (bfd *abfd, asymbol **location, unsigned int count);
958
   *Description*
959
Arrange that when the output BFD ABFD is closed, the table LOCATION of
960
COUNT pointers to symbols will be written.
961
 
962
`bfd_print_symbol_vandf'
963
........................
964
 
965
   *Synopsis*
966
     void bfd_print_symbol_vandf(PTR file, asymbol *symbol);
967
   *Description*
968
Print the value and flags of the SYMBOL supplied to the stream FILE.
969
 
970
`bfd_make_empty_symbol'
971
.......................
972
 
973
   *Description*
974
Create a new `asymbol' structure for the BFD ABFD and return a pointer
975
to it.
976
 
977
   This routine is necessary because each back end has private
978
information surrounding the `asymbol'. Building your own `asymbol' and
979
pointing to it will not create the private information, and will cause
980
problems later on.
981
     #define bfd_make_empty_symbol(abfd) \
982
          BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd))
983
 
984
`bfd_make_debug_symbol'
985
.......................
986
 
987
   *Description*
988
Create a new `asymbol' structure for the BFD ABFD, to be used as a
989
debugging symbol.  Further details of its use have yet to be worked out.
990
     #define bfd_make_debug_symbol(abfd,ptr,size) \
991
             BFD_SEND (abfd, _bfd_make_debug_symbol, (abfd, ptr, size))
992
 
993
`bfd_decode_symclass'
994
.....................
995
 
996
   *Description*
997
Return a character corresponding to the symbol class of SYMBOL, or '?'
998
for an unknown class.
999
 
1000
   *Synopsis*
1001
     int bfd_decode_symclass(asymbol *symbol);
1002
 
1003
`bfd_is_undefined_symclass'
1004
...........................
1005
 
1006
   *Description*
1007
Returns non-zero if the class symbol returned by bfd_decode_symclass
1008
represents an undefined symbol.  Returns zero otherwise.
1009
 
1010
   *Synopsis*
1011
     boolean bfd_is_undefined_symclass (int symclass);
1012
 
1013
`bfd_symbol_info'
1014
.................
1015
 
1016
   *Description*
1017
Fill in the basic info about symbol that nm needs.  Additional info may
1018
be added by the back-ends after calling this function.
1019
 
1020
   *Synopsis*
1021
     void bfd_symbol_info(asymbol *symbol, symbol_info *ret);
1022
 
1023
`bfd_copy_private_symbol_data'
1024
..............................
1025
 
1026
   *Synopsis*
1027
     boolean bfd_copy_private_symbol_data(bfd *ibfd, asymbol *isym, bfd *obfd, asymbol *osym);
1028
   *Description*
1029
Copy private symbol information from ISYM in the BFD IBFD to the symbol
1030
OSYM in the BFD OBFD.  Return `true' on success, `false' on error.
1031
Possible error returns are:
1032
 
1033
   * `bfd_error_no_memory' - Not enough memory exists to create private
1034
     data for OSEC.
1035
 
1036
     #define bfd_copy_private_symbol_data(ibfd, isymbol, obfd, osymbol) \
1037
          BFD_SEND (obfd, _bfd_copy_private_symbol_data, \
1038
                    (ibfd, isymbol, obfd, osymbol))
1039
 
1040

1041
File: bfd.info,  Node: Archives,  Next: Formats,  Prev: Symbols,  Up: BFD front end
1042
 
1043
Archives
1044
========
1045
 
1046
   *Description*
1047
An archive (or library) is just another BFD.  It has a symbol table,
1048
although there's not much a user program will do with it.
1049
 
1050
   The big difference between an archive BFD and an ordinary BFD is
1051
that the archive doesn't have sections.  Instead it has a chain of BFDs
1052
that are considered its contents.  These BFDs can be manipulated like
1053
any other.  The BFDs contained in an archive opened for reading will
1054
all be opened for reading.  You may put either input or output BFDs
1055
into an archive opened for output; they will be handled correctly when
1056
the archive is closed.
1057
 
1058
   Use `bfd_openr_next_archived_file' to step through the contents of
1059
an archive opened for input.  You don't have to read the entire archive
1060
if you don't want to!  Read it until you find what you want.
1061
 
1062
   Archive contents of output BFDs are chained through the `next'
1063
pointer in a BFD.  The first one is findable through the `archive_head'
1064
slot of the archive.  Set it with `bfd_set_archive_head' (q.v.).  A
1065
given BFD may be in only one open output archive at a time.
1066
 
1067
   As expected, the BFD archive code is more general than the archive
1068
code of any given environment.  BFD archives may contain files of
1069
different formats (e.g., a.out and coff) and even different
1070
architectures.  You may even place archives recursively into archives!
1071
 
1072
   This can cause unexpected confusion, since some archive formats are
1073
more expressive than others.  For instance, Intel COFF archives can
1074
preserve long filenames; SunOS a.out archives cannot.  If you move a
1075
file from the first to the second format and back again, the filename
1076
may be truncated.  Likewise, different a.out environments have different
1077
conventions as to how they truncate filenames, whether they preserve
1078
directory names in filenames, etc.  When interoperating with native
1079
tools, be sure your files are homogeneous.
1080
 
1081
   Beware: most of these formats do not react well to the presence of
1082
spaces in filenames.  We do the best we can, but can't always handle
1083
this case due to restrictions in the format of archives.  Many Unix
1084
utilities are braindead in regards to spaces and such in filenames
1085
anyway, so this shouldn't be much of a restriction.
1086
 
1087
   Archives are supported in BFD in `archive.c'.
1088
 
1089
`bfd_get_next_mapent'
1090
.....................
1091
 
1092
   *Synopsis*
1093
     symindex bfd_get_next_mapent(bfd *abfd, symindex previous, carsym **sym);
1094
   *Description*
1095
Step through archive ABFD's symbol table (if it has one).  Successively
1096
update SYM with the next symbol's information, returning that symbol's
1097
(internal) index into the symbol table.
1098
 
1099
   Supply `BFD_NO_MORE_SYMBOLS' as the PREVIOUS entry to get the first
1100
one; returns `BFD_NO_MORE_SYMBOLS' when you've already got the last one.
1101
 
1102
   A `carsym' is a canonical archive symbol.  The only user-visible
1103
element is its name, a null-terminated string.
1104
 
1105
`bfd_set_archive_head'
1106
......................
1107
 
1108
   *Synopsis*
1109
     boolean bfd_set_archive_head(bfd *output, bfd *new_head);
1110
   *Description*
1111
Set the head of the chain of BFDs contained in the archive OUTPUT to
1112
NEW_HEAD.
1113
 
1114
`bfd_openr_next_archived_file'
1115
..............................
1116
 
1117
   *Synopsis*
1118
     bfd *bfd_openr_next_archived_file(bfd *archive, bfd *previous);
1119
   *Description*
1120
Provided a BFD, ARCHIVE, containing an archive and NULL, open an input
1121
BFD on the first contained element and returns that.  Subsequent calls
1122
should pass the archive and the previous return value to return a
1123
created BFD to the next contained element. NULL is returned when there
1124
are no more.
1125
 
1126

1127
File: bfd.info,  Node: Formats,  Next: Relocations,  Prev: Archives,  Up: BFD front end
1128
 
1129
File formats
1130
============
1131
 
1132
   A format is a BFD concept of high level file contents type. The
1133
formats supported by BFD are:
1134
 
1135
   * `bfd_object'
1136
   The BFD may contain data, symbols, relocations and debug info.
1137
 
1138
   * `bfd_archive'
1139
   The BFD contains other BFDs and an optional index.
1140
 
1141
   * `bfd_core'
1142
   The BFD contains the result of an executable core dump.
1143
 
1144
`bfd_check_format'
1145
..................
1146
 
1147
   *Synopsis*
1148
     boolean bfd_check_format(bfd *abfd, bfd_format format);
1149
   *Description*
1150
Verify if the file attached to the BFD ABFD is compatible with the
1151
format FORMAT (i.e., one of `bfd_object', `bfd_archive' or `bfd_core').
1152
 
1153
   If the BFD has been set to a specific target before the call, only
1154
the named target and format combination is checked. If the target has
1155
not been set, or has been set to `default', then all the known target
1156
backends is interrogated to determine a match.  If the default target
1157
matches, it is used.  If not, exactly one target must recognize the
1158
file, or an error results.
1159
 
1160
   The function returns `true' on success, otherwise `false' with one
1161
of the following error codes:
1162
 
1163
   * `bfd_error_invalid_operation' - if `format' is not one of
1164
     `bfd_object', `bfd_archive' or `bfd_core'.
1165
 
1166
   * `bfd_error_system_call' - if an error occured during a read - even
1167
     some file mismatches can cause bfd_error_system_calls.
1168
 
1169
   * `file_not_recognised' - none of the backends recognised the file
1170
     format.
1171
 
1172
   * `bfd_error_file_ambiguously_recognized' - more than one backend
1173
     recognised the file format.
1174
 
1175
`bfd_check_format_matches'
1176
..........................
1177
 
1178
   *Synopsis*
1179
     boolean bfd_check_format_matches(bfd *abfd, bfd_format format, char ***matching);
1180
   *Description*
1181
Like `bfd_check_format', except when it returns false with `bfd_errno'
1182
set to `bfd_error_file_ambiguously_recognized'.  In that case, if
1183
MATCHING is not NULL, it will be filled in with a NULL-terminated list
1184
of the names of the formats that matched, allocated with `malloc'.
1185
Then the user may choose a format and try again.
1186
 
1187
   When done with the list that MATCHING points to, the caller should
1188
free it.
1189
 
1190
`bfd_set_format'
1191
................
1192
 
1193
   *Synopsis*
1194
     boolean bfd_set_format(bfd *abfd, bfd_format format);
1195
   *Description*
1196
This function sets the file format of the BFD ABFD to the format
1197
FORMAT. If the target set in the BFD does not support the format
1198
requested, the format is invalid, or the BFD is not open for writing,
1199
then an error occurs.
1200
 
1201
`bfd_format_string'
1202
...................
1203
 
1204
   *Synopsis*
1205
     CONST char *bfd_format_string(bfd_format format);
1206
   *Description*
1207
Return a pointer to a const string `invalid', `object', `archive',
1208
`core', or `unknown', depending upon the value of FORMAT.
1209
 
1210

1211
File: bfd.info,  Node: Relocations,  Next: Core Files,  Prev: Formats,  Up: BFD front end
1212
 
1213
Relocations
1214
===========
1215
 
1216
   BFD maintains relocations in much the same way it maintains symbols:
1217
they are left alone until required, then read in en-masse and
1218
translated into an internal form.  A common routine
1219
`bfd_perform_relocation' acts upon the canonical form to do the fixup.
1220
 
1221
   Relocations are maintained on a per section basis, while symbols are
1222
maintained on a per BFD basis.
1223
 
1224
   All that a back end has to do to fit the BFD interface is to create
1225
a `struct reloc_cache_entry' for each relocation in a particular
1226
section, and fill in the right bits of the structures.
1227
 
1228
* Menu:
1229
 
1230
* typedef arelent::
1231
* howto manager::
1232
 

powered by: WebSVN 2.1.0

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