binutils-gdb/binutils/srconv.c

1857 lines
39 KiB
C
Raw Normal View History

1999-05-03 09:29:11 +02:00
/* srconv.c -- Sysroff conversion program
Copyright (C) 1994-2020 Free Software Foundation, Inc.
1999-05-03 09:29:11 +02:00
This file is part of GNU Binutils.
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
2007-07-05 18:54:46 +02:00
the Free Software Foundation; either version 3 of the License, or
1999-05-03 09:29:11 +02:00
(at your option) any later version.
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
2005-05-08 16:17:41 +02:00
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 program can be used to convert a coff object file
into a Hitachi OM/LM (Sysroff) format.
All debugging information is preserved */
#include "sysdep.h"
#include "bfd.h"
1999-05-03 09:29:11 +02:00
#include "bucomm.h"
#include "sysroff.h"
#include "coffgrok.h"
#include "libiberty.h"
#include "filenames.h"
#include "getopt.h"
1999-05-03 09:29:11 +02:00
#include "coff/internal.h"
#include "../bfd/libcoff.h"
/*#define FOOP1 1 */
static int addrsize;
static char *toolname;
static char **rnames;
static void walk_tree_symbol
(struct coff_sfile *, struct coff_section *, struct coff_symbol *, int);
static void walk_tree_scope
(struct coff_section *, struct coff_sfile *, struct coff_scope *, int, int);
static int find_base (struct coff_sfile *, struct coff_section *);
static void wr_globals (struct coff_ofile *, struct coff_sfile *, int);
1999-05-03 09:29:11 +02:00
static FILE *file;
static bfd *abfd;
static int debug = 0;
static int quick = 0;
static int noprescan = 0;
static struct coff_ofile *tree;
/* Obsolete ??
1999-05-03 09:29:11 +02:00
static int absolute_p;
*/
static int segmented_p;
static int code;
static int ids1[20000];
static int ids2[20000];
static int base1 = 0x18;
static int base2 = 0x2018;
static int
get_member_id (int x)
1999-05-03 09:29:11 +02:00
{
if (ids2[x])
2002-01-23 17:12:56 +01:00
return ids2[x];
1999-05-03 09:29:11 +02:00
ids2[x] = base2++;
return ids2[x];
}
static int
get_ordinary_id (int x)
1999-05-03 09:29:11 +02:00
{
if (ids1[x])
2002-01-23 17:12:56 +01:00
return ids1[x];
1999-05-03 09:29:11 +02:00
ids1[x] = base1++;
return ids1[x];
}
static char *
section_translate (char *n)
1999-05-03 09:29:11 +02:00
{
if (strcmp (n, ".text") == 0)
return "P";
if (strcmp (n, ".data") == 0)
return "D";
if (strcmp (n, ".bss") == 0)
return "B";
return n;
}
#define DATE "940201073000"; /* Just a time on my birthday */
static char *
strip_suffix (const char *name)
1999-05-03 09:29:11 +02:00
{
int i;
char *res;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
for (i = 0; name[i] != 0 && name[i] != '.'; i++)
;
res = (char *) xmalloc (i + 1);
memcpy (res, name, i);
res[i] = 0;
return res;
}
/* IT LEN stuff CS */
static void
checksum (FILE *ffile, unsigned char *ptr, int size, int ccode)
1999-05-03 09:29:11 +02:00
{
int j;
int last;
int sum = 0;
int bytes = size / 8;
2002-01-23 17:12:56 +01:00
last = !(ccode & 0xff00);
1999-05-03 09:29:11 +02:00
if (size & 0x7)
fatal (_("Checksum failure"));
ptr[0] = ccode | (last ? 0x80 : 0);
1999-05-03 09:29:11 +02:00
ptr[1] = bytes + 1;
for (j = 0; j < bytes; j++)
2002-01-23 17:12:56 +01:00
sum += ptr[j];
/* Glue on a checksum too. */
1999-05-03 09:29:11 +02:00
ptr[bytes] = ~sum;
if (fwrite (ptr, bytes + 1, 1, ffile) != 1)
/* FIXME: Return error status. */
fatal (_("Failed to write checksum"));
1999-05-03 09:29:11 +02:00
}
static void
writeINT (int n, unsigned char *ptr, int *idx, int size, FILE *ffile)
1999-05-03 09:29:11 +02:00
{
int byte = *idx / 8;
if (size == -2)
size = addrsize;
else if (size == -1)
size = 0;
if (byte > 240)
{
2002-01-23 17:12:56 +01:00
/* Lets write out that record and do another one. */
checksum (ffile, ptr, *idx, code | 0x1000);
1999-05-03 09:29:11 +02:00
*idx = 16;
byte = *idx / 8;
}
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
switch (size)
{
case 0:
break;
case 1:
ptr[byte] = n;
break;
case 2:
ptr[byte + 0] = n >> 8;
ptr[byte + 1] = n;
break;
case 4:
ptr[byte + 0] = n >> 24;
ptr[byte + 1] = n >> 16;
ptr[byte + 2] = n >> 8;
ptr[byte + 3] = n >> 0;
break;
default:
fatal (_("Unsupported integer write size: %d"), size);
1999-05-03 09:29:11 +02:00
}
*idx += size * 8;
}
static void
writeBITS (int val, unsigned char *ptr, int *idx, int size)
1999-05-03 09:29:11 +02:00
{
int byte = *idx / 8;
int bit = *idx % 8;
int old;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
*idx += size;
old = ptr[byte];
2002-01-23 17:12:56 +01:00
/* Turn off all about to change bits. */
1999-05-03 09:29:11 +02:00
old &= ~((~0 >> (8 - bit - size)) & ((1 << size) - 1));
2002-01-23 17:12:56 +01:00
/* Turn on the bits we want. */
1999-05-03 09:29:11 +02:00
old |= (val & ((1 << size) - 1)) << (8 - bit - size);
ptr[byte] = old;
}
static void
writeBARRAY (barray data, unsigned char *ptr, int *idx,
int size ATTRIBUTE_UNUSED, FILE *ffile)
1999-05-03 09:29:11 +02:00
{
int i;
2002-01-23 17:12:56 +01:00
writeINT (data.len, ptr, idx, 1, ffile);
1999-05-03 09:29:11 +02:00
for (i = 0; i < data.len; i++)
writeINT (data.data[i], ptr, idx, 1, ffile);
1999-05-03 09:29:11 +02:00
}
static void
writeCHARS (char *string, unsigned char *ptr, int *idx, int size, FILE *ffile)
1999-05-03 09:29:11 +02:00
{
int i = *idx / 8;
if (i > 240)
{
2002-01-23 17:12:56 +01:00
/* Lets write out that record and do another one. */
checksum (ffile, ptr, *idx, code | 0x1000);
1999-05-03 09:29:11 +02:00
*idx = 16;
i = *idx / 8;
}
if (size == 0)
{
2002-01-23 17:12:56 +01:00
/* Variable length string. */
1999-05-03 09:29:11 +02:00
size = strlen (string);
ptr[i++] = size;
}
2002-01-23 17:12:56 +01:00
/* BUG WAITING TO HAPPEN. */
1999-05-03 09:29:11 +02:00
memcpy (ptr + i, string, size);
i += size;
*idx = i * 8;
}
#define SYSROFF_SWAP_OUT
#include "sysroff.c"
static char *rname_sh[] =
{
"R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", "R10", "R11", "R12", "R13", "R14", "R15"
};
static char *rname_h8300[] =
{
"ER0", "ER1", "ER2", "ER3", "ER4", "ER5", "ER6", "ER7", "PC", "CCR"
};
static void
wr_tr (void)
1999-05-03 09:29:11 +02:00
{
2002-01-23 17:12:56 +01:00
/* The TR block is not normal - it doesn't have any contents. */
1999-05-03 09:29:11 +02:00
2002-01-23 17:12:56 +01:00
static char b[] =
{
0xff, /* IT */
0x03, /* RL */
0xfd, /* CS */
};
if (fwrite (b, sizeof (b), 1, file) != 1)
/* FIXME: Return error status. */
fatal (_("Failed to write TR block"));
1999-05-03 09:29:11 +02:00
}
static void
wr_un (struct coff_ofile *ptr, struct coff_sfile *sfile, int first,
int nsecs ATTRIBUTE_UNUSED)
1999-05-03 09:29:11 +02:00
{
struct IT_un un;
struct coff_symbol *s;
un.spare1 = 0;
if (bfd_get_file_flags (abfd) & EXEC_P)
un.format = FORMAT_LM;
else
un.format = FORMAT_OM;
un.spare1 = 0;
/* Don't count the abs section. */
un.nsections = ptr->nsections - 1;
1999-05-03 09:29:11 +02:00
un.nextdefs = 0;
un.nextrefs = 0;
2002-01-23 17:12:56 +01:00
/* Count all the undefined and defined variables with global scope. */
1999-05-03 09:29:11 +02:00
if (first)
{
for (s = ptr->symbol_list_head; s; s = s->next_in_ofile_list)
{
if (s->visible->type == coff_vis_ext_def
|| s->visible->type == coff_vis_common)
un.nextdefs++;
if (s->visible->type == coff_vis_ext_ref)
un.nextrefs++;
}
}
un.tool = toolname;
un.tcd = DATE;
un.linker = "L_GX00";
un.lcd = DATE;
un.name = sfile->name;
sysroff_swap_un_out (file, &un);
}
static void
wr_hd (struct coff_ofile *p)
1999-05-03 09:29:11 +02:00
{
struct IT_hd hd;
hd.spare1 = 0;
if (bfd_get_file_flags (abfd) & EXEC_P)
2002-01-23 17:12:56 +01:00
hd.mt = MTYPE_ABS_LM;
1999-05-03 09:29:11 +02:00
else
2002-01-23 17:12:56 +01:00
hd.mt = MTYPE_OMS_OR_LMS;
1999-05-03 09:29:11 +02:00
hd.cd = DATE;
hd.nu = p->nsources; /* Always one unit */
hd.code = 0; /* Always ASCII */
hd.ver = "0200"; /* Version 2.00 */
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
switch (bfd_get_arch (abfd))
{
case bfd_arch_h8300:
hd.au = 8;
hd.si = 0;
hd.spcsz = 32;
hd.segsz = 0;
hd.segsh = 0;
switch (bfd_get_mach (abfd))
{
case bfd_mach_h8300:
hd.cpu = "H8300";
hd.afl = 2;
addrsize = 2;
toolname = "C_H8/300";
break;
case bfd_mach_h8300h:
hd.cpu = "H8300H";
hd.afl = 4;
addrsize = 4;
toolname = "C_H8/300H";
break;
case bfd_mach_h8300s:
hd.cpu = "H8300S";
hd.afl = 4;
addrsize = 4;
toolname = "C_H8/300S";
break;
default:
fatal (_("Unrecognized H8300 sub-architecture: %ld"),
bfd_get_mach (abfd));
1999-05-03 09:29:11 +02:00
}
rnames = rname_h8300;
break;
case bfd_arch_sh:
hd.au = 8;
hd.si = 0;
hd.afl = 4;
hd.spcsz = 32;
hd.segsz = 0;
hd.segsh = 0;
hd.cpu = "SH";
addrsize = 4;
toolname = "C_SH";
rnames = rname_sh;
break;
default:
fatal (_("Unsupported architecture: %d"), bfd_get_arch (abfd));
1999-05-03 09:29:11 +02:00
}
if (! (bfd_get_file_flags(abfd) & EXEC_P))
1999-05-03 09:29:11 +02:00
{
hd.ep = 0;
}
else
{
hd.ep = 1;
hd.uan = 0;
hd.sa = 0;
hd.sad = 0;
hd.address = bfd_get_start_address (abfd);
}
hd.os = "";
hd.sys = "";
hd.mn = strip_suffix (bfd_get_filename (abfd));
sysroff_swap_hd_out (file, &hd);
}
static void
wr_sh (struct coff_ofile *p ATTRIBUTE_UNUSED, struct coff_section *sec)
1999-05-03 09:29:11 +02:00
{
struct IT_sh sh;
sh.unit = 0;
sh.section = sec->number;
#ifdef FOOP1
sh.section = 0;
#endif
sysroff_swap_sh_out (file, &sh);
}
static void
wr_ob (struct coff_ofile *p ATTRIBUTE_UNUSED, struct coff_section *section)
1999-05-03 09:29:11 +02:00
{
bfd_size_type i;
int first = 1;
unsigned char stuff[200];
i = 0;
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
while (i < bfd_section_size (section->bfd_section))
1999-05-03 09:29:11 +02:00
{
struct IT_ob ob;
2002-01-23 17:12:56 +01:00
int todo = 200; /* Copy in 200 byte lumps. */
1999-05-03 09:29:11 +02:00
ob.spare = 0;
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
if (i + todo > bfd_section_size (section->bfd_section))
todo = bfd_section_size (section->bfd_section) - i;
1999-05-03 09:29:11 +02:00
if (first)
{
ob.saf = 1;
if (bfd_get_file_flags (abfd) & EXEC_P)
ob.address = section->address;
else
ob.address = 0;
first = 0;
}
else
{
ob.saf = 0;
}
2002-01-23 17:12:56 +01:00
ob.cpf = 0; /* Never compress. */
1999-05-03 09:29:11 +02:00
ob.data.len = todo;
bfd_get_section_contents (abfd, section->bfd_section, stuff, i, todo);
ob.data.data = stuff;
sysroff_swap_ob_out (file, &ob /*, i + todo < section->size */ );
i += todo;
}
2002-01-23 17:12:56 +01:00
/* Now fill the rest with blanks. */
1999-05-03 09:29:11 +02:00
while (i < (bfd_size_type) section->size)
{
struct IT_ob ob;
2002-01-23 17:12:56 +01:00
int todo = 200; /* Copy in 200 byte lumps. */
1999-05-03 09:29:11 +02:00
ob.spare = 0;
if (i + todo > (bfd_size_type) section->size)
todo = section->size - i;
ob.saf = 0;
2002-01-23 17:12:56 +01:00
ob.cpf = 0; /* Never compress. */
1999-05-03 09:29:11 +02:00
ob.data.len = todo;
memset (stuff, 0, todo);
ob.data.data = stuff;
sysroff_swap_ob_out (file, &ob);
i += todo;
}
2002-01-23 17:12:56 +01:00
/* Now fill the rest with blanks. */
1999-05-03 09:29:11 +02:00
}
static void
wr_rl (struct coff_ofile *ptr ATTRIBUTE_UNUSED, struct coff_section *sec)
1999-05-03 09:29:11 +02:00
{
int nr = sec->nrelocs;
int i;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
for (i = 0; i < nr; i++)
{
struct coff_reloc *r = sec->relocs + i;
struct coff_symbol *ref;
struct IT_rl rl;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
rl.apol = 0;
rl.boundary = 0;
rl.segment = 1;
rl.sign = 0;
rl.check = 0;
rl.addr = r->offset;
rl.bitloc = 0;
2002-01-23 17:12:56 +01:00
rl.flen = 32; /* SH Specific. */
/* What sort of reloc ? Look in the section to find out. */
1999-05-03 09:29:11 +02:00
ref = r->symbol;
if (ref->visible->type == coff_vis_ext_ref)
{
2002-01-23 17:12:56 +01:00
rl.bcount = 4; /* Always 4 for us. */
1999-05-03 09:29:11 +02:00
rl.op = OP_EXT_REF;
rl.symn = ref->er_number;
}
else if (ref->visible->type == coff_vis_common)
{
2002-01-23 17:12:56 +01:00
rl.bcount = 11; /* Always 11 for us. */
1999-05-03 09:29:11 +02:00
rl.op = OP_SEC_REF;
rl.secn = ref->where->section->number;
rl.copcode_is_3 = 3;
rl.alength_is_4 = 4;
rl.addend = ref->where->offset - ref->where->section->address;
rl.aopcode_is_0x20 = 0x20;
}
else
{
2002-01-23 17:12:56 +01:00
rl.bcount = 11; /* Always 11 for us. */
1999-05-03 09:29:11 +02:00
rl.op = OP_SEC_REF;
rl.secn = ref->where->section->number;
rl.copcode_is_3 = 3;
rl.alength_is_4 = 4;
rl.addend = -ref->where->section->address;
rl.aopcode_is_0x20 = 0x20;
}
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
rl.end = 0xff;
2002-01-23 17:12:56 +01:00
if ( rl.op == OP_SEC_REF
1999-05-03 09:29:11 +02:00
|| rl.op == OP_EXT_REF)
2002-01-23 17:12:56 +01:00
sysroff_swap_rl_out (file, &rl);
1999-05-03 09:29:11 +02:00
}
}
static void
wr_object_body (struct coff_ofile *p)
1999-05-03 09:29:11 +02:00
{
int i;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
for (i = 1; i < p->nsections; i++)
{
wr_sh (p, p->sections + i);
wr_ob (p, p->sections + i);
wr_rl (p, p->sections + i);
}
}
static void
wr_dps_start (struct coff_sfile *sfile,
struct coff_section *section ATTRIBUTE_UNUSED,
struct coff_scope *scope, int type, int nest)
1999-05-03 09:29:11 +02:00
{
struct IT_dps dps;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
dps.end = 0;
dps.opt = 0;
dps.type = type;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
if (scope->sec)
{
dps.san = scope->sec->number;
dps.address = scope->offset - find_base (sfile, scope->sec);
dps.block_size = scope->size;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
if (debug)
{
printf ("DPS %s %d %x\n",
sfile->name,
nest,
dps.address);
}
}
else
{
dps.san = 0;
dps.address = 0;
dps.block_size = 0;
}
dps.nesting = nest;
dps.neg = 0x1001;
sysroff_swap_dps_out (file, &dps);
}
static void
wr_dps_end (struct coff_section *section ATTRIBUTE_UNUSED,
struct coff_scope *scope ATTRIBUTE_UNUSED, int type)
1999-05-03 09:29:11 +02:00
{
struct IT_dps dps;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
dps.end = 1;
dps.type = type;
sysroff_swap_dps_out (file, &dps);
}
static int *
nints (int x)
1999-05-03 09:29:11 +02:00
{
return (int *) (xcalloc (sizeof (int), x));
}
static void
walk_tree_type_1 (struct coff_sfile *sfile, struct coff_symbol *symbol,
struct coff_type *type, int nest)
1999-05-03 09:29:11 +02:00
{
switch (type->type)
{
case coff_secdef_type:
case coff_basic_type:
{
struct IT_dbt dbt;
switch (type->u.basic)
{
case T_NULL:
case T_VOID:
dbt.btype = BTYPE_VOID;
dbt.sign = BTYPE_UNSPEC;
dbt.fptype = FPTYPE_NOTSPEC;
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case T_CHAR:
dbt.btype = BTYPE_CHAR;
dbt.sign = BTYPE_UNSPEC;
dbt.fptype = FPTYPE_NOTSPEC;
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case T_SHORT:
case T_INT:
case T_LONG:
dbt.btype = BTYPE_INT;
dbt.sign = SIGN_SIGNED;
dbt.fptype = FPTYPE_NOTSPEC;
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case T_FLOAT:
dbt.btype = BTYPE_FLOAT;
dbt.fptype = FPTYPE_SINGLE;
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case T_DOUBLE:
dbt.btype = BTYPE_FLOAT;
dbt.fptype = FPTYPE_DOUBLE;
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case T_LNGDBL:
dbt.btype = BTYPE_FLOAT;
dbt.fptype = FPTYPE_EXTENDED;
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case T_UCHAR:
dbt.btype = BTYPE_CHAR;
dbt.sign = SIGN_UNSIGNED;
dbt.fptype = FPTYPE_NOTSPEC;
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case T_USHORT:
case T_UINT:
case T_ULONG:
dbt.btype = BTYPE_INT;
dbt.sign = SIGN_UNSIGNED;
dbt.fptype = FPTYPE_NOTSPEC;
break;
}
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
dbt.bitsize = type->size;
dbt.neg = 0x1001;
sysroff_swap_dbt_out (file, &dbt);
break;
}
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case coff_pointer_type:
{
struct IT_dpt dpt;
2002-01-23 17:12:56 +01:00
dpt.dunno = 0;
1999-05-03 09:29:11 +02:00
walk_tree_type_1 (sfile, symbol, type->u.pointer.points_to, nest + 1);
dpt.neg = 0x1001;
sysroff_swap_dpt_out (file, &dpt);
break;
}
case coff_function_type:
{
struct IT_dfp dfp;
struct coff_symbol *param;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
dfp.end = 0;
dfp.spare = 0;
dfp.nparams = type->u.function.parameters->nvars;
dfp.neg = 0x1001;
walk_tree_type_1 (sfile, symbol, type->u.function.function_returns, nest + 1);
sysroff_swap_dfp_out (file, &dfp);
for (param = type->u.function.parameters->vars_head;
param;
param = param->next)
2002-01-23 17:12:56 +01:00
walk_tree_symbol (sfile, 0, param, nest);
1999-05-03 09:29:11 +02:00
dfp.end = 1;
sysroff_swap_dfp_out (file, &dfp);
break;
}
case coff_structdef_type:
{
struct IT_dbt dbt;
struct IT_dds dds;
struct coff_symbol *member;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
dds.spare = 0;
dbt.btype = BTYPE_STRUCT;
dbt.bitsize = type->size;
dbt.sign = SIGN_UNSPEC;
dbt.fptype = FPTYPE_NOTSPEC;
dbt.sid = get_member_id (type->u.astructdef.idx);
dbt.neg = 0x1001;
sysroff_swap_dbt_out (file, &dbt);
dds.end = 0;
dds.neg = 0x1001;
sysroff_swap_dds_out (file, &dds);
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
for (member = type->u.astructdef.elements->vars_head;
member;
member = member->next)
2002-01-23 17:12:56 +01:00
walk_tree_symbol (sfile, 0, member, nest + 1);
1999-05-03 09:29:11 +02:00
dds.end = 1;
sysroff_swap_dds_out (file, &dds);
}
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case coff_structref_type:
{
struct IT_dbt dbt;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
dbt.btype = BTYPE_TAG;
dbt.bitsize = type->size;
dbt.sign = SIGN_UNSPEC;
dbt.fptype = FPTYPE_NOTSPEC;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
if (type->u.astructref.ref)
2002-01-23 17:12:56 +01:00
dbt.sid = get_member_id (type->u.astructref.ref->number);
1999-05-03 09:29:11 +02:00
else
2002-01-23 17:12:56 +01:00
dbt.sid = 0;
1999-05-03 09:29:11 +02:00
dbt.neg = 0x1001;
sysroff_swap_dbt_out (file, &dbt);
}
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case coff_array_type:
{
struct IT_dar dar;
int j;
2002-01-23 17:12:56 +01:00
int dims = 1; /* Only output one dimension at a time. */
1999-05-03 09:29:11 +02:00
dar.dims = dims;
dar.variable = nints (dims);
dar.subtype = nints (dims);
dar.spare = nints (dims);
dar.max_variable = nints (dims);
dar.maxspare = nints (dims);
dar.max = nints (dims);
dar.min_variable = nints (dims);
dar.min = nints (dims);
dar.minspare = nints (dims);
dar.neg = 0x1001;
dar.length = type->size / type->u.array.dim;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
for (j = 0; j < dims; j++)
{
dar.variable[j] = VARIABLE_FIXED;
dar.subtype[j] = SUB_INTEGER;
dar.spare[j] = 0;
dar.max_variable[j] = 0;
dar.max[j] = type->u.array.dim;
dar.min_variable[j] = 0;
dar.min[j] = 1; /* Why isn't this 0 ? */
}
walk_tree_type_1 (sfile, symbol, type->u.array.array_of, nest + 1);
sysroff_swap_dar_out (file, &dar);
}
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case coff_enumdef_type:
{
struct IT_dbt dbt;
struct IT_den den;
struct coff_symbol *member;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
dbt.btype = BTYPE_ENUM;
dbt.bitsize = type->size;
dbt.sign = SIGN_UNSPEC;
dbt.fptype = FPTYPE_NOTSPEC;
dbt.sid = get_member_id (type->u.aenumdef.idx);
dbt.neg = 0x1001;
sysroff_swap_dbt_out (file, &dbt);
den.end = 0;
den.neg = 0x1001;
den.spare = 0;
sysroff_swap_den_out (file, &den);
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
for (member = type->u.aenumdef.elements->vars_head;
member;
member = member->next)
2002-01-23 17:12:56 +01:00
walk_tree_symbol (sfile, 0, member, nest + 1);
1999-05-03 09:29:11 +02:00
den.end = 1;
sysroff_swap_den_out (file, &den);
}
break;
case coff_enumref_type:
{
struct IT_dbt dbt;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
dbt.btype = BTYPE_TAG;
dbt.bitsize = type->size;
dbt.sign = SIGN_UNSPEC;
dbt.fptype = FPTYPE_NOTSPEC;
dbt.sid = get_member_id (type->u.aenumref.ref->number);
dbt.neg = 0x1001;
sysroff_swap_dbt_out (file, &dbt);
}
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
default:
fatal (_("Unrecognised type: %d"), type->type);
1999-05-03 09:29:11 +02:00
}
}
/* Obsolete ?
1999-05-03 09:29:11 +02:00
static void
dty_start ()
{
struct IT_dty dty;
dty.end = 0;
dty.neg = 0x1001;
dty.spare = 0;
sysroff_swap_dty_out (file, &dty);
}
static void
dty_stop ()
{
struct IT_dty dty;
dty.end = 0;
dty.neg = 0x1001;
dty.end = 1;
sysroff_swap_dty_out (file, &dty);
}
static void
dump_tree_structure (sfile, symbol, type, nest)
struct coff_sfile *sfile;
struct coff_symbol *symbol;
struct coff_type *type;
int nest;
{
if (symbol->type->type == coff_function_type)
{
}
}
*/
static void
walk_tree_type (struct coff_sfile *sfile, struct coff_symbol *symbol,
struct coff_type *type, int nest)
1999-05-03 09:29:11 +02:00
{
struct IT_dty dty;
2002-01-23 17:12:56 +01:00
dty.spare = 0;
dty.end = 0;
dty.neg = 0x1001;
1999-05-03 09:29:11 +02:00
if (symbol->type->type == coff_function_type)
{
1999-05-03 09:29:11 +02:00
sysroff_swap_dty_out (file, &dty);
walk_tree_type_1 (sfile, symbol, type, nest);
dty.end = 1;
sysroff_swap_dty_out (file, &dty);
wr_dps_start (sfile,
symbol->where->section,
symbol->type->u.function.code,
BLOCK_TYPE_FUNCTION, nest);
wr_dps_start (sfile, symbol->where->section,
symbol->type->u.function.code,
BLOCK_TYPE_BLOCK, nest);
walk_tree_scope (symbol->where->section,
sfile,
symbol->type->u.function.code,
nest + 1, BLOCK_TYPE_BLOCK);
wr_dps_end (symbol->where->section,
symbol->type->u.function.code,
BLOCK_TYPE_BLOCK);
wr_dps_end (symbol->where->section,
symbol->type->u.function.code, BLOCK_TYPE_FUNCTION);
}
else
{
sysroff_swap_dty_out (file, &dty);
walk_tree_type_1 (sfile, symbol, type, nest);
dty.end = 1;
sysroff_swap_dty_out (file, &dty);
}
}
static void
walk_tree_symbol (struct coff_sfile *sfile, struct coff_section *section ATTRIBUTE_UNUSED, struct coff_symbol *symbol, int nest)
1999-05-03 09:29:11 +02:00
{
struct IT_dsy dsy;
2002-01-23 17:12:56 +01:00
memset (&dsy, 0, sizeof(dsy));
1999-05-03 09:29:11 +02:00
dsy.nesting = nest;
switch (symbol->type->type)
{
case coff_function_type:
dsy.type = STYPE_FUNC;
dsy.assign = 1;
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case coff_structref_type:
case coff_pointer_type:
case coff_array_type:
case coff_basic_type:
case coff_enumref_type:
dsy.type = STYPE_VAR;
dsy.assign = 1;
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case coff_enumdef_type:
dsy.type = STYPE_TAG;
dsy.assign = 0;
dsy.magic = 2;
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case coff_structdef_type:
dsy.type = STYPE_TAG;
dsy.assign = 0;
dsy.magic = symbol->type->u.astructdef.isstruct ? 0 : 1;
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case coff_secdef_type:
return;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
default:
fatal (_("Unrecognised coff symbol type: %d"), symbol->type->type);
1999-05-03 09:29:11 +02:00
}
if (symbol->where->where == coff_where_member_of_struct)
{
dsy.assign = 0;
dsy.type = STYPE_MEMBER;
}
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
if (symbol->where->where == coff_where_member_of_enum)
{
dsy.type = STYPE_ENUM;
dsy.assign = 0;
dsy.evallen = 4;
dsy.evalue = symbol->where->offset;
}
if (symbol->type->type == coff_structdef_type
|| symbol->where->where == coff_where_entag
|| symbol->where->where == coff_where_strtag)
{
dsy.snumber = get_member_id (symbol->number);
}
else
{
dsy.snumber = get_ordinary_id (symbol->number);
}
dsy.sname = symbol->name[0] == '_' ? symbol->name + 1 : symbol->name;
switch (symbol->visible->type)
{
case coff_vis_common:
case coff_vis_ext_def:
dsy.ainfo = AINFO_STATIC_EXT_DEF;
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case coff_vis_ext_ref:
dsy.ainfo = AINFO_STATIC_EXT_REF;
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case coff_vis_int_def:
dsy.ainfo = AINFO_STATIC_INT;
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case coff_vis_auto:
case coff_vis_autoparam:
dsy.ainfo = AINFO_AUTO;
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case coff_vis_register:
case coff_vis_regparam:
dsy.ainfo = AINFO_REG;
break;
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case coff_vis_tag:
case coff_vis_member_of_struct:
case coff_vis_member_of_enum:
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
default:
fatal (_("Unrecognised coff symbol visibility: %d"), symbol->visible->type);
1999-05-03 09:29:11 +02:00
}
dsy.dlength = symbol->type->size;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
switch (symbol->where->where)
{
case coff_where_memory:
dsy.section = symbol->where->section->number;
#ifdef FOOP
dsy.section = 0;
#endif
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case coff_where_member_of_struct:
case coff_where_member_of_enum:
case coff_where_stack:
case coff_where_register:
case coff_where_unknown:
case coff_where_strtag:
case coff_where_entag:
case coff_where_typedef:
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
default:
fatal (_("Unrecognised coff symbol location: %d"), symbol->where->where);
1999-05-03 09:29:11 +02:00
}
switch (symbol->where->where)
{
case coff_where_memory:
dsy.address = symbol->where->offset - find_base (sfile, symbol->where->section);
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case coff_where_stack:
dsy.address = symbol->where->offset;
break;
2002-01-23 17:12:56 +01:00
case coff_where_member_of_struct:
1999-05-03 09:29:11 +02:00
if (symbol->where->bitsize)
{
int bits = (symbol->where->offset * 8 + symbol->where->bitoffset);
dsy.bitunit = 1;
dsy.field_len = symbol->where->bitsize;
dsy.field_off = (bits / 32) * 4;
dsy.field_bitoff = bits % 32;
}
else
{
dsy.bitunit = 0;
dsy.field_len = symbol->type->size;
dsy.field_off = symbol->where->offset;
}
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case coff_where_member_of_enum:
/* dsy.bitunit = 0;
dsy.field_len = symbol->type->size;
dsy.field_off = symbol->where->offset; */
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
case coff_where_register:
case coff_where_unknown:
case coff_where_strtag:
case coff_where_entag:
case coff_where_typedef:
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
default:
fatal (_("Unrecognised coff symbol location: %d"), symbol->where->where);
1999-05-03 09:29:11 +02:00
}
if (symbol->where->where == coff_where_register)
dsy.reg = rnames[symbol->where->offset];
switch (symbol->visible->type)
{
case coff_vis_common:
2002-01-23 17:12:56 +01:00
/* We do this 'cause common C symbols are treated as extdefs. */
1999-05-03 09:29:11 +02:00
case coff_vis_ext_def:
case coff_vis_ext_ref:
dsy.ename = symbol->name;
break;
case coff_vis_regparam:
case coff_vis_autoparam:
dsy.type = STYPE_PARAMETER;
break;
case coff_vis_int_def:
case coff_vis_auto:
case coff_vis_register:
case coff_vis_tag:
case coff_vis_member_of_struct:
case coff_vis_member_of_enum:
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
default:
fatal (_("Unrecognised coff symbol visibility: %d"), symbol->visible->type);
1999-05-03 09:29:11 +02:00
}
dsy.sfn = 0;
dsy.sln = 2;
dsy.neg = 0x1001;
sysroff_swap_dsy_out (file, &dsy);
walk_tree_type (sfile, symbol, symbol->type, nest);
}
static void
walk_tree_scope (struct coff_section *section, struct coff_sfile *sfile, struct coff_scope *scope, int nest, int type)
1999-05-03 09:29:11 +02:00
{
struct coff_symbol *vars;
struct coff_scope *child;
if (scope->vars_head
|| (scope->list_head && scope->list_head->vars_head))
{
wr_dps_start (sfile, section, scope, type, nest);
if (nest == 0)
wr_globals (tree, sfile, nest + 1);
for (vars = scope->vars_head; vars; vars = vars->next)
2002-01-23 17:12:56 +01:00
walk_tree_symbol (sfile, section, vars, nest);
1999-05-03 09:29:11 +02:00
for (child = scope->list_head; child; child = child->next)
2002-01-23 17:12:56 +01:00
walk_tree_scope (section, sfile, child, nest + 1, BLOCK_TYPE_BLOCK);
1999-05-03 09:29:11 +02:00
wr_dps_end (section, scope, type);
}
}
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
static void
walk_tree_sfile (struct coff_section *section, struct coff_sfile *sfile)
1999-05-03 09:29:11 +02:00
{
walk_tree_scope (section, sfile, sfile->scope, 0, BLOCK_TYPE_COMPUNIT);
}
static void
wr_program_structure (struct coff_ofile *p, struct coff_sfile *sfile)
1999-05-03 09:29:11 +02:00
{
if (p->nsections < 4)
return;
1999-05-03 09:29:11 +02:00
walk_tree_sfile (p->sections + 4, sfile);
}
static void
wr_du (struct coff_ofile *p, struct coff_sfile *sfile, int n)
1999-05-03 09:29:11 +02:00
{
struct IT_du du;
int lim;
int i;
int j;
unsigned int *lowest = (unsigned *) nints (p->nsections);
unsigned int *highest = (unsigned *) nints (p->nsections);
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
du.format = bfd_get_file_flags (abfd) & EXEC_P ? 0 : 1;
du.optimized = 0;
du.stackfrmt = 0;
du.spare = 0;
du.unit = n;
du.sections = p->nsections - 1;
du.san = (int *) xcalloc (sizeof (int), du.sections);
du.address = nints (du.sections);
du.length = nints (du.sections);
for (i = 0; i < du.sections; i++)
{
lowest[i] = ~0;
highest[i] = 0;
}
lim = du.sections;
for (j = 0; j < lim; j++)
{
int src = j;
int dst = j;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
du.san[dst] = dst;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
if (sfile->section[src].init)
{
du.length[dst]
= sfile->section[src].high - sfile->section[src].low + 1;
du.address[dst]
= sfile->section[src].low;
}
else
{
du.length[dst] = 0;
du.address[dst] = 0;
}
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
if (debug)
{
if (sfile->section[src].parent)
{
printf (" section %6s 0x%08x..0x%08x\n",
sfile->section[src].parent->name,
du.address[dst],
du.address[dst] + du.length[dst] - 1);
}
}
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
du.sections = dst + 1;
}
du.tool = "c_gcc";
du.date = DATE;
sysroff_swap_du_out (file, &du);
}
static void
wr_dus (struct coff_ofile *p ATTRIBUTE_UNUSED, struct coff_sfile *sfile)
1999-05-03 09:29:11 +02:00
{
struct IT_dus dus;
dus.efn = 0x1001;
dus.ns = 1; /* p->nsources; sac 14 jul 94 */
dus.drb = nints (dus.ns);
dus.fname = (char **) xcalloc (sizeof (char *), dus.ns);
dus.spare = nints (dus.ns);
dus.ndir = 0;
2002-01-23 17:12:56 +01:00
/* Find the filenames. */
1999-05-03 09:29:11 +02:00
dus.drb[0] = 0;
dus.fname[0] = sfile->name;
sysroff_swap_dus_out (file, &dus);
}
/* Find the offset of the .text section for this sfile in the
2002-01-23 17:12:56 +01:00
.text section for the output file. */
1999-05-03 09:29:11 +02:00
static int
find_base (struct coff_sfile *sfile, struct coff_section *section)
1999-05-03 09:29:11 +02:00
{
return sfile->section[section->number].low;
}
2000-05-02 04:29:17 +02:00
1999-05-03 09:29:11 +02:00
static void
wr_dln (struct coff_ofile *p ATTRIBUTE_UNUSED, struct coff_sfile *sfile,
int n ATTRIBUTE_UNUSED)
1999-05-03 09:29:11 +02:00
{
/* Count up all the linenumbers */
struct coff_symbol *sy;
int lc = 0;
struct IT_dln dln;
int idx;
for (sy = sfile->scope->vars_head;
sy;
sy = sy->next)
{
struct coff_type *t = sy->type;
if (t->type == coff_function_type)
{
struct coff_line *l = t->u.function.lines;
if (l)
lc += l->nlines;
}
}
dln.sfn = nints (lc);
dln.sln = nints (lc);
dln.cc = nints (lc);
dln.section = nints (lc);
dln.from_address = nints (lc);
dln.to_address = nints (lc);
dln.neg = 0x1001;
dln.nln = lc;
/* Run through once more and fill up the structure */
idx = 0;
for (sy = sfile->scope->vars_head;
sy;
sy = sy->next)
{
if (sy->type->type == coff_function_type)
{
int i;
struct coff_line *l = sy->type->u.function.lines;
if (l)
{
int base = find_base (sfile, sy->where->section);
for (i = 0; i < l->nlines; i++)
{
dln.section[idx] = sy->where->section->number;
dln.sfn[idx] = 0;
dln.sln[idx] = l->lines[i];
dln.from_address[idx] =
l->addresses[i] + sy->where->section->address - base;
dln.cc[idx] = 0;
if (idx)
dln.to_address[idx - 1] = dln.from_address[idx];
idx++;
}
dln.to_address[idx - 1] = dln.from_address[idx - 1] + 2;
}
}
}
if (lc)
sysroff_swap_dln_out (file, &dln);
}
2002-01-23 17:12:56 +01:00
/* Write the global symbols out to the debug info. */
1999-05-03 09:29:11 +02:00
static void
wr_globals (struct coff_ofile *p, struct coff_sfile *sfile,
int n ATTRIBUTE_UNUSED)
1999-05-03 09:29:11 +02:00
{
struct coff_symbol *sy;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
for (sy = p->symbol_list_head;
sy;
sy = sy->next_in_ofile_list)
{
if (sy->visible->type == coff_vis_ext_def
|| sy->visible->type == coff_vis_ext_ref)
{
/* Only write out symbols if they belong to
2002-01-23 17:12:56 +01:00
the current source file. */
1999-05-03 09:29:11 +02:00
if (sy->sfile == sfile)
walk_tree_symbol (sfile, 0, sy, 0);
}
}
}
static void
wr_debug (struct coff_ofile *p)
1999-05-03 09:29:11 +02:00
{
struct coff_sfile *sfile;
int n = 0;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
for (sfile = p->source_head;
sfile;
sfile = sfile->next)
{
if (debug)
2002-01-23 17:12:56 +01:00
printf ("%s\n", sfile->name);
1999-05-03 09:29:11 +02:00
wr_du (p, sfile, n);
wr_dus (p, sfile);
wr_program_structure (p, sfile);
wr_dln (p, sfile, n);
n++;
}
}
static void
wr_cs (void)
1999-05-03 09:29:11 +02:00
{
/* It seems that the CS struct is not normal - the size is wrong
2002-01-23 17:12:56 +01:00
heres one I prepared earlier. */
static char b[] =
{
1999-05-03 09:29:11 +02:00
0x80, /* IT */
0x21, /* RL */
0x00, /* number of chars in variable length part */
0x80, /* hd */
0x00, /* hs */
0x80, /* un */
0x00, /* us */
0x80, /* sc */
0x00, /* ss */
0x80, /* er */
0x80, /* ed */
0x80, /* sh */
0x80, /* ob */
0x80, /* rl */
1999-05-03 09:29:11 +02:00
0x80, /* du */
0x80, /* dps */
0x80, /* dsy */
0x80, /* dty */
0x80, /* dln */
0x80, /* dso */
0x80, /* dus */
0x00, /* dss */
0x80, /* dbt */
0x00, /* dpp */
0x80, /* dfp */
0x80, /* den */
0x80, /* dds */
0x80, /* dar */
0x80, /* dpt */
0x00, /* dul */
0x00, /* dse */
0x00, /* dot */
0xDE /* CS */
};
if (fwrite (b, sizeof (b), 1, file) != 1)
/* FIXME: Return error status. */
fatal (_("Failed to write CS struct"));
1999-05-03 09:29:11 +02:00
}
/* Write out the SC records for a unit. Create an SC
for all the sections which appear in the output file, even
2002-01-23 17:12:56 +01:00
if there isn't an equivalent one on the input. */
1999-05-03 09:29:11 +02:00
static int
wr_sc (struct coff_ofile *ptr, struct coff_sfile *sfile)
1999-05-03 09:29:11 +02:00
{
int i;
2002-01-23 17:12:56 +01:00
int scount = 0;
/* First work out the total number of sections. */
1999-05-03 09:29:11 +02:00
int total_sec = ptr->nsections;
struct myinfo
{
struct coff_section *sec;
struct coff_symbol *symbol;
};
struct coff_symbol *symbol;
struct myinfo *info
= (struct myinfo *) calloc (total_sec, sizeof (struct myinfo));
for (i = 0; i < total_sec; i++)
{
info[i].sec = ptr->sections + i;
info[i].symbol = 0;
}
for (symbol = sfile->scope->vars_head;
symbol;
symbol = symbol->next)
{
if (symbol->type->type == coff_secdef_type)
{
for (i = 0; i < total_sec; i++)
{
if (symbol->where->section == info[i].sec)
{
info[i].symbol = symbol;
break;
}
}
}
}
/* Now output all the section info, and fake up some stuff for sections
2002-01-23 17:12:56 +01:00
we don't have. */
1999-05-03 09:29:11 +02:00
for (i = 1; i < total_sec; i++)
{
struct IT_sc sc;
char *name;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
symbol = info[i].symbol;
sc.spare = 0;
sc.spare1 = 0;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
if (!symbol)
{
2002-01-23 17:12:56 +01:00
/* Don't have a symbol set aside for this section, which means
that nothing in this file does anything for the section. */
1999-05-03 09:29:11 +02:00
sc.format = !(bfd_get_file_flags (abfd) & EXEC_P);
sc.addr = 0;
sc.length = 0;
name = info[i].sec->name;
}
else
{
if (bfd_get_file_flags (abfd) & EXEC_P)
{
sc.format = 0;
sc.addr = symbol->where->offset;
}
else
{
sc.format = 1;
sc.addr = 0;
}
sc.length = symbol->type->size;
name = symbol->name;
}
sc.align = 4;
sc.concat = CONCAT_SIMPLE;
sc.read = 3;
sc.write = 3;
sc.exec = 3;
sc.init = 3;
sc.mode = 3;
sc.spare = 0;
sc.segadd = 0;
2002-01-23 17:12:56 +01:00
sc.spare1 = 0; /* If not zero, then it doesn't work. */
1999-05-03 09:29:11 +02:00
sc.name = section_translate (name);
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
if (strlen (sc.name) == 1)
{
switch (sc.name[0])
{
case 'D':
case 'B':
sc.contents = CONTENTS_DATA;
break;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
default:
sc.contents = CONTENTS_CODE;
}
}
else
{
sc.contents = CONTENTS_CODE;
}
sysroff_swap_sc_out (file, &sc);
scount++;
1999-05-03 09:29:11 +02:00
}
free (info);
2002-01-23 17:12:56 +01:00
return scount;
1999-05-03 09:29:11 +02:00
}
2002-01-23 17:12:56 +01:00
/* Write out the ER records for a unit. */
1999-05-03 09:29:11 +02:00
static void
wr_er (struct coff_ofile *ptr, struct coff_sfile *sfile ATTRIBUTE_UNUSED,
int first)
1999-05-03 09:29:11 +02:00
{
int idx = 0;
struct coff_symbol *sym;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
if (first)
{
for (sym = ptr->symbol_list_head; sym; sym = sym->next_in_ofile_list)
{
if (sym->visible->type == coff_vis_ext_ref)
{
struct IT_er er;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
er.spare = 0;
er.type = ER_NOTSPEC;
er.name = sym->name;
sysroff_swap_er_out (file, &er);
sym->er_number = idx++;
}
}
}
}
2002-01-23 17:12:56 +01:00
/* Write out the ED records for a unit. */
1999-05-03 09:29:11 +02:00
static void
wr_ed (struct coff_ofile *ptr, struct coff_sfile *sfile ATTRIBUTE_UNUSED,
int first)
1999-05-03 09:29:11 +02:00
{
struct coff_symbol *s;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
if (first)
{
for (s = ptr->symbol_list_head; s; s = s->next_in_ofile_list)
{
if (s->visible->type == coff_vis_ext_def
|| s->visible->type == coff_vis_common)
{
struct IT_ed ed;
ed.section = s->where->section->number;
ed.spare = 0;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
if (s->where->section->data)
{
ed.type = ED_TYPE_DATA;
}
else if (s->where->section->code & SEC_CODE)
{
ed.type = ED_TYPE_ENTRY;
}
else
{
ed.type = ED_TYPE_NOTSPEC;
ed.type = ED_TYPE_DATA;
}
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
ed.address = s->where->offset - s->where->section->address;
ed.name = s->name;
sysroff_swap_ed_out (file, &ed);
}
}
}
}
static void
wr_unit_info (struct coff_ofile *ptr)
1999-05-03 09:29:11 +02:00
{
struct coff_sfile *sfile;
int first = 1;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
for (sfile = ptr->source_head;
sfile;
sfile = sfile->next)
{
long p1;
long p2;
int nsecs;
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
p1 = ftell (file);
wr_un (ptr, sfile, first, 0);
nsecs = wr_sc (ptr, sfile);
p2 = ftell (file);
fseek (file, p1, SEEK_SET);
wr_un (ptr, sfile, first, nsecs);
fseek (file, p2, SEEK_SET);
1999-05-03 09:29:11 +02:00
wr_er (ptr, sfile, first);
wr_ed (ptr, sfile, first);
first = 0;
}
}
static void
wr_module (struct coff_ofile *p)
1999-05-03 09:29:11 +02:00
{
wr_cs ();
wr_hd (p);
wr_unit_info (p);
wr_object_body (p);
wr_debug (p);
wr_tr ();
}
static int
align (int x)
1999-05-03 09:29:11 +02:00
{
return (x + 3) & ~3;
}
/* Find all the common variables and turn them into
2002-01-23 17:12:56 +01:00
ordinary defs - dunno why, but thats what hitachi does with 'em. */
1999-05-03 09:29:11 +02:00
static void
prescan (struct coff_ofile *otree)
1999-05-03 09:29:11 +02:00
{
struct coff_symbol *s;
struct coff_section *common_section;
2002-01-23 17:12:56 +01:00
if (otree->nsections < 3)
return;
2002-01-23 17:12:56 +01:00
/* Find the common section - always section 3. */
common_section = otree->sections + 3;
2002-01-23 17:12:56 +01:00
for (s = otree->symbol_list_head;
1999-05-03 09:29:11 +02:00
s;
s = s->next_in_ofile_list)
{
if (s->visible->type == coff_vis_common)
{
struct coff_where *w = s->where;
/* s->visible->type = coff_vis_ext_def; leave it as common */
common_section->size = align (common_section->size);
w->offset = common_section->size + common_section->address;
w->section = common_section;
common_section->size += s->type->size;
common_section->size = align (common_section->size);
}
}
}
ATTRIBUTE_NORETURN static void
show_usage (FILE *ffile, int status)
1999-05-03 09:29:11 +02:00
{
fprintf (ffile, _("Usage: %s [option(s)] in-file [out-file]\n"), program_name);
fprintf (ffile, _("Convert a COFF object file into a SYSROFF object file\n"));
fprintf (ffile, _(" The options are:\n\
-q --quick (Obsolete - ignored)\n\
2002-01-23 17:12:56 +01:00
-n --noprescan Do not perform a scan to convert commons into defs\n\
-d --debug Display information about what is being done\n\
@<file> Read options from <file>\n\
2002-01-23 17:12:56 +01:00
-h --help Display this information\n\
-v --version Print the program's version number\n"));
top level: 2007-02-17 Mark Mitchell <mark@codesourcery.com> Nathan Sidwell <nathan@codesourcery.com> Vladimir Prus <vladimir@codesourcery.com Joseph Myers <joseph@codesourcery.com> * configure.ac (TOPLEVEL_CONFIGURE_ARGUMENTS): Fix quoting. * configure: Regenerate. bfd: 2007-02-17 Mark Mitchell <mark@codesourcery.com> Nathan Sidwell <nathan@codesourcery.com> Vladimir Prus <vladimir@codesourcery.com Joseph Myers <joseph@codesourcery.com> * configure.in (--with-pkgversion): New option. * configure: Regenerate. * Makefile.am (bfdver.h): Substitute for @bfd_version_package@. * Makefile.in: Regenerate. * version.h (BFD_VERSION_STRING): Define using @bfd_version_package@. bfd/doc: 2007-02-17 Mark Mitchell <mark@codesourcery.com> Nathan Sidwell <nathan@codesourcery.com> Vladimir Prus <vladimir@codesourcery.com Joseph Myers <joseph@codesourcery.com> * Makefile.in: Regenerate. binutils: 2007-02-17 Mark Mitchell <mark@codesourcery.com> Nathan Sidwell <nathan@codesourcery.com> Vladimir Prus <vladimir@codesourcery.com Joseph Myers <joseph@codesourcery.com> * configure.in (--with-bugurl): New option. * configure: Regenerate. * Makefile.am (REPORT_BUGS_TO): Define. (INCLUDES): Define REPORT_BUGS_TO. Regenerate dependencies. * Makefile.in: Regenerate. * doc/Makefile.in: Regenerate. * bucomm.h: Remove include of bin-bugs.h. * addr2line.c (usage): Don't print empty REPORT_BUGS_TO. * ar.c (usage): Pass s to list_supported_targets. Don't print empty REPORT_BUGS_TO. * coffdump.c (show_usage): Don't print empty REPORT_BUGS_TO. * cxxfilt.c (usage): Print bug url when giving help. * dlltool.c (usage): Likewise. * dllwrap.c (usage): Likewise. * nlmconv.c (show_usage): Don't print empty REPORT_BUGS_TO. * nm.c (usage): Likewise. * objcopy.c (copy_usage, strip_usage): Likewise. * objdump.c (usage): Likewise. * readelf.c ((usage): Likewise. Add STREAM argument. Adjust callers. * size.c (usage): Don't print empty REPORT_BUGS_TO. * srconv.c (show_usage): Likewise. * strings.c (usage): Likewise. * sysdymp.c (show_usage): Likewise. * windres.c (usage): Likewise. gas: 2007-02-17 Mark Mitchell <mark@codesourcery.com> Nathan Sidwell <nathan@codesourcery.com> Vladimir Prus <vladimir@codesourcery.com Joseph Myers <joseph@codesourcery.com> * configure.in (--with-bugurl): New option. * configure: Regenerate. * dep-in.sed: Remove bin-bugs.h. * Makefile.am (REPORT_BUGS_TO): Define. (INCLUDES): Define REPORT_BUGS_TO. (DEP_INCLUDES): Likewise. ($(OBJS)): No longer depend on bin-bugs.h. * Makefile.in: Regenerate. * doc/Makefile.in: Regenerate. * as.c (show_usage): Don't print empty REPORT_BUGS_TO. * as.h: Remove include of bin-bugs.h. gprof: 2007-02-17 Mark Mitchell <mark@codesourcery.com> Nathan Sidwell <nathan@codesourcery.com> Vladimir Prus <vladimir@codesourcery.com Joseph Myers <joseph@codesourcery.com> * configure.in (--with-pkgversion, --with-bugurl): New options. * configure: Regenerate. * Makefile.am (PKGVERSION, REPORT_BUGS_TO): Define. (INCLUDES): Define PKGVERSION and REPORT_BUGS_TO. Regenerate dependencies. * Makefile.in: Regenerate. * gprof.c (usage): Don't print empty REPORT_BUGS_TO. (main): Include PKGVERSION in version output. * gprof.h: Remove include of bin-bugs.h. include: 2007-02-17 Mark Mitchell <mark@codesourcery.com> Nathan Sidwell <nathan@codesourcery.com> Vladimir Prus <vladimir@codesourcery.com Joseph Myers <joseph@codesourcery.com> * bin-bugs.h: Remove. ld: 2007-02-17 Mark Mitchell <mark@codesourcery.com> Nathan Sidwell <nathan@codesourcery.com> Vladimir Prus <vladimir@codesourcery.com Joseph Myers <joseph@codesourcery.com> * configure.in (--with-bugurl): New option. * configure: Regenerate. * Makefile.am (REPORT_BUGS_TO): Define. (INCLUDES): Define REPORT_BUGS_TO. Regenerate dependencies. * Makefile.in: Regenerate. * ld.h: Remove include of bin-bugs.h. * lexsup.c (help): Don't print empty REPORT_BUGS_TO.
2007-02-17 14:33:57 +01:00
if (REPORT_BUGS_TO[0] && status == 0)
fprintf (ffile, _("Report bugs to %s\n"), REPORT_BUGS_TO);
1999-05-03 09:29:11 +02:00
exit (status);
}
int
main (int ac, char **av)
1999-05-03 09:29:11 +02:00
{
int opt;
static struct option long_options[] =
{
{"debug", no_argument, 0, 'd'},
{"quick", no_argument, 0, 'q'},
{"noprescan", no_argument, 0, 'n'},
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{NULL, no_argument, 0, 0}
};
char **matching;
char *input_file;
char *output_file;
#if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
setlocale (LC_MESSAGES, "");
#endif
#if defined (HAVE_SETLOCALE)
setlocale (LC_CTYPE, "");
1999-05-03 09:29:11 +02:00
#endif
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
program_name = av[0];
xmalloc_set_program_name (program_name);
Fix memory access violations triggered by running strip on fuzzed binaries. PR binutils/17512 * coffcode.h (coff_set_arch_mach_hook): Check return value from bfd_malloc. (coff_slurp_line_table): Return FALSE if the line number information was corrupt. (coff_slurp_symbol_table): Return FALSE if the symbol information was corrupt. * mach-o.c (bfd_mach_o_bfd_copy_private_header_data): Always initialise the fields of the dyld_info structure. (bfd_mach_o_build_exec_seg_command): Replace assertion with an error message and a return value. (bfd_mach_o_layout_commands): Change the function to boolean. Return FALSE if the function fails. (bfd_mach_o_build_commands): Fail if bfd_mach_o_layout_commands fails. (bfd_mach_o_read_command): Fail if an unrecognised command is encountered. * peXXigen.c (_bfd_XXi_swap_aouthdr_in): Set bfd_error if the read fails. (slurp_symtab): Check the return from bfd_malloc. (_bfd_XX_bfd_copy_private_bfd_data_common): Fail if the copy encountered an error. (_bfd_XXi_final_link_postscript): Fail if a section could not be copied. * peicode.h (pe_bfd_object_p): Fail if the header could not be swapped in. * tekhex.c (first_phase): Fail if the section is too big. * versados.c (struct esdid): Add content_size field. (process_otr): Use and check the new field. (versados_get_section_contents): Check that the section exists and that the requested data is available. PR binutils/17512 * addr2line.c (main): Call bfd_set_error_program_name. * ar.c (main): Likewise. * coffdump.c (main): Likewise. * cxxfilt.c (main): Likewise. * dlltool.c (main): Likewise. * nlmconv.c (main): Likewise. * nm.c (main): Likewise. * objdump.c (main): Likewise. * size.c (main): Likewise. * srconv.c (main): Likewise. * strings.c (main): Likewise. * sysdump.c (main): Likewise. * windmc.c (main): Likewise. * windres.c (main): Likewise. * objcopy.c (main): Likewise. (copy_relocations_in_section): Check for relocs without associated symbol pointers.
2015-01-21 18:37:23 +01:00
bfd_set_error_program_name (program_name);
1999-05-03 09:29:11 +02:00
expandargv (&ac, &av);
2002-01-23 17:12:56 +01:00
while ((opt = getopt_long (ac, av, "dHhVvqn", long_options,
1999-05-03 09:29:11 +02:00
(int *) NULL))
!= EOF)
{
switch (opt)
{
case 'q':
quick = 1;
break;
case 'n':
noprescan = 1;
break;
case 'd':
debug = 1;
break;
2002-01-23 17:12:56 +01:00
case 'H':
1999-05-03 09:29:11 +02:00
case 'h':
2002-01-23 17:12:56 +01:00
show_usage (stdout, 0);
1999-05-03 09:29:11 +02:00
/*NOTREACHED */
2002-01-23 17:12:56 +01:00
case 'v':
1999-05-03 09:29:11 +02:00
case 'V':
print_version ("srconv");
1999-05-03 09:29:11 +02:00
exit (0);
/*NOTREACHED */
case 0:
break;
default:
show_usage (stderr, 1);
/*NOTREACHED */
}
}
/* The input and output files may be named on the command line. */
output_file = NULL;
if (optind < ac)
{
input_file = av[optind];
++optind;
if (optind < ac)
{
output_file = av[optind];
++optind;
if (optind < ac)
show_usage (stderr, 1);
if (filename_cmp (input_file, output_file) == 0)
1999-05-03 09:29:11 +02:00
{
fatal (_("input and output files must be different"));
1999-05-03 09:29:11 +02:00
}
}
}
else
input_file = 0;
if (!input_file)
{
fatal (_("no input file specified"));
1999-05-03 09:29:11 +02:00
}
if (!output_file)
{
/* Take a .o off the input file and stick on a .obj. If
it doesn't end in .o, then stick a .obj on anyway */
int len = strlen (input_file);
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
output_file = xmalloc (len + 5);
strcpy (output_file, input_file);
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
if (len > 3
&& output_file[len - 2] == '.'
&& output_file[len - 1] == 'o')
{
output_file[len] = 'b';
output_file[len + 1] = 'j';
output_file[len + 2] = 0;
}
else
{
strcat (output_file, ".obj");
}
}
abfd = bfd_openr (input_file, 0);
if (!abfd)
bfd_fatal (input_file);
if (!bfd_check_format_matches (abfd, bfd_object, &matching))
{
bfd_nonfatal (input_file);
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
{
list_matching_formats (matching);
free (matching);
}
exit (1);
}
file = fopen (output_file, FOPEN_WB);
if (!file)
2002-01-23 17:12:56 +01:00
fatal (_("unable to open output file %s"), output_file);
1999-05-03 09:29:11 +02:00
if (debug)
printf ("ids %d %d\n", base1, base2);
2002-01-23 17:12:56 +01:00
1999-05-03 09:29:11 +02:00
tree = coff_grok (abfd);
if (tree)
{
if (!noprescan)
prescan (tree);
2002-01-23 17:12:56 +01:00
wr_module (tree);
}
1999-05-03 09:29:11 +02:00
return 0;
}