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

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [gdb-5.0/] [bfd/] [doc/] [syms.texi] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 104 markom
@section Symbols
2
BFD tries to maintain as much symbol information as it can when
3
it moves information from file to file. BFD passes information
4
to applications though the @code{asymbol} structure. When the
5
application requests the symbol table, BFD reads the table in
6
the native form and translates parts of it into the internal
7
format. To maintain more than the information passed to
8
applications, some targets keep some information ``behind the
9
scenes'' in a structure only the particular back end knows
10
about. For example, the coff back end keeps the original
11
symbol table structure as well as the canonical structure when
12
a BFD is read in. On output, the coff back end can reconstruct
13
the output symbol table so that no information is lost, even
14
information unique to coff which BFD doesn't know or
15
understand. If a coff symbol table were read, but were written
16
through an a.out back end, all the coff specific information
17
would be lost. The symbol table of a BFD
18
is not necessarily read in until a canonicalize request is
19
made. Then the BFD back end fills in a table provided by the
20
application with pointers to the canonical information.  To
21
output symbols, the application provides BFD with a table of
22
pointers to pointers to @code{asymbol}s. This allows applications
23
like the linker to output a symbol as it was read, since the ``behind
24
the scenes'' information will be still available.
25
@menu
26
* Reading Symbols::
27
* Writing Symbols::
28
* Mini Symbols::
29
* typedef asymbol::
30
* symbol handling functions::
31
@end menu
32
 
33
@node Reading Symbols, Writing Symbols, Symbols, Symbols
34
@subsection Reading symbols
35
There are two stages to reading a symbol table from a BFD:
36
allocating storage, and the actual reading process. This is an
37
excerpt from an application which reads the symbol table:
38
 
39
@example
40
         long storage_needed;
41
         asymbol **symbol_table;
42
         long number_of_symbols;
43
         long i;
44
 
45
         storage_needed = bfd_get_symtab_upper_bound (abfd);
46
 
47
         if (storage_needed < 0)
48
           FAIL
49
 
50
         if (storage_needed == 0) @{
51
            return ;
52
         @}
53
         symbol_table = (asymbol **) xmalloc (storage_needed);
54
           ...
55
         number_of_symbols =
56
            bfd_canonicalize_symtab (abfd, symbol_table);
57
 
58
         if (number_of_symbols < 0)
59
           FAIL
60
 
61
         for (i = 0; i < number_of_symbols; i++) @{
62
            process_symbol (symbol_table[i]);
63
         @}
64
@end example
65
 
66
All storage for the symbols themselves is in an objalloc
67
connected to the BFD; it is freed when the BFD is closed.
68
 
69
@node Writing Symbols, Mini Symbols, Reading Symbols, Symbols
70
@subsection Writing symbols
71
Writing of a symbol table is automatic when a BFD open for
72
writing is closed. The application attaches a vector of
73
pointers to pointers to symbols to the BFD being written, and
74
fills in the symbol count. The close and cleanup code reads
75
through the table provided and performs all the necessary
76
operations. The BFD output code must always be provided with an
77
``owned'' symbol: one which has come from another BFD, or one
78
which has been created using @code{bfd_make_empty_symbol}.  Here is an
79
example showing the creation of a symbol table with only one element:
80
 
81
@example
82
       #include "bfd.h"
83
       main()
84
       @{
85
         bfd *abfd;
86
         asymbol *ptrs[2];
87
         asymbol *new;
88
 
89
         abfd = bfd_openw("foo","a.out-sunos-big");
90
         bfd_set_format(abfd, bfd_object);
91
         new = bfd_make_empty_symbol(abfd);
92
         new->name = "dummy_symbol";
93
         new->section = bfd_make_section_old_way(abfd, ".text");
94
         new->flags = BSF_GLOBAL;
95
         new->value = 0x12345;
96
 
97
         ptrs[0] = new;
98
         ptrs[1] = (asymbol *)0;
99
 
100
         bfd_set_symtab(abfd, ptrs, 1);
101
         bfd_close(abfd);
102
       @}
103
 
104
       ./makesym
105
       nm foo
106
       00012345 A dummy_symbol
107
@end example
108
 
109
Many formats cannot represent arbitary symbol information; for
110
instance, the @code{a.out} object format does not allow an
111
arbitary number of sections. A symbol pointing to a section
112
which is not one  of @code{.text}, @code{.data} or @code{.bss} cannot
113
be described.
114
 
115
@node Mini Symbols, typedef asymbol, Writing Symbols, Symbols
116
@subsection Mini Symbols
117
Mini symbols provide read-only access to the symbol table.
118
They use less memory space, but require more time to access.
119
They can be useful for tools like nm or objdump, which may
120
have to handle symbol tables of extremely large executables.
121
 
122
The @code{bfd_read_minisymbols} function will read the symbols
123
into memory in an internal form.  It will return a @code{void *}
124
pointer to a block of memory, a symbol count, and the size of
125
each symbol.  The pointer is allocated using @code{malloc}, and
126
should be freed by the caller when it is no longer needed.
127
 
128
The function @code{bfd_minisymbol_to_symbol} will take a pointer
129
to a minisymbol, and a pointer to a structure returned by
130
@code{bfd_make_empty_symbol}, and return a @code{asymbol} structure.
131
The return value may or may not be the same as the value from
132
@code{bfd_make_empty_symbol} which was passed in.
133
 
134
 
135
@node typedef asymbol, symbol handling functions, Mini Symbols, Symbols
136
@subsection typedef asymbol
137
An @code{asymbol} has the form:
138
 
139
 
140
@example
141
 
142
typedef struct symbol_cache_entry
143
@{
144
       /* A pointer to the BFD which owns the symbol. This information
145
          is necessary so that a back end can work out what additional
146
          information (invisible to the application writer) is carried
147
          with the symbol.
148
 
149
          This field is *almost* redundant, since you can use section->owner
150
          instead, except that some symbols point to the global sections
151
          bfd_@{abs,com,und@}_section.  This could be fixed by making
152
          these globals be per-bfd (or per-target-flavor).  FIXME. */
153
 
154
  struct _bfd *the_bfd; /* Use bfd_asymbol_bfd(sym) to access this field. */
155
 
156
       /* The text of the symbol. The name is left alone, and not copied; the
157
          application may not alter it. */
158
  CONST char *name;
159
 
160
       /* The value of the symbol.  This really should be a union of a
161
          numeric value with a pointer, since some flags indicate that
162
          a pointer to another symbol is stored here.  */
163
  symvalue value;
164
 
165
       /* Attributes of a symbol: */
166
 
167
#define BSF_NO_FLAGS    0x00
168
 
169
       /* The symbol has local scope; @code{static} in @code{C}. The value
170
          is the offset into the section of the data. */
171
#define BSF_LOCAL      0x01
172
 
173
       /* The symbol has global scope; initialized data in @code{C}. The
174
          value is the offset into the section of the data. */
175
#define BSF_GLOBAL     0x02
176
 
177
       /* The symbol has global scope and is exported. The value is
178
          the offset into the section of the data. */
179
#define BSF_EXPORT     BSF_GLOBAL /* no real difference */
180
 
181
       /* A normal C symbol would be one of:
182
          @code{BSF_LOCAL}, @code{BSF_FORT_COMM},  @code{BSF_UNDEFINED} or
183
          @code{BSF_GLOBAL} */
184
 
185
       /* The symbol is a debugging record. The value has an arbitary
186
          meaning, unless BSF_DEBUGGING_RELOC is also set.  */
187
#define BSF_DEBUGGING  0x08
188
 
189
       /* The symbol denotes a function entry point.  Used in ELF,
190
          perhaps others someday.  */
191
#define BSF_FUNCTION    0x10
192
 
193
       /* Used by the linker. */
194
#define BSF_KEEP        0x20
195
#define BSF_KEEP_G      0x40
196
 
197
       /* A weak global symbol, overridable without warnings by
198
          a regular global symbol of the same name.  */
199
#define BSF_WEAK        0x80
200
 
201
       /* This symbol was created to point to a section, e.g. ELF's
202
          STT_SECTION symbols.  */
203
#define BSF_SECTION_SYM 0x100
204
 
205
       /* The symbol used to be a common symbol, but now it is
206
          allocated. */
207
#define BSF_OLD_COMMON  0x200
208
 
209
       /* The default value for common data. */
210
#define BFD_FORT_COMM_DEFAULT_VALUE 0
211
 
212
       /* In some files the type of a symbol sometimes alters its
213
          location in an output file - ie in coff a @code{ISFCN} symbol
214
          which is also @code{C_EXT} symbol appears where it was
215
          declared and not at the end of a section.  This bit is set
216
          by the target BFD part to convey this information. */
217
 
218
#define BSF_NOT_AT_END    0x400
219
 
220
       /* Signal that the symbol is the label of constructor section. */
221
#define BSF_CONSTRUCTOR   0x800
222
 
223
       /* Signal that the symbol is a warning symbol.  The name is a
224
          warning.  The name of the next symbol is the one to warn about;
225
          if a reference is made to a symbol with the same name as the next
226
          symbol, a warning is issued by the linker. */
227
#define BSF_WARNING       0x1000
228
 
229
       /* Signal that the symbol is indirect.  This symbol is an indirect
230
          pointer to the symbol with the same name as the next symbol. */
231
#define BSF_INDIRECT      0x2000
232
 
233
       /* BSF_FILE marks symbols that contain a file name.  This is used
234
          for ELF STT_FILE symbols.  */
235
#define BSF_FILE          0x4000
236
 
237
       /* Symbol is from dynamic linking information.  */
238
#define BSF_DYNAMIC       0x8000
239
 
240
       /* The symbol denotes a data object.  Used in ELF, and perhaps
241
          others someday.  */
242
#define BSF_OBJECT        0x10000
243
 
244
       /* This symbol is a debugging symbol.  The value is the offset
245
          into the section of the data.  BSF_DEBUGGING should be set
246
          as well.  */
247
#define BSF_DEBUGGING_RELOC 0x20000
248
 
249
  flagword flags;
250
 
251
       /* A pointer to the section to which this symbol is
252
          relative.  This will always be non NULL, there are special
253
          sections for undefined and absolute symbols.  */
254
  struct sec *section;
255
 
256
       /* Back end special data.  */
257
  union
258
    @{
259
      PTR p;
260
      bfd_vma i;
261
    @} udata;
262
 
263
@} asymbol;
264
@end example
265
 
266
@node symbol handling functions,  , typedef asymbol, Symbols
267
@subsection Symbol handling functions
268
 
269
 
270
@findex bfd_get_symtab_upper_bound
271
@subsubsection @code{bfd_get_symtab_upper_bound}
272
@strong{Description}@*
273
Return the number of bytes required to store a vector of pointers
274
to @code{asymbols} for all the symbols in the BFD @var{abfd},
275
including a terminal NULL pointer. If there are no symbols in
276
the BFD, then return 0.  If an error occurs, return -1.
277
@example
278
#define bfd_get_symtab_upper_bound(abfd) \
279
     BFD_SEND (abfd, _bfd_get_symtab_upper_bound, (abfd))
280
@end example
281
 
282
@findex bfd_is_local_label
283
@subsubsection @code{bfd_is_local_label}
284
@strong{Synopsis}
285
@example
286
boolean bfd_is_local_label(bfd *abfd, asymbol *sym);
287
@end example
288
@strong{Description}@*
289
Return true if the given symbol @var{sym} in the BFD @var{abfd} is
290
a compiler generated local label, else return false.
291
 
292
@findex bfd_is_local_label_name
293
@subsubsection @code{bfd_is_local_label_name}
294
@strong{Synopsis}
295
@example
296
boolean bfd_is_local_label_name(bfd *abfd, const char *name);
297
@end example
298
@strong{Description}@*
299
Return true if a symbol with the name @var{name} in the BFD
300
@var{abfd} is a compiler generated local label, else return
301
false.  This just checks whether the name has the form of a
302
local label.
303
@example
304
#define bfd_is_local_label_name(abfd, name) \
305
     BFD_SEND (abfd, _bfd_is_local_label_name, (abfd, name))
306
@end example
307
 
308
@findex bfd_canonicalize_symtab
309
@subsubsection @code{bfd_canonicalize_symtab}
310
@strong{Description}@*
311
Read the symbols from the BFD @var{abfd}, and fills in
312
the vector @var{location} with pointers to the symbols and
313
a trailing NULL.
314
Return the actual number of symbol pointers, not
315
including the NULL.
316
@example
317
#define bfd_canonicalize_symtab(abfd, location) \
318
     BFD_SEND (abfd, _bfd_canonicalize_symtab,\
319
                  (abfd, location))
320
@end example
321
 
322
@findex bfd_set_symtab
323
@subsubsection @code{bfd_set_symtab}
324
@strong{Synopsis}
325
@example
326
boolean bfd_set_symtab (bfd *abfd, asymbol **location, unsigned int count);
327
@end example
328
@strong{Description}@*
329
Arrange that when the output BFD @var{abfd} is closed,
330
the table @var{location} of @var{count} pointers to symbols
331
will be written.
332
 
333
@findex bfd_print_symbol_vandf
334
@subsubsection @code{bfd_print_symbol_vandf}
335
@strong{Synopsis}
336
@example
337
void bfd_print_symbol_vandf(PTR file, asymbol *symbol);
338
@end example
339
@strong{Description}@*
340
Print the value and flags of the @var{symbol} supplied to the
341
stream @var{file}.
342
 
343
@findex bfd_make_empty_symbol
344
@subsubsection @code{bfd_make_empty_symbol}
345
@strong{Description}@*
346
Create a new @code{asymbol} structure for the BFD @var{abfd}
347
and return a pointer to it.
348
 
349
This routine is necessary because each back end has private
350
information surrounding the @code{asymbol}. Building your own
351
@code{asymbol} and pointing to it will not create the private
352
information, and will cause problems later on.
353
@example
354
#define bfd_make_empty_symbol(abfd) \
355
     BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd))
356
@end example
357
 
358
@findex bfd_make_debug_symbol
359
@subsubsection @code{bfd_make_debug_symbol}
360
@strong{Description}@*
361
Create a new @code{asymbol} structure for the BFD @var{abfd},
362
to be used as a debugging symbol.  Further details of its use have
363
yet to be worked out.
364
@example
365
#define bfd_make_debug_symbol(abfd,ptr,size) \
366
        BFD_SEND (abfd, _bfd_make_debug_symbol, (abfd, ptr, size))
367
@end example
368
 
369
@findex bfd_decode_symclass
370
@subsubsection @code{bfd_decode_symclass}
371
@strong{Description}@*
372
Return a character corresponding to the symbol
373
class of @var{symbol}, or '?' for an unknown class.
374
 
375
@strong{Synopsis}
376
@example
377
int bfd_decode_symclass(asymbol *symbol);
378
@end example
379
@findex bfd_is_undefined_symclass
380
@subsubsection @code{bfd_is_undefined_symclass }
381
@strong{Description}@*
382
Returns non-zero if the class symbol returned by
383
bfd_decode_symclass represents an undefined symbol.
384
Returns zero otherwise.
385
 
386
@strong{Synopsis}
387
@example
388
boolean bfd_is_undefined_symclass (int symclass);
389
@end example
390
@findex bfd_symbol_info
391
@subsubsection @code{bfd_symbol_info}
392
@strong{Description}@*
393
Fill in the basic info about symbol that nm needs.
394
Additional info may be added by the back-ends after
395
calling this function.
396
 
397
@strong{Synopsis}
398
@example
399
void bfd_symbol_info(asymbol *symbol, symbol_info *ret);
400
@end example
401
@findex bfd_copy_private_symbol_data
402
@subsubsection @code{bfd_copy_private_symbol_data}
403
@strong{Synopsis}
404
@example
405
boolean bfd_copy_private_symbol_data(bfd *ibfd, asymbol *isym, bfd *obfd, asymbol *osym);
406
@end example
407
@strong{Description}@*
408
Copy private symbol information from @var{isym} in the BFD
409
@var{ibfd} to the symbol @var{osym} in the BFD @var{obfd}.
410
Return @code{true} on success, @code{false} on error.  Possible error
411
returns are:
412
 
413
@itemize @bullet
414
 
415
@item
416
@code{bfd_error_no_memory} -
417
Not enough memory exists to create private data for @var{osec}.
418
@end itemize
419
@example
420
#define bfd_copy_private_symbol_data(ibfd, isymbol, obfd, osymbol) \
421
     BFD_SEND (obfd, _bfd_copy_private_symbol_data, \
422
               (ibfd, isymbol, obfd, osymbol))
423
@end example
424
 

powered by: WebSVN 2.1.0

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