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