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

Subversion Repositories or1k

[/] [or1k/] [branches/] [oc/] [gdb-5.0/] [bfd/] [doc/] [bfd.info-2] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 104 markom
This is bfd.info, produced by Makeinfo version 3.12f 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 Free Software Foundation, Inc.
10
 
11
   Permission is granted to make and distribute verbatim copies of this
12
manual provided the copyright notice and this permission notice are
13
preserved on all copies.
14
 
15
   Permission is granted to copy and distribute modified versions of
16
this manual under the conditions for verbatim copying, subject to the
17
terms of the GNU General Public License, which includes the provision
18
that the entire resulting derived work is distributed under the terms
19
of a permission notice identical to this one.
20
 
21
   Permission is granted to copy and distribute translations of this
22
manual into another language, under the above conditions for modified
23
versions.
24
 
25

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

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

596
File: bfd.info,  Node: Symbols,  Next: Archives,  Prev: Sections,  Up: BFD front end
597
 
598
Symbols
599
=======
600
 
601
   BFD tries to maintain as much symbol information as it can when it
602
moves information from file to file. BFD passes information to
603
applications though the `asymbol' structure. When the application
604
requests the symbol table, BFD reads the table in the native form and
605
translates parts of it into the internal format. To maintain more than
606
the information passed to applications, some targets keep some
607
information "behind the scenes" in a structure only the particular back
608
end knows about. For example, the coff back end keeps the original
609
symbol table structure as well as the canonical structure when a BFD is
610
read in. On output, the coff back end can reconstruct the output symbol
611
table so that no information is lost, even information unique to coff
612
which BFD doesn't know or understand. If a coff symbol table were read,
613
but were written through an a.out back end, all the coff specific
614
information would be lost. The symbol table of a BFD is not necessarily
615
read in until a canonicalize request is made. Then the BFD back end
616
fills in a table provided by the application with pointers to the
617
canonical information.  To output symbols, the application provides BFD
618
with a table of pointers to pointers to `asymbol's. This allows
619
applications like the linker to output a symbol as it was read, since
620
the "behind the scenes" information will be still available.
621
 
622
* Menu:
623
 
624
* Reading Symbols::
625
* Writing Symbols::
626
* Mini Symbols::
627
* typedef asymbol::
628
* symbol handling functions::
629
 
630

631
File: bfd.info,  Node: Reading Symbols,  Next: Writing Symbols,  Prev: Symbols,  Up: Symbols
632
 
633
Reading symbols
634
---------------
635
 
636
   There are two stages to reading a symbol table from a BFD:
637
allocating storage, and the actual reading process. This is an excerpt
638
from an application which reads the symbol table:
639
 
640
              long storage_needed;
641
              asymbol **symbol_table;
642
              long number_of_symbols;
643
              long i;
644
 
645
              storage_needed = bfd_get_symtab_upper_bound (abfd);
646
 
647
              if (storage_needed < 0)
648
                FAIL
649
 
650
              if (storage_needed == 0) {
651
                 return ;
652
              }
653
              symbol_table = (asymbol **) xmalloc (storage_needed);
654
                ...
655
              number_of_symbols =
656
                 bfd_canonicalize_symtab (abfd, symbol_table);
657
 
658
              if (number_of_symbols < 0)
659
                FAIL
660
 
661
              for (i = 0; i < number_of_symbols; i++) {
662
                 process_symbol (symbol_table[i]);
663
              }
664
 
665
   All storage for the symbols themselves is in an objalloc connected
666
to the BFD; it is freed when the BFD is closed.
667
 
668

669
File: bfd.info,  Node: Writing Symbols,  Next: Mini Symbols,  Prev: Reading Symbols,  Up: Symbols
670
 
671
Writing symbols
672
---------------
673
 
674
   Writing of a symbol table is automatic when a BFD open for writing
675
is closed. The application attaches a vector of pointers to pointers to
676
symbols to the BFD being written, and fills in the symbol count. The
677
close and cleanup code reads through the table provided and performs
678
all the necessary operations. The BFD output code must always be
679
provided with an "owned" symbol: one which has come from another BFD,
680
or one which has been created using `bfd_make_empty_symbol'.  Here is an
681
example showing the creation of a symbol table with only one element:
682
 
683
            #include "bfd.h"
684
            main()
685
            {
686
              bfd *abfd;
687
              asymbol *ptrs[2];
688
              asymbol *new;
689
 
690
              abfd = bfd_openw("foo","a.out-sunos-big");
691
              bfd_set_format(abfd, bfd_object);
692
              new = bfd_make_empty_symbol(abfd);
693
              new->name = "dummy_symbol";
694
              new->section = bfd_make_section_old_way(abfd, ".text");
695
              new->flags = BSF_GLOBAL;
696
              new->value = 0x12345;
697
 
698
              ptrs[0] = new;
699
              ptrs[1] = (asymbol *)0;
700
 
701
              bfd_set_symtab(abfd, ptrs, 1);
702
              bfd_close(abfd);
703
            }
704
 
705
            ./makesym
706
            nm foo
707
            00012345 A dummy_symbol
708
 
709
   Many formats cannot represent arbitary symbol information; for
710
instance, the `a.out' object format does not allow an arbitary number
711
of sections. A symbol pointing to a section which is not one  of
712
`.text', `.data' or `.bss' cannot be described.
713
 
714

715
File: bfd.info,  Node: Mini Symbols,  Next: typedef asymbol,  Prev: Writing Symbols,  Up: Symbols
716
 
717
Mini Symbols
718
------------
719
 
720
   Mini symbols provide read-only access to the symbol table.  They use
721
less memory space, but require more time to access.  They can be useful
722
for tools like nm or objdump, which may have to handle symbol tables of
723
extremely large executables.
724
 
725
   The `bfd_read_minisymbols' function will read the symbols into
726
memory in an internal form.  It will return a `void *' pointer to a
727
block of memory, a symbol count, and the size of each symbol.  The
728
pointer is allocated using `malloc', and should be freed by the caller
729
when it is no longer needed.
730
 
731
   The function `bfd_minisymbol_to_symbol' will take a pointer to a
732
minisymbol, and a pointer to a structure returned by
733
`bfd_make_empty_symbol', and return a `asymbol' structure.  The return
734
value may or may not be the same as the value from
735
`bfd_make_empty_symbol' which was passed in.
736
 
737

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

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

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

1092
File: bfd.info,  Node: Formats,  Next: Relocations,  Prev: Archives,  Up: BFD front end
1093
 
1094
File formats
1095
============
1096
 
1097
   A format is a BFD concept of high level file contents type. The
1098
formats supported by BFD are:
1099
 
1100
   * `bfd_object'
1101
   The BFD may contain data, symbols, relocations and debug info.
1102
 
1103
   * `bfd_archive'
1104
   The BFD contains other BFDs and an optional index.
1105
 
1106
   * `bfd_core'
1107
   The BFD contains the result of an executable core dump.
1108
 
1109
`bfd_check_format'
1110
..................
1111
 
1112
   *Synopsis*
1113
     boolean bfd_check_format(bfd *abfd, bfd_format format);
1114
   *Description*
1115
Verify if the file attached to the BFD ABFD is compatible with the
1116
format FORMAT (i.e., one of `bfd_object', `bfd_archive' or `bfd_core').
1117
 
1118
   If the BFD has been set to a specific target before the call, only
1119
the named target and format combination is checked. If the target has
1120
not been set, or has been set to `default', then all the known target
1121
backends is interrogated to determine a match.  If the default target
1122
matches, it is used.  If not, exactly one target must recognize the
1123
file, or an error results.
1124
 
1125
   The function returns `true' on success, otherwise `false' with one
1126
of the following error codes:
1127
 
1128
   * `bfd_error_invalid_operation' - if `format' is not one of
1129
     `bfd_object', `bfd_archive' or `bfd_core'.
1130
 
1131
   * `bfd_error_system_call' - if an error occured during a read - even
1132
     some file mismatches can cause bfd_error_system_calls.
1133
 
1134
   * `file_not_recognised' - none of the backends recognised the file
1135
     format.
1136
 
1137
   * `bfd_error_file_ambiguously_recognized' - more than one backend
1138
     recognised the file format.
1139
 
1140
`bfd_check_format_matches'
1141
..........................
1142
 
1143
   *Synopsis*
1144
     boolean bfd_check_format_matches(bfd *abfd, bfd_format format, char ***matching);
1145
   *Description*
1146
Like `bfd_check_format', except when it returns false with `bfd_errno'
1147
set to `bfd_error_file_ambiguously_recognized'.  In that case, if
1148
MATCHING is not NULL, it will be filled in with a NULL-terminated list
1149
of the names of the formats that matched, allocated with `malloc'.
1150
Then the user may choose a format and try again.
1151
 
1152
   When done with the list that MATCHING points to, the caller should
1153
free it.
1154
 
1155
`bfd_set_format'
1156
................
1157
 
1158
   *Synopsis*
1159
     boolean bfd_set_format(bfd *abfd, bfd_format format);
1160
   *Description*
1161
This function sets the file format of the BFD ABFD to the format
1162
FORMAT. If the target set in the BFD does not support the format
1163
requested, the format is invalid, or the BFD is not open for writing,
1164
then an error occurs.
1165
 
1166
`bfd_format_string'
1167
...................
1168
 
1169
   *Synopsis*
1170
     CONST char *bfd_format_string(bfd_format format);
1171
   *Description*
1172
Return a pointer to a const string `invalid', `object', `archive',
1173
`core', or `unknown', depending upon the value of FORMAT.
1174
 
1175

1176
File: bfd.info,  Node: Relocations,  Next: Core Files,  Prev: Formats,  Up: BFD front end
1177
 
1178
Relocations
1179
===========
1180
 
1181
   BFD maintains relocations in much the same way it maintains symbols:
1182
they are left alone until required, then read in en-mass and translated
1183
into an internal form.  A common routine `bfd_perform_relocation' acts
1184
upon the canonical form to do the fixup.
1185
 
1186
   Relocations are maintained on a per section basis, while symbols are
1187
maintained on a per BFD basis.
1188
 
1189
   All that a back end has to do to fit the BFD interface is to create
1190
a `struct reloc_cache_entry' for each relocation in a particular
1191
section, and fill in the right bits of the structures.
1192
 
1193
* Menu:
1194
 
1195
* typedef arelent::
1196
* howto manager::
1197
 

powered by: WebSVN 2.1.0

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