]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Read HP PA/Risc object files for GDB. |
8b92e4d5 EZ |
2 | Copyright 1991, 1992, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, |
3 | 2004 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 |
40 | static int init_import_symbols (struct objfile *objfile); |
41 | ||
a14ed312 | 42 | static void som_symfile_init (struct objfile *); |
c906108c | 43 | |
a14ed312 | 44 | static void som_new_init (struct objfile *); |
c906108c | 45 | |
a14ed312 | 46 | static void som_symfile_read (struct objfile *, int); |
c906108c | 47 | |
a14ed312 | 48 | static void som_symfile_finish (struct objfile *); |
c906108c | 49 | |
570b8f7c AC |
50 | static void som_symtab_read (bfd *, struct objfile *, |
51 | struct section_offsets *); | |
c906108c | 52 | |
570b8f7c | 53 | static 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 | 57 | extern void hpread_build_psymtabs (struct objfile *, int); |
c906108c | 58 | |
a14ed312 | 59 | extern void hpread_symfile_finish (struct objfile *); |
c906108c | 60 | |
a14ed312 | 61 | extern void hpread_symfile_init (struct objfile *); |
c906108c | 62 | |
a14ed312 | 63 | extern 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 | |
84 | static void | |
fba45db2 KB |
85 | som_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 | 221 | || (symname[0] == 'D' && symname[1] == '$') |
b887c273 | 222 | || (strncmp (symname, "L0\001", 3) == 0) |
c906108c SS |
223 | || (strncmp (symname, "$PIC", 4) == 0)) |
224 | continue; | |
225 | break; | |
226 | ||
227 | case ST_PRI_PROG: | |
228 | case ST_SEC_PROG: | |
229 | case ST_MILLICODE: | |
230 | symname = bufp->name.n_strx + stringtab; | |
231 | ms_type = mst_file_text; | |
232 | bufp->symbol_value += text_offset; | |
181c1381 | 233 | bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value); |
c906108c SS |
234 | break; |
235 | ||
236 | case ST_ENTRY: | |
237 | symname = bufp->name.n_strx + stringtab; | |
3fa41cdb JL |
238 | /* SS_LOCAL symbols in a shared library do not have |
239 | export stubs, so we do not have to worry about | |
240 | using mst_file_text vs mst_solib_trampoline here like | |
241 | we do for SS_UNIVERSAL and SS_EXTERNAL symbols above. */ | |
242 | ms_type = mst_file_text; | |
c906108c | 243 | bufp->symbol_value += text_offset; |
181c1381 | 244 | bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value); |
c906108c SS |
245 | break; |
246 | ||
247 | case ST_STUB: | |
248 | symname = bufp->name.n_strx + stringtab; | |
249 | ms_type = mst_solib_trampoline; | |
250 | bufp->symbol_value += text_offset; | |
181c1381 | 251 | bufp->symbol_value = SMASH_TEXT_ADDRESS (bufp->symbol_value); |
c906108c SS |
252 | break; |
253 | ||
254 | ||
255 | case ST_DATA: | |
256 | symname = bufp->name.n_strx + stringtab; | |
257 | bufp->symbol_value += data_offset; | |
258 | ms_type = mst_file_data; | |
259 | goto check_strange_names; | |
260 | ||
261 | default: | |
262 | continue; | |
263 | } | |
264 | break; | |
265 | ||
c5aa993b JM |
266 | /* This can happen for common symbols when -E is passed to the |
267 | final link. No idea _why_ that would make the linker force | |
268 | common symbols to have an SS_UNSAT scope, but it does. | |
c906108c | 269 | |
c5aa993b JM |
270 | This also happens for weak symbols, but their type is |
271 | ST_DATA. */ | |
c906108c SS |
272 | case SS_UNSAT: |
273 | switch (bufp->symbol_type) | |
274 | { | |
c5aa993b JM |
275 | case ST_STORAGE: |
276 | case ST_DATA: | |
277 | symname = bufp->name.n_strx + stringtab; | |
278 | bufp->symbol_value += data_offset; | |
279 | ms_type = mst_data; | |
280 | break; | |
281 | ||
282 | default: | |
283 | continue; | |
c906108c SS |
284 | } |
285 | break; | |
286 | ||
287 | default: | |
288 | continue; | |
289 | } | |
290 | ||
291 | if (bufp->name.n_strx > obj_som_stringtab_size (abfd)) | |
292 | error ("Invalid symbol data; bad HP string table offset: %d", | |
293 | bufp->name.n_strx); | |
294 | ||
c5aa993b | 295 | prim_record_minimal_symbol (symname, bufp->symbol_value, ms_type, |
c906108c SS |
296 | objfile); |
297 | } | |
298 | } | |
299 | ||
300 | /* Scan and build partial symbols for a symbol file. | |
301 | We have been initialized by a call to som_symfile_init, which | |
302 | currently does nothing. | |
303 | ||
304 | SECTION_OFFSETS is a set of offsets to apply to relocate the symbols | |
305 | in each section. This is ignored, as it isn't needed for SOM. | |
306 | ||
307 | MAINLINE is true if we are reading the main symbol | |
308 | table (as opposed to a shared lib or dynamically loaded file). | |
309 | ||
310 | This function only does the minimum work necessary for letting the | |
311 | user "name" things symbolically; it does not read the entire symtab. | |
312 | Instead, it reads the external and static symbols and puts them in partial | |
313 | symbol tables. When more extensive information is requested of a | |
314 | file, the corresponding partial symbol table is mutated into a full | |
315 | fledged symbol table by going back and reading the symbols | |
316 | for real. | |
317 | ||
318 | We look for sections with specific names, to tell us what debug | |
319 | format to look for: FIXME!!! | |
320 | ||
321 | somstab_build_psymtabs() handles STABS symbols. | |
322 | ||
323 | Note that SOM files have a "minimal" symbol table, which is vaguely | |
324 | reminiscent of a COFF symbol table, but has only the minimal information | |
325 | necessary for linking. We process this also, and use the information to | |
326 | build gdb's minimal symbol table. This gives us some minimal debugging | |
327 | capability even for files compiled without -g. */ | |
328 | ||
329 | static void | |
fba45db2 | 330 | som_symfile_read (struct objfile *objfile, int mainline) |
c906108c SS |
331 | { |
332 | bfd *abfd = objfile->obfd; | |
333 | struct cleanup *back_to; | |
334 | ||
335 | do_pxdb (symfile_bfd_open (objfile->name)); | |
336 | ||
337 | init_minimal_symbol_collection (); | |
56e290f4 | 338 | back_to = make_cleanup_discard_minimal_symbols (); |
c906108c SS |
339 | |
340 | /* Read in the import list and the export list. Currently | |
341 | the export list isn't used; the import list is used in | |
342 | hp-symtab-read.c to handle static vars declared in other | |
343 | shared libraries. */ | |
344 | init_import_symbols (objfile); | |
c5aa993b | 345 | #if 0 /* Export symbols not used today 1997-08-05 */ |
c906108c SS |
346 | init_export_symbols (objfile); |
347 | #else | |
348 | objfile->export_list = NULL; | |
349 | objfile->export_list_size = 0; | |
350 | #endif | |
351 | ||
352 | /* Process the normal SOM symbol table first. | |
353 | This reads in the DNTT and string table, but doesn't | |
354 | actually scan the DNTT. It does scan the linker symbol | |
355 | table and thus build up a "minimal symbol table". */ | |
c5aa993b | 356 | |
96baa820 | 357 | som_symtab_read (abfd, objfile, objfile->section_offsets); |
c906108c | 358 | |
7134143f DJ |
359 | /* Install any minimal symbols that have been collected as the current |
360 | minimal symbols for this objfile. | |
361 | Further symbol-reading is done incrementally, file-by-file, | |
362 | in a step known as "psymtab-to-symtab" expansion. hp-symtab-read.c | |
363 | contains the code to do the actual DNTT scanning and symtab building. */ | |
364 | install_minimal_symbols (objfile); | |
365 | do_cleanups (back_to); | |
366 | ||
c906108c SS |
367 | /* Now read information from the stabs debug sections. |
368 | This is a no-op for SOM. | |
369 | Perhaps it is intended for some kind of mixed STABS/SOM | |
c5aa993b | 370 | situation? */ |
96baa820 | 371 | stabsect_build_psymtabs (objfile, mainline, |
c906108c SS |
372 | "$GDB_SYMBOLS$", "$GDB_STRINGS$", "$TEXT$"); |
373 | ||
374 | /* Now read the native debug information. | |
375 | This builds the psymtab. This used to be done via a scan of | |
376 | the DNTT, but is now done via the PXDB-built quick-lookup tables | |
377 | together with a scan of the GNTT. See hp-psymtab-read.c. */ | |
d4f3574e | 378 | hpread_build_psymtabs (objfile, mainline); |
c906108c | 379 | |
c906108c | 380 | /* Force hppa-tdep.c to re-read the unwind descriptors. */ |
0a6ddd08 | 381 | objfile->deprecated_obj_private = NULL; |
c906108c SS |
382 | } |
383 | ||
384 | /* Initialize anything that needs initializing when a completely new symbol | |
385 | file is specified (not just adding some symbols from another file, e.g. a | |
386 | shared library). | |
387 | ||
388 | We reinitialize buildsym, since we may be reading stabs from a SOM file. */ | |
389 | ||
390 | static void | |
fba45db2 | 391 | som_new_init (struct objfile *ignore) |
c906108c SS |
392 | { |
393 | stabsread_new_init (); | |
394 | buildsym_new_init (); | |
395 | } | |
396 | ||
397 | /* Perform any local cleanups required when we are done with a particular | |
398 | objfile. I.E, we are in the process of discarding all symbol information | |
399 | for an objfile, freeing up all memory held for it, and unlinking the | |
400 | objfile struct from the global list of known objfiles. */ | |
401 | ||
402 | static void | |
fba45db2 | 403 | som_symfile_finish (struct objfile *objfile) |
c906108c | 404 | { |
0a6ddd08 | 405 | if (objfile->deprecated_sym_stab_info != NULL) |
c906108c | 406 | { |
0a6ddd08 | 407 | xfree (objfile->deprecated_sym_stab_info); |
c906108c SS |
408 | } |
409 | hpread_symfile_finish (objfile); | |
410 | } | |
411 | ||
412 | /* SOM specific initialization routine for reading symbols. */ | |
413 | ||
414 | static void | |
fba45db2 | 415 | som_symfile_init (struct objfile *objfile) |
c906108c SS |
416 | { |
417 | /* SOM objects may be reordered, so set OBJF_REORDERED. If we | |
418 | find this causes a significant slowdown in gdb then we could | |
419 | set it in the debug symbol readers only when necessary. */ | |
420 | objfile->flags |= OBJF_REORDERED; | |
421 | hpread_symfile_init (objfile); | |
422 | } | |
423 | ||
424 | /* SOM specific parsing routine for section offsets. | |
425 | ||
426 | Plain and simple for now. */ | |
427 | ||
d4f3574e | 428 | static void |
fba45db2 | 429 | som_symfile_offsets (struct objfile *objfile, struct section_addr_info *addrs) |
c906108c | 430 | { |
c906108c | 431 | int i; |
0aa9cf96 | 432 | CORE_ADDR text_addr; |
c906108c | 433 | |
a39a16c4 | 434 | objfile->num_sections = bfd_count_sections (objfile->obfd); |
d4f3574e | 435 | objfile->section_offsets = (struct section_offsets *) |
8b92e4d5 | 436 | obstack_alloc (&objfile->objfile_obstack, |
a39a16c4 | 437 | SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)); |
c906108c | 438 | |
b8fbeb18 EZ |
439 | /* FIXME: ezannoni 2000-04-20 The section names in SOM are not |
440 | .text, .data, etc, but $TEXT$, $DATA$,... We should initialize | |
441 | SET_OFF_* from bfd. (See default_symfile_offsets()). But I don't | |
442 | know the correspondence between SOM sections and GDB's idea of | |
443 | section names. So for now we default to what is was before these | |
444 | changes.*/ | |
445 | objfile->sect_index_text = 0; | |
446 | objfile->sect_index_data = 1; | |
447 | objfile->sect_index_bss = 2; | |
448 | objfile->sect_index_rodata = 3; | |
449 | ||
c906108c | 450 | /* First see if we're a shared library. If so, get the section |
2acceee2 | 451 | offsets from the library, else get them from addrs. */ |
d4f3574e | 452 | if (!som_solib_section_offsets (objfile, objfile->section_offsets)) |
c906108c | 453 | { |
b8fbeb18 EZ |
454 | /* Note: Here is OK to compare with ".text" because this is the |
455 | name that gdb itself gives to that section, not the SOM | |
456 | name. */ | |
64176fa3 | 457 | for (i = 0; i < objfile->num_sections && addrs->other[i].name; i++) |
0aa9cf96 EZ |
458 | if (strcmp (addrs->other[i].name, ".text") == 0) |
459 | break; | |
460 | text_addr = addrs->other[i].addr; | |
461 | ||
a39a16c4 | 462 | for (i = 0; i < objfile->num_sections; i++) |
f0a58b0b | 463 | (objfile->section_offsets)->offsets[i] = text_addr; |
c906108c | 464 | } |
c906108c SS |
465 | } |
466 | ||
c906108c SS |
467 | /* Read in and initialize the SOM import list which is present |
468 | for all executables and shared libraries. The import list | |
469 | consists of the symbols that are referenced in OBJFILE but | |
470 | not defined there. (Variables that are imported are dealt | |
471 | with as "loc_indirect" vars.) | |
472 | Return value = number of import symbols read in. */ | |
65e82032 | 473 | static int |
fba45db2 | 474 | init_import_symbols (struct objfile *objfile) |
c906108c SS |
475 | { |
476 | unsigned int import_list; | |
477 | unsigned int import_list_size; | |
478 | unsigned int string_table; | |
479 | unsigned int string_table_size; | |
c5aa993b | 480 | char *string_buffer; |
52f0bd74 AC |
481 | int i; |
482 | int j; | |
483 | int k; | |
c5aa993b JM |
484 | asection *text_section; /* section handle */ |
485 | unsigned int dl_header[12]; /* SOM executable header */ | |
c906108c SS |
486 | |
487 | /* A struct for an entry in the SOM import list */ | |
c5aa993b JM |
488 | typedef struct |
489 | { | |
490 | int name; /* index into the string table */ | |
491 | short dont_care1; /* we don't use this */ | |
492 | unsigned char type; /* 0 = NULL, 2 = Data, 3 = Code, 7 = Storage, 13 = Plabel */ | |
493 | unsigned int reserved2:8; /* not used */ | |
494 | } | |
495 | SomImportEntry; | |
496 | ||
497 | /* We read 100 entries in at a time from the disk file. */ | |
498 | #define SOM_READ_IMPORTS_NUM 100 | |
499 | #define SOM_READ_IMPORTS_CHUNK_SIZE (sizeof (SomImportEntry) * SOM_READ_IMPORTS_NUM) | |
c906108c | 500 | SomImportEntry buffer[SOM_READ_IMPORTS_NUM]; |
c5aa993b | 501 | |
c906108c SS |
502 | /* Initialize in case we error out */ |
503 | objfile->import_list = NULL; | |
504 | objfile->import_list_size = 0; | |
505 | ||
c906108c | 506 | /* It doesn't work, for some reason, to read in space $TEXT$; |
c5aa993b | 507 | the subspace $SHLIB_INFO$ has to be used. Some BFD quirk? pai/1997-08-05 */ |
c906108c SS |
508 | text_section = bfd_get_section_by_name (objfile->obfd, "$SHLIB_INFO$"); |
509 | if (!text_section) | |
510 | return 0; | |
c5aa993b | 511 | /* Get the SOM executable header */ |
c906108c SS |
512 | bfd_get_section_contents (objfile->obfd, text_section, dl_header, 0, 12 * sizeof (int)); |
513 | ||
514 | /* Check header version number for 10.x HP-UX */ | |
515 | /* Currently we deal only with 10.x systems; on 9.x the version # is 89060912. | |
c5aa993b | 516 | FIXME: Change for future HP-UX releases and mods to the SOM executable format */ |
c906108c SS |
517 | if (dl_header[0] != 93092112) |
518 | return 0; | |
c5aa993b JM |
519 | |
520 | import_list = dl_header[4]; | |
c906108c SS |
521 | import_list_size = dl_header[5]; |
522 | if (!import_list_size) | |
523 | return 0; | |
c5aa993b | 524 | string_table = dl_header[10]; |
c906108c SS |
525 | string_table_size = dl_header[11]; |
526 | if (!string_table_size) | |
527 | return 0; | |
528 | ||
c5aa993b | 529 | /* Suck in SOM string table */ |
c906108c SS |
530 | string_buffer = (char *) xmalloc (string_table_size); |
531 | bfd_get_section_contents (objfile->obfd, text_section, string_buffer, | |
c5aa993b | 532 | string_table, string_table_size); |
c906108c SS |
533 | |
534 | /* Allocate import list in the psymbol obstack; this has nothing | |
535 | to do with psymbols, just a matter of convenience. We want the | |
c5aa993b | 536 | import list to be freed when the objfile is deallocated */ |
c906108c | 537 | objfile->import_list |
8b92e4d5 | 538 | = (ImportEntry *) obstack_alloc (&objfile->objfile_obstack, |
c5aa993b | 539 | import_list_size * sizeof (ImportEntry)); |
c906108c | 540 | |
c5aa993b JM |
541 | /* Read in the import entries, a bunch at a time */ |
542 | for (j = 0, k = 0; | |
c906108c SS |
543 | j < (import_list_size / SOM_READ_IMPORTS_NUM); |
544 | j++) | |
545 | { | |
546 | bfd_get_section_contents (objfile->obfd, text_section, buffer, | |
c5aa993b JM |
547 | import_list + j * SOM_READ_IMPORTS_CHUNK_SIZE, |
548 | SOM_READ_IMPORTS_CHUNK_SIZE); | |
549 | for (i = 0; i < SOM_READ_IMPORTS_NUM; i++, k++) | |
550 | { | |
551 | if (buffer[i].type != (unsigned char) 0) | |
552 | { | |
553 | objfile->import_list[k] | |
8b92e4d5 | 554 | = (char *) obstack_alloc (&objfile->objfile_obstack, strlen (string_buffer + buffer[i].name) + 1); |
c5aa993b JM |
555 | strcpy (objfile->import_list[k], string_buffer + buffer[i].name); |
556 | /* Some day we might want to record the type and other information too */ | |
557 | } | |
558 | else /* null type */ | |
559 | objfile->import_list[k] = NULL; | |
560 | ||
561 | } | |
c906108c SS |
562 | } |
563 | ||
c5aa993b | 564 | /* Get the leftovers */ |
c906108c SS |
565 | if (k < import_list_size) |
566 | bfd_get_section_contents (objfile->obfd, text_section, buffer, | |
c5aa993b JM |
567 | import_list + k * sizeof (SomImportEntry), |
568 | (import_list_size - k) * sizeof (SomImportEntry)); | |
569 | for (i = 0; k < import_list_size; i++, k++) | |
c906108c SS |
570 | { |
571 | if (buffer[i].type != (unsigned char) 0) | |
c5aa993b JM |
572 | { |
573 | objfile->import_list[k] | |
8b92e4d5 | 574 | = (char *) obstack_alloc (&objfile->objfile_obstack, strlen (string_buffer + buffer[i].name) + 1); |
c5aa993b JM |
575 | strcpy (objfile->import_list[k], string_buffer + buffer[i].name); |
576 | /* Some day we might want to record the type and other information too */ | |
577 | } | |
c906108c | 578 | else |
c5aa993b | 579 | objfile->import_list[k] = NULL; |
c906108c SS |
580 | } |
581 | ||
582 | objfile->import_list_size = import_list_size; | |
b8c9b27d | 583 | xfree (string_buffer); |
c906108c SS |
584 | return import_list_size; |
585 | } | |
586 | ||
587 | /* Read in and initialize the SOM export list which is present | |
588 | for all executables and shared libraries. The import list | |
589 | consists of the symbols that are referenced in OBJFILE but | |
590 | not defined there. (Variables that are imported are dealt | |
591 | with as "loc_indirect" vars.) | |
592 | Return value = number of import symbols read in. */ | |
593 | int | |
fba45db2 | 594 | init_export_symbols (struct objfile *objfile) |
c906108c SS |
595 | { |
596 | unsigned int export_list; | |
597 | unsigned int export_list_size; | |
598 | unsigned int string_table; | |
599 | unsigned int string_table_size; | |
c5aa993b | 600 | char *string_buffer; |
52f0bd74 AC |
601 | int i; |
602 | int j; | |
603 | int k; | |
c5aa993b JM |
604 | asection *text_section; /* section handle */ |
605 | unsigned int dl_header[12]; /* SOM executable header */ | |
c906108c SS |
606 | |
607 | /* A struct for an entry in the SOM export list */ | |
c5aa993b JM |
608 | typedef struct |
609 | { | |
610 | int next; /* for hash table use -- we don't use this */ | |
611 | int name; /* index into string table */ | |
612 | int value; /* offset or plabel */ | |
613 | int dont_care1; /* not used */ | |
614 | unsigned char type; /* 0 = NULL, 2 = Data, 3 = Code, 7 = Storage, 13 = Plabel */ | |
615 | char dont_care2; /* not used */ | |
616 | short dont_care3; /* not used */ | |
617 | } | |
618 | SomExportEntry; | |
619 | ||
620 | /* We read 100 entries in at a time from the disk file. */ | |
621 | #define SOM_READ_EXPORTS_NUM 100 | |
622 | #define SOM_READ_EXPORTS_CHUNK_SIZE (sizeof (SomExportEntry) * SOM_READ_EXPORTS_NUM) | |
c906108c SS |
623 | SomExportEntry buffer[SOM_READ_EXPORTS_NUM]; |
624 | ||
625 | /* Initialize in case we error out */ | |
626 | objfile->export_list = NULL; | |
627 | objfile->export_list_size = 0; | |
628 | ||
c906108c | 629 | /* It doesn't work, for some reason, to read in space $TEXT$; |
c5aa993b | 630 | the subspace $SHLIB_INFO$ has to be used. Some BFD quirk? pai/1997-08-05 */ |
c906108c SS |
631 | text_section = bfd_get_section_by_name (objfile->obfd, "$SHLIB_INFO$"); |
632 | if (!text_section) | |
633 | return 0; | |
c5aa993b | 634 | /* Get the SOM executable header */ |
c906108c SS |
635 | bfd_get_section_contents (objfile->obfd, text_section, dl_header, 0, 12 * sizeof (int)); |
636 | ||
637 | /* Check header version number for 10.x HP-UX */ | |
638 | /* Currently we deal only with 10.x systems; on 9.x the version # is 89060912. | |
c5aa993b | 639 | FIXME: Change for future HP-UX releases and mods to the SOM executable format */ |
c906108c SS |
640 | if (dl_header[0] != 93092112) |
641 | return 0; | |
c5aa993b JM |
642 | |
643 | export_list = dl_header[8]; | |
644 | export_list_size = dl_header[9]; | |
c906108c SS |
645 | if (!export_list_size) |
646 | return 0; | |
c5aa993b | 647 | string_table = dl_header[10]; |
c906108c SS |
648 | string_table_size = dl_header[11]; |
649 | if (!string_table_size) | |
650 | return 0; | |
651 | ||
c5aa993b | 652 | /* Suck in SOM string table */ |
c906108c SS |
653 | string_buffer = (char *) xmalloc (string_table_size); |
654 | bfd_get_section_contents (objfile->obfd, text_section, string_buffer, | |
c5aa993b | 655 | string_table, string_table_size); |
c906108c SS |
656 | |
657 | /* Allocate export list in the psymbol obstack; this has nothing | |
658 | to do with psymbols, just a matter of convenience. We want the | |
c5aa993b | 659 | export list to be freed when the objfile is deallocated */ |
c906108c | 660 | objfile->export_list |
8b92e4d5 | 661 | = (ExportEntry *) obstack_alloc (&objfile->objfile_obstack, |
c5aa993b | 662 | export_list_size * sizeof (ExportEntry)); |
c906108c | 663 | |
c5aa993b JM |
664 | /* Read in the export entries, a bunch at a time */ |
665 | for (j = 0, k = 0; | |
c906108c SS |
666 | j < (export_list_size / SOM_READ_EXPORTS_NUM); |
667 | j++) | |
668 | { | |
669 | bfd_get_section_contents (objfile->obfd, text_section, buffer, | |
c5aa993b JM |
670 | export_list + j * SOM_READ_EXPORTS_CHUNK_SIZE, |
671 | SOM_READ_EXPORTS_CHUNK_SIZE); | |
672 | for (i = 0; i < SOM_READ_EXPORTS_NUM; i++, k++) | |
673 | { | |
674 | if (buffer[i].type != (unsigned char) 0) | |
675 | { | |
676 | objfile->export_list[k].name | |
8b92e4d5 | 677 | = (char *) obstack_alloc (&objfile->objfile_obstack, strlen (string_buffer + buffer[i].name) + 1); |
c5aa993b JM |
678 | strcpy (objfile->export_list[k].name, string_buffer + buffer[i].name); |
679 | objfile->export_list[k].address = buffer[i].value; | |
680 | /* Some day we might want to record the type and other information too */ | |
681 | } | |
682 | else | |
683 | /* null type */ | |
684 | { | |
685 | objfile->export_list[k].name = NULL; | |
686 | objfile->export_list[k].address = 0; | |
687 | } | |
688 | } | |
c906108c SS |
689 | } |
690 | ||
c5aa993b | 691 | /* Get the leftovers */ |
c906108c SS |
692 | if (k < export_list_size) |
693 | bfd_get_section_contents (objfile->obfd, text_section, buffer, | |
c5aa993b JM |
694 | export_list + k * sizeof (SomExportEntry), |
695 | (export_list_size - k) * sizeof (SomExportEntry)); | |
696 | for (i = 0; k < export_list_size; i++, k++) | |
c906108c SS |
697 | { |
698 | if (buffer[i].type != (unsigned char) 0) | |
c5aa993b JM |
699 | { |
700 | objfile->export_list[k].name | |
8b92e4d5 | 701 | = (char *) obstack_alloc (&objfile->objfile_obstack, strlen (string_buffer + buffer[i].name) + 1); |
c5aa993b JM |
702 | strcpy (objfile->export_list[k].name, string_buffer + buffer[i].name); |
703 | /* Some day we might want to record the type and other information too */ | |
704 | objfile->export_list[k].address = buffer[i].value; | |
705 | } | |
c906108c | 706 | else |
c5aa993b JM |
707 | { |
708 | objfile->export_list[k].name = NULL; | |
709 | objfile->export_list[k].address = 0; | |
710 | } | |
c906108c SS |
711 | } |
712 | ||
713 | objfile->export_list_size = export_list_size; | |
b8c9b27d | 714 | xfree (string_buffer); |
c906108c SS |
715 | return export_list_size; |
716 | } | |
c5aa993b | 717 | \f |
c906108c SS |
718 | |
719 | ||
c906108c SS |
720 | /* Register that we are able to handle SOM object file formats. */ |
721 | ||
722 | static struct sym_fns som_sym_fns = | |
723 | { | |
724 | bfd_target_som_flavour, | |
c5aa993b JM |
725 | som_new_init, /* sym_new_init: init anything gbl to entire symtab */ |
726 | som_symfile_init, /* sym_init: read initial info, setup for sym_read() */ | |
727 | som_symfile_read, /* sym_read: read a symbol file into symtab */ | |
728 | som_symfile_finish, /* sym_finish: finished with file, cleanup */ | |
729 | som_symfile_offsets, /* sym_offsets: Translate ext. to int. relocation */ | |
730 | NULL /* next: pointer to next struct sym_fns */ | |
c906108c SS |
731 | }; |
732 | ||
733 | void | |
fba45db2 | 734 | _initialize_somread (void) |
c906108c SS |
735 | { |
736 | add_symtab_fns (&som_sym_fns); | |
737 | } |