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