* ecofflink.c (_bfd_ecoff_locate_line): When handling stabs:
[deliverable/binutils-gdb.git] / bfd / syms.c
CommitLineData
6724ff46 1/* Generic symbol-table support for the BFD library.
c188b0be 2 Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
6724ff46
RP
3 Written by Cygnus Support.
4
5This file is part of BFD, the Binary File Descriptor library.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
c3246d9b 19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
6724ff46 20
0cda46cf
SC
21/*
22SECTION
23 Symbols
24
c188b0be 25 BFD tries to maintain as much symbol information as it can when
0cda46cf
SC
26 it moves information from file to file. BFD passes information
27 to applications though the <<asymbol>> structure. When the
e98e6ec1 28 application requests the symbol table, BFD reads the table in
0cda46cf 29 the native form and translates parts of it into the internal
c188b0be
DM
30 format. To maintain more than the information passed to
31 applications, some targets keep some information ``behind the
32 scenes'' in a structure only the particular back end knows
0cda46cf
SC
33 about. For example, the coff back end keeps the original
34 symbol table structure as well as the canonical structure when
35 a BFD is read in. On output, the coff back end can reconstruct
36 the output symbol table so that no information is lost, even
37 information unique to coff which BFD doesn't know or
c188b0be 38 understand. If a coff symbol table were read, but were written
0cda46cf 39 through an a.out back end, all the coff specific information
e98e6ec1 40 would be lost. The symbol table of a BFD
0cda46cf
SC
41 is not necessarily read in until a canonicalize request is
42 made. Then the BFD back end fills in a table provided by the
43 application with pointers to the canonical information. To
44 output symbols, the application provides BFD with a table of
45 pointers to pointers to <<asymbol>>s. This allows applications
c188b0be 46 like the linker to output a symbol as it was read, since the ``behind
57a1867e 47 the scenes'' information will be still available.
6724ff46 48@menu
151760d0
RP
49@* Reading Symbols::
50@* Writing Symbols::
51@* typedef asymbol::
52@* symbol handling functions::
6724ff46
RP
53@end menu
54
c188b0be
DM
55INODE
56Reading Symbols, Writing Symbols, Symbols, Symbols
0cda46cf 57SUBSECTION
c91884b3 58 Reading symbols
0cda46cf 59
c188b0be 60 There are two stages to reading a symbol table from a BFD:
0cda46cf 61 allocating storage, and the actual reading process. This is an
c188b0be 62 excerpt from an application which reads the symbol table:
0cda46cf 63
ec591fcf 64| long storage_needed;
e98e6ec1 65| asymbol **symbol_table;
ec591fcf
ILT
66| long number_of_symbols;
67| long i;
57a1867e 68|
ec591fcf
ILT
69| storage_needed = bfd_get_symtab_upper_bound (abfd);
70|
71| if (storage_needed < 0)
72| FAIL
57a1867e 73|
e98e6ec1
SC
74| if (storage_needed == 0) {
75| return ;
76| }
57a1867e 77| symbol_table = (asymbol **) xmalloc (storage_needed);
e98e6ec1 78| ...
57a1867e
DM
79| number_of_symbols =
80| bfd_canonicalize_symtab (abfd, symbol_table);
81|
ec591fcf
ILT
82| if (number_of_symbols < 0)
83| FAIL
84|
e98e6ec1
SC
85| for (i = 0; i < number_of_symbols; i++) {
86| process_symbol (symbol_table[i]);
87| }
0cda46cf
SC
88
89 All storage for the symbols themselves is in an obstack
c188b0be 90 connected to the BFD; it is freed when the BFD is closed.
0cda46cf 91
6724ff46 92
c188b0be 93INODE
c3246d9b 94Writing Symbols, Mini symbols, Reading Symbols, Symbols
0cda46cf 95SUBSECTION
c91884b3 96 Writing symbols
0cda46cf 97
0cda46cf
SC
98 Writing of a symbol table is automatic when a BFD open for
99 writing is closed. The application attaches a vector of
100 pointers to pointers to symbols to the BFD being written, and
101 fills in the symbol count. The close and cleanup code reads
102 through the table provided and performs all the necessary
c188b0be
DM
103 operations. The BFD output code must always be provided with an
104 ``owned'' symbol: one which has come from another BFD, or one
105 which has been created using <<bfd_make_empty_symbol>>. Here is an
0cda46cf
SC
106 example showing the creation of a symbol table with only one element:
107
e98e6ec1 108| #include "bfd.h"
57a1867e 109| main()
e98e6ec1
SC
110| {
111| bfd *abfd;
112| asymbol *ptrs[2];
113| asymbol *new;
57a1867e 114|
e98e6ec1
SC
115| abfd = bfd_openw("foo","a.out-sunos-big");
116| bfd_set_format(abfd, bfd_object);
117| new = bfd_make_empty_symbol(abfd);
118| new->name = "dummy_symbol";
119| new->section = bfd_make_section_old_way(abfd, ".text");
120| new->flags = BSF_GLOBAL;
121| new->value = 0x12345;
57a1867e 122|
e98e6ec1
SC
123| ptrs[0] = new;
124| ptrs[1] = (asymbol *)0;
57a1867e 125|
e98e6ec1
SC
126| bfd_set_symtab(abfd, ptrs, 1);
127| bfd_close(abfd);
128| }
57a1867e
DM
129|
130| ./makesym
e98e6ec1
SC
131| nm foo
132| 00012345 A dummy_symbol
6724ff46 133
0cda46cf 134 Many formats cannot represent arbitary symbol information; for
c188b0be 135 instance, the <<a.out>> object format does not allow an
0cda46cf
SC
136 arbitary number of sections. A symbol pointing to a section
137 which is not one of <<.text>>, <<.data>> or <<.bss>> cannot
57a1867e 138 be described.
6724ff46 139
c3246d9b
ILT
140INODE
141Mini symbols, typedef asymbol, Writing Symbols, Symbols
142SUBSECTION
143 Mini symbols
144
145 Mini symbols provide read-only access to the symbol table.
146 They use less memory space, but require more time to access.
147 They can be useful for tools like nm or objdump, which may
148 have to handle symbol tables of extremely large executables.
149
150 The <<bfd_read_minisymbols>> function will read the symbols
151 into memory in an internal form. It will return a <<void *>>
152 pointer to a block of memory, a symbol count, and the size of
153 each symbol. The pointer is allocated using <<malloc>>, and
154 should be freed by the caller when it is no longer needed.
155
156 The function <<bfd_minisymbol_to_symbol>> will take a pointer
157 to a minisymbol, and a pointer to a structure returned by
158 <<bfd_make_empty_symbol>>, and return a <<asymbol>> structure.
159 The return value may or may not be the same as the value from
160 <<bfd_make_empty_symbol>> which was passed in.
161
6724ff46
RP
162*/
163
164
c188b0be 165
e98e6ec1 166/*
c188b0be
DM
167DOCDD
168INODE
c3246d9b 169typedef asymbol, symbol handling functions, Mini symbols, Symbols
6724ff46
RP
170
171*/
0cda46cf 172/*
e98e6ec1 173SUBSECTION
0cda46cf 174 typedef asymbol
6724ff46 175
0cda46cf 176 An <<asymbol>> has the form:
6724ff46 177
e98e6ec1
SC
178*/
179
180/*
181CODE_FRAGMENT
182
c188b0be 183.
57a1867e 184.typedef struct symbol_cache_entry
0cda46cf 185.{
e98e6ec1
SC
186. {* A pointer to the BFD which owns the symbol. This information
187. is necessary so that a back end can work out what additional
c188b0be
DM
188. information (invisible to the application writer) is carried
189. with the symbol.
190.
191. This field is *almost* redundant, since you can use section->owner
192. instead, except that some symbols point to the global sections
193. bfd_{abs,com,und}_section. This could be fixed by making
194. these globals be per-bfd (or per-target-flavor). FIXME. *}
e98e6ec1 195.
c188b0be 196. struct _bfd *the_bfd; {* Use bfd_asymbol_bfd(sym) to access this field. *}
e98e6ec1 197.
c188b0be 198. {* The text of the symbol. The name is left alone, and not copied; the
e98e6ec1
SC
199. application may not alter it. *}
200. CONST char *name;
201.
c188b0be
DM
202. {* The value of the symbol. This really should be a union of a
203. numeric value with a pointer, since some flags indicate that
204. a pointer to another symbol is stored here. *}
e98e6ec1
SC
205. symvalue value;
206.
207. {* Attributes of a symbol: *}
208.
0cda46cf 209.#define BSF_NO_FLAGS 0x00
e98e6ec1
SC
210.
211. {* The symbol has local scope; <<static>> in <<C>>. The value
212. is the offset into the section of the data. *}
0cda46cf 213.#define BSF_LOCAL 0x01
e98e6ec1
SC
214.
215. {* The symbol has global scope; initialized data in <<C>>. The
216. value is the offset into the section of the data. *}
0cda46cf 217.#define BSF_GLOBAL 0x02
e98e6ec1 218.
c188b0be 219. {* The symbol has global scope and is exported. The value is
e98e6ec1 220. the offset into the section of the data. *}
c188b0be 221.#define BSF_EXPORT BSF_GLOBAL {* no real difference *}
e98e6ec1
SC
222.
223. {* A normal C symbol would be one of:
224. <<BSF_LOCAL>>, <<BSF_FORT_COMM>>, <<BSF_UNDEFINED>> or
c188b0be 225. <<BSF_GLOBAL>> *}
e98e6ec1
SC
226.
227. {* The symbol is a debugging record. The value has an arbitary
228. meaning. *}
c188b0be 229.#define BSF_DEBUGGING 0x08
e98e6ec1 230.
c188b0be
DM
231. {* The symbol denotes a function entry point. Used in ELF,
232. perhaps others someday. *}
233.#define BSF_FUNCTION 0x10
e98e6ec1 234.
c188b0be
DM
235. {* Used by the linker. *}
236.#define BSF_KEEP 0x20
237.#define BSF_KEEP_G 0x40
e98e6ec1 238.
c188b0be
DM
239. {* A weak global symbol, overridable without warnings by
240. a regular global symbol of the same name. *}
241.#define BSF_WEAK 0x80
242.
243. {* This symbol was created to point to a section, e.g. ELF's
244. STT_SECTION symbols. *}
245.#define BSF_SECTION_SYM 0x100
e98e6ec1
SC
246.
247. {* The symbol used to be a common symbol, but now it is
248. allocated. *}
c188b0be 249.#define BSF_OLD_COMMON 0x200
e98e6ec1
SC
250.
251. {* The default value for common data. *}
0cda46cf 252.#define BFD_FORT_COMM_DEFAULT_VALUE 0
e98e6ec1
SC
253.
254. {* In some files the type of a symbol sometimes alters its
255. location in an output file - ie in coff a <<ISFCN>> symbol
256. which is also <<C_EXT>> symbol appears where it was
257. declared and not at the end of a section. This bit is set
258. by the target BFD part to convey this information. *}
259.
c188b0be 260.#define BSF_NOT_AT_END 0x400
e98e6ec1
SC
261.
262. {* Signal that the symbol is the label of constructor section. *}
c188b0be 263.#define BSF_CONSTRUCTOR 0x800
e98e6ec1
SC
264.
265. {* Signal that the symbol is a warning symbol. If the symbol
266. is a warning symbol, then the value field (I know this is
267. tacky) will point to the asymbol which when referenced will
268. cause the warning. *}
c188b0be 269.#define BSF_WARNING 0x1000
e98e6ec1
SC
270.
271. {* Signal that the symbol is indirect. The value of the symbol
272. is a pointer to an undefined asymbol which contains the
273. name to use instead. *}
c188b0be
DM
274.#define BSF_INDIRECT 0x2000
275.
276. {* BSF_FILE marks symbols that contain a file name. This is used
277. for ELF STT_FILE symbols. *}
278.#define BSF_FILE 0x4000
e98e6ec1 279.
0ee75d02
ILT
280. {* Symbol is from dynamic linking information. *}
281.#define BSF_DYNAMIC 0x8000
282.
0cda46cf 283. flagword flags;
e98e6ec1 284.
57a1867e 285. {* A pointer to the section to which this symbol is
e98e6ec1 286. relative. This will always be non NULL, there are special
89665c85 287. sections for undefined and absolute symbols. *}
0cda46cf 288. struct sec *section;
e98e6ec1 289.
89665c85
SC
290. {* Back end special data. *}
291. union
292. {
293. PTR p;
294. bfd_vma i;
295. } udata;
e98e6ec1 296.
0cda46cf 297.} asymbol;
6724ff46
RP
298*/
299
6724ff46 300#include "bfd.h"
7d68537f 301#include "sysdep.h"
c188b0be 302
6724ff46 303#include "libbfd.h"
e98e6ec1 304#include "aout/stab_gnu.h"
57a1867e 305
0cda46cf 306/*
c188b0be
DM
307DOCDD
308INODE
309symbol handling functions, , typedef asymbol, Symbols
0cda46cf 310SUBSECTION
c91884b3 311 Symbol handling functions
6724ff46
RP
312*/
313
0cda46cf
SC
314/*
315FUNCTION
ec591fcf 316 bfd_get_symtab_upper_bound
0cda46cf
SC
317
318DESCRIPTION
c188b0be
DM
319 Return the number of bytes required to store a vector of pointers
320 to <<asymbols>> for all the symbols in the BFD @var{abfd},
0cda46cf 321 including a terminal NULL pointer. If there are no symbols in
ec591fcf
ILT
322 the BFD, then return 0. If an error occurs, return -1.
323
324.#define bfd_get_symtab_upper_bound(abfd) \
325. BFD_SEND (abfd, _bfd_get_symtab_upper_bound, (abfd))
326
327*/
0cda46cf 328
ec591fcf
ILT
329/*
330FUNCTION
331 bfd_is_local_label
6724ff46 332
ec591fcf
ILT
333SYNOPSIS
334 boolean bfd_is_local_label(bfd *abfd, asymbol *sym);
335
336DESCRIPTION
337 Return true if the given symbol @var{sym} in the BFD @var{abfd} is
338 a compiler generated local label, else return false.
339.#define bfd_is_local_label(abfd, sym) \
340. BFD_SEND (abfd, _bfd_is_local_label,(abfd, sym))
6724ff46
RP
341*/
342
0cda46cf
SC
343/*
344FUNCTION
345 bfd_canonicalize_symtab
346
347DESCRIPTION
c188b0be
DM
348 Read the symbols from the BFD @var{abfd}, and fills in
349 the vector @var{location} with pointers to the symbols and
57a1867e 350 a trailing NULL.
c188b0be 351 Return the actual number of symbol pointers, not
0cda46cf 352 including the NULL.
6724ff46 353
6724ff46 354
0cda46cf
SC
355.#define bfd_canonicalize_symtab(abfd, location) \
356. BFD_SEND (abfd, _bfd_canonicalize_symtab,\
357. (abfd, location))
358
6724ff46
RP
359*/
360
361
0cda46cf
SC
362/*
363FUNCTION
364 bfd_set_symtab
365
0cda46cf 366SYNOPSIS
c188b0be
DM
367 boolean bfd_set_symtab (bfd *abfd, asymbol **location, unsigned int count);
368
369DESCRIPTION
370 Arrange that when the output BFD @var{abfd} is closed,
371 the table @var{location} of @var{count} pointers to symbols
372 will be written.
6724ff46
RP
373*/
374
375boolean
376bfd_set_symtab (abfd, location, symcount)
377 bfd *abfd;
378 asymbol **location;
379 unsigned int symcount;
380{
57a1867e
DM
381 if ((abfd->format != bfd_object) || (bfd_read_p (abfd)))
382 {
383 bfd_set_error (bfd_error_invalid_operation);
384 return false;
385 }
6724ff46
RP
386
387 bfd_get_outsymbols (abfd) = location;
388 bfd_get_symcount (abfd) = symcount;
389 return true;
390}
391
0cda46cf
SC
392/*
393FUNCTION
394 bfd_print_symbol_vandf
6724ff46 395
0cda46cf
SC
396SYNOPSIS
397 void bfd_print_symbol_vandf(PTR file, asymbol *symbol);
c188b0be
DM
398
399DESCRIPTION
400 Print the value and flags of the @var{symbol} supplied to the
401 stream @var{file}.
6724ff46
RP
402*/
403void
57a1867e
DM
404bfd_print_symbol_vandf (arg, symbol)
405 PTR arg;
406 asymbol *symbol;
6724ff46 407{
0ee75d02 408 FILE *file = (FILE *) arg;
6724ff46 409 flagword type = symbol->flags;
57a1867e
DM
410 if (symbol->section != (asection *) NULL)
411 {
412 fprintf_vma (file, symbol->value + symbol->section->vma);
413 }
414 else
415 {
416 fprintf_vma (file, symbol->value);
417 }
0ee75d02
ILT
418
419 /* This presumes that a symbol can not be both BSF_DEBUGGING and
89665c85 420 BSF_DYNAMIC, nor both BSF_FUNCTION and BSF_FILE. */
57a1867e 421 fprintf (file, " %c%c%c%c%c%c%c",
89665c85
SC
422 ((type & BSF_LOCAL)
423 ? (type & BSF_GLOBAL) ? '!' : 'l'
424 : (type & BSF_GLOBAL) ? 'g' : ' '),
57a1867e
DM
425 (type & BSF_WEAK) ? 'w' : ' ',
426 (type & BSF_CONSTRUCTOR) ? 'C' : ' ',
427 (type & BSF_WARNING) ? 'W' : ' ',
428 (type & BSF_INDIRECT) ? 'I' : ' ',
89665c85
SC
429 (type & BSF_DEBUGGING) ? 'd' : (type & BSF_DYNAMIC) ? 'D' : ' ',
430 (type & BSF_FUNCTION) ? 'F' : (type & BSF_FILE) ? 'f' : ' ');
6724ff46
RP
431}
432
433
0cda46cf
SC
434/*
435FUNCTION
436 bfd_make_empty_symbol
437
438DESCRIPTION
c188b0be
DM
439 Create a new <<asymbol>> structure for the BFD @var{abfd}
440 and return a pointer to it.
6724ff46 441
c188b0be 442 This routine is necessary because each back end has private
0cda46cf
SC
443 information surrounding the <<asymbol>>. Building your own
444 <<asymbol>> and pointing to it will not create the private
445 information, and will cause problems later on.
446
447.#define bfd_make_empty_symbol(abfd) \
448. BFD_SEND (abfd, _bfd_make_empty_symbol, (abfd))
6724ff46 449*/
7d68537f 450
c188b0be
DM
451/*
452FUNCTION
453 bfd_make_debug_symbol
454
455DESCRIPTION
456 Create a new <<asymbol>> structure for the BFD @var{abfd},
457 to be used as a debugging symbol. Further details of its use have
458 yet to be worked out.
459
460.#define bfd_make_debug_symbol(abfd,ptr,size) \
461. BFD_SEND (abfd, _bfd_make_debug_symbol, (abfd, ptr, size))
462*/
463
464struct section_to_type
465{
466 CONST char *section;
467 char type;
468};
469
470/* Map section names to POSIX/BSD single-character symbol types.
471 This table is probably incomplete. It is sorted for convenience of
472 adding entries. Since it is so short, a linear search is used. */
57a1867e
DM
473static CONST struct section_to_type stt[] =
474{
c188b0be
DM
475 {"*DEBUG*", 'N'},
476 {".bss", 'b'},
477 {".data", 'd'},
ec591fcf
ILT
478 {".rdata", 'r'}, /* Read only data. */
479 {".rodata", 'r'}, /* Read only data. */
480 {".sbss", 's'}, /* Small BSS (uninitialized data). */
481 {".scommon", 'c'}, /* Small common. */
482 {".sdata", 'g'}, /* Small initialized data. */
c188b0be
DM
483 {".text", 't'},
484 {0, 0}
485};
486
487/* Return the single-character symbol type corresponding to
89665c85
SC
488 section S, or '?' for an unknown COFF section.
489
490 Check for any leading string which matches, so .text5 returns
491 't' as well as .text */
c188b0be
DM
492
493static char
494coff_section_type (s)
495 char *s;
496{
497 CONST struct section_to_type *t;
498
89665c85
SC
499 for (t = &stt[0]; t->section; t++)
500 if (!strncmp (s, t->section, strlen (t->section)))
c188b0be 501 return t->type;
89665c85 502
c188b0be
DM
503 return '?';
504}
505
506#ifndef islower
507#define islower(c) ((c) >= 'a' && (c) <= 'z')
508#endif
509#ifndef toupper
510#define toupper(c) (islower(c) ? ((c) & ~0x20) : (c))
511#endif
512
0cda46cf
SC
513/*
514FUNCTION
515 bfd_decode_symclass
516
517DESCRIPTION
c188b0be
DM
518 Return a character corresponding to the symbol
519 class of @var{symbol}, or '?' for an unknown class.
7d68537f 520
0cda46cf
SC
521SYNOPSIS
522 int bfd_decode_symclass(asymbol *symbol);
7d68537f
FF
523*/
524int
57a1867e
DM
525bfd_decode_symclass (symbol)
526 asymbol *symbol;
7d68537f 527{
c188b0be
DM
528 char c;
529
530 if (bfd_is_com_section (symbol->section))
531 return 'C';
ec591fcf 532 if (bfd_is_und_section (symbol->section))
c188b0be 533 return 'U';
ec591fcf 534 if (bfd_is_ind_section (symbol->section))
c188b0be 535 return 'I';
89665c85
SC
536 if (symbol->flags & BSF_WEAK)
537 return 'W';
57a1867e 538 if (!(symbol->flags & (BSF_GLOBAL | BSF_LOCAL)))
c188b0be
DM
539 return '?';
540
ec591fcf 541 if (bfd_is_abs_section (symbol->section))
c188b0be
DM
542 c = 'a';
543 else if (symbol->section)
544 c = coff_section_type (symbol->section->name);
545 else
546 return '?';
547 if (symbol->flags & BSF_GLOBAL)
548 c = toupper (c);
549 return c;
7d68537f
FF
550
551 /* We don't have to handle these cases just yet, but we will soon:
57a1867e
DM
552 N_SETV: 'v';
553 N_SETA: 'l';
7d68537f
FF
554 N_SETT: 'x';
555 N_SETD: 'z';
556 N_SETB: 's';
557 N_INDR: 'i';
558 */
7d68537f 559}
e98e6ec1 560
c188b0be
DM
561/*
562FUNCTION
563 bfd_symbol_info
564
565DESCRIPTION
566 Fill in the basic info about symbol that nm needs.
567 Additional info may be added by the back-ends after
568 calling this function.
569
570SYNOPSIS
571 void bfd_symbol_info(asymbol *symbol, symbol_info *ret);
572*/
e98e6ec1 573
c188b0be 574void
57a1867e
DM
575bfd_symbol_info (symbol, ret)
576 asymbol *symbol;
577 symbol_info *ret;
c188b0be
DM
578{
579 ret->type = bfd_decode_symclass (symbol);
580 if (ret->type != 'U')
57a1867e 581 ret->value = symbol->value + symbol->section->vma;
c188b0be
DM
582 else
583 ret->value = 0;
584 ret->name = symbol->name;
585}
586
587void
57a1867e 588bfd_symbol_is_absolute ()
e98e6ec1 589{
57a1867e 590 abort ();
e98e6ec1 591}
89665c85
SC
592
593/*
594FUNCTION
595 bfd_copy_private_symbol_data
596
597SYNOPSIS
598 boolean bfd_copy_private_symbol_data(bfd *ibfd, asymbol *isym, bfd *obfd, asymbol *osym);
599
600DESCRIPTION
601 Copy private symbol information from @var{isym} in the BFD
602 @var{ibfd} to the symbol @var{osym} in the BFD @var{obfd}.
603 Return <<true>> on success, <<false>> on error. Possible error
604 returns are:
605
606 o <<bfd_error_no_memory>> -
607 Not enough memory exists to create private data for @var{osec}.
608
609.#define bfd_copy_private_symbol_data(ibfd, isymbol, obfd, osymbol) \
610. BFD_SEND (ibfd, _bfd_copy_private_symbol_data, \
611. (ibfd, isymbol, obfd, osymbol))
612
613*/
c3246d9b
ILT
614
615/* The generic version of the function which returns mini symbols.
616 This is used when the backend does not provide a more efficient
617 version. It just uses BFD asymbol structures as mini symbols. */
618
619long
620_bfd_generic_read_minisymbols (abfd, dynamic, minisymsp, sizep)
621 bfd *abfd;
622 boolean dynamic;
623 PTR *minisymsp;
624 unsigned int *sizep;
625{
626 long storage;
627 asymbol **syms = NULL;
628 long symcount;
629
630 if (dynamic)
631 storage = bfd_get_dynamic_symtab_upper_bound (abfd);
632 else
633 storage = bfd_get_symtab_upper_bound (abfd);
634 if (storage < 0)
635 goto error_return;
636
3fe22b98 637 syms = (asymbol **) malloc ((size_t) storage);
c3246d9b
ILT
638 if (syms == NULL)
639 {
640 bfd_set_error (bfd_error_no_memory);
641 goto error_return;
642 }
643
644 if (dynamic)
645 symcount = bfd_canonicalize_dynamic_symtab (abfd, syms);
646 else
647 symcount = bfd_canonicalize_symtab (abfd, syms);
648 if (symcount < 0)
649 goto error_return;
650
651 *minisymsp = (PTR) syms;
652 *sizep = sizeof (asymbol *);
653 return symcount;
654
655 error_return:
656 if (syms != NULL)
657 free (syms);
658 return -1;
659}
660
661/* The generic version of the function which converts a minisymbol to
662 an asymbol. We don't worry about the sym argument we are passed;
663 we just return the asymbol the minisymbol points to. */
664
665/*ARGSUSED*/
666asymbol *
667_bfd_generic_minisymbol_to_symbol (abfd, dynamic, minisym, sym)
668 bfd *abfd;
669 boolean dynamic;
670 const PTR minisym;
671 asymbol *sym;
672{
673 return *(asymbol **) minisym;
674}
This page took 0.176689 seconds and 4 git commands to generate.