Commit | Line | Data |
---|---|---|
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 | ||
a14ed312 | 40 | static void som_symfile_init (struct objfile *); |
c906108c | 41 | |
a14ed312 | 42 | static void som_new_init (struct objfile *); |
c906108c | 43 | |
a14ed312 | 44 | static void som_symfile_read (struct objfile *, int); |
c906108c | 45 | |
a14ed312 | 46 | static void som_symfile_finish (struct objfile *); |
c906108c | 47 | |
570b8f7c AC |
48 | static void som_symtab_read (bfd *, struct objfile *, |
49 | struct section_offsets *); | |
c906108c | 50 | |
570b8f7c | 51 | static void som_symfile_offsets (struct objfile *, struct section_addr_info *); |
c906108c SS |
52 | |
53 | /* FIXME: These should really be in a common header somewhere */ | |
54 | ||
a14ed312 | 55 | extern void hpread_build_psymtabs (struct objfile *, int); |
c906108c | 56 | |
a14ed312 | 57 | extern void hpread_symfile_finish (struct objfile *); |
c906108c | 58 | |
a14ed312 | 59 | extern void hpread_symfile_init (struct objfile *); |
c906108c | 60 | |
a14ed312 | 61 | extern void do_pxdb (bfd *); |
c906108c SS |
62 | |
63 | /* | |
64 | ||
c5aa993b | 65 | LOCAL FUNCTION |
c906108c | 66 | |
c5aa993b | 67 | som_symtab_read -- read the symbol table of a SOM file |
c906108c | 68 | |
c5aa993b | 69 | SYNOPSIS |
c906108c | 70 | |
c5aa993b JM |
71 | void som_symtab_read (bfd *abfd, struct objfile *objfile, |
72 | struct section_offsets *section_offsets) | |
c906108c | 73 | |
c5aa993b | 74 | DESCRIPTION |
c906108c | 75 | |
c5aa993b JM |
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 | */ | |
c906108c SS |
81 | |
82 | static void | |
fba45db2 KB |
83 | som_symtab_read (bfd *abfd, struct objfile *objfile, |
84 | struct section_offsets *section_offsets) | |
c906108c SS |
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 | ||
34c0bd93 | 101 | /* FIXME (alloca): could be quite large. */ |
c906108c SS |
102 | buf = alloca (symsize * number_of_symbols); |
103 | bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET); | |
3a42e9d0 | 104 | val = bfd_bread (buf, symsize * number_of_symbols, abfd); |
c906108c SS |
105 | if (val != symsize * number_of_symbols) |
106 | error ("Couldn't read symbol dictionary!"); | |
107 | ||
34c0bd93 | 108 | /* FIXME (alloca): could be quite large. */ |
c906108c SS |
109 | stringtab = alloca (obj_som_stringtab_size (abfd)); |
110 | bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET); | |
3a42e9d0 | 111 | val = bfd_bread (stringtab, obj_som_stringtab_size (abfd), abfd); |
c906108c SS |
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 | |
3fa41cdb JL |
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. */ | |
c906108c SS |
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; | |
181c1381 | 152 | bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value); |
c906108c SS |
153 | break; |
154 | ||
155 | case ST_ENTRY: | |
156 | symname = bufp->name.n_strx + stringtab; | |
157 | /* For a dynamic executable, ST_ENTRY symbols are | |
c5aa993b JM |
158 | the stubs, while the ST_CODE symbol is the real |
159 | function. */ | |
c906108c SS |
160 | if (dynamic) |
161 | ms_type = mst_solib_trampoline; | |
162 | else | |
163 | ms_type = mst_text; | |
164 | bufp->symbol_value += text_offset; | |
181c1381 | 165 | bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value); |
c906108c SS |
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; | |
181c1381 | 172 | bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value); |
c906108c SS |
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; | |
181c1381 | 200 | bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value); |
c906108c SS |
201 | |
202 | check_strange_names: | |
203 | /* Utah GCC 2.5, FSF GCC 2.6 and later generate correct local | |
c5aa993b JM |
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. */ | |
c906108c | 217 | if ((symname[0] == 'L' && symname[1] == '$') |
c5aa993b | 218 | || (symname[0] == '$' && symname[strlen (symname) - 1] == '$') |
c906108c SS |
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; | |
181c1381 | 230 | bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value); |
c906108c SS |
231 | break; |
232 | ||
233 | case ST_ENTRY: | |
234 | symname = bufp->name.n_strx + stringtab; | |
3fa41cdb JL |
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; | |
c906108c | 240 | bufp->symbol_value += text_offset; |
181c1381 | 241 | bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value); |
c906108c SS |
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; | |
181c1381 | 248 | bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value); |
c906108c SS |
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 | ||
c5aa993b JM |
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. | |
c906108c | 266 | |
c5aa993b JM |
267 | This also happens for weak symbols, but their type is |
268 | ST_DATA. */ | |
c906108c SS |
269 | case SS_UNSAT: |
270 | switch (bufp->symbol_type) | |
271 | { | |
c5aa993b JM |
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; | |
c906108c SS |
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 | ||
c5aa993b | 292 | prim_record_minimal_symbol (symname, bufp->symbol_value, ms_type, |
c906108c SS |
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 | |
fba45db2 | 327 | som_symfile_read (struct objfile *objfile, int mainline) |
c906108c SS |
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 (); | |
56e290f4 | 335 | back_to = make_cleanup_discard_minimal_symbols (); |
c906108c SS |
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); | |
c5aa993b | 342 | #if 0 /* Export symbols not used today 1997-08-05 */ |
c906108c SS |
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". */ | |
c5aa993b | 353 | |
96baa820 | 354 | som_symtab_read (abfd, objfile, objfile->section_offsets); |
c906108c | 355 | |
7134143f DJ |
356 | /* Install any minimal symbols that have been collected as the current |
357 | minimal symbols for this objfile. | |
358 | Further symbol-reading is done incrementally, file-by-file, | |
359 | in a step known as "psymtab-to-symtab" expansion. hp-symtab-read.c | |
360 | contains the code to do the actual DNTT scanning and symtab building. */ | |
361 | install_minimal_symbols (objfile); | |
362 | do_cleanups (back_to); | |
363 | ||
c906108c SS |
364 | /* Now read information from the stabs debug sections. |
365 | This is a no-op for SOM. | |
366 | Perhaps it is intended for some kind of mixed STABS/SOM | |
c5aa993b | 367 | situation? */ |
96baa820 | 368 | stabsect_build_psymtabs (objfile, mainline, |
c906108c SS |
369 | "$GDB_SYMBOLS$", "$GDB_STRINGS$", "$TEXT$"); |
370 | ||
371 | /* Now read the native debug information. | |
372 | This builds the psymtab. This used to be done via a scan of | |
373 | the DNTT, but is now done via the PXDB-built quick-lookup tables | |
374 | together with a scan of the GNTT. See hp-psymtab-read.c. */ | |
d4f3574e | 375 | hpread_build_psymtabs (objfile, mainline); |
c906108c | 376 | |
c906108c SS |
377 | /* Force hppa-tdep.c to re-read the unwind descriptors. */ |
378 | objfile->obj_private = NULL; | |
c906108c SS |
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 | |
fba45db2 | 388 | som_new_init (struct objfile *ignore) |
c906108c SS |
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 | |
fba45db2 | 400 | som_symfile_finish (struct objfile *objfile) |
c906108c | 401 | { |
c5aa993b | 402 | if (objfile->sym_stab_info != NULL) |
c906108c | 403 | { |
aac7f4ea | 404 | xmfree (objfile->md, objfile->sym_stab_info); |
c906108c SS |
405 | } |
406 | hpread_symfile_finish (objfile); | |
407 | } | |
408 | ||
409 | /* SOM specific initialization routine for reading symbols. */ | |
410 | ||
411 | static void | |
fba45db2 | 412 | som_symfile_init (struct objfile *objfile) |
c906108c SS |
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 | ||
d4f3574e | 425 | static void |
fba45db2 | 426 | som_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs) |
c906108c | 427 | { |
c906108c | 428 | int i; |
0aa9cf96 | 429 | CORE_ADDR text_addr; |
c906108c SS |
430 | |
431 | objfile->num_sections = SECT_OFF_MAX; | |
d4f3574e | 432 | objfile->section_offsets = (struct section_offsets *) |
c5aa993b | 433 | obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS); |
c906108c | 434 | |
b8fbeb18 EZ |
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 | ||
c906108c | 446 | /* First see if we're a shared library. If so, get the section |
2acceee2 | 447 | offsets from the library, else get them from addrs. */ |
d4f3574e | 448 | if (!som_solib_section_offsets (objfile, objfile->section_offsets)) |
c906108c | 449 | { |
b8fbeb18 EZ |
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. */ | |
0aa9cf96 EZ |
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 | ||
c906108c | 458 | for (i = 0; i < SECT_OFF_MAX; i++) |
f0a58b0b | 459 | (objfile->section_offsets)->offsets[i] = text_addr; |
c906108c | 460 | } |
c906108c SS |
461 | } |
462 | ||
c906108c SS |
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 | |
fba45db2 | 470 | init_import_symbols (struct objfile *objfile) |
c906108c SS |
471 | { |
472 | unsigned int import_list; | |
473 | unsigned int import_list_size; | |
474 | unsigned int string_table; | |
475 | unsigned int string_table_size; | |
c5aa993b | 476 | char *string_buffer; |
c906108c SS |
477 | register int i; |
478 | register int j; | |
479 | register int k; | |
c5aa993b JM |
480 | asection *text_section; /* section handle */ |
481 | unsigned int dl_header[12]; /* SOM executable header */ | |
c906108c SS |
482 | |
483 | /* A struct for an entry in the SOM import list */ | |
c5aa993b JM |
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) | |
c906108c | 496 | SomImportEntry buffer[SOM_READ_IMPORTS_NUM]; |
c5aa993b | 497 | |
c906108c SS |
498 | /* Initialize in case we error out */ |
499 | objfile->import_list = NULL; | |
500 | objfile->import_list_size = 0; | |
501 | ||
c906108c | 502 | /* It doesn't work, for some reason, to read in space $TEXT$; |
c5aa993b | 503 | the subspace $SHLIB_INFO$ has to be used. Some BFD quirk? pai/1997-08-05 */ |
c906108c SS |
504 | text_section = bfd_get_section_by_name (objfile->obfd, "$SHLIB_INFO$"); |
505 | if (!text_section) | |
506 | return 0; | |
c5aa993b | 507 | /* Get the SOM executable header */ |
c906108c SS |
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. | |
c5aa993b | 512 | FIXME: Change for future HP-UX releases and mods to the SOM executable format */ |
c906108c SS |
513 | if (dl_header[0] != 93092112) |
514 | return 0; | |
c5aa993b JM |
515 | |
516 | import_list = dl_header[4]; | |
c906108c SS |
517 | import_list_size = dl_header[5]; |
518 | if (!import_list_size) | |
519 | return 0; | |
c5aa993b | 520 | string_table = dl_header[10]; |
c906108c SS |
521 | string_table_size = dl_header[11]; |
522 | if (!string_table_size) | |
523 | return 0; | |
524 | ||
c5aa993b | 525 | /* Suck in SOM string table */ |
c906108c SS |
526 | string_buffer = (char *) xmalloc (string_table_size); |
527 | bfd_get_section_contents (objfile->obfd, text_section, string_buffer, | |
c5aa993b | 528 | string_table, string_table_size); |
c906108c SS |
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 | |
c5aa993b | 532 | import list to be freed when the objfile is deallocated */ |
c906108c SS |
533 | objfile->import_list |
534 | = (ImportEntry *) obstack_alloc (&objfile->psymbol_obstack, | |
c5aa993b | 535 | import_list_size * sizeof (ImportEntry)); |
c906108c | 536 | |
c5aa993b JM |
537 | /* Read in the import entries, a bunch at a time */ |
538 | for (j = 0, k = 0; | |
c906108c SS |
539 | j < (import_list_size / SOM_READ_IMPORTS_NUM); |
540 | j++) | |
541 | { | |
542 | bfd_get_section_contents (objfile->obfd, text_section, buffer, | |
c5aa993b JM |
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 | } | |
c906108c SS |
558 | } |
559 | ||
c5aa993b | 560 | /* Get the leftovers */ |
c906108c SS |
561 | if (k < import_list_size) |
562 | bfd_get_section_contents (objfile->obfd, text_section, buffer, | |
c5aa993b JM |
563 | import_list + k * sizeof (SomImportEntry), |
564 | (import_list_size - k) * sizeof (SomImportEntry)); | |
565 | for (i = 0; k < import_list_size; i++, k++) | |
c906108c SS |
566 | { |
567 | if (buffer[i].type != (unsigned char) 0) | |
c5aa993b JM |
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 | } | |
c906108c | 574 | else |
c5aa993b | 575 | objfile->import_list[k] = NULL; |
c906108c SS |
576 | } |
577 | ||
578 | objfile->import_list_size = import_list_size; | |
b8c9b27d | 579 | xfree (string_buffer); |
c906108c SS |
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 | |
fba45db2 | 590 | init_export_symbols (struct objfile *objfile) |
c906108c SS |
591 | { |
592 | unsigned int export_list; | |
593 | unsigned int export_list_size; | |
594 | unsigned int string_table; | |
595 | unsigned int string_table_size; | |
c5aa993b | 596 | char *string_buffer; |
c906108c SS |
597 | register int i; |
598 | register int j; | |
599 | register int k; | |
c5aa993b JM |
600 | asection *text_section; /* section handle */ |
601 | unsigned int dl_header[12]; /* SOM executable header */ | |
c906108c SS |
602 | |
603 | /* A struct for an entry in the SOM export list */ | |
c5aa993b JM |
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) | |
c906108c SS |
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 | ||
c906108c | 625 | /* It doesn't work, for some reason, to read in space $TEXT$; |
c5aa993b | 626 | the subspace $SHLIB_INFO$ has to be used. Some BFD quirk? pai/1997-08-05 */ |
c906108c SS |
627 | text_section = bfd_get_section_by_name (objfile->obfd, "$SHLIB_INFO$"); |
628 | if (!text_section) | |
629 | return 0; | |
c5aa993b | 630 | /* Get the SOM executable header */ |
c906108c SS |
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. | |
c5aa993b | 635 | FIXME: Change for future HP-UX releases and mods to the SOM executable format */ |
c906108c SS |
636 | if (dl_header[0] != 93092112) |
637 | return 0; | |
c5aa993b JM |
638 | |
639 | export_list = dl_header[8]; | |
640 | export_list_size = dl_header[9]; | |
c906108c SS |
641 | if (!export_list_size) |
642 | return 0; | |
c5aa993b | 643 | string_table = dl_header[10]; |
c906108c SS |
644 | string_table_size = dl_header[11]; |
645 | if (!string_table_size) | |
646 | return 0; | |
647 | ||
c5aa993b | 648 | /* Suck in SOM string table */ |
c906108c SS |
649 | string_buffer = (char *) xmalloc (string_table_size); |
650 | bfd_get_section_contents (objfile->obfd, text_section, string_buffer, | |
c5aa993b | 651 | string_table, string_table_size); |
c906108c SS |
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 | |
c5aa993b | 655 | export list to be freed when the objfile is deallocated */ |
c906108c | 656 | objfile->export_list |
c5aa993b JM |
657 | = (ExportEntry *) obstack_alloc (&objfile->psymbol_obstack, |
658 | export_list_size * sizeof (ExportEntry)); | |
c906108c | 659 | |
c5aa993b JM |
660 | /* Read in the export entries, a bunch at a time */ |
661 | for (j = 0, k = 0; | |
c906108c SS |
662 | j < (export_list_size / SOM_READ_EXPORTS_NUM); |
663 | j++) | |
664 | { | |
665 | bfd_get_section_contents (objfile->obfd, text_section, buffer, | |
c5aa993b JM |
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 | } | |
c906108c SS |
685 | } |
686 | ||
c5aa993b | 687 | /* Get the leftovers */ |
c906108c SS |
688 | if (k < export_list_size) |
689 | bfd_get_section_contents (objfile->obfd, text_section, buffer, | |
c5aa993b JM |
690 | export_list + k * sizeof (SomExportEntry), |
691 | (export_list_size - k) * sizeof (SomExportEntry)); | |
692 | for (i = 0; k < export_list_size; i++, k++) | |
c906108c SS |
693 | { |
694 | if (buffer[i].type != (unsigned char) 0) | |
c5aa993b JM |
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 | } | |
c906108c | 702 | else |
c5aa993b JM |
703 | { |
704 | objfile->export_list[k].name = NULL; | |
705 | objfile->export_list[k].address = 0; | |
706 | } | |
c906108c SS |
707 | } |
708 | ||
709 | objfile->export_list_size = export_list_size; | |
b8c9b27d | 710 | xfree (string_buffer); |
c906108c SS |
711 | return export_list_size; |
712 | } | |
c5aa993b | 713 | \f |
c906108c SS |
714 | |
715 | ||
c906108c SS |
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, | |
c5aa993b JM |
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 */ | |
c906108c SS |
727 | }; |
728 | ||
729 | void | |
fba45db2 | 730 | _initialize_somread (void) |
c906108c SS |
731 | { |
732 | add_symtab_fns (&som_sym_fns); | |
733 | } |