1999-05-03 09:29:11 +02:00
|
|
|
/* coffgrok.c
|
2019-01-01 11:31:27 +01:00
|
|
|
Copyright (C) 1994-2019 Free Software Foundation, Inc.
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2007-07-05 18:54:46 +02:00
|
|
|
This file is part of GNU Binutils.
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2007-07-05 18:54:46 +02:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2007-07-05 18:54:46 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Written by Steve Chamberlain (sac@cygnus.com)
|
|
|
|
|
|
|
|
This module reads a coff file and builds a really simple type tree
|
|
|
|
which can be read by other programs. The first application is a
|
2007-07-05 18:54:46 +02:00
|
|
|
coff->sysroff converter. It can be tested with coffdump.c. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2007-04-26 16:47:00 +02:00
|
|
|
#include "sysdep.h"
|
2002-05-25 14:51:38 +02:00
|
|
|
#include "bfd.h"
|
|
|
|
#include "libiberty.h"
|
1999-05-03 09:29:11 +02:00
|
|
|
#include "coff/internal.h"
|
|
|
|
#include "../bfd/libcoff.h"
|
2007-04-26 16:47:00 +02:00
|
|
|
#include "bucomm.h"
|
1999-05-03 09:29:11 +02:00
|
|
|
#include "coffgrok.h"
|
2007-04-26 16:47:00 +02:00
|
|
|
|
2015-01-06 17:06:45 +01:00
|
|
|
static int lofile = 1;
|
|
|
|
|
|
|
|
static struct coff_scope * top_scope;
|
|
|
|
static struct coff_scope * file_scope;
|
|
|
|
static struct coff_ofile * ofile;
|
|
|
|
static struct coff_symbol * last_function_symbol;
|
|
|
|
static struct coff_type * last_function_type;
|
|
|
|
static struct coff_type * last_struct;
|
|
|
|
static struct coff_type * last_enum;
|
|
|
|
static struct coff_sfile * cur_sfile;
|
|
|
|
static struct coff_symbol ** tindex;
|
|
|
|
static asymbol ** syms;
|
|
|
|
static long symcount;
|
|
|
|
static struct coff_ptr_struct * rawsyms;
|
|
|
|
static unsigned int rawcount;
|
|
|
|
static bfd * abfd;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
#define N(x) ((x)->_n._n_nptr[1])
|
|
|
|
|
2003-09-14 14:20:17 +02:00
|
|
|
#define PTR_SIZE 4
|
|
|
|
#define SHORT_SIZE 2
|
|
|
|
#define INT_SIZE 4
|
|
|
|
#define LONG_SIZE 4
|
|
|
|
#define FLOAT_SIZE 4
|
|
|
|
#define DOUBLE_SIZE 8
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
#define INDEXOF(p) ((struct coff_ptr_struct *)(p)-(rawsyms))
|
|
|
|
|
2001-08-21 12:02:27 +02:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
static struct coff_scope *
|
2003-09-14 14:20:17 +02:00
|
|
|
empty_scope (void)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
return (struct coff_scope *) (xcalloc (sizeof (struct coff_scope), 1));
|
1999-05-03 09:29:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct coff_symbol *
|
2003-09-14 14:20:17 +02:00
|
|
|
empty_symbol (void)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
return (struct coff_symbol *) (xcalloc (sizeof (struct coff_symbol), 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-11 14:42:17 +01:00
|
|
|
push_scope (int slink)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
struct coff_scope *n = empty_scope ();
|
2009-12-11 14:42:17 +01:00
|
|
|
|
|
|
|
if (slink)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
if (top_scope)
|
|
|
|
{
|
|
|
|
if (top_scope->list_tail)
|
|
|
|
{
|
|
|
|
top_scope->list_tail->next = n;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
top_scope->list_head = n;
|
|
|
|
}
|
|
|
|
top_scope->list_tail = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
n->parent = top_scope;
|
|
|
|
|
|
|
|
top_scope = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-09-14 14:20:17 +02:00
|
|
|
pop_scope (void)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
/* PR 17512: file: 809933ac. */
|
|
|
|
if (top_scope == NULL)
|
|
|
|
fatal (_("Out of context scope change encountered"));
|
1999-05-03 09:29:11 +02:00
|
|
|
top_scope = top_scope->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-09-14 14:20:17 +02:00
|
|
|
do_sections_p1 (struct coff_ofile *head)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
asection *section;
|
|
|
|
int idx;
|
|
|
|
struct coff_section *all = (struct coff_section *) (xcalloc (abfd->section_count + 1,
|
|
|
|
sizeof (struct coff_section)));
|
|
|
|
head->nsections = abfd->section_count + 1;
|
|
|
|
head->sections = all;
|
|
|
|
|
|
|
|
for (idx = 0, section = abfd->sections; section; section = section->next, idx++)
|
|
|
|
{
|
|
|
|
long relsize;
|
2015-01-06 17:06:45 +01:00
|
|
|
unsigned int i = section->target_index;
|
1999-05-03 09:29:11 +02:00
|
|
|
arelent **relpp;
|
|
|
|
long relcount;
|
|
|
|
|
2015-01-06 17:06:45 +01:00
|
|
|
/* PR 17512: file: 2d6effca. */
|
|
|
|
if (i > abfd->section_count)
|
|
|
|
fatal (_("Invalid section target index: %u"), i);
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
relsize = bfd_get_reloc_upper_bound (abfd, section);
|
|
|
|
if (relsize < 0)
|
|
|
|
bfd_fatal (bfd_get_filename (abfd));
|
|
|
|
if (relsize == 0)
|
2002-05-19 18:17:54 +02:00
|
|
|
continue;
|
1999-05-03 09:29:11 +02:00
|
|
|
relpp = (arelent **) xmalloc (relsize);
|
|
|
|
relcount = bfd_canonicalize_reloc (abfd, section, relpp, syms);
|
|
|
|
if (relcount < 0)
|
|
|
|
bfd_fatal (bfd_get_filename (abfd));
|
|
|
|
|
|
|
|
head->sections[i].name = (char *) (section->name);
|
|
|
|
head->sections[i].code = section->flags & SEC_CODE;
|
|
|
|
head->sections[i].data = section->flags & SEC_DATA;
|
|
|
|
if (strcmp (section->name, ".bss") == 0)
|
|
|
|
head->sections[i].data = 1;
|
|
|
|
head->sections[i].address = section->lma;
|
bfd_section_* macros
This large patch removes the unnecessary bfd parameter from various
bfd section macros and functions. The bfd is hardly ever used and if
needed for the bfd_set_section_* or bfd_rename_section functions can
be found via section->owner except for the com, und, abs, and ind
std_section special sections. Those sections shouldn't be modified
anyway.
The patch also removes various bfd_get_section_<field> macros,
replacing their use with bfd_section_<field>, and adds
bfd_set_section_lma. I've also fixed a minor bug in gas where
compressed section renaming was done directly rather than calling
bfd_rename_section. This would have broken bfd_get_section_by_name
and similar functions, but that hardly mattered at such a late stage
in gas processing.
bfd/
* bfd-in.h (bfd_get_section_name, bfd_get_section_vma),
(bfd_get_section_lma, bfd_get_section_alignment),
(bfd_get_section_size, bfd_get_section_flags),
(bfd_get_section_userdata): Delete.
(bfd_section_name, bfd_section_size, bfd_section_vma),
(bfd_section_lma, bfd_section_alignment): Lose bfd parameter.
(bfd_section_flags, bfd_section_userdata): New.
(bfd_is_com_section): Rename parameter.
* section.c (bfd_set_section_userdata, bfd_set_section_vma),
(bfd_set_section_alignment, bfd_set_section_flags, bfd_rename_section),
(bfd_set_section_size): Delete bfd parameter, rename section parameter.
(bfd_set_section_lma): New.
* bfd-in2.h: Regenerate.
* mach-o.c (bfd_mach_o_init_section_from_mach_o): Delete bfd param,
update callers.
* aoutx.h, * bfd.c, * coff-alpha.c, * coff-arm.c, * coff-mips.c,
* coff64-rs6000.c, * coffcode.h, * coffgen.c, * cofflink.c,
* compress.c, * ecoff.c, * elf-eh-frame.c, * elf-hppa.h,
* elf-ifunc.c, * elf-m10200.c, * elf-m10300.c, * elf-properties.c,
* elf-s390-common.c, * elf-vxworks.c, * elf.c, * elf32-arc.c,
* elf32-arm.c, * elf32-avr.c, * elf32-bfin.c, * elf32-cr16.c,
* elf32-cr16c.c, * elf32-cris.c, * elf32-crx.c, * elf32-csky.c,
* elf32-d10v.c, * elf32-epiphany.c, * elf32-fr30.c, * elf32-frv.c,
* elf32-ft32.c, * elf32-h8300.c, * elf32-hppa.c, * elf32-i386.c,
* elf32-ip2k.c, * elf32-iq2000.c, * elf32-lm32.c, * elf32-m32c.c,
* elf32-m32r.c, * elf32-m68hc1x.c, * elf32-m68k.c, * elf32-mcore.c,
* elf32-mep.c, * elf32-metag.c, * elf32-microblaze.c,
* elf32-moxie.c, * elf32-msp430.c, * elf32-mt.c, * elf32-nds32.c,
* elf32-nios2.c, * elf32-or1k.c, * elf32-ppc.c, * elf32-pru.c,
* elf32-rl78.c, * elf32-rx.c, * elf32-s390.c, * elf32-score.c,
* elf32-score7.c, * elf32-sh.c, * elf32-spu.c, * elf32-tic6x.c,
* elf32-tilepro.c, * elf32-v850.c, * elf32-vax.c, * elf32-visium.c,
* elf32-xstormy16.c, * elf32-xtensa.c, * elf64-alpha.c,
* elf64-bpf.c, * elf64-hppa.c, * elf64-ia64-vms.c, * elf64-mmix.c,
* elf64-ppc.c, * elf64-s390.c, * elf64-sparc.c, * elf64-x86-64.c,
* elflink.c, * elfnn-aarch64.c, * elfnn-ia64.c, * elfnn-riscv.c,
* elfxx-aarch64.c, * elfxx-mips.c, * elfxx-sparc.c,
* elfxx-tilegx.c, * elfxx-x86.c, * i386msdos.c, * linker.c,
* mach-o.c, * mmo.c, * opncls.c, * pdp11.c, * pei-x86_64.c,
* peicode.h, * reloc.c, * section.c, * syms.c, * vms-alpha.c,
* xcofflink.c: Update throughout for bfd section macro and function
changes.
binutils/
* addr2line.c, * bucomm.c, * coffgrok.c, * dlltool.c, * nm.c,
* objcopy.c, * objdump.c, * od-elf32_avr.c, * od-macho.c,
* od-xcoff.c, * prdbg.c, * rdcoff.c, * rddbg.c, * rescoff.c,
* resres.c, * size.c, * srconv.c, * strings.c, * windmc.c: Update
throughout for bfd section macro and function changes.
gas/
* as.c, * as.h, * dw2gencfi.c, * dwarf2dbg.c, * ecoff.c,
* read.c, * stabs.c, * subsegs.c, * subsegs.h, * write.c,
* config/obj-coff-seh.c, * config/obj-coff.c, * config/obj-ecoff.c,
* config/obj-elf.c, * config/obj-macho.c, * config/obj-som.c,
* config/tc-aarch64.c, * config/tc-alpha.c, * config/tc-arc.c,
* config/tc-arm.c, * config/tc-avr.c, * config/tc-bfin.c,
* config/tc-bpf.c, * config/tc-d10v.c, * config/tc-d30v.c,
* config/tc-epiphany.c, * config/tc-fr30.c, * config/tc-frv.c,
* config/tc-h8300.c, * config/tc-hppa.c, * config/tc-i386.c,
* config/tc-ia64.c, * config/tc-ip2k.c, * config/tc-iq2000.c,
* config/tc-lm32.c, * config/tc-m32c.c, * config/tc-m32r.c,
* config/tc-m68hc11.c, * config/tc-mep.c, * config/tc-microblaze.c,
* config/tc-mips.c, * config/tc-mmix.c, * config/tc-mn10200.c,
* config/tc-mn10300.c, * config/tc-msp430.c, * config/tc-mt.c,
* config/tc-nds32.c, * config/tc-or1k.c, * config/tc-ppc.c,
* config/tc-pru.c, * config/tc-rl78.c, * config/tc-rx.c,
* config/tc-s12z.c, * config/tc-s390.c, * config/tc-score.c,
* config/tc-score7.c, * config/tc-sh.c, * config/tc-sparc.c,
* config/tc-spu.c, * config/tc-tic4x.c, * config/tc-tic54x.c,
* config/tc-tic6x.c, * config/tc-tilegx.c, * config/tc-tilepro.c,
* config/tc-v850.c, * config/tc-visium.c, * config/tc-wasm32.c,
* config/tc-xc16x.c, * config/tc-xgate.c, * config/tc-xstormy16.c,
* config/tc-xtensa.c, * config/tc-z8k.c: Update throughout for
bfd section macro and function changes.
* write.c (compress_debug): Use bfd_rename_section.
gdb/
* aarch64-linux-tdep.c, * arm-tdep.c, * auto-load.c,
* coff-pe-read.c, * coffread.c, * corelow.c, * dbxread.c,
* dicos-tdep.c, * dwarf2-frame.c, * dwarf2read.c, * elfread.c,
* exec.c, * fbsd-tdep.c, * gcore.c, * gdb_bfd.c, * gdb_bfd.h,
* hppa-tdep.c, * i386-cygwin-tdep.c, * i386-fbsd-tdep.c,
* i386-linux-tdep.c, * jit.c, * linux-tdep.c, * machoread.c,
* maint.c, * mdebugread.c, * minidebug.c, * mips-linux-tdep.c,
* mips-sde-tdep.c, * mips-tdep.c, * mipsread.c, * nto-tdep.c,
* objfiles.c, * objfiles.h, * osabi.c, * ppc-linux-tdep.c,
* ppc64-tdep.c, * record-btrace.c, * record-full.c, * remote.c,
* rs6000-aix-tdep.c, * rs6000-tdep.c, * s390-linux-tdep.c,
* s390-tdep.c, * solib-aix.c, * solib-dsbt.c, * solib-frv.c,
* solib-spu.c, * solib-svr4.c, * solib-target.c,
* spu-linux-nat.c, * spu-tdep.c, * symfile-mem.c, * symfile.c,
* symmisc.c, * symtab.c, * target.c, * windows-nat.c,
* xcoffread.c, * cli/cli-dump.c, * compile/compile-object-load.c,
* mi/mi-interp.c: Update throughout for bfd section macro and
function changes.
* gcore (gcore_create_callback): Use bfd_set_section_lma.
* spu-tdep.c (spu_overlay_new_objfile): Likewise.
gprof/
* corefile.c, * symtab.c: Update throughout for bfd section
macro and function changes.
ld/
* ldcref.c, * ldctor.c, * ldelf.c, * ldlang.c, * pe-dll.c,
* emultempl/aarch64elf.em, * emultempl/aix.em,
* emultempl/armcoff.em, * emultempl/armelf.em,
* emultempl/cr16elf.em, * emultempl/cskyelf.em,
* emultempl/m68hc1xelf.em, * emultempl/m68kelf.em,
* emultempl/mipself.em, * emultempl/mmix-elfnmmo.em,
* emultempl/mmo.em, * emultempl/msp430.em,
* emultempl/nios2elf.em, * emultempl/pe.em, * emultempl/pep.em,
* emultempl/ppc64elf.em, * emultempl/xtensaelf.em: Update
throughout for bfd section macro and function changes.
libctf/
* ctf-open-bfd.c: Update throughout for bfd section macro changes.
opcodes/
* arc-ext.c: Update throughout for bfd section macro changes.
sim/
* common/sim-load.c, * common/sim-utils.c, * cris/sim-if.c,
* erc32/func.c, * lm32/sim-if.c, * m32c/load.c, * m32c/trace.c,
* m68hc11/interp.c, * ppc/hw_htab.c, * ppc/hw_init.c,
* rl78/load.c, * rl78/trace.c, * rx/gdb-if.c, * rx/load.c,
* rx/trace.c: Update throughout for bfd section macro changes.
2019-09-16 12:55:17 +02:00
|
|
|
head->sections[i].size = bfd_section_size (section);
|
1999-05-03 09:29:11 +02:00
|
|
|
head->sections[i].number = idx;
|
|
|
|
head->sections[i].nrelocs = section->reloc_count;
|
|
|
|
head->sections[i].relocs =
|
|
|
|
(struct coff_reloc *) (xcalloc (section->reloc_count,
|
|
|
|
sizeof (struct coff_reloc)));
|
|
|
|
head->sections[i].bfd_section = section;
|
|
|
|
}
|
|
|
|
head->sections[0].name = "ABSOLUTE";
|
|
|
|
head->sections[0].code = 0;
|
|
|
|
head->sections[0].data = 0;
|
|
|
|
head->sections[0].address = 0;
|
|
|
|
head->sections[0].size = 0;
|
|
|
|
head->sections[0].number = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-09-14 14:20:17 +02:00
|
|
|
do_sections_p2 (struct coff_ofile *head)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
asection *section;
|
2015-01-06 17:06:45 +01:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
for (section = abfd->sections; section; section = section->next)
|
|
|
|
{
|
|
|
|
unsigned int j;
|
|
|
|
|
2015-01-06 17:06:45 +01:00
|
|
|
/* PR 17512: file: 7c1a36e8.
|
|
|
|
A corrupt COFF binary might have a reloc count but no relocs.
|
|
|
|
Handle this here. */
|
|
|
|
if (section->relocation == NULL)
|
|
|
|
continue;
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
for (j = 0; j < section->reloc_count; j++)
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
unsigned int idx;
|
1999-05-03 09:29:11 +02:00
|
|
|
int i = section->target_index;
|
2015-01-06 17:06:45 +01:00
|
|
|
struct coff_reloc *r;
|
1999-05-03 09:29:11 +02:00
|
|
|
arelent *sr = section->relocation + j;
|
2015-01-06 17:06:45 +01:00
|
|
|
|
|
|
|
if (i > head->nsections)
|
|
|
|
fatal (_("Invalid section target index: %d"), i);
|
|
|
|
/* PR 17512: file: db850ff4. */
|
|
|
|
if (j >= head->sections[i].nrelocs)
|
|
|
|
fatal (_("Target section has insufficient relocs"));
|
|
|
|
r = head->sections[i].relocs + j;
|
1999-05-03 09:29:11 +02:00
|
|
|
r->offset = sr->address;
|
|
|
|
r->addend = sr->addend;
|
|
|
|
idx = ((coff_symbol_type *) (sr->sym_ptr_ptr[0]))->native - rawsyms;
|
2015-01-06 17:06:45 +01:00
|
|
|
if (idx >= rawcount)
|
|
|
|
{
|
|
|
|
if (rawcount == 0)
|
|
|
|
fatal (_("Symbol index %u encountered when there are no symbols"), idx);
|
|
|
|
non_fatal (_("Invalid symbol index %u encountered"), idx);
|
|
|
|
idx = 0;
|
|
|
|
}
|
1999-05-03 09:29:11 +02:00
|
|
|
r->symbol = tindex[idx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct coff_where *
|
2015-01-06 17:06:45 +01:00
|
|
|
do_where (unsigned int i)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
struct internal_syment *sym;
|
1999-05-03 09:29:11 +02:00
|
|
|
struct coff_where *where =
|
|
|
|
(struct coff_where *) (xmalloc (sizeof (struct coff_where)));
|
2015-01-06 17:06:45 +01:00
|
|
|
|
|
|
|
if (i >= rawcount)
|
|
|
|
fatal ("Invalid symbol index: %d\n", i);
|
|
|
|
|
|
|
|
sym = &rawsyms[i].u.syment;
|
1999-05-03 09:29:11 +02:00
|
|
|
where->offset = sym->n_value;
|
|
|
|
|
|
|
|
if (sym->n_scnum == -1)
|
|
|
|
sym->n_scnum = 0;
|
|
|
|
|
|
|
|
switch (sym->n_sclass)
|
|
|
|
{
|
|
|
|
case C_FIELD:
|
|
|
|
where->where = coff_where_member_of_struct;
|
|
|
|
where->offset = sym->n_value / 8;
|
|
|
|
where->bitoffset = sym->n_value % 8;
|
|
|
|
where->bitsize = rawsyms[i + 1].u.auxent.x_sym.x_misc.x_lnsz.x_size;
|
|
|
|
break;
|
|
|
|
case C_MOE:
|
|
|
|
where->where = coff_where_member_of_enum;
|
|
|
|
break;
|
|
|
|
case C_MOS:
|
|
|
|
case C_MOU:
|
|
|
|
where->where = coff_where_member_of_struct;
|
|
|
|
break;
|
|
|
|
case C_AUTO:
|
|
|
|
case C_ARG:
|
|
|
|
where->where = coff_where_stack;
|
|
|
|
break;
|
|
|
|
case C_EXT:
|
|
|
|
case C_STAT:
|
|
|
|
case C_EXTDEF:
|
|
|
|
case C_LABEL:
|
|
|
|
where->where = coff_where_memory;
|
2015-01-06 17:06:45 +01:00
|
|
|
/* PR 17512: file: 07a37c40. */
|
|
|
|
/* PR 17512: file: 0c2eb101. */
|
|
|
|
if (sym->n_scnum >= ofile->nsections || sym->n_scnum < 0)
|
|
|
|
{
|
|
|
|
non_fatal (_("Invalid section number (%d) encountered"),
|
|
|
|
sym->n_scnum);
|
|
|
|
where->section = ofile->sections;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
where->section = &ofile->sections[sym->n_scnum];
|
1999-05-03 09:29:11 +02:00
|
|
|
break;
|
|
|
|
case C_REG:
|
|
|
|
case C_REGPARM:
|
|
|
|
where->where = coff_where_register;
|
|
|
|
break;
|
|
|
|
case C_ENTAG:
|
|
|
|
where->where = coff_where_entag;
|
|
|
|
break;
|
|
|
|
case C_STRTAG:
|
|
|
|
case C_UNTAG:
|
|
|
|
where->where = coff_where_strtag;
|
|
|
|
break;
|
|
|
|
case C_TPDEF:
|
|
|
|
where->where = coff_where_typedef;
|
|
|
|
break;
|
|
|
|
default:
|
2015-01-06 17:06:45 +01:00
|
|
|
fatal (_("Unrecognized symbol class: %d"), sym->n_sclass);
|
1999-05-03 09:29:11 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return where;
|
|
|
|
}
|
|
|
|
|
2015-01-06 17:06:45 +01:00
|
|
|
static struct coff_line *
|
2003-09-14 14:20:17 +02:00
|
|
|
do_lines (int i, char *name ATTRIBUTE_UNUSED)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
struct coff_line *res = (struct coff_line *) xcalloc (sizeof (struct coff_line), 1);
|
|
|
|
asection *s;
|
|
|
|
unsigned int l;
|
|
|
|
|
2015-01-06 17:06:45 +01:00
|
|
|
/* Find out if this function has any line numbers in the table. */
|
1999-05-03 09:29:11 +02:00
|
|
|
for (s = abfd->sections; s; s = s->next)
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
/* PR 17512: file: 07a37c40.
|
|
|
|
A corrupt COFF binary can have a linenumber count in the header
|
|
|
|
but no line number table. This should be reported elsewhere, but
|
|
|
|
do not rely upon this. */
|
|
|
|
if (s->lineno == NULL)
|
|
|
|
continue;
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
for (l = 0; l < s->lineno_count; l++)
|
|
|
|
{
|
|
|
|
if (s->lineno[l].line_number == 0)
|
|
|
|
{
|
|
|
|
if (rawsyms + i == ((coff_symbol_type *) (&(s->lineno[l].u.sym[0])))->native)
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
/* These lines are for this function - so count them and stick them on. */
|
1999-05-03 09:29:11 +02:00
|
|
|
int c = 0;
|
|
|
|
/* Find the linenumber of the top of the function, since coff linenumbers
|
2002-05-19 18:17:54 +02:00
|
|
|
are relative to the start of the function. */
|
1999-05-03 09:29:11 +02:00
|
|
|
int start_line = rawsyms[i + 3].u.auxent.x_sym.x_misc.x_lnsz.x_lnno;
|
|
|
|
|
|
|
|
l++;
|
2015-01-06 17:06:45 +01:00
|
|
|
for (c = 0;
|
|
|
|
/* PR 17512: file: c2825452. */
|
|
|
|
l + c + 1 < s->lineno_count
|
|
|
|
&& s->lineno[l + c + 1].line_number;
|
|
|
|
c++)
|
1999-05-03 09:29:11 +02:00
|
|
|
;
|
|
|
|
|
2015-01-06 17:06:45 +01:00
|
|
|
/* Add two extra records, one for the prologue and one for the epilogue. */
|
1999-05-03 09:29:11 +02:00
|
|
|
c += 1;
|
|
|
|
res->nlines = c;
|
|
|
|
res->lines = (int *) (xcalloc (sizeof (int), c));
|
|
|
|
res->addresses = (int *) (xcalloc (sizeof (int), c));
|
|
|
|
res->lines[0] = start_line;
|
|
|
|
res->addresses[0] = rawsyms[i].u.syment.n_value - s->vma;
|
2015-01-06 17:06:45 +01:00
|
|
|
for (c = 0;
|
|
|
|
/* PR 17512: file: c2825452. */
|
|
|
|
l + c + 1 < s->lineno_count
|
|
|
|
&& s->lineno[l + c + 1].line_number;
|
|
|
|
c++)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
res->lines[c + 1] = s->lineno[l + c].line_number + start_line - 1;
|
|
|
|
res->addresses[c + 1] = s->lineno[l + c].u.offset;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2015-01-06 17:06:45 +01:00
|
|
|
static struct coff_type *
|
|
|
|
do_type (unsigned int i)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
struct internal_syment *sym;
|
|
|
|
union internal_auxent *aux;
|
|
|
|
struct coff_type *res = (struct coff_type *) xmalloc (sizeof (struct coff_type));
|
|
|
|
int type;
|
1999-05-03 09:29:11 +02:00
|
|
|
int which_dt = 0;
|
|
|
|
int dimind = 0;
|
|
|
|
|
2015-01-06 17:06:45 +01:00
|
|
|
if (i >= rawcount)
|
|
|
|
fatal (_("Type entry %u does not have enough symbolic information"), i);
|
|
|
|
|
|
|
|
if (!rawsyms[i].is_sym)
|
|
|
|
fatal (_("Type entry %u does not refer to a symbol"), i);
|
|
|
|
sym = &rawsyms[i].u.syment;
|
|
|
|
|
|
|
|
if (sym->n_numaux == 0 || i >= rawcount -1 || rawsyms[i + 1].is_sym)
|
|
|
|
aux = NULL;
|
|
|
|
else
|
|
|
|
aux = &rawsyms[i + 1].u.auxent;
|
|
|
|
|
|
|
|
type = sym->n_type;
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
res->type = coff_basic_type;
|
|
|
|
res->u.basic = type & 0xf;
|
|
|
|
|
|
|
|
switch (type & 0xf)
|
|
|
|
{
|
|
|
|
case T_NULL:
|
|
|
|
case T_VOID:
|
|
|
|
if (sym->n_numaux && sym->n_sclass == C_STAT)
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
/* This is probably a section definition. */
|
1999-05-03 09:29:11 +02:00
|
|
|
res->type = coff_secdef_type;
|
2015-01-06 17:06:45 +01:00
|
|
|
if (aux == NULL)
|
|
|
|
fatal (_("Section definition needs a section length"));
|
1999-05-03 09:29:11 +02:00
|
|
|
res->size = aux->x_scn.x_scnlen;
|
2015-01-06 17:06:45 +01:00
|
|
|
|
|
|
|
/* PR 17512: file: 081c955d.
|
|
|
|
Fill in the asecdef structure as well. */
|
|
|
|
res->u.asecdef.address = 0;
|
|
|
|
res->u.asecdef.size = 0;
|
1999-05-03 09:29:11 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (type == 0)
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
/* Don't know what this is, let's make it a simple int. */
|
1999-05-03 09:29:11 +02:00
|
|
|
res->size = INT_SIZE;
|
|
|
|
res->u.basic = T_UINT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
/* Else it could be a function or pointer to void. */
|
1999-05-03 09:29:11 +02:00
|
|
|
res->size = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_UCHAR:
|
|
|
|
case T_CHAR:
|
|
|
|
res->size = 1;
|
|
|
|
break;
|
|
|
|
case T_USHORT:
|
|
|
|
case T_SHORT:
|
|
|
|
res->size = SHORT_SIZE;
|
|
|
|
break;
|
|
|
|
case T_UINT:
|
|
|
|
case T_INT:
|
|
|
|
res->size = INT_SIZE;
|
|
|
|
break;
|
|
|
|
case T_ULONG:
|
|
|
|
case T_LONG:
|
|
|
|
res->size = LONG_SIZE;
|
|
|
|
break;
|
|
|
|
case T_FLOAT:
|
|
|
|
res->size = FLOAT_SIZE;
|
|
|
|
break;
|
|
|
|
case T_DOUBLE:
|
|
|
|
res->size = DOUBLE_SIZE;
|
|
|
|
break;
|
|
|
|
case T_STRUCT:
|
|
|
|
case T_UNION:
|
|
|
|
if (sym->n_numaux)
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
if (aux == NULL)
|
|
|
|
fatal (_("Aggregate definition needs auxillary information"));
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
if (aux->x_sym.x_tagndx.p)
|
|
|
|
{
|
2015-02-26 23:16:16 +01:00
|
|
|
unsigned int idx;
|
|
|
|
|
|
|
|
/* PR 17512: file: e72f3988. */
|
|
|
|
if (aux->x_sym.x_tagndx.l < 0 || aux->x_sym.x_tagndx.p < rawsyms)
|
|
|
|
{
|
|
|
|
non_fatal (_("Invalid tag index %#lx encountered"), aux->x_sym.x_tagndx.l);
|
|
|
|
idx = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
idx = INDEXOF (aux->x_sym.x_tagndx.p);
|
2015-01-06 17:06:45 +01:00
|
|
|
|
|
|
|
if (idx >= rawcount)
|
|
|
|
{
|
|
|
|
if (rawcount == 0)
|
|
|
|
fatal (_("Symbol index %u encountered when there are no symbols"), idx);
|
|
|
|
non_fatal (_("Invalid symbol index %u encountered"), idx);
|
|
|
|
idx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Referring to a struct defined elsewhere. */
|
1999-05-03 09:29:11 +02:00
|
|
|
res->type = coff_structref_type;
|
2015-01-06 17:06:45 +01:00
|
|
|
res->u.astructref.ref = tindex[idx];
|
1999-05-03 09:29:11 +02:00
|
|
|
res->size = res->u.astructref.ref ?
|
|
|
|
res->u.astructref.ref->type->size : 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
/* A definition of a struct. */
|
1999-05-03 09:29:11 +02:00
|
|
|
last_struct = res;
|
|
|
|
res->type = coff_structdef_type;
|
|
|
|
res->u.astructdef.elements = empty_scope ();
|
|
|
|
res->u.astructdef.idx = 0;
|
|
|
|
res->u.astructdef.isstruct = (type & 0xf) == T_STRUCT;
|
|
|
|
res->size = aux->x_sym.x_misc.x_lnsz.x_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
/* No auxents - it's anonymous. */
|
1999-05-03 09:29:11 +02:00
|
|
|
res->type = coff_structref_type;
|
|
|
|
res->u.astructref.ref = 0;
|
|
|
|
res->size = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case T_ENUM:
|
2015-01-06 17:06:45 +01:00
|
|
|
if (aux == NULL)
|
|
|
|
fatal (_("Enum definition needs auxillary information"));
|
1999-05-03 09:29:11 +02:00
|
|
|
if (aux->x_sym.x_tagndx.p)
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
unsigned int idx = INDEXOF (aux->x_sym.x_tagndx.p);
|
|
|
|
|
|
|
|
/* PR 17512: file: 1ef037c7. */
|
|
|
|
if (idx >= rawcount)
|
|
|
|
fatal (_("Invalid enum symbol index %u encountered"), idx);
|
|
|
|
/* Referring to a enum defined elsewhere. */
|
1999-05-03 09:29:11 +02:00
|
|
|
res->type = coff_enumref_type;
|
2015-01-06 17:06:45 +01:00
|
|
|
res->u.aenumref.ref = tindex[idx];
|
2015-01-21 11:33:19 +01:00
|
|
|
/* PR 17512: file: b85b67e8. */
|
|
|
|
if (res->u.aenumref.ref)
|
|
|
|
res->size = res->u.aenumref.ref->type->size;
|
|
|
|
else
|
|
|
|
res->size = 0;
|
1999-05-03 09:29:11 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
/* A definition of an enum. */
|
1999-05-03 09:29:11 +02:00
|
|
|
last_enum = res;
|
|
|
|
res->type = coff_enumdef_type;
|
|
|
|
res->u.aenumdef.elements = empty_scope ();
|
|
|
|
res->size = aux->x_sym.x_misc.x_lnsz.x_size;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case T_MOE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (which_dt = 5; which_dt >= 0; which_dt--)
|
|
|
|
{
|
|
|
|
switch ((type >> ((which_dt * 2) + 4)) & 0x3)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case DT_ARY:
|
|
|
|
{
|
|
|
|
struct coff_type *ptr = ((struct coff_type *)
|
|
|
|
xmalloc (sizeof (struct coff_type)));
|
2015-01-06 17:06:45 +01:00
|
|
|
int els;
|
|
|
|
|
|
|
|
if (aux == NULL)
|
|
|
|
fatal (_("Array definition needs auxillary information"));
|
|
|
|
els = (dimind < DIMNUM
|
|
|
|
? aux->x_sym.x_fcnary.x_ary.x_dimen[dimind]
|
|
|
|
: 0);
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
++dimind;
|
|
|
|
ptr->type = coff_array_type;
|
2015-02-26 23:16:16 +01:00
|
|
|
/* PR 17512: file: ae1971e2.
|
|
|
|
Check for integer overflow. */
|
|
|
|
{
|
|
|
|
long long a, z;
|
|
|
|
a = els;
|
|
|
|
z = res->size;
|
|
|
|
a *= z;
|
|
|
|
ptr->size = (int) a;
|
|
|
|
if (ptr->size != a)
|
|
|
|
non_fatal (_("Out of range sum for els (%#x) * size (%#x)"), els, res->size);
|
|
|
|
}
|
1999-05-03 09:29:11 +02:00
|
|
|
ptr->u.array.dim = els;
|
|
|
|
ptr->u.array.array_of = res;
|
|
|
|
res = ptr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DT_PTR:
|
|
|
|
{
|
|
|
|
struct coff_type *ptr =
|
|
|
|
(struct coff_type *) xmalloc (sizeof (struct coff_type));
|
2015-01-06 17:06:45 +01:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
ptr->size = PTR_SIZE;
|
|
|
|
ptr->type = coff_pointer_type;
|
|
|
|
ptr->u.pointer.points_to = res;
|
|
|
|
res = ptr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DT_FCN:
|
|
|
|
{
|
|
|
|
struct coff_type *ptr
|
|
|
|
= (struct coff_type *) xmalloc (sizeof (struct coff_type));
|
2015-01-06 17:06:45 +01:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
ptr->size = 0;
|
|
|
|
ptr->type = coff_function_type;
|
|
|
|
ptr->u.function.function_returns = res;
|
|
|
|
ptr->u.function.parameters = empty_scope ();
|
2015-01-06 17:06:45 +01:00
|
|
|
ptr->u.function.lines = do_lines (i, N(sym));
|
1999-05-03 09:29:11 +02:00
|
|
|
ptr->u.function.code = 0;
|
|
|
|
last_function_type = ptr;
|
|
|
|
res = ptr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct coff_visible *
|
2003-09-14 14:20:17 +02:00
|
|
|
do_visible (int i)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
struct internal_syment *sym = &rawsyms[i].u.syment;
|
|
|
|
struct coff_visible *visible =
|
|
|
|
(struct coff_visible *) (xmalloc (sizeof (struct coff_visible)));
|
|
|
|
enum coff_vis_type t;
|
2015-01-06 17:06:45 +01:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
switch (sym->n_sclass)
|
|
|
|
{
|
|
|
|
case C_MOS:
|
|
|
|
case C_MOU:
|
|
|
|
case C_FIELD:
|
|
|
|
t = coff_vis_member_of_struct;
|
|
|
|
break;
|
|
|
|
case C_MOE:
|
|
|
|
t = coff_vis_member_of_enum;
|
|
|
|
break;
|
|
|
|
case C_REGPARM:
|
|
|
|
t = coff_vis_regparam;
|
|
|
|
break;
|
|
|
|
case C_REG:
|
|
|
|
t = coff_vis_register;
|
|
|
|
break;
|
|
|
|
case C_STRTAG:
|
|
|
|
case C_UNTAG:
|
|
|
|
case C_ENTAG:
|
|
|
|
case C_TPDEF:
|
|
|
|
t = coff_vis_tag;
|
|
|
|
break;
|
|
|
|
case C_AUTOARG:
|
|
|
|
case C_ARG:
|
|
|
|
t = coff_vis_autoparam;
|
|
|
|
break;
|
|
|
|
case C_AUTO:
|
|
|
|
t = coff_vis_auto;
|
|
|
|
break;
|
|
|
|
case C_LABEL:
|
|
|
|
case C_STAT:
|
|
|
|
t = coff_vis_int_def;
|
|
|
|
break;
|
|
|
|
case C_EXT:
|
|
|
|
if (sym->n_scnum == N_UNDEF)
|
|
|
|
{
|
|
|
|
if (sym->n_value)
|
|
|
|
t = coff_vis_common;
|
|
|
|
else
|
|
|
|
t = coff_vis_ext_ref;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
t = coff_vis_ext_def;
|
|
|
|
break;
|
|
|
|
default:
|
2015-01-06 17:06:45 +01:00
|
|
|
fatal (_("Unrecognised symbol class: %d"), sym->n_sclass);
|
1999-05-03 09:29:11 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
visible->type = t;
|
|
|
|
return visible;
|
|
|
|
}
|
|
|
|
|
2015-01-06 17:06:45 +01:00
|
|
|
/* Define a symbol and attach to block B. */
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
static int
|
2015-01-06 17:06:45 +01:00
|
|
|
do_define (unsigned int i, struct coff_scope *b)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
static int symbol_index;
|
2015-01-06 17:06:45 +01:00
|
|
|
struct internal_syment *sym;
|
1999-05-03 09:29:11 +02:00
|
|
|
struct coff_symbol *s = empty_symbol ();
|
|
|
|
|
2015-01-06 17:06:45 +01:00
|
|
|
if (b == NULL)
|
|
|
|
fatal (_("ICE: do_define called without a block"));
|
|
|
|
if (i >= rawcount)
|
|
|
|
fatal (_("Out of range symbol index: %u"), i);
|
|
|
|
|
|
|
|
sym = &rawsyms[i].u.syment;
|
1999-05-03 09:29:11 +02:00
|
|
|
s->number = ++symbol_index;
|
2015-01-06 17:06:45 +01:00
|
|
|
s->name = N(sym);
|
1999-05-03 09:29:11 +02:00
|
|
|
s->sfile = cur_sfile;
|
2015-01-06 17:06:45 +01:00
|
|
|
/* Glue onto the ofile list. */
|
1999-05-03 09:29:11 +02:00
|
|
|
if (lofile >= 0)
|
|
|
|
{
|
|
|
|
if (ofile->symbol_list_tail)
|
|
|
|
ofile->symbol_list_tail->next_in_ofile_list = s;
|
|
|
|
else
|
|
|
|
ofile->symbol_list_head = s;
|
|
|
|
ofile->symbol_list_tail = s;
|
2015-01-06 17:06:45 +01:00
|
|
|
/* And the block list. */
|
1999-05-03 09:29:11 +02:00
|
|
|
}
|
|
|
|
if (b->vars_tail)
|
|
|
|
b->vars_tail->next = s;
|
|
|
|
else
|
|
|
|
b->vars_head = s;
|
|
|
|
|
|
|
|
b->vars_tail = s;
|
|
|
|
b->nvars++;
|
|
|
|
s->type = do_type (i);
|
|
|
|
s->where = do_where (i);
|
|
|
|
s->visible = do_visible (i);
|
|
|
|
|
|
|
|
tindex[i] = s;
|
|
|
|
|
2015-01-06 17:06:45 +01:00
|
|
|
/* We remember the lowest address in each section for each source file. */
|
1999-05-03 09:29:11 +02:00
|
|
|
if (s->where->where == coff_where_memory
|
|
|
|
&& s->type->type == coff_secdef_type)
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
struct coff_isection *is;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2015-01-06 17:06:45 +01:00
|
|
|
/* PR 17512: file: 4676c97f. */
|
|
|
|
if (cur_sfile == NULL)
|
|
|
|
non_fatal (_("Section referenced before any file is defined"));
|
|
|
|
else
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
is = cur_sfile->section + s->where->section->number;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2015-01-06 17:06:45 +01:00
|
|
|
if (!is->init)
|
|
|
|
{
|
|
|
|
is->low = s->where->offset;
|
2015-02-26 23:16:16 +01:00
|
|
|
/* PR 17512: file: 37e7a80d.
|
|
|
|
Check for integer overflow computing low + size. */
|
|
|
|
{
|
|
|
|
long long a, z;
|
|
|
|
|
|
|
|
a = s->where->offset;
|
|
|
|
z = s->type->size;
|
|
|
|
a += z;
|
|
|
|
is->high = (int) a;
|
|
|
|
if (a != is->high)
|
|
|
|
non_fatal (_("Out of range sum for offset (%#x) + size (%#x)"),
|
|
|
|
is->low, s->type->size);
|
|
|
|
}
|
2015-02-13 12:13:20 +01:00
|
|
|
/* PR 17512: file: 37e7a80d. */
|
2015-02-13 13:14:05 +01:00
|
|
|
if (is->high < s->where->offset)
|
2015-02-13 12:13:20 +01:00
|
|
|
fatal (_("Out of range type size: %u"), s->type->size);
|
2015-01-06 17:06:45 +01:00
|
|
|
is->init = 1;
|
|
|
|
is->parent = s->where->section;
|
|
|
|
}
|
|
|
|
}
|
1999-05-03 09:29:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (s->type->type == coff_function_type)
|
|
|
|
last_function_symbol = s;
|
|
|
|
|
|
|
|
return i + sym->n_numaux + 1;
|
|
|
|
}
|
|
|
|
|
2015-01-06 17:06:45 +01:00
|
|
|
static struct coff_ofile *
|
2003-09-14 14:20:17 +02:00
|
|
|
doit (void)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
unsigned int i;
|
|
|
|
bfd_boolean infile = FALSE;
|
1999-05-03 09:29:11 +02:00
|
|
|
struct coff_ofile *head =
|
2002-05-19 18:17:54 +02:00
|
|
|
(struct coff_ofile *) xmalloc (sizeof (struct coff_ofile));
|
2015-01-06 17:06:45 +01:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
ofile = head;
|
|
|
|
head->source_head = 0;
|
|
|
|
head->source_tail = 0;
|
|
|
|
head->nsources = 0;
|
|
|
|
head->symbol_list_tail = 0;
|
|
|
|
head->symbol_list_head = 0;
|
|
|
|
do_sections_p1 (head);
|
|
|
|
push_scope (1);
|
|
|
|
|
|
|
|
for (i = 0; i < rawcount;)
|
|
|
|
{
|
|
|
|
struct internal_syment *sym = &rawsyms[i].u.syment;
|
2015-01-06 17:06:45 +01:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
switch (sym->n_sclass)
|
|
|
|
{
|
|
|
|
case C_FILE:
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
/* New source file announced. */
|
1999-05-03 09:29:11 +02:00
|
|
|
struct coff_sfile *n =
|
|
|
|
(struct coff_sfile *) xmalloc (sizeof (struct coff_sfile));
|
2015-01-06 17:06:45 +01:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
n->section = (struct coff_isection *) xcalloc (sizeof (struct coff_isection), abfd->section_count + 1);
|
|
|
|
cur_sfile = n;
|
2015-01-06 17:06:45 +01:00
|
|
|
n->name = N(sym);
|
1999-05-03 09:29:11 +02:00
|
|
|
n->next = 0;
|
|
|
|
|
|
|
|
if (infile)
|
2015-01-06 17:06:45 +01:00
|
|
|
pop_scope ();
|
|
|
|
else
|
|
|
|
infile = TRUE;
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
push_scope (1);
|
|
|
|
file_scope = n->scope = top_scope;
|
|
|
|
|
|
|
|
if (head->source_tail)
|
|
|
|
head->source_tail->next = n;
|
|
|
|
else
|
|
|
|
head->source_head = n;
|
|
|
|
head->source_tail = n;
|
|
|
|
head->nsources++;
|
|
|
|
i += sym->n_numaux + 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case C_FCN:
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
char *name = N(sym);
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
if (name[1] == 'b')
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
/* Function start. */
|
1999-05-03 09:29:11 +02:00
|
|
|
push_scope (0);
|
2015-01-06 17:06:45 +01:00
|
|
|
/* PR 17512: file: 0ef7fbaf. */
|
|
|
|
if (last_function_type)
|
|
|
|
last_function_type->u.function.code = top_scope;
|
2015-01-21 11:33:19 +01:00
|
|
|
/* PR 17512: file: 22908266. */
|
|
|
|
if (sym->n_scnum < ofile->nsections && sym->n_scnum >= 0)
|
|
|
|
top_scope->sec = ofile->sections + sym->n_scnum;
|
|
|
|
else
|
|
|
|
top_scope->sec = NULL;
|
1999-05-03 09:29:11 +02:00
|
|
|
top_scope->offset = sym->n_value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
/* PR 17512: file: e92e42e1. */
|
|
|
|
if (top_scope == NULL)
|
|
|
|
fatal (_("Function start encountered without a top level scope."));
|
1999-05-03 09:29:11 +02:00
|
|
|
top_scope->size = sym->n_value - top_scope->offset + 1;
|
|
|
|
pop_scope ();
|
|
|
|
}
|
|
|
|
i += sym->n_numaux + 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case C_BLOCK:
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
char *name = N(sym);
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
if (name[1] == 'b')
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
/* Block start. */
|
1999-05-03 09:29:11 +02:00
|
|
|
push_scope (1);
|
2015-01-21 11:33:19 +01:00
|
|
|
/* PR 17512: file: af7e8e83. */
|
|
|
|
if (sym->n_scnum < ofile->nsections && sym->n_scnum >= 0)
|
|
|
|
top_scope->sec = ofile->sections + sym->n_scnum;
|
|
|
|
else
|
|
|
|
top_scope->sec = NULL;
|
1999-05-03 09:29:11 +02:00
|
|
|
top_scope->offset = sym->n_value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-06 17:06:45 +01:00
|
|
|
if (top_scope == NULL)
|
|
|
|
fatal (_("Block start encountered without a scope for it."));
|
1999-05-03 09:29:11 +02:00
|
|
|
top_scope->size = sym->n_value - top_scope->offset + 1;
|
|
|
|
pop_scope ();
|
|
|
|
}
|
|
|
|
i += sym->n_numaux + 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case C_REGPARM:
|
|
|
|
case C_ARG:
|
2015-01-06 17:06:45 +01:00
|
|
|
if (last_function_symbol == NULL)
|
|
|
|
fatal (_("Function arguments encountered without a function definition"));
|
1999-05-03 09:29:11 +02:00
|
|
|
i = do_define (i, last_function_symbol->type->u.function.parameters);
|
|
|
|
break;
|
|
|
|
case C_MOS:
|
|
|
|
case C_MOU:
|
|
|
|
case C_FIELD:
|
2015-01-06 17:06:45 +01:00
|
|
|
/* PR 17512: file: 43ab21f4. */
|
|
|
|
if (last_struct == NULL)
|
|
|
|
fatal (_("Structure element encountered without a structure definition"));
|
1999-05-03 09:29:11 +02:00
|
|
|
i = do_define (i, last_struct->u.astructdef.elements);
|
|
|
|
break;
|
|
|
|
case C_MOE:
|
2015-01-06 17:06:45 +01:00
|
|
|
if (last_enum == NULL)
|
|
|
|
fatal (_("Enum element encountered without an enum definition"));
|
1999-05-03 09:29:11 +02:00
|
|
|
i = do_define (i, last_enum->u.aenumdef.elements);
|
|
|
|
break;
|
|
|
|
case C_STRTAG:
|
|
|
|
case C_ENTAG:
|
|
|
|
case C_UNTAG:
|
2015-01-06 17:06:45 +01:00
|
|
|
/* Various definition. */
|
|
|
|
if (top_scope == NULL)
|
2017-07-18 17:58:14 +02:00
|
|
|
fatal (_("Aggregate definition encountered without a scope"));
|
1999-05-03 09:29:11 +02:00
|
|
|
i = do_define (i, top_scope);
|
|
|
|
break;
|
|
|
|
case C_EXT:
|
|
|
|
case C_LABEL:
|
2015-01-06 17:06:45 +01:00
|
|
|
if (file_scope == NULL)
|
2017-07-18 17:58:14 +02:00
|
|
|
fatal (_("Label definition encountered without a file scope"));
|
1999-05-03 09:29:11 +02:00
|
|
|
i = do_define (i, file_scope);
|
|
|
|
break;
|
|
|
|
case C_STAT:
|
|
|
|
case C_TPDEF:
|
|
|
|
case C_AUTO:
|
|
|
|
case C_REG:
|
2015-01-06 17:06:45 +01:00
|
|
|
if (top_scope == NULL)
|
2017-07-18 17:58:14 +02:00
|
|
|
fatal (_("Variable definition encountered without a scope"));
|
1999-05-03 09:29:11 +02:00
|
|
|
i = do_define (i, top_scope);
|
|
|
|
break;
|
|
|
|
case C_EOS:
|
|
|
|
i += sym->n_numaux + 1;
|
|
|
|
break;
|
2015-01-06 17:06:45 +01:00
|
|
|
default:
|
|
|
|
fatal (_("Unrecognised symbol class: %d"), sym->n_sclass);
|
1999-05-03 09:29:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
do_sections_p2 (head);
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct coff_ofile *
|
2003-09-14 14:20:17 +02:00
|
|
|
coff_grok (bfd *inabfd)
|
1999-05-03 09:29:11 +02:00
|
|
|
{
|
|
|
|
long storage;
|
|
|
|
struct coff_ofile *p;
|
|
|
|
abfd = inabfd;
|
2015-01-06 17:06:45 +01:00
|
|
|
|
|
|
|
if (! bfd_family_coff (abfd))
|
|
|
|
{
|
|
|
|
non_fatal (_("%s: is not a COFF format file"), bfd_get_filename (abfd));
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-12 13:42:37 +02:00
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
storage = bfd_get_symtab_upper_bound (abfd);
|
|
|
|
|
|
|
|
if (storage < 0)
|
|
|
|
bfd_fatal (abfd->filename);
|
|
|
|
|
|
|
|
syms = (asymbol **) xmalloc (storage);
|
|
|
|
symcount = bfd_canonicalize_symtab (abfd, syms);
|
|
|
|
if (symcount < 0)
|
|
|
|
bfd_fatal (abfd->filename);
|
|
|
|
rawsyms = obj_raw_syments (abfd);
|
2012-11-09 09:29:34 +01:00
|
|
|
rawcount = obj_raw_syment_count (abfd);
|
1999-05-03 09:29:11 +02:00
|
|
|
tindex = (struct coff_symbol **) (xcalloc (sizeof (struct coff_symbol *), rawcount));
|
|
|
|
|
|
|
|
p = doit ();
|
|
|
|
return p;
|
|
|
|
}
|