* coff-h8300.c (h8300_reloc16_estimate): Declare return type.
Remove useless statement probably left by code copy.
* cpu-i960.c (compatible): Fully bracket matrix initializer.
* elf32-hppa.c (hppa_elf_build_arg_reloc_stub): Use bfd_xmalloc
rather than xmalloc. Use realloc and check the return value
rather than xrealloc.
(hppa_elf_get_section_contents): Add some casts.
* elf32-i386.c (elf_i386_reloc_type_lookup): Remove unused
variable. Add default case to switch.
* hp300hpux.c: Declare aout_32_write_syms.
* i386bsd.c, i386linux.c, netbsd386.c (N_SHARED_LIB): Define as 0
(definition from aout/aout64.h is always 0 anyhow).
* i386lynx.c (swap_std_reloc_in): Remove unused variable.
* ieee.c (ieee_write_id): length can never be negative.
(read_id): Likewise.
(ieee_archive_p): Remove unused variable.
* libcoff-in.h (bfd_perform_slip): Declare.
* libcoff.h: Rebuilt.
* oasys.c (oasys_write_sections): Remove zero initialization of
static structure.
* reloc16.c: Indentation change.
+Thu Oct 28 16:23:40 1993 Ian Lance Taylor (ian@tweedledumb.cygnus.com)
+
+ gcc -Wall lint:
+ * coff-h8300.c (h8300_reloc16_estimate): Declare return type.
+ Remove useless statement probably left by code copy.
+ * cpu-i960.c (compatible): Fully bracket matrix initializer.
+ * elf32-hppa.c (hppa_elf_build_arg_reloc_stub): Use bfd_xmalloc
+ rather than xmalloc. Use realloc and check the return value
+ rather than xrealloc.
+ (hppa_elf_get_section_contents): Add some casts.
+ * elf32-i386.c (elf_i386_reloc_type_lookup): Remove unused
+ variable. Add default case to switch.
+ * hp300hpux.c: Declare aout_32_write_syms.
+ * i386bsd.c, i386linux.c, netbsd386.c (N_SHARED_LIB): Define as 0
+ (definition from aout/aout64.h is always 0 anyhow).
+ * i386lynx.c (swap_std_reloc_in): Remove unused variable.
+ * ieee.c (ieee_write_id): length can never be negative.
+ (read_id): Likewise.
+ (ieee_archive_p): Remove unused variable.
+ * libcoff-in.h (bfd_perform_slip): Declare.
+ * libcoff.h: Rebuilt.
+ * oasys.c (oasys_write_sections): Remove zero initialization of
+ static structure.
+ * reloc16.c: Indentation change.
+
Wed Oct 27 16:51:29 1993 Jim Kingdon (kingdon@lioth.cygnus.com)
* configure.in, config/i386-mach3.mt: Update for new configuration
-/* Hitachi H8/300 COFF back-end for BFD.
- Copyright (C) 1990-1991 Free Software Foundation, Inc.
- Written by Steve Chamberlain
- sac@cygnus.com
+/* BFD back-end for Hitachi H8/300 COFF binaries.
+ Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+ Written by Steve Chamberlain, <sac@cygnus.com>.
This file is part of BFD, the Binary File Descriptor library.
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#include "obstack.h"
#include "coff/h8300.h"
#include "coff/internal.h"
+#include "seclet.h"
#include "libcoff.h"
+extern bfd_error_vector_type bfd_error_vector;
-static reloc_howto_type howto_table[] =
+static reloc_howto_type howto_table[] =
{
- HOWTO(R_RELBYTE, 0, 0, 8, false, 0, true, true,0,"8", true, 0x000000ff,0x000000ff, false),
- HOWTO(R_RELWORD, 0, 1, 16, false, 0, true, true,0,"16", true, 0x0000ffff,0x0000ffff, false),
- HOWTO(R_RELLONG, 0, 2, 32, false, 0, true, true,0,"32", true, 0xffffffff,0xffffffff, false),
- HOWTO(R_PCRBYTE, 0, 0, 8, true, 0, false, true,0,"DISP8", true, 0x000000ff,0x000000ff, true),
- HOWTO(R_PCRWORD, 0, 1, 16, true, 0, false, true,0,"DISP16", true, 0x0000ffff,0x0000ffff, true),
- HOWTO(R_PCRLONG, 0, 2, 32, true, 0, false, true,0,"DISP32", true, 0xffffffff,0xffffffff, true),
- HOWTO(R_MOVB1, 0, 1, 16, false, 0, true,
- true,0,"16/8", true, 0x0000ffff,0x0000ffff, false),
- HOWTO(R_MOVB2, 0, 1, 16, false, 0, true,
- true,0,"8/16", true, 0x0000ffff,0x0000ffff, false),
- HOWTO(R_JMP1, 0, 1, 16, false, 0, true, true,0,"16/pcrel", true, 0x0000ffff,0x0000ffff, false),
- HOWTO(R_JMP2, 0, 0, 8, false, 0, true, true,0,"pcrecl/16", true, 0x000000ff,0x000000ff, false),
+ HOWTO (R_RELBYTE, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "8", true, 0x000000ff, 0x000000ff, false),
+ HOWTO (R_RELWORD, 0, 1, 16, false, 0, complain_overflow_bitfield, 0, "16", true, 0x0000ffff, 0x0000ffff, false),
+ HOWTO (R_RELLONG, 0, 2, 32, false, 0, complain_overflow_bitfield, 0, "32", true, 0xffffffff, 0xffffffff, false),
+ HOWTO (R_PCRBYTE, 0, 0, 8, true, 0, complain_overflow_signed, 0, "DISP8", true, 0x000000ff, 0x000000ff, true),
+ HOWTO (R_PCRWORD, 0, 1, 16, true, 0, complain_overflow_signed, 0, "DISP16", true, 0x0000ffff, 0x0000ffff, true),
+ HOWTO (R_PCRLONG, 0, 2, 32, true, 0, complain_overflow_signed, 0, "DISP32", true, 0xffffffff, 0xffffffff, true),
+ HOWTO (R_MOVB1, 0, 1, 16, false, 0, complain_overflow_bitfield, 0, "16/8", true, 0x0000ffff, 0x0000ffff, false),
+ HOWTO (R_MOVB2, 0, 1, 16, false, 0, complain_overflow_bitfield, 0, "8/16", true, 0x0000ffff, 0x0000ffff, false),
+ HOWTO (R_JMP1, 0, 1, 16, false, 0, complain_overflow_bitfield, 0, "16/pcrel", true, 0x0000ffff, 0x0000ffff, false),
+ HOWTO (R_JMP2, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "pcrecl/16", true, 0x000000ff, 0x000000ff, false),
+
+
+ HOWTO (R_JMPL1, 0, 1, 32, false, 0, complain_overflow_bitfield, 0, "24/pcrell", true, 0x0000ffff, 0x0000ffff, false),
+ HOWTO (R_JMPL_B8, 0, 0, 8, false, 0, complain_overflow_bitfield, 0, "pc8/24", true, 0x000000ff, 0x000000ff, false),
+
+ HOWTO (R_MOVLB1, 0, 1, 16, false, 0, complain_overflow_bitfield, 0, "24/8", true, 0x0000ffff, 0x0000ffff, false),
+ HOWTO (R_MOVLB2, 0, 1, 16, false, 0, complain_overflow_bitfield, 0, "8/24", true, 0x0000ffff, 0x0000ffff, false),
};
/* Turn a howto into a reloc number */
#define SELECT_RELOC(x,howto) \
- { x = howto_table[howto->size +(int)howto->pc_relative*3].type; }
+ { x = select_reloc(howto); }
-#define BADMAG(x) H8300BADMAG(x)
-#define H8300 1 /* Customize coffcode.h */
+#define BADMAG(x) (H8300BADMAG(x)&& H8300HBADMAG(x))
+#define H8300 1 /* Customize coffcode.h */
#define __A_MAGIC_SET__
#define SWAP_OUT_RELOC_OFFSET bfd_h_put_32
#define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \
dst->r_stuff[0] = 'S'; \
- dst->r_stuff[1] = 'C';
+ dst->r_stuff[1] = 'C';
+
+
+static int
+select_reloc (howto)
+ reloc_howto_type *howto;
+{
+ return howto->type;
+}
/* Code to turn a r_type into a howto ptr, uses the above howto table
*/
-static void
-DEFUN(rtype2howto,(internal, dst),
-arelent *internal AND
-struct internal_reloc *dst)
+static void
+rtype2howto (internal, dst)
+ arelent *internal;
+ struct internal_reloc *dst;
{
- switch (dst->r_type) {
+ switch (dst->r_type)
+ {
case R_RELBYTE:
- internal->howto = howto_table+ 0;
+ internal->howto = howto_table + 0;
break;
case R_RELWORD:
- internal->howto = howto_table+ 1;
- break;
+ internal->howto = howto_table + 1;
+ break;
+ case R_RELLONG:
+ internal->howto = howto_table + 2;
+ break;
case R_PCRBYTE:
- internal->howto = howto_table+3;
+ internal->howto = howto_table + 3;
break;
case R_PCRWORD:
- internal->howto = howto_table+ 4;
+ internal->howto = howto_table + 4;
+ break;
+ case R_PCRLONG:
+ internal->howto = howto_table + 5;
break;
case R_MOVB1:
internal->howto = howto_table + 6;
internal->howto = howto_table + 7;
break;
case R_JMP1:
- internal->howto = howto_table +8;
+ internal->howto = howto_table + 8;
break;
-
case R_JMP2:
- internal->howto = howto_table +9;
+ internal->howto = howto_table + 9;
+ break;
+ case R_JMPL1:
+ internal->howto = howto_table + 10;
+ break;
+ case R_JMPL_B8:
+ internal->howto = howto_table + 11;
+ break;
+ case R_MOVLB1:
+ internal->howto = howto_table + 12;
+ break;
+ case R_MOVLB2:
+ internal->howto = howto_table + 13;
break;
-
default:
-fprintf(stderr,"Bad reloc\n");
+ fprintf (stderr, "Bad reloc\n");
break;
}
}
#define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \
cache_ptr->addend = ext_reloc.r_offset;
-
+
#define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \
reloc_processing(relent, reloc, symbols, abfd, section)
-static void DEFUN(reloc_processing,(relent,reloc, symbols, abfd, section) ,
- arelent *relent AND
- struct internal_reloc *reloc AND
- asymbol **symbols AND
- bfd *abfd AND
- asection *section)
+static void
+DEFUN (reloc_processing, (relent, reloc, symbols, abfd, section),
+ arelent * relent AND
+ struct internal_reloc *reloc AND
+ asymbol ** symbols AND
+ bfd * abfd AND
+ asection * section)
{
- relent->address = reloc->r_vaddr;
- rtype2howto(relent,reloc);
-
- if (reloc->r_symndx > 0)
- {
-
- relent->sym_ptr_ptr = symbols + obj_convert(abfd)[reloc->r_symndx];
-
- }
- else
- {
- relent->sym_ptr_ptr = &(bfd_abs_symbol);
- }
+ relent->address = reloc->r_vaddr;
+ rtype2howto (relent, reloc);
+
+ if (((int) reloc->r_symndx) > 0)
+ {
+ relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx];
+ }
+ else
+ {
+ relent->sym_ptr_ptr = &(bfd_abs_symbol);
+ }
+
+
+
+ relent->addend = reloc->r_offset;
+
+ relent->address -= section->vma;
+ /* relent->section = 0;*/
+}
+
+
+static int
+h8300_reloc16_estimate(input_section, symbols, reloc, shrink)
+ asection *input_section;
+ asymbol **symbols;
+ arelent *reloc;
+ unsigned int shrink;
+{
+ bfd_vma value;
+ bfd_vma dot;
+ bfd_vma gap;
+
+ /* The address of the thing to be relocated will have moved back by
+ the size of the shrink - but we don't change reloc->address here,
+ since we need it to know where the relocation lives in the source
+ uncooked section */
+
+ /* reloc->address -= shrink; conceptual */
+
+ bfd_vma address = reloc->address - shrink;
+ switch (reloc->howto->type)
+ {
+ case R_MOVB2:
+ case R_JMP2:
+ shrink+=2;
+ break;
+
+ /* Thing is a move one byte */
+ case R_MOVB1:
+ value = bfd_coff_reloc16_get_value(reloc,0);
+
+ if (value >= 0xff00)
+ {
+
+ /* Change the reloc type from 16bit, possible 8 to 8bit
+ possible 16 */
+ reloc->howto = reloc->howto + 1;
+ /* The place to relc moves back by one */
+ /* This will be two bytes smaller in the long run */
+ shrink +=2 ;
+ bfd_perform_slip(symbols, 2, input_section, address);
+ }
+
+ break;
+ /* This is the 24 bit branch which could become an 8 bitter,
+ the relocation points to the first byte of the insn, not the
+ actual data */
+
+ case R_JMPL1:
+ value = bfd_coff_reloc16_get_value(reloc, 0);
+
+ dot = input_section->output_section->vma +
+ input_section->output_offset + address;
- relent->addend = reloc->r_offset;
+ /* See if the address we're looking at within 127 bytes of where
+ we are, if so then we can use a small branch rather than the
+ jump we were going to */
+
+ gap = value - dot ;
+
+ if (-120 < (long)gap && (long)gap < 120 )
+ {
+
+ /* Change the reloc type from 24bit, possible 8 to 8bit
+ possible 32 */
+ reloc->howto = reloc->howto + 1;
+ /* This will be two bytes smaller in the long run */
+ shrink +=2 ;
+ bfd_perform_slip(symbols, 2, input_section, address);
+ }
+ break;
+
+ case R_JMP1:
+
+ value = bfd_coff_reloc16_get_value(reloc, 0);
+
+ dot = input_section->output_section->vma +
+ input_section->output_offset + address;
+
+ /* See if the address we're looking at within 127 bytes of where
+ we are, if so then we can use a small branch rather than the
+ jump we were going to */
+
+ gap = value - (dot - shrink);
+
+
+ if (-120 < (long)gap && (long)gap < 120 )
+ {
+
+ /* Change the reloc type from 16bit, possible 8 to 8bit
+ possible 16 */
+ reloc->howto = reloc->howto + 1;
+ /* The place to relc moves back by one */
+
+ /* This will be two bytes smaller in the long run */
+ shrink +=2 ;
+ bfd_perform_slip(symbols, 2, input_section, address);
+ }
+ break;
+ }
+
- relent->address-= section->vma;
-/* relent->section = 0;*/
+ return shrink;
}
+
+/* First phase of a relaxing link */
+
+/* Reloc types
+ large small
+ R_MOVB1 R_MOVB2 mov.b with 16bit or 8 bit address
+ R_JMP1 R_JMP2 jmp or pcrel branch
+ R_JMPL1 R_JMPL_B8 24jmp or pcrel branch
+ R_MOVLB1 R_MOVLB2 24 or 8 bit reloc for mov.b
+
+*/
+
+static void
+h8300_reloc16_extra_cases (abfd, seclet, reloc, data, src_ptr, dst_ptr)
+ bfd *abfd;
+ struct bfd_seclet *seclet;
+ arelent *reloc;
+ bfd_byte *data;
+ unsigned int *src_ptr;
+ unsigned int *dst_ptr;
+{
+ unsigned int src_address = *src_ptr;
+ unsigned int dst_address = *dst_ptr;
+
+ switch (reloc->howto->type)
+ {
+ /* A 24 bit branch which could be a 8 bit pcrel, really pointing to
+ the byte before the 24bit hole, so we can treat it as a 32bit pointer */
+ case R_PCRBYTE:
+ {
+ bfd_vma dot = seclet->offset
+ + dst_address
+ + seclet->u.indirect.section->output_section->vma;
+ int gap = bfd_coff_reloc16_get_value (reloc, seclet) - dot;
+ if (gap > 127 || gap < -128)
+ {
+ bfd_error_vector.reloc_value_truncated (reloc, seclet);
+ }
+
+ bfd_put_8 (abfd, gap, data + dst_address);
+ dst_address++;
+ src_address++;
+
+ break;
+ }
+
+ case R_RELBYTE:
+ {
+ unsigned int gap = bfd_coff_reloc16_get_value (reloc, seclet);
+ if (gap > 0xff && gap < ~0xff)
+ {
+ bfd_error_vector.reloc_value_truncated (reloc, seclet);
+ }
+
+ bfd_put_8 (abfd, gap, data + dst_address);
+ dst_address += 1;
+ src_address += 1;
+
+
+ }
+ break;
+ case R_JMP1:
+ /* A relword which would have like to have been a pcrel */
+ case R_MOVB1:
+ /* A relword which would like to have been modified but
+ didn't make it */
+ case R_RELWORD:
+ bfd_put_16 (abfd, bfd_coff_reloc16_get_value (reloc, seclet),
+ data + dst_address);
+ dst_address += 2;
+ src_address += 2;
+ break;
+ case R_RELLONG:
+ bfd_put_32 (abfd, bfd_coff_reloc16_get_value (reloc, seclet),
+ data + dst_address);
+ dst_address += 4;
+ src_address += 4;
+ break;
+
+ case R_MOVB2:
+ /* Special relaxed type, there will be a gap between where we
+ get stuff from and where we put stuff to now
+
+ for a mov.b @aa:16 -> mov.b @aa:8
+ opcode 0x6a 0x0y offset
+ -> 0x2y off
+ */
+ if (data[dst_address - 1] != 0x6a)
+ abort ();
+ switch (data[src_address] & 0xf0)
+ {
+ case 0x00:
+ /* Src is memory */
+ data[dst_address - 1] = (data[src_address] & 0xf) | 0x20;
+ break;
+ case 0x80:
+ /* Src is reg */
+ data[dst_address - 1] = (data[src_address] & 0xf) | 0x30;
+ break;
+ default:
+ abort ();
+ }
+
+ /* the offset must fit ! after all, what was all the relaxing
+ about ? */
+
+ bfd_put_8 (abfd, bfd_coff_reloc16_get_value (reloc, seclet),
+ data + dst_address);
+
+ /* Note the magic - src goes up by two bytes, but dst by only
+ one */
+ dst_address += 1;
+ src_address += 3;
+
+ break;
+
+ case R_JMP2:
+
+ /* Speciial relaxed type */
+ {
+ bfd_vma dot = seclet->offset
+ + dst_address
+ + seclet->u.indirect.section->output_section->vma;
+
+ int gap = bfd_coff_reloc16_get_value (reloc, seclet) - dot - 1;
+
+ if ((gap & ~0xff) != 0 && ((gap & 0xff00) != 0xff00))
+ abort ();
+
+ bfd_put_8 (abfd, gap, data + dst_address);
+
+ switch (data[dst_address - 1])
+ {
+ case 0x5e:
+ /* jsr -> bsr */
+ bfd_put_8 (abfd, 0x55, data + dst_address - 1);
+ break;
+ case 0x5a:
+ /* jmp ->bra */
+ bfd_put_8 (abfd, 0x40, data + dst_address - 1);
+ break;
+
+ default:
+ abort ();
+ }
+ dst_address++;
+ src_address += 3;
+
+ break;
+ }
+ break;
+
+ case R_JMPL_B8: /* 24 bit branch which is now 8 bits */
+
+ /* Speciial relaxed type */
+ {
+ bfd_vma dot = seclet->offset
+ + dst_address
+ + seclet->u.indirect.section->output_section->vma;
+
+ int gap = bfd_coff_reloc16_get_value (reloc, seclet) - dot - 2;
+
+ if ((gap & ~0xff) != 0 && ((gap & 0xff00) != 0xff00))
+ abort ();
+
+ switch (data[src_address])
+ {
+ case 0x5e:
+ /* jsr -> bsr */
+ bfd_put_8 (abfd, 0x55, data + dst_address);
+ break;
+ case 0x5a:
+ /* jmp ->bra */
+ bfd_put_8 (abfd, 0x40, data + dst_address);
+ break;
+
+ default:
+ bfd_put_8 (abfd, 0xde, data + dst_address);
+ break;
+ }
+
+ bfd_put_8 (abfd, gap, data + dst_address + 1);
+ dst_address += 2;
+ src_address += 4;
+
+ break;
+ }
+
+ case R_JMPL1:
+ {
+ int v = bfd_coff_reloc16_get_value (reloc, seclet);
+ int o = bfd_get_32 (abfd, data + src_address);
+ v = (v & 0x00ffffff) | (o & 0xff000000);
+ bfd_put_32 (abfd, v, data + dst_address);
+ dst_address += 4;
+ src_address += 4;
+ }
+
+ break;
+
+
+ /* A 24 bit mov which could be an 8 bit move, really pointing to
+ the byte before the 24bit hole, so we can treat it as a 32bit pointer */
+ case R_MOVLB1:
+ {
+ int v = bfd_coff_reloc16_get_value (reloc, seclet);
+ int o = bfd_get_32 (abfd, data + dst_address);
+ v = (v & 0x00ffffff) | (o & 0xff000000);
+ bfd_put_32 (abfd, v, data + dst_address);
+ dst_address += 4;
+ src_address += 4;
+ }
+
+ break;
+ default:
+
+ abort ();
+ break;
+
+ }
+ *src_ptr = src_address;
+ *dst_ptr = dst_address;
+
+}
+
+#define coff_reloc16_extra_cases h8300_reloc16_extra_cases
+#define coff_reloc16_estimate h8300_reloc16_estimate
+
#include "coffcode.h"
-#undef coff_bfd_get_relocated_section_contents
+#undef coff_bfd_get_relocated_section_contents
#undef coff_bfd_relax_section
-#define coff_bfd_get_relocated_section_contents bfd_coff_get_relocated_section_contents
-#define coff_bfd_relax_section bfd_coff_relax_section
+#define coff_bfd_get_relocated_section_contents bfd_coff_reloc16_get_relocated_section_contents
+#define coff_bfd_relax_section bfd_coff_reloc16_relax_section
+
+
bfd_target h8300coff_vec =
{
- "coff-h8300", /* name */
+ "coff-h8300", /* name */
bfd_target_coff_flavour,
true, /* data byte order is big */
true, /* header byte order is big */
(HAS_RELOC | EXEC_P | /* object flags */
HAS_LINENO | HAS_DEBUG |
HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
- ( SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
- '_', /* leading char */
+ (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
+ '_', /* leading char */
'/', /* ar_pad_char */
15, /* ar_max_namelen */
1, /* minimum section alignment */
-_do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
-_do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
-
- {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
- bfd_generic_archive_p, _bfd_dummy_target},
- {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
- bfd_false},
+ bfd_getb64, bfd_getb_signed_64, bfd_putb64,
+ bfd_getb32, bfd_getb_signed_32, bfd_putb32,
+ bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
+ bfd_getb64, bfd_getb_signed_64, bfd_putb64,
+ bfd_getb32, bfd_getb_signed_32, bfd_putb32,
+ bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
+
+ {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
+ bfd_generic_archive_p, _bfd_dummy_target},
+ {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
+ bfd_false},
{bfd_false, coff_write_object_contents, /* bfd_write_contents */
- _bfd_write_archive_contents, bfd_false},
+ _bfd_write_archive_contents, bfd_false},
- JUMP_TABLE(coff),
- COFF_SWAP_TABLE
+ JUMP_TABLE (coff),
+ COFF_SWAP_TABLE,
};
CONST char *id)
{
size_t length = strlen(id);
- if (length >= 0 && length <= 127) {
+ if (length <= 127) {
ieee_write_byte(abfd, (bfd_byte)length);
}
else if (length < 255) {
size_t length;
char *string;
length = this_byte_and_next(ieee);
- if (length >= 0x00 && length <= 0x7f) {
+ if (length <= 0x7f) {
/* Simple string of length 0 to 127 */
}
else if (length == 0xde) {
static
reloc_howto_type abs32_howto
- = HOWTO(1,0,2,32,false,0,false,true,0,"abs32",true,0xffffffff, 0xffffffff,false);
+ = HOWTO(1,0,2,32,false,0,complain_overflow_bitfield,0,"abs32",true,0xffffffff, 0xffffffff,false);
static
reloc_howto_type abs16_howto
- = HOWTO(1,0,1,16,false,0,false,true,0,"abs16",true,0x0000ffff, 0x0000ffff,false);
+ = HOWTO(1,0,1,16,false,0,complain_overflow_bitfield,0,"abs16",true,0x0000ffff, 0x0000ffff,false);
static
reloc_howto_type abs8_howto
- = HOWTO(1,0,0,8,false,0,false,true,0,"abs8",true,0x000000ff, 0x000000ff,false);
+ = HOWTO(1,0,0,8,false,0,complain_overflow_bitfield,0,"abs8",true,0x000000ff, 0x000000ff,false);
static
reloc_howto_type rel32_howto
- = HOWTO(1,0,2,32,true,0,false,true,0,"rel32",true,0xffffffff,
+ = HOWTO(1,0,2,32,true,0,complain_overflow_signed,0,"rel32",true,0xffffffff,
0xffffffff,false);
static
reloc_howto_type rel16_howto
- = HOWTO(1,0,1,16,true,0,false,true,0,"rel16",true,0x0000ffff, 0x0000ffff,false);
+ = HOWTO(1,0,1,16,true,0,complain_overflow_signed,0,"rel16",true,0x0000ffff, 0x0000ffff,false);
static
reloc_howto_type rel8_howto
- = HOWTO(1,0,0,8,true,0,false,true,0,"rel8",true,0x000000ff, 0x000000ff,false);
+ = HOWTO(1,0,0,8,true,0,complain_overflow_signed,0,"rel8",true,0x000000ff, 0x000000ff,false);
static ieee_symbol_index_type NOSYMBOL = { 0, 0};
ieee_ar_obstack_type t;
int rec =read_2bytes(&(ieee->h));
if (rec ==(int)ieee_assign_value_to_variable_enum) {
- int record_number = must_parse_int(&(ieee->h));
+ must_parse_int(&(ieee->h));
t.file_offset = must_parse_int(&(ieee->h));
t.abfd = (bfd *)NULL;
ieee->element_count++;
' ', /* ar_pad_char */
16, /* ar_max_namelen */
1, /* minimum alignment */
-_do_getb64, _do_getb_signed_64, _do_putb64,
- _do_getb32, _do_getb_signed_32, _do_putb32,
- _do_getb16, _do_getb_signed_16, _do_putb16, /* data */
-_do_getb64, _do_getb_signed_64, _do_putb64,
- _do_getb32, _do_getb_signed_32, _do_putb32,
- _do_getb16, _do_getb_signed_16, _do_putb16, /* hdrs */
+bfd_getb64, bfd_getb_signed_64, bfd_putb64,
+ bfd_getb32, bfd_getb_signed_32, bfd_putb32,
+ bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
+bfd_getb64, bfd_getb_signed_64, bfd_putb64,
+ bfd_getb32, bfd_getb_signed_32, bfd_putb32,
+ bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
{ _bfd_dummy_target,
ieee_object_p, /* bfd_check_format */
/* ZMAGIC files start at address 0. This does not apply to QMAGIC. */
#define TEXT_START_ADDR 0
+#define N_SHARED_LIB(x) 0
#define PAGE_SIZE 4096
#define SEGMENT_SIZE PAGE_SIZE
}
break;
case RELOCATION_TYPE_UND:
- dest = data->symbols + bfd_h_get_16(abfd, (bfd_byte *)&record.symbol.refno[0]);
+ dest = data->symbols + bfd_h_get_16(abfd, record.symbol.refno);
dest->section = &bfd_und_section;
break;
case RELOCATION_TYPE_COM:
dest->name = string_ptr;
dest->the_bfd = abfd;
dest->udata = (PTR)NULL;
- dest->value = bfd_h_get_32(abfd, (bfd_byte *)&record.symbol.value[0]);
+ dest->value = bfd_h_get_32(abfd, record.symbol.value);
#ifdef UNDERSCORE_HACK
if (record.symbol.name[0] != '_') {
oasys_extarchive_header_type header_ext;
unsigned int i;
file_ptr filepos;
- bfd_seek(abfd, (file_ptr) 0, false);
-
+ bfd_seek(abfd, (file_ptr) 0, false);
bfd_read((PTR)&header_ext, 1, sizeof(header_ext), abfd);
-
- header.version = bfd_h_get_32(abfd, (bfd_byte *)header_ext.version);
- header.mod_count = bfd_h_get_32(abfd, (bfd_byte *)header_ext.mod_count);
- header.mod_tbl_offset = bfd_h_get_32(abfd, (bfd_byte *)header_ext.mod_tbl_offset);
- header.sym_tbl_size = bfd_h_get_32(abfd, (bfd_byte *)header_ext.sym_tbl_size);
- header.sym_count = bfd_h_get_32(abfd, (bfd_byte *)header_ext.sym_count);
- header.sym_tbl_offset = bfd_h_get_32(abfd, (bfd_byte *)header_ext.sym_tbl_offset);
- header.xref_count = bfd_h_get_32(abfd, (bfd_byte *)header_ext.xref_count);
- header.xref_lst_offset = bfd_h_get_32(abfd, (bfd_byte *)header_ext.xref_lst_offset);
+ header.version = bfd_h_get_32(abfd, header_ext.version);
+ header.mod_count = bfd_h_get_32(abfd, header_ext.mod_count);
+ header.mod_tbl_offset = bfd_h_get_32(abfd, header_ext.mod_tbl_offset);
+ header.sym_tbl_size = bfd_h_get_32(abfd, header_ext.sym_tbl_size);
+ header.sym_count = bfd_h_get_32(abfd, header_ext.sym_count);
+ header.sym_tbl_offset = bfd_h_get_32(abfd, header_ext.sym_tbl_offset);
+ header.xref_count = bfd_h_get_32(abfd, header_ext.xref_count);
+ header.xref_lst_offset = bfd_h_get_32(abfd, header_ext.xref_lst_offset);
/*
There isn't a magic number in an Oasys archive, so the best we
header.xref_count > 100000) return (bfd_target *)NULL;
/*
- That all worked, lets buy the space for the header and read in
+ That all worked, let's buy the space for the header and read in
the headers.
*/
{
oasys_ar_data_type *ar =
(oasys_ar_data_type*) bfd_alloc(abfd, sizeof(oasys_ar_data_type));
-
oasys_module_info_type *module =
(oasys_module_info_type*)
bfd_alloc(abfd, sizeof(oasys_module_info_type) * header.mod_count);
-
oasys_module_table_type record;
-
abfd->tdata.oasys_ar_data = ar;
ar->module = module;
ar->module_count = header.mod_count;
-
filepos = header.mod_tbl_offset;
for (i = 0; i < header.mod_count; i++) {
bfd_seek(abfd, filepos, SEEK_SET);
oasys_extmodule_table_type_a_type record_ext;
bfd_read((PTR)&record_ext, 1, sizeof(record_ext), abfd);
- record.mod_size = bfd_h_get_32(abfd, (bfd_byte *)record_ext.mod_size);
- record.file_offset = bfd_h_get_32(abfd,
- (bfd_byte *) record_ext.file_offset);
-
- record.dep_count = bfd_h_get_32(abfd, (bfd_byte *)record_ext.dep_count);
- record.depee_count = bfd_h_get_32(abfd,(bfd_byte *) record_ext.depee_count);
- record.sect_count = bfd_h_get_32(abfd, (bfd_byte *) record_ext.sect_count);
+ record.mod_size = bfd_h_get_32(abfd, record_ext.mod_size);
+ record.file_offset = bfd_h_get_32(abfd, record_ext.file_offset);
+ record.dep_count = bfd_h_get_32(abfd, record_ext.dep_count);
+ record.depee_count = bfd_h_get_32(abfd, record_ext.depee_count);
+ record.sect_count = bfd_h_get_32(abfd, record_ext.sect_count);
module[i].name = bfd_alloc(abfd,33);
oasys_extmodule_table_type_b_type record_ext;
bfd_read((PTR)&record_ext, 1, sizeof(record_ext), abfd);
- record.mod_size = bfd_h_get_32(abfd, (bfd_byte *) record_ext.mod_size);
- record.file_offset = bfd_h_get_32(abfd,
- (bfd_byte *)record_ext.file_offset);
+ record.mod_size = bfd_h_get_32(abfd, record_ext.mod_size);
+ record.file_offset = bfd_h_get_32(abfd, record_ext.file_offset);
- record.dep_count = bfd_h_get_32(abfd, (bfd_byte *) record_ext.dep_count);
- record.depee_count = bfd_h_get_32(abfd, (bfd_byte *) record_ext.depee_count);
- record.sect_count = bfd_h_get_32(abfd, (bfd_byte *) record_ext.sect_count);
- record.module_name_size = bfd_h_get_32(abfd, (bfd_byte *) record_ext.mod_name_length);
+ record.dep_count = bfd_h_get_32(abfd, record_ext.dep_count);
+ record.depee_count = bfd_h_get_32(abfd, record_ext.depee_count);
+ record.sect_count = bfd_h_get_32(abfd, record_ext.sect_count);
+ record.module_name_size = bfd_h_get_32(abfd, record_ext.mod_name_length);
module[i].name = bfd_alloc(abfd,record.module_name_size + 1);
bfd_read((PTR)module[i].name, 1, record.module_name_size, abfd);
BFD_FAIL();
}
- s->_raw_size = bfd_h_get_32(abfd, (bfd_byte *) & record.section.value[0]) ;
- s->vma = bfd_h_get_32(abfd, (bfd_byte *)&record.section.vma[0]);
+ s->_raw_size = bfd_h_get_32(abfd, record.section.value);
+ s->vma = bfd_h_get_32(abfd, record.section.vma);
s->flags= 0;
had_usefull = true;
}
}
+static void
+DEFUN(oasys_get_symbol_info,(ignore_abfd, symbol, ret),
+ bfd *ignore_abfd AND
+ asymbol *symbol AND
+ symbol_info *ret)
+{
+ bfd_symbol_info (symbol, ret);
+ if (!symbol->section)
+ ret->type = (symbol->flags & BSF_LOCAL) ? 'a' : 'A';
+}
+
static void
DEFUN(oasys_print_symbol,(ignore_abfd, afile, symbol, how),
bfd *ignore_abfd AND
fprintf(file,"%s", symbol->name);
break;
case bfd_print_symbol_all:
- case bfd_print_symbol_nm:
{
CONST char *section_name = symbol->section == (asection *)NULL ?
(CONST char *) "*abs" : symbol->section->name;
static reloc_howto_type howto_table[]=
{
-HOWTO( 0, 0, 1, 16, false,0, true,true,0,"abs16",true,0x0000ffff, 0x0000ffff,false),
-HOWTO( 0, 0, 2, 32, false,0, true,true,0,"abs32",true,0xffffffff, 0xffffffff,false),
-HOWTO( 0, 0, 1, 16, true,0, true,true,0,"pcrel16",true,0x0000ffff, 0x0000ffff,false),
-HOWTO( 0, 0, 2, 32, true,0, true,true,0,"pcrel32",true,0xffffffff, 0xffffffff,false)
+HOWTO( 0, 0, 1, 16, false,0,complain_overflow_bitfield,0,"abs16",true,0x0000ffff, 0x0000ffff,false),
+HOWTO( 0, 0, 2, 32, false,0,complain_overflow_bitfield,0,"abs32",true,0xffffffff, 0xffffffff,false),
+HOWTO( 0, 0, 1, 16, true,0,complain_overflow_signed,0,"pcrel16",true,0x0000ffff, 0x0000ffff,false),
+HOWTO( 0, 0, 2, 32, true,0,complain_overflow_signed,0,"pcrel32",true,0xffffffff, 0xffffffff,false)
};
/* Read in all the section data and relocation stuff too */
case oasys_record_is_data_enum:
{
- uint8e_type *src = record.data.data;
- uint8e_type *end_src = ((uint8e_type *)&record) +
- record.header.length;
+ bfd_byte *src = record.data.data;
+ bfd_byte *end_src = ((bfd_byte *)&record) + record.header.length;
+ bfd_byte *dst_ptr;
+ bfd_byte *dst_base_ptr;
unsigned int relbit;
- bfd_byte *dst_ptr ;
- bfd_byte *dst_base_ptr ;
unsigned int count;
asection * section =
data->sections[record.data.relb & RELOCATION_SECT_BITS];
bfd_vma dst_offset ;
- per = oasys_per_section(section);
+ per = oasys_per_section(section);
if (per->initialized == false)
{
dst_offset = bfd_h_get_32(abfd, record.data.addr) ;
if (per->had_vma == false) {
/* Take the first vma we see as the base */
-
section->vma = dst_offset;
per->had_vma = true;
}
-
dst_offset -= section->vma;
-
dst_base_ptr = oasys_per_section(section)->data;
dst_ptr = oasys_per_section(section)->data +
dst_offset;
section->flags |= SEC_LOAD | SEC_HAS_CONTENTS;
}
while (src < end_src) {
- uint8e_type mod_byte = *src++;
- uint32_type gap = end_src - src;
+ unsigned char mod_byte = *src++;
+ size_t gap = end_src - src;
count = 8;
if (mod_byte == 0 && gap >= 8) {
{
if (relbit & mod_byte)
{
- uint8e_type reloc = *src;
+ unsigned char reloc = *src;
/* This item needs to be relocated */
switch (reloc & RELOCATION_TYPE_BITS) {
case RELOCATION_TYPE_ABS:
RELOCATION_SECT_BITS];
r->relent.addend = -
- r->relent.section->vma;
+ r->relent.section->vma;
#endif
r->relent.address = dst_ptr - dst_base_ptr;
r->relent.howto = &howto_table[reloc>>6];
-bfd_error_vector_type bfd_error_vector;
+extern bfd_error_vector_type bfd_error_vector;
static boolean
DEFUN(oasys_new_section_hook,(abfd, newsect),
{
int checksum;
size_t i;
- uint8e_type *ptr;
+ unsigned char *ptr;
+
record->header.length = size;
record->header.type = (int)type;
record->header.check_sum = 0;
record->header.fill = 0;
- ptr = &record->pad[0];
+ ptr = (unsigned char *)&record->pad[0];
checksum = 0;
for (i = 0; i < size; i++) {
checksum += *ptr++;
if (bfd_is_com_section (g->section)) {
symbol.relb = RELOCATION_TYPE_COM;
- bfd_h_put_16(abfd, index, (uint8e_type *)(&symbol.refno[0]));
+ bfd_h_put_16(abfd, index, symbol.refno);
index++;
}
else if (g->section == & bfd_abs_section) {
symbol.relb = RELOCATION_TYPE_ABS;
- bfd_h_put_16(abfd, 0, (uint8e_type *)(&symbol.refno[0]));
+ bfd_h_put_16(abfd, 0, symbol.refno);
}
else if (g->section == &bfd_und_section) {
symbol.relb = RELOCATION_TYPE_UND ;
- bfd_h_put_16(abfd, index, (uint8e_type *)(&symbol.refno[0]));
+ bfd_h_put_16(abfd, index, symbol.refno);
/* Overload the value field with the output index number */
index++;
}
else {
symbol.relb = RELOCATION_TYPE_REL |g->section->output_section->target_index;
}
- bfd_h_put_16(abfd, 0, (uint8e_type *)(&symbol.refno[0]));
+ bfd_h_put_16(abfd, 0, symbol.refno);
}
#ifdef UNDERSCORE_HACK
if (src[l] == '_')
l++;
}
- bfd_h_put_32(abfd, g->value, (bfd_byte*) symbol.value);
+ bfd_h_put_32(abfd, g->value, symbol.value);
if (g->flags & BSF_LOCAL) {
bfd *CONST abfd)
{
asection *s;
- static oasys_section_record_type out = {0};
+ static oasys_section_record_type out;
for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
if (!isdigit(s->name[0]))
s->name);
}
out.relb = RELOCATION_TYPE_REL | s->target_index;
- bfd_h_put_32(abfd, s->_cooked_size, (bfd_byte *) out.value);
- bfd_h_put_32(abfd, s->vma, (bfd_byte *) out.vma);
+ bfd_h_put_32(abfd, s->_cooked_size, out.value);
+ bfd_h_put_32(abfd, s->vma, out.vma);
oasys_write_record(abfd,
oasys_record_is_section_enum,
bfd *CONST abfd)
{
oasys_end_record_type end;
- uint8e_type null = 0;
+ unsigned char null = 0;
end.relb = RELOCATION_TYPE_ABS;
- bfd_h_put_32(abfd, abfd->start_address, (bfd_byte *)end.entry);
- bfd_h_put_16(abfd, 0, (bfd_byte *)end.fill);
- end.zero =0;
+ bfd_h_put_32(abfd, abfd->start_address, end.entry);
+ bfd_h_put_16(abfd, 0, end.fill);
+ end.zero = 0;
oasys_write_record(abfd,
oasys_record_is_end_enum,
(oasys_record_union_type *)&end,
asection *s;
for (s = abfd->sections; s != (asection *)NULL; s = s->next) {
if (s->flags & SEC_LOAD) {
- uint8e_type *raw_data = oasys_per_section(s)->data;
+ bfd_byte *raw_data = oasys_per_section(s)->data;
oasys_data_record_type processed_data;
bfd_size_type current_byte_index = 0;
unsigned int relocs_to_go = s->reloc_count;
{
/* Scan forwards by eight bytes or however much is left and see if
there are any relocations going on */
- uint8e_type *mod = &processed_data.data[0];
- uint8e_type *dst = &processed_data.data[1];
+ bfd_byte *mod = &processed_data.data[0];
+ bfd_byte *dst = &processed_data.data[1];
- unsigned int i;
+ unsigned int i = 0;
*mod = 0;
the magic number 8 comes from.
*/
while (current_byte_index < s->_raw_size && dst <=
- (uint8e_type*)&processed_data.data[sizeof(processed_data.data)-8]) {
+ &processed_data.data[sizeof(processed_data.data)-8]) {
if (relocs_to_go != 0) {
reloc_howto_type *CONST how=r->howto;
/* There is a relocation, is it for this byte ? */
if (r->address == current_byte_index) {
- uint8e_type rel_byte;
+ unsigned char rel_byte;
+
p++;
relocs_to_go--;
*mod |= (1<<i);
if(how->pc_relative) {
- rel_byte = 0x80;
+ rel_byte = RELOCATION_PCREL_BIT;
/* Also patch the raw data so that it doesn't have
the -ve stuff any more */
rel_byte = 0;
}
if (how->size ==2) {
- rel_byte |= 0x40;
+ rel_byte |= RELOCATION_32BIT_BIT;
}
/* Is this a section relative relocation, or a symbol
}
else {
rel_byte |= RELOCATION_TYPE_UND;
-
-
*dst++ = rel_byte;
/* Next two bytes are a symbol index - we can get
this from the symbol value which has been zapped
*dst++ = p->value >> 8;
*dst++ = p->value;
}
-
}
#define ADVANCE { if (++i >= 8) { i = 0; mod = dst++; *mod = 0; } current_byte_index++; }
/* relocations never occur from an unloadable section,
}
/* If this is coming from an unloadable section then copy
zeros */
- if (raw_data == (uint8e_type *)NULL) {
+ if (raw_data == NULL) {
*dst++ = 0;
}
else {
oasys_write_record(abfd,
oasys_record_is_data_enum,
(oasys_record_union_type *)&processed_data,
- dst - (uint8e_type*)&processed_data);
+ dst - (bfd_byte *)&processed_data);
}
}
' ', /* ar_pad_char */
16, /* ar_max_namelen */
1, /* minimum alignment */
- _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
- _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
+ bfd_getb64, bfd_getb_signed_64, bfd_putb64,
+ bfd_getb32, bfd_getb_signed_32, bfd_putb32,
+ bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
+ bfd_getb64, bfd_getb_signed_64, bfd_putb64,
+ bfd_getb32, bfd_getb_signed_32, bfd_putb32,
+ bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
{_bfd_dummy_target,
oasys_object_p, /* bfd_check_format */