Tue Sep 28 09:45:38 1993 Peter Schauer (pes@regent.e-technik.tu-muenchen.de)
[deliverable/binutils-gdb.git] / gdb / elfread.c
CommitLineData
35f5886e 1/* Read ELF (Executable and Linking Format) object files for GDB.
c2e4669f 2 Copyright 1991, 1992 Free Software Foundation, Inc.
35f5886e
FF
3 Written by Fred Fish at Cygnus Support.
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
35f5886e 21#include "defs.h"
35f5886e 22#include "bfd.h"
fc773653 23#include <time.h> /* For time_t in libbfd.h. */
ddf5d7e8 24#include <sys/types.h> /* For time_t, if not in time.h. */
f70be3e4 25#include "libbfd.h" /* For bfd_elf_find_section */
2084a176 26#include "libelf.h"
35f5886e 27#include "symtab.h"
1ab3bf1b 28#include "symfile.h"
5e2e79f8 29#include "objfiles.h"
be772100 30#include "buildsym.h"
2731625a 31#include "stabsread.h"
2670f34d 32#include "gdb-stabs.h"
51b80b00 33#include "complaints.h"
740b7efa 34#include <string.h>
2e4964ad 35#include "demangle.h"
35f5886e 36
2670f34d
JG
37/* The struct elfinfo is available only during ELF symbol table and
38 psymtab reading. It is destroyed at the complation of psymtab-reading.
39 It's local to elf_symfile_read. */
40
35f5886e 41struct elfinfo {
d5931d79 42 file_ptr dboffset; /* Offset to dwarf debug section */
35f5886e 43 unsigned int dbsize; /* Size of dwarf debug section */
d5931d79 44 file_ptr lnoffset; /* Offset to dwarf line number section */
35f5886e 45 unsigned int lnsize; /* Size of dwarf line number section */
346168a2
JG
46 asection *stabsect; /* Section pointer for .stab section */
47 asection *stabindexsect; /* Section pointer for .stab.index section */
35f5886e
FF
48};
49
2670f34d
JG
50/* Various things we might complain about... */
51
52struct complaint section_info_complaint =
53 {"elf/stab section information %s without a preceding file symbol", 0, 0};
54
55struct complaint section_info_dup_complaint =
56 {"duplicated elf/stab section information for %s", 0, 0};
57
58struct complaint stab_info_mismatch_complaint =
59 {"elf/stab section information missing for %s", 0, 0};
60
61struct complaint stab_info_questionable_complaint =
62 {"elf/stab section information questionable for %s", 0, 0};
63
1ab3bf1b 64static void
80d68b1d 65elf_symfile_init PARAMS ((struct objfile *));
1ab3bf1b
JG
66
67static void
80d68b1d 68elf_new_init PARAMS ((struct objfile *));
1ab3bf1b
JG
69
70static void
2670f34d 71elf_symfile_read PARAMS ((struct objfile *, struct section_offsets *, int));
80d68b1d
FF
72
73static void
74elf_symfile_finish PARAMS ((struct objfile *));
1ab3bf1b
JG
75
76static void
be772100 77elf_symtab_read PARAMS ((bfd *, CORE_ADDR, struct objfile *));
1ab3bf1b 78
2670f34d
JG
79static void
80free_elfinfo PARAMS ((PTR));
81
82static struct section_offsets *
83elf_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR));
84
51b57ded
FF
85static void
86record_minimal_symbol_and_info PARAMS ((char *, CORE_ADDR,
87 enum minimal_symbol_type, char *,
88 struct objfile *));
1ab3bf1b
JG
89
90static void
91elf_locate_sections PARAMS ((bfd *, asection *, PTR));
92
35f5886e
FF
93/* We are called once per section from elf_symfile_read. We
94 need to examine each section we are passed, check to see
95 if it is something we are interested in processing, and
96 if so, stash away some access information for the section.
97
98 For now we recognize the dwarf debug information sections and
99 line number sections from matching their section names. The
100 ELF definition is no real help here since it has no direct
101 knowledge of DWARF (by design, so any debugging format can be
102 used).
103
346168a2
JG
104 We also recognize the ".stab" sections used by the Sun compilers
105 released with Solaris 2.
106
35f5886e
FF
107 FIXME: The section names should not be hardwired strings. */
108
109static void
be772100
JG
110elf_locate_sections (ignore_abfd, sectp, eip)
111 bfd *ignore_abfd;
1ab3bf1b
JG
112 asection *sectp;
113 PTR eip;
35f5886e 114{
1ab3bf1b
JG
115 register struct elfinfo *ei;
116
117 ei = (struct elfinfo *) eip;
35f5886e
FF
118 if (STREQ (sectp -> name, ".debug"))
119 {
120 ei -> dboffset = sectp -> filepos;
e5849334 121 ei -> dbsize = bfd_get_section_size_before_reloc (sectp);
35f5886e
FF
122 }
123 else if (STREQ (sectp -> name, ".line"))
124 {
125 ei -> lnoffset = sectp -> filepos;
e5849334 126 ei -> lnsize = bfd_get_section_size_before_reloc (sectp);
35f5886e 127 }
346168a2
JG
128 else if (STREQ (sectp -> name, ".stab"))
129 {
130 ei -> stabsect = sectp;
131 }
132 else if (STREQ (sectp -> name, ".stab.index"))
133 {
134 ei -> stabindexsect = sectp;
135 }
35f5886e
FF
136}
137
1ab3bf1b
JG
138#if 0 /* Currently unused */
139
f8b76e70 140char *
1ab3bf1b
JG
141elf_interpreter (abfd)
142 bfd *abfd;
f8b76e70
FF
143{
144 sec_ptr interp_sec;
145 unsigned size;
146 char *interp = NULL;
147
148 interp_sec = bfd_get_section_by_name (abfd, ".interp");
149 if (interp_sec)
150 {
151 size = bfd_section_size (abfd, interp_sec);
152 interp = alloca (size);
153 if (bfd_get_section_contents (abfd, interp_sec, interp, (file_ptr)0,
154 size))
155 {
156 interp = savestring (interp, size - 1);
157 }
158 else
159 {
160 interp = NULL;
161 }
162 }
163 return (interp);
164}
165
1ab3bf1b
JG
166#endif
167
346168a2
JG
168static void
169record_minimal_symbol_and_info (name, address, ms_type, info, objfile)
170 char *name;
171 CORE_ADDR address;
172 enum minimal_symbol_type ms_type;
173 char *info; /* FIXME, is this really char *? */
174 struct objfile *objfile;
175{
610a7e74
ILT
176 int section;
177
178 /* Guess the section from the type. This is likely to be wrong in
179 some cases. */
180 switch (ms_type)
181 {
182 case mst_text:
183 case mst_file_text:
184 section = SECT_OFF_TEXT;
185 break;
186 case mst_data:
187 case mst_file_data:
188 section = SECT_OFF_DATA;
189 break;
190 case mst_bss:
191 case mst_file_bss:
192 section = SECT_OFF_BSS;
193 break;
194 default:
195 section = -1;
196 break;
197 }
198
346168a2 199 name = obsavestring (name, strlen (name), &objfile -> symbol_obstack);
610a7e74 200 prim_record_minimal_symbol_and_info (name, address, ms_type, info, section);
346168a2
JG
201}
202
f8b76e70
FF
203/*
204
205LOCAL FUNCTION
206
207 elf_symtab_read -- read the symbol table of an ELF file
208
209SYNOPSIS
210
be772100 211 void elf_symtab_read (bfd *abfd, CORE_ADDR addr,
1ab3bf1b 212 struct objfile *objfile)
f8b76e70
FF
213
214DESCRIPTION
215
216 Given an open bfd, a base address to relocate symbols to, and a
217 flag that specifies whether or not this bfd is for an executable
218 or not (may be shared library for example), add all the global
1ab3bf1b 219 function and data symbols to the minimal symbol table.
f8b76e70 220
2670f34d
JG
221 In stabs-in-ELF, as implemented by Sun, there are some local symbols
222 defined in the ELF symbol table, which can be used to locate
223 the beginnings of sections from each ".o" file that was linked to
224 form the executable objfile. We gather any such info and record it
225 in data structures hung off the objfile's private data.
226
f8b76e70
FF
227*/
228
a7446af6 229static void
be772100 230elf_symtab_read (abfd, addr, objfile)
1ab3bf1b
JG
231 bfd *abfd;
232 CORE_ADDR addr;
1ab3bf1b 233 struct objfile *objfile;
a7446af6
FF
234{
235 unsigned int storage_needed;
236 asymbol *sym;
237 asymbol **symbol_table;
238 unsigned int number_of_symbols;
239 unsigned int i;
2670f34d 240 int index;
a7446af6 241 struct cleanup *back_to;
f8b76e70 242 CORE_ADDR symaddr;
1ab3bf1b 243 enum minimal_symbol_type ms_type;
6c8f91a1 244 /* If sectinfo is nonNULL, it contains section info that should end up
2670f34d 245 filed in the objfile. */
6c8f91a1 246 struct stab_section_info *sectinfo = NULL;
2670f34d
JG
247 /* If filesym is nonzero, it points to a file symbol, but we haven't
248 seen any section info for it yet. */
249 asymbol *filesym = 0;
250 struct dbx_symfile_info *dbx = (struct dbx_symfile_info *)
251 objfile->sym_private;
6c8f91a1 252 unsigned long size;
a7446af6
FF
253
254 storage_needed = get_symtab_upper_bound (abfd);
a7446af6
FF
255 if (storage_needed > 0)
256 {
3b0b9220 257 symbol_table = (asymbol **) xmalloc (storage_needed);
a7446af6
FF
258 back_to = make_cleanup (free, symbol_table);
259 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
a7446af6
FF
260 for (i = 0; i < number_of_symbols; i++)
261 {
2670f34d 262 sym = symbol_table[i];
6c8f91a1 263 if (sym -> name == NULL || *sym -> name == '\0')
379dd965 264 {
6c8f91a1
FF
265 /* Skip names that don't exist (shouldn't happen), or names
266 that are null strings (may happen). */
379dd965
FF
267 continue;
268 }
6c8f91a1
FF
269 if (sym -> flags & BSF_FILE)
270 {
271 /* STT_FILE debugging symbol that helps stabs-in-elf debugging.
272 Chain any old one onto the objfile; remember new sym. */
273 if (sectinfo != NULL)
274 {
275 sectinfo -> next = dbx -> stab_section_info;
276 dbx -> stab_section_info = sectinfo;
277 sectinfo = NULL;
278 }
279 filesym = sym;
280 }
281 else if (sym -> flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK))
a7446af6 282 {
6c8f91a1
FF
283 /* Select global/local/weak symbols. Note that bfd puts abs
284 symbols in their own section, so all symbols we are
285 interested in will have a section. */
a608f919
FF
286 /* Bfd symbols are section relative. */
287 symaddr = sym -> value + sym -> section -> vma;
c2e4669f
JG
288 /* Relocate all non-absolute symbols by base address. */
289 if (sym -> section != &bfd_abs_section)
6c8f91a1
FF
290 {
291 symaddr += addr;
292 }
f8b76e70
FF
293 /* For non-absolute symbols, use the type of the section
294 they are relative to, to intuit text/data. Bfd provides
295 no way of figuring this out for absolute symbols. */
6c8f91a1
FF
296 if (sym -> section == &bfd_abs_section)
297 {
298 ms_type = mst_abs;
299 }
300 else if (sym -> section -> flags & SEC_CODE)
f8b76e70 301 {
379dd965
FF
302 if (sym -> flags & BSF_GLOBAL)
303 {
304 ms_type = mst_text;
305 }
5ec3ba25 306 else if (sym->name[0] == '.' && sym->name[1] == 'L')
bbf1ff10
JK
307 /* Looks like a compiler-generated label. Skip it.
308 The assembler should be skipping these (to keep
309 executables small), but apparently with gcc on the
310 delta m88k SVR4, it loses. So to have us check too
311 should be harmless (but I encourage people to fix this
312 in the assembler instead of adding checks here). */
5ec3ba25 313 continue;
379dd965
FF
314 else
315 {
316 ms_type = mst_file_text;
317 }
f8b76e70 318 }
d35bf52d 319 else if (sym -> section -> flags & SEC_DATA)
f8b76e70 320 {
379dd965
FF
321 if (sym -> flags & BSF_GLOBAL)
322 {
323 if (sym -> section -> flags & SEC_HAS_CONTENTS)
324 {
325 ms_type = mst_data;
326 }
327 else
328 {
329 ms_type = mst_bss;
330 }
331 }
6c8f91a1 332 else if (sym -> flags & BSF_LOCAL)
379dd965 333 {
6c8f91a1
FF
334 /* Named Local variable in a Data section. Check its
335 name for stabs-in-elf. The STREQ macro checks the
336 first character inline, so we only actually do a
337 strcmp function call on names that start with 'B'
338 or 'D' */
339 index = SECT_OFF_MAX;
340 if (STREQ ("Bbss.bss", sym -> name))
341 {
342 index = SECT_OFF_BSS;
343 }
344 else if (STREQ ("Ddata.data", sym -> name))
345 {
346 index = SECT_OFF_DATA;
347 }
348 else if (STREQ ("Drodata.rodata", sym -> name))
349 {
350 index = SECT_OFF_RODATA;
351 }
352 if (index != SECT_OFF_MAX)
353 {
354 /* Found a special local symbol. Allocate a
355 sectinfo, if needed, and fill it in. */
356 if (sectinfo == NULL)
357 {
358 sectinfo = (struct stab_section_info *)
359 xmmalloc (objfile -> md, sizeof (*sectinfo));
360 memset ((PTR) sectinfo, 0, sizeof (*sectinfo));
361 if (filesym == NULL)
362 {
363 complain (&section_info_complaint,
364 sym -> name);
365 }
366 else
367 {
368 sectinfo -> filename =
369 (char *) filesym -> name;
370 }
371 }
372 if (sectinfo -> sections[index] != 0)
373 {
374 complain (&section_info_dup_complaint,
375 sectinfo -> filename);
376 }
377 /* Bfd symbols are section relative. */
378 symaddr = sym -> value + sym -> section -> vma;
379 /* Relocate non-absolute symbols by base address. */
380 if (sym -> section != &bfd_abs_section)
381 {
382 symaddr += addr;
383 }
384 sectinfo -> sections[index] = symaddr;
385 /* The special local symbols don't go in the
386 minimal symbol table, so ignore this one. */
387 continue;
388 }
389 /* Not a special stabs-in-elf symbol, do regular
390 symbol processing. */
379dd965
FF
391 if (sym -> section -> flags & SEC_HAS_CONTENTS)
392 {
393 ms_type = mst_file_data;
394 }
395 else
396 {
397 ms_type = mst_file_bss;
398 }
399 }
6c8f91a1
FF
400 else
401 {
402 ms_type = mst_unknown;
403 }
f8b76e70
FF
404 }
405 else
406 {
4c7c6bab
JG
407 /* FIXME: Solaris2 shared libraries include lots of
408 odd "absolute" and "undefined" symbols, that play
409 hob with actions like finding what function the PC
379dd965 410 is in. Ignore them if they aren't text, data, or bss. */
4c7c6bab
JG
411 /* ms_type = mst_unknown; */
412 continue; /* Skip this symbol. */
f8b76e70 413 }
346168a2 414 /* Pass symbol size field in via BFD. FIXME!!! */
538b2068 415 size = ((elf_symbol_type *) sym) -> internal_elf_sym.st_size;
6c8f91a1
FF
416 record_minimal_symbol_and_info ((char *) sym -> name, symaddr,
417 ms_type, (PTR) size, objfile);
2670f34d 418 }
a7446af6
FF
419 }
420 do_cleanups (back_to);
421 }
422}
423
35f5886e
FF
424/* Scan and build partial symbols for a symbol file.
425 We have been initialized by a call to elf_symfile_init, which
426 currently does nothing.
427
2670f34d
JG
428 SECTION_OFFSETS is a set of offsets to apply to relocate the symbols
429 in each section. We simplify it down to a single offset for all
430 symbols. FIXME.
35f5886e
FF
431
432 MAINLINE is true if we are reading the main symbol
433 table (as opposed to a shared lib or dynamically loaded file).
434
435 This function only does the minimum work necessary for letting the
436 user "name" things symbolically; it does not read the entire symtab.
437 Instead, it reads the external and static symbols and puts them in partial
438 symbol tables. When more extensive information is requested of a
439 file, the corresponding partial symbol table is mutated into a full
440 fledged symbol table by going back and reading the symbols
346168a2
JG
441 for real.
442
443 We look for sections with specific names, to tell us what debug
444 format to look for: FIXME!!!
445
446 dwarf_build_psymtabs() builds psymtabs for DWARF symbols;
447 elfstab_build_psymtabs() handles STABS symbols.
a7446af6
FF
448
449 Note that ELF files have a "minimal" symbol table, which looks a lot
450 like a COFF symbol table, but has only the minimal information necessary
346168a2
JG
451 for linking. We process this also, and use the information to
452 build gdb's minimal symbol table. This gives us some minimal debugging
453 capability even for files compiled without -g. */
35f5886e
FF
454
455static void
2670f34d 456elf_symfile_read (objfile, section_offsets, mainline)
80d68b1d 457 struct objfile *objfile;
2670f34d 458 struct section_offsets *section_offsets;
1ab3bf1b 459 int mainline;
35f5886e 460{
80d68b1d 461 bfd *abfd = objfile->obfd;
35f5886e 462 struct elfinfo ei;
a7446af6 463 struct cleanup *back_to;
346168a2 464 CORE_ADDR offset;
35f5886e 465
1ab3bf1b
JG
466 init_minimal_symbol_collection ();
467 back_to = make_cleanup (discard_minimal_symbols, 0);
a7446af6 468
2670f34d 469 memset ((char *) &ei, 0, sizeof (ei));
6b801388 470
2670f34d
JG
471 /* Allocate struct to keep track of the symfile */
472 objfile->sym_private = (PTR)
473 xmmalloc (objfile -> md, sizeof (struct dbx_symfile_info));
474 memset ((char *) objfile->sym_private, 0, sizeof (struct dbx_symfile_info));
475 make_cleanup (free_elfinfo, (PTR) objfile);
6b801388 476
2670f34d
JG
477 /* Process the normal ELF symbol table first. This may write some
478 chain of info into the dbx_symfile_info in objfile->sym_private,
479 which can later be used by elfstab_offset_sections. */
a7446af6 480
2670f34d
JG
481 /* FIXME, should take a section_offsets param, not just an offset. */
482 offset = ANOFFSET (section_offsets, 0);
346168a2 483 elf_symtab_read (abfd, offset, objfile);
a7446af6 484
346168a2 485 /* Now process debugging information, which is contained in
a7446af6
FF
486 special ELF sections. We first have to find them... */
487
1ab3bf1b 488 bfd_map_over_sections (abfd, elf_locate_sections, (PTR) &ei);
35f5886e
FF
489 if (ei.dboffset && ei.lnoffset)
490 {
346168a2 491 /* DWARF sections */
d5931d79 492 dwarf_build_psymtabs (objfile,
2670f34d 493 section_offsets, mainline,
35f5886e 494 ei.dboffset, ei.dbsize,
d5931d79 495 ei.lnoffset, ei.lnsize);
35f5886e 496 }
346168a2
JG
497 if (ei.stabsect)
498 {
499 /* STABS sections */
500
501 /* FIXME: Sun didn't really know how to implement this well.
502 They made .stab sections that don't point to the .stabstr
503 section with the sh_link field. BFD doesn't make string table
504 sections visible to the caller. So we have to search the
505 ELF section table, not the BFD section table, for the string
506 table. */
2084a176 507 struct elf32_internal_shdr *elf_sect;
346168a2 508
872dd3fe 509 elf_sect = bfd_elf_find_section (abfd, ".stabstr");
346168a2
JG
510 if (elf_sect)
511 elfstab_build_psymtabs (objfile,
2670f34d 512 section_offsets,
346168a2
JG
513 mainline,
514 ei.stabsect->filepos, /* .stab offset */
515 bfd_get_section_size_before_reloc (ei.stabsect),/* .stab size */
d5931d79 516 (file_ptr) elf_sect->sh_offset, /* .stabstr offset */
346168a2
JG
517 elf_sect->sh_size); /* .stabstr size */
518 }
a7446af6 519
1ab3bf1b 520 if (!have_partial_symbols ())
35f5886e
FF
521 {
522 wrap_here ("");
523 printf_filtered ("(no debugging symbols found)...");
524 wrap_here ("");
525 }
a7446af6 526
1ab3bf1b
JG
527 /* Install any minimal symbols that have been collected as the current
528 minimal symbols for this objfile. */
529
80d68b1d 530 install_minimal_symbols (objfile);
1ab3bf1b 531
a7446af6 532 do_cleanups (back_to);
35f5886e
FF
533}
534
2670f34d
JG
535/* This cleans up the objfile's sym_private pointer, and the chain of
536 stab_section_info's, that might be dangling from it. */
537
538static void
539free_elfinfo (objp)
540 PTR objp;
541{
542 struct objfile *objfile = (struct objfile *)objp;
543 struct dbx_symfile_info *dbxinfo = (struct dbx_symfile_info *)
544 objfile->sym_private;
545 struct stab_section_info *ssi, *nssi;
546
547 ssi = dbxinfo->stab_section_info;
548 while (ssi)
549 {
550 nssi = ssi->next;
551 mfree (objfile->md, ssi);
552 ssi = nssi;
553 }
554
555 dbxinfo->stab_section_info = 0; /* Just say No mo info about this. */
556}
557
558
35f5886e
FF
559/* Initialize anything that needs initializing when a completely new symbol
560 file is specified (not just adding some symbols from another file, e.g. a
561 shared library).
562
346168a2 563 We reinitialize buildsym, since we may be reading stabs from an ELF file. */
35f5886e
FF
564
565static void
be772100
JG
566elf_new_init (ignore)
567 struct objfile *ignore;
80d68b1d 568{
d07734e3 569 stabsread_new_init ();
80d68b1d
FF
570 buildsym_new_init ();
571}
572
573/* Perform any local cleanups required when we are done with a particular
574 objfile. I.E, we are in the process of discarding all symbol information
575 for an objfile, freeing up all memory held for it, and unlinking the
576 objfile struct from the global list of known objfiles. */
577
578static void
579elf_symfile_finish (objfile)
580 struct objfile *objfile;
35f5886e 581{
80d68b1d
FF
582 if (objfile -> sym_private != NULL)
583 {
584 mfree (objfile -> md, objfile -> sym_private);
585 }
35f5886e
FF
586}
587
588/* ELF specific initialization routine for reading symbols.
589
590 It is passed a pointer to a struct sym_fns which contains, among other
591 things, the BFD for the file whose symbols are being read, and a slot for
592 a pointer to "private data" which we can fill with goodies.
593
594 For now at least, we have nothing in particular to do, so this function is
595 just a stub. */
596
597static void
be772100
JG
598elf_symfile_init (ignore)
599 struct objfile *ignore;
35f5886e
FF
600{
601}
602
2670f34d
JG
603/* ELF specific parsing routine for section offsets.
604
605 Plain and simple for now. */
606
607static
608struct section_offsets *
609elf_symfile_offsets (objfile, addr)
610 struct objfile *objfile;
611 CORE_ADDR addr;
612{
613 struct section_offsets *section_offsets;
614 int i;
615
616 section_offsets = (struct section_offsets *)
617 obstack_alloc (&objfile -> psymbol_obstack,
618 sizeof (struct section_offsets) +
619 sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1));
620
621 for (i = 0; i < SECT_OFF_MAX; i++)
622 ANOFFSET (section_offsets, i) = addr;
623
624 return section_offsets;
625}
626\f
627/* When handling an ELF file that contains Sun STABS debug info,
628 some of the debug info is relative to the particular chunk of the
629 section that was generated in its individual .o file. E.g.
630 offsets to static variables are relative to the start of the data
631 segment *for that module before linking*. This information is
632 painfully squirreled away in the ELF symbol table as local symbols
633 with wierd names. Go get 'em when needed. */
634
635void
636elfstab_offset_sections (objfile, pst)
637 struct objfile *objfile;
638 struct partial_symtab *pst;
639{
640 char *filename = pst->filename;
641 struct dbx_symfile_info *dbx = (struct dbx_symfile_info *)
642 objfile->sym_private;
643 struct stab_section_info *maybe = dbx->stab_section_info;
644 struct stab_section_info *questionable = 0;
645 int i;
646 char *p;
647
648 /* The ELF symbol info doesn't include path names, so strip the path
649 (if any) from the psymtab filename. */
650 while (0 != (p = strchr (filename, '/')))
651 filename = p+1;
652
653 /* FIXME: This linear search could speed up significantly
654 if it was chained in the right order to match how we search it,
655 and if we unchained when we found a match. */
656 for (; maybe; maybe = maybe->next)
657 {
658 if (filename[0] == maybe->filename[0]
2e4964ad 659 && STREQ (filename, maybe->filename))
2670f34d
JG
660 {
661 /* We found a match. But there might be several source files
662 (from different directories) with the same name. */
663 if (0 == maybe->found)
664 break;
665 questionable = maybe; /* Might use it later. */
666 }
667 }
668
669 if (maybe == 0 && questionable != 0)
670 {
671 complain (&stab_info_questionable_complaint, filename);
672 maybe = questionable;
673 }
674
675 if (maybe)
676 {
677 /* Found it! Allocate a new psymtab struct, and fill it in. */
678 maybe->found++;
679 pst->section_offsets = (struct section_offsets *)
680 obstack_alloc (&objfile -> psymbol_obstack,
681 sizeof (struct section_offsets) +
682 sizeof (pst->section_offsets->offsets) * (SECT_OFF_MAX-1));
683
684 for (i = 0; i < SECT_OFF_MAX; i++)
685 ANOFFSET (pst->section_offsets, i) = maybe->sections[i];
686 return;
687 }
688
689 /* We were unable to find any offsets for this file. Complain. */
690 if (dbx->stab_section_info) /* If there *is* any info, */
691 complain (&stab_info_mismatch_complaint, filename);
692}
35f5886e
FF
693\f
694/* Register that we are able to handle ELF object file formats and DWARF
695 debugging formats.
696
697 Unlike other object file formats, where the debugging information format
698 is implied by the object file format, the ELF object file format and the
699 DWARF debugging information format are two distinct, and potentially
700 separate entities. I.E. it is perfectly possible to have ELF objects
701 with debugging formats other than DWARF. And it is conceivable that the
702 DWARF debugging format might be used with another object file format,
703 like COFF, by simply using COFF's custom section feature.
704
705 GDB, and to a lesser extent BFD, should support the notion of separate
706 object file formats and debugging information formats. For now, we just
707 use "elf" in the same sense as "a.out" or "coff", to imply both the ELF
708 object file format and the DWARF debugging format. */
709
80d68b1d
FF
710static struct sym_fns elf_sym_fns =
711{
35f5886e
FF
712 "elf", /* sym_name: name or name prefix of BFD target type */
713 3, /* sym_namelen: number of significant sym_name chars */
714 elf_new_init, /* sym_new_init: init anything gbl to entire symtab */
715 elf_symfile_init, /* sym_init: read initial info, setup for sym_read() */
716 elf_symfile_read, /* sym_read: read a symbol file into symtab */
80d68b1d 717 elf_symfile_finish, /* sym_finish: finished with file, cleanup */
2670f34d 718 elf_symfile_offsets, /* sym_offsets: Translate ext. to int. relocation */
35f5886e
FF
719 NULL /* next: pointer to next struct sym_fns */
720};
721
722void
1ab3bf1b 723_initialize_elfread ()
35f5886e
FF
724{
725 add_symtab_fns (&elf_sym_fns);
726}
This page took 0.13985 seconds and 4 git commands to generate.