2003-02-01 Michael Chastain <mec@shout.net>
[binutils-gdb.git] / gdb / somread.c
1 /* Read HP PA/Risc object files for GDB.
2 Copyright 1991, 1992, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Written by Fred Fish at Cygnus Support.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 #include "defs.h"
24 #include "bfd.h"
25 #include <syms.h>
26 #include "symtab.h"
27 #include "symfile.h"
28 #include "objfiles.h"
29 #include "buildsym.h"
30 #include "stabsread.h"
31 #include "gdb-stabs.h"
32 #include "complaints.h"
33 #include "gdb_string.h"
34 #include "demangle.h"
35 #include "som.h"
36 #include "libhppa.h"
37
38 /* Various things we might complain about... */
39
40 static void som_symfile_init (struct objfile *);
41
42 static void som_new_init (struct objfile *);
43
44 static void som_symfile_read (struct objfile *, int);
45
46 static void som_symfile_finish (struct objfile *);
47
48 static void som_symtab_read (bfd *, struct objfile *,
49 struct section_offsets *);
50
51 static void som_symfile_offsets (struct objfile *, struct section_addr_info *);
52
53 /* FIXME: These should really be in a common header somewhere */
54
55 extern void hpread_build_psymtabs (struct objfile *, int);
56
57 extern void hpread_symfile_finish (struct objfile *);
58
59 extern void hpread_symfile_init (struct objfile *);
60
61 extern void do_pxdb (bfd *);
62
63 /*
64
65 LOCAL FUNCTION
66
67 som_symtab_read -- read the symbol table of a SOM file
68
69 SYNOPSIS
70
71 void som_symtab_read (bfd *abfd, struct objfile *objfile,
72 struct section_offsets *section_offsets)
73
74 DESCRIPTION
75
76 Given an open bfd, a base address to relocate symbols to, and a
77 flag that specifies whether or not this bfd is for an executable
78 or not (may be shared library for example), add all the global
79 function and data symbols to the minimal symbol table.
80 */
81
82 static void
83 som_symtab_read (bfd *abfd, struct objfile *objfile,
84 struct section_offsets *section_offsets)
85 {
86 unsigned int number_of_symbols;
87 int val, dynamic;
88 char *stringtab;
89 asection *shlib_info;
90 struct symbol_dictionary_record *buf, *bufp, *endbufp;
91 char *symname;
92 CONST int symsize = sizeof (struct symbol_dictionary_record);
93 CORE_ADDR text_offset, data_offset;
94
95
96 text_offset = ANOFFSET (section_offsets, 0);
97 data_offset = ANOFFSET (section_offsets, 1);
98
99 number_of_symbols = bfd_get_symcount (abfd);
100
101 /* FIXME (alloca): could be quite large. */
102 buf = alloca (symsize * number_of_symbols);
103 bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET);
104 val = bfd_bread (buf, symsize * number_of_symbols, abfd);
105 if (val != symsize * number_of_symbols)
106 error ("Couldn't read symbol dictionary!");
107
108 /* FIXME (alloca): could be quite large. */
109 stringtab = alloca (obj_som_stringtab_size (abfd));
110 bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET);
111 val = bfd_bread (stringtab, obj_som_stringtab_size (abfd), abfd);
112 if (val != obj_som_stringtab_size (abfd))
113 error ("Can't read in HP string table.");
114
115 /* We need to determine if objfile is a dynamic executable (so we
116 can do the right thing for ST_ENTRY vs ST_CODE symbols).
117
118 There's nothing in the header which easily allows us to do
119 this.
120
121 This code used to rely upon the existence of a $SHLIB_INFO$
122 section to make this determination. HP claims that it is
123 more accurate to check for a nonzero text offset, but they
124 have not provided any information about why that test is
125 more accurate. */
126 dynamic = (text_offset != 0);
127
128 endbufp = buf + number_of_symbols;
129 for (bufp = buf; bufp < endbufp; ++bufp)
130 {
131 enum minimal_symbol_type ms_type;
132
133 QUIT;
134
135 switch (bufp->symbol_scope)
136 {
137 case SS_UNIVERSAL:
138 case SS_EXTERNAL:
139 switch (bufp->symbol_type)
140 {
141 case ST_SYM_EXT:
142 case ST_ARG_EXT:
143 continue;
144
145 case ST_CODE:
146 case ST_PRI_PROG:
147 case ST_SEC_PROG:
148 case ST_MILLICODE:
149 symname = bufp->name.n_strx + stringtab;
150 ms_type = mst_text;
151 bufp->symbol_value += text_offset;
152 bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value);
153 break;
154
155 case ST_ENTRY:
156 symname = bufp->name.n_strx + stringtab;
157 /* For a dynamic executable, ST_ENTRY symbols are
158 the stubs, while the ST_CODE symbol is the real
159 function. */
160 if (dynamic)
161 ms_type = mst_solib_trampoline;
162 else
163 ms_type = mst_text;
164 bufp->symbol_value += text_offset;
165 bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value);
166 break;
167
168 case ST_STUB:
169 symname = bufp->name.n_strx + stringtab;
170 ms_type = mst_solib_trampoline;
171 bufp->symbol_value += text_offset;
172 bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value);
173 break;
174
175 case ST_DATA:
176 symname = bufp->name.n_strx + stringtab;
177 bufp->symbol_value += data_offset;
178 ms_type = mst_data;
179 break;
180 default:
181 continue;
182 }
183 break;
184
185 #if 0
186 /* SS_GLOBAL and SS_LOCAL are two names for the same thing (!). */
187 case SS_GLOBAL:
188 #endif
189 case SS_LOCAL:
190 switch (bufp->symbol_type)
191 {
192 case ST_SYM_EXT:
193 case ST_ARG_EXT:
194 continue;
195
196 case ST_CODE:
197 symname = bufp->name.n_strx + stringtab;
198 ms_type = mst_file_text;
199 bufp->symbol_value += text_offset;
200 bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value);
201
202 check_strange_names:
203 /* Utah GCC 2.5, FSF GCC 2.6 and later generate correct local
204 label prefixes for stabs, constant data, etc. So we need
205 only filter out L$ symbols which are left in due to
206 limitations in how GAS generates SOM relocations.
207
208 When linking in the HPUX C-library the HP linker has
209 the nasty habit of placing section symbols from the literal
210 subspaces in the middle of the program's text. Filter
211 those out as best we can. Check for first and last character
212 being '$'.
213
214 And finally, the newer HP compilers emit crud like $PIC_foo$N
215 in some circumstance (PIC code I guess). It's also claimed
216 that they emit D$ symbols too. What stupidity. */
217 if ((symname[0] == 'L' && symname[1] == '$')
218 || (symname[0] == '$' && symname[strlen (symname) - 1] == '$')
219 || (symname[0] == 'D' && symname[1] == '$')
220 || (strncmp (symname, "$PIC", 4) == 0))
221 continue;
222 break;
223
224 case ST_PRI_PROG:
225 case ST_SEC_PROG:
226 case ST_MILLICODE:
227 symname = bufp->name.n_strx + stringtab;
228 ms_type = mst_file_text;
229 bufp->symbol_value += text_offset;
230 bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value);
231 break;
232
233 case ST_ENTRY:
234 symname = bufp->name.n_strx + stringtab;
235 /* SS_LOCAL symbols in a shared library do not have
236 export stubs, so we do not have to worry about
237 using mst_file_text vs mst_solib_trampoline here like
238 we do for SS_UNIVERSAL and SS_EXTERNAL symbols above. */
239 ms_type = mst_file_text;
240 bufp->symbol_value += text_offset;
241 bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value);
242 break;
243
244 case ST_STUB:
245 symname = bufp->name.n_strx + stringtab;
246 ms_type = mst_solib_trampoline;
247 bufp->symbol_value += text_offset;
248 bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value);
249 break;
250
251
252 case ST_DATA:
253 symname = bufp->name.n_strx + stringtab;
254 bufp->symbol_value += data_offset;
255 ms_type = mst_file_data;
256 goto check_strange_names;
257
258 default:
259 continue;
260 }
261 break;
262
263 /* This can happen for common symbols when -E is passed to the
264 final link. No idea _why_ that would make the linker force
265 common symbols to have an SS_UNSAT scope, but it does.
266
267 This also happens for weak symbols, but their type is
268 ST_DATA. */
269 case SS_UNSAT:
270 switch (bufp->symbol_type)
271 {
272 case ST_STORAGE:
273 case ST_DATA:
274 symname = bufp->name.n_strx + stringtab;
275 bufp->symbol_value += data_offset;
276 ms_type = mst_data;
277 break;
278
279 default:
280 continue;
281 }
282 break;
283
284 default:
285 continue;
286 }
287
288 if (bufp->name.n_strx > obj_som_stringtab_size (abfd))
289 error ("Invalid symbol data; bad HP string table offset: %d",
290 bufp->name.n_strx);
291
292 prim_record_minimal_symbol (symname, bufp->symbol_value, ms_type,
293 objfile);
294 }
295 }
296
297 /* Scan and build partial symbols for a symbol file.
298 We have been initialized by a call to som_symfile_init, which
299 currently does nothing.
300
301 SECTION_OFFSETS is a set of offsets to apply to relocate the symbols
302 in each section. This is ignored, as it isn't needed for SOM.
303
304 MAINLINE is true if we are reading the main symbol
305 table (as opposed to a shared lib or dynamically loaded file).
306
307 This function only does the minimum work necessary for letting the
308 user "name" things symbolically; it does not read the entire symtab.
309 Instead, it reads the external and static symbols and puts them in partial
310 symbol tables. When more extensive information is requested of a
311 file, the corresponding partial symbol table is mutated into a full
312 fledged symbol table by going back and reading the symbols
313 for real.
314
315 We look for sections with specific names, to tell us what debug
316 format to look for: FIXME!!!
317
318 somstab_build_psymtabs() handles STABS symbols.
319
320 Note that SOM files have a "minimal" symbol table, which is vaguely
321 reminiscent of a COFF symbol table, but has only the minimal information
322 necessary for linking. We process this also, and use the information to
323 build gdb's minimal symbol table. This gives us some minimal debugging
324 capability even for files compiled without -g. */
325
326 static void
327 som_symfile_read (struct objfile *objfile, int mainline)
328 {
329 bfd *abfd = objfile->obfd;
330 struct cleanup *back_to;
331
332 do_pxdb (symfile_bfd_open (objfile->name));
333
334 init_minimal_symbol_collection ();
335 back_to = make_cleanup_discard_minimal_symbols ();
336
337 /* Read in the import list and the export list. Currently
338 the export list isn't used; the import list is used in
339 hp-symtab-read.c to handle static vars declared in other
340 shared libraries. */
341 init_import_symbols (objfile);
342 #if 0 /* Export symbols not used today 1997-08-05 */
343 init_export_symbols (objfile);
344 #else
345 objfile->export_list = NULL;
346 objfile->export_list_size = 0;
347 #endif
348
349 /* Process the normal SOM symbol table first.
350 This reads in the DNTT and string table, but doesn't
351 actually scan the DNTT. It does scan the linker symbol
352 table and thus build up a "minimal symbol table". */
353
354 som_symtab_read (abfd, objfile, objfile->section_offsets);
355
356 /* Now read information from the stabs debug sections.
357 This is a no-op for SOM.
358 Perhaps it is intended for some kind of mixed STABS/SOM
359 situation? */
360 stabsect_build_psymtabs (objfile, mainline,
361 "$GDB_SYMBOLS$", "$GDB_STRINGS$", "$TEXT$");
362
363 /* Now read the native debug information.
364 This builds the psymtab. This used to be done via a scan of
365 the DNTT, but is now done via the PXDB-built quick-lookup tables
366 together with a scan of the GNTT. See hp-psymtab-read.c. */
367 hpread_build_psymtabs (objfile, mainline);
368
369 /* Install any minimal symbols that have been collected as the current
370 minimal symbols for this objfile.
371 Further symbol-reading is done incrementally, file-by-file,
372 in a step known as "psymtab-to-symtab" expansion. hp-symtab-read.c
373 contains the code to do the actual DNTT scanning and symtab building. */
374 install_minimal_symbols (objfile);
375
376 /* Force hppa-tdep.c to re-read the unwind descriptors. */
377 objfile->obj_private = NULL;
378 do_cleanups (back_to);
379 }
380
381 /* Initialize anything that needs initializing when a completely new symbol
382 file is specified (not just adding some symbols from another file, e.g. a
383 shared library).
384
385 We reinitialize buildsym, since we may be reading stabs from a SOM file. */
386
387 static void
388 som_new_init (struct objfile *ignore)
389 {
390 stabsread_new_init ();
391 buildsym_new_init ();
392 }
393
394 /* Perform any local cleanups required when we are done with a particular
395 objfile. I.E, we are in the process of discarding all symbol information
396 for an objfile, freeing up all memory held for it, and unlinking the
397 objfile struct from the global list of known objfiles. */
398
399 static void
400 som_symfile_finish (struct objfile *objfile)
401 {
402 if (objfile->sym_stab_info != NULL)
403 {
404 xmfree (objfile->md, objfile->sym_stab_info);
405 }
406 hpread_symfile_finish (objfile);
407 }
408
409 /* SOM specific initialization routine for reading symbols. */
410
411 static void
412 som_symfile_init (struct objfile *objfile)
413 {
414 /* SOM objects may be reordered, so set OBJF_REORDERED. If we
415 find this causes a significant slowdown in gdb then we could
416 set it in the debug symbol readers only when necessary. */
417 objfile->flags |= OBJF_REORDERED;
418 hpread_symfile_init (objfile);
419 }
420
421 /* SOM specific parsing routine for section offsets.
422
423 Plain and simple for now. */
424
425 static void
426 som_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs)
427 {
428 int i;
429 CORE_ADDR text_addr;
430
431 objfile->num_sections = SECT_OFF_MAX;
432 objfile->section_offsets = (struct section_offsets *)
433 obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
434
435 /* FIXME: ezannoni 2000-04-20 The section names in SOM are not
436 .text, .data, etc, but $TEXT$, $DATA$,... We should initialize
437 SET_OFF_* from bfd. (See default_symfile_offsets()). But I don't
438 know the correspondence between SOM sections and GDB's idea of
439 section names. So for now we default to what is was before these
440 changes.*/
441 objfile->sect_index_text = 0;
442 objfile->sect_index_data = 1;
443 objfile->sect_index_bss = 2;
444 objfile->sect_index_rodata = 3;
445
446 /* First see if we're a shared library. If so, get the section
447 offsets from the library, else get them from addrs. */
448 if (!som_solib_section_offsets (objfile, objfile->section_offsets))
449 {
450 /* Note: Here is OK to compare with ".text" because this is the
451 name that gdb itself gives to that section, not the SOM
452 name. */
453 for (i = 0; i < SECT_OFF_MAX && addrs->other[i].name; i++)
454 if (strcmp (addrs->other[i].name, ".text") == 0)
455 break;
456 text_addr = addrs->other[i].addr;
457
458 for (i = 0; i < SECT_OFF_MAX; i++)
459 (objfile->section_offsets)->offsets[i] = text_addr;
460 }
461 }
462
463 /* Read in and initialize the SOM import list which is present
464 for all executables and shared libraries. The import list
465 consists of the symbols that are referenced in OBJFILE but
466 not defined there. (Variables that are imported are dealt
467 with as "loc_indirect" vars.)
468 Return value = number of import symbols read in. */
469 int
470 init_import_symbols (struct objfile *objfile)
471 {
472 unsigned int import_list;
473 unsigned int import_list_size;
474 unsigned int string_table;
475 unsigned int string_table_size;
476 char *string_buffer;
477 register int i;
478 register int j;
479 register int k;
480 asection *text_section; /* section handle */
481 unsigned int dl_header[12]; /* SOM executable header */
482
483 /* A struct for an entry in the SOM import list */
484 typedef struct
485 {
486 int name; /* index into the string table */
487 short dont_care1; /* we don't use this */
488 unsigned char type; /* 0 = NULL, 2 = Data, 3 = Code, 7 = Storage, 13 = Plabel */
489 unsigned int reserved2:8; /* not used */
490 }
491 SomImportEntry;
492
493 /* We read 100 entries in at a time from the disk file. */
494 #define SOM_READ_IMPORTS_NUM 100
495 #define SOM_READ_IMPORTS_CHUNK_SIZE (sizeof (SomImportEntry) * SOM_READ_IMPORTS_NUM)
496 SomImportEntry buffer[SOM_READ_IMPORTS_NUM];
497
498 /* Initialize in case we error out */
499 objfile->import_list = NULL;
500 objfile->import_list_size = 0;
501
502 /* It doesn't work, for some reason, to read in space $TEXT$;
503 the subspace $SHLIB_INFO$ has to be used. Some BFD quirk? pai/1997-08-05 */
504 text_section = bfd_get_section_by_name (objfile->obfd, "$SHLIB_INFO$");
505 if (!text_section)
506 return 0;
507 /* Get the SOM executable header */
508 bfd_get_section_contents (objfile->obfd, text_section, dl_header, 0, 12 * sizeof (int));
509
510 /* Check header version number for 10.x HP-UX */
511 /* Currently we deal only with 10.x systems; on 9.x the version # is 89060912.
512 FIXME: Change for future HP-UX releases and mods to the SOM executable format */
513 if (dl_header[0] != 93092112)
514 return 0;
515
516 import_list = dl_header[4];
517 import_list_size = dl_header[5];
518 if (!import_list_size)
519 return 0;
520 string_table = dl_header[10];
521 string_table_size = dl_header[11];
522 if (!string_table_size)
523 return 0;
524
525 /* Suck in SOM string table */
526 string_buffer = (char *) xmalloc (string_table_size);
527 bfd_get_section_contents (objfile->obfd, text_section, string_buffer,
528 string_table, string_table_size);
529
530 /* Allocate import list in the psymbol obstack; this has nothing
531 to do with psymbols, just a matter of convenience. We want the
532 import list to be freed when the objfile is deallocated */
533 objfile->import_list
534 = (ImportEntry *) obstack_alloc (&objfile->psymbol_obstack,
535 import_list_size * sizeof (ImportEntry));
536
537 /* Read in the import entries, a bunch at a time */
538 for (j = 0, k = 0;
539 j < (import_list_size / SOM_READ_IMPORTS_NUM);
540 j++)
541 {
542 bfd_get_section_contents (objfile->obfd, text_section, buffer,
543 import_list + j * SOM_READ_IMPORTS_CHUNK_SIZE,
544 SOM_READ_IMPORTS_CHUNK_SIZE);
545 for (i = 0; i < SOM_READ_IMPORTS_NUM; i++, k++)
546 {
547 if (buffer[i].type != (unsigned char) 0)
548 {
549 objfile->import_list[k]
550 = (char *) obstack_alloc (&objfile->psymbol_obstack, strlen (string_buffer + buffer[i].name) + 1);
551 strcpy (objfile->import_list[k], string_buffer + buffer[i].name);
552 /* Some day we might want to record the type and other information too */
553 }
554 else /* null type */
555 objfile->import_list[k] = NULL;
556
557 }
558 }
559
560 /* Get the leftovers */
561 if (k < import_list_size)
562 bfd_get_section_contents (objfile->obfd, text_section, buffer,
563 import_list + k * sizeof (SomImportEntry),
564 (import_list_size - k) * sizeof (SomImportEntry));
565 for (i = 0; k < import_list_size; i++, k++)
566 {
567 if (buffer[i].type != (unsigned char) 0)
568 {
569 objfile->import_list[k]
570 = (char *) obstack_alloc (&objfile->psymbol_obstack, strlen (string_buffer + buffer[i].name) + 1);
571 strcpy (objfile->import_list[k], string_buffer + buffer[i].name);
572 /* Some day we might want to record the type and other information too */
573 }
574 else
575 objfile->import_list[k] = NULL;
576 }
577
578 objfile->import_list_size = import_list_size;
579 xfree (string_buffer);
580 return import_list_size;
581 }
582
583 /* Read in and initialize the SOM export list which is present
584 for all executables and shared libraries. The import list
585 consists of the symbols that are referenced in OBJFILE but
586 not defined there. (Variables that are imported are dealt
587 with as "loc_indirect" vars.)
588 Return value = number of import symbols read in. */
589 int
590 init_export_symbols (struct objfile *objfile)
591 {
592 unsigned int export_list;
593 unsigned int export_list_size;
594 unsigned int string_table;
595 unsigned int string_table_size;
596 char *string_buffer;
597 register int i;
598 register int j;
599 register int k;
600 asection *text_section; /* section handle */
601 unsigned int dl_header[12]; /* SOM executable header */
602
603 /* A struct for an entry in the SOM export list */
604 typedef struct
605 {
606 int next; /* for hash table use -- we don't use this */
607 int name; /* index into string table */
608 int value; /* offset or plabel */
609 int dont_care1; /* not used */
610 unsigned char type; /* 0 = NULL, 2 = Data, 3 = Code, 7 = Storage, 13 = Plabel */
611 char dont_care2; /* not used */
612 short dont_care3; /* not used */
613 }
614 SomExportEntry;
615
616 /* We read 100 entries in at a time from the disk file. */
617 #define SOM_READ_EXPORTS_NUM 100
618 #define SOM_READ_EXPORTS_CHUNK_SIZE (sizeof (SomExportEntry) * SOM_READ_EXPORTS_NUM)
619 SomExportEntry buffer[SOM_READ_EXPORTS_NUM];
620
621 /* Initialize in case we error out */
622 objfile->export_list = NULL;
623 objfile->export_list_size = 0;
624
625 /* It doesn't work, for some reason, to read in space $TEXT$;
626 the subspace $SHLIB_INFO$ has to be used. Some BFD quirk? pai/1997-08-05 */
627 text_section = bfd_get_section_by_name (objfile->obfd, "$SHLIB_INFO$");
628 if (!text_section)
629 return 0;
630 /* Get the SOM executable header */
631 bfd_get_section_contents (objfile->obfd, text_section, dl_header, 0, 12 * sizeof (int));
632
633 /* Check header version number for 10.x HP-UX */
634 /* Currently we deal only with 10.x systems; on 9.x the version # is 89060912.
635 FIXME: Change for future HP-UX releases and mods to the SOM executable format */
636 if (dl_header[0] != 93092112)
637 return 0;
638
639 export_list = dl_header[8];
640 export_list_size = dl_header[9];
641 if (!export_list_size)
642 return 0;
643 string_table = dl_header[10];
644 string_table_size = dl_header[11];
645 if (!string_table_size)
646 return 0;
647
648 /* Suck in SOM string table */
649 string_buffer = (char *) xmalloc (string_table_size);
650 bfd_get_section_contents (objfile->obfd, text_section, string_buffer,
651 string_table, string_table_size);
652
653 /* Allocate export list in the psymbol obstack; this has nothing
654 to do with psymbols, just a matter of convenience. We want the
655 export list to be freed when the objfile is deallocated */
656 objfile->export_list
657 = (ExportEntry *) obstack_alloc (&objfile->psymbol_obstack,
658 export_list_size * sizeof (ExportEntry));
659
660 /* Read in the export entries, a bunch at a time */
661 for (j = 0, k = 0;
662 j < (export_list_size / SOM_READ_EXPORTS_NUM);
663 j++)
664 {
665 bfd_get_section_contents (objfile->obfd, text_section, buffer,
666 export_list + j * SOM_READ_EXPORTS_CHUNK_SIZE,
667 SOM_READ_EXPORTS_CHUNK_SIZE);
668 for (i = 0; i < SOM_READ_EXPORTS_NUM; i++, k++)
669 {
670 if (buffer[i].type != (unsigned char) 0)
671 {
672 objfile->export_list[k].name
673 = (char *) obstack_alloc (&objfile->psymbol_obstack, strlen (string_buffer + buffer[i].name) + 1);
674 strcpy (objfile->export_list[k].name, string_buffer + buffer[i].name);
675 objfile->export_list[k].address = buffer[i].value;
676 /* Some day we might want to record the type and other information too */
677 }
678 else
679 /* null type */
680 {
681 objfile->export_list[k].name = NULL;
682 objfile->export_list[k].address = 0;
683 }
684 }
685 }
686
687 /* Get the leftovers */
688 if (k < export_list_size)
689 bfd_get_section_contents (objfile->obfd, text_section, buffer,
690 export_list + k * sizeof (SomExportEntry),
691 (export_list_size - k) * sizeof (SomExportEntry));
692 for (i = 0; k < export_list_size; i++, k++)
693 {
694 if (buffer[i].type != (unsigned char) 0)
695 {
696 objfile->export_list[k].name
697 = (char *) obstack_alloc (&objfile->psymbol_obstack, strlen (string_buffer + buffer[i].name) + 1);
698 strcpy (objfile->export_list[k].name, string_buffer + buffer[i].name);
699 /* Some day we might want to record the type and other information too */
700 objfile->export_list[k].address = buffer[i].value;
701 }
702 else
703 {
704 objfile->export_list[k].name = NULL;
705 objfile->export_list[k].address = 0;
706 }
707 }
708
709 objfile->export_list_size = export_list_size;
710 xfree (string_buffer);
711 return export_list_size;
712 }
713 \f
714
715
716 /* Register that we are able to handle SOM object file formats. */
717
718 static struct sym_fns som_sym_fns =
719 {
720 bfd_target_som_flavour,
721 som_new_init, /* sym_new_init: init anything gbl to entire symtab */
722 som_symfile_init, /* sym_init: read initial info, setup for sym_read() */
723 som_symfile_read, /* sym_read: read a symbol file into symtab */
724 som_symfile_finish, /* sym_finish: finished with file, cleanup */
725 som_symfile_offsets, /* sym_offsets: Translate ext. to int. relocation */
726 NULL /* next: pointer to next struct sym_fns */
727 };
728
729 void
730 _initialize_somread (void)
731 {
732 add_symtab_fns (&som_sym_fns);
733 }