]> Git Repo - binutils.git/blobdiff - bfd/oasys.c
i960-bout linker fixes, i960 coff config changes
[binutils.git] / bfd / oasys.c
index 7a7d1d4e6d312febaf5f3aa200b69d64d07cfe80..adad8bf33e0faf4977dc5a64e4c8e77f34cdb927 100644 (file)
@@ -1,6 +1,6 @@
-/* bfd backend for oasys objects.
-   Copyright (C) 1990-1991 Free Software Foundation, Inc.
-   Written by Steve Chamberlain of Cygnus Support <steve@cygnus.com>.
+/* BFD back-end for oasys objects.
+   Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+   Written by Steve Chamberlain of Cygnus Support, <sac@cygnus.com>.
 
 This file is part of BFD, the Binary File Descriptor library.
 
@@ -18,8 +18,6 @@ You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
-/* $Id$ */
-
 #define UNDERSCORE_HACK 1
 #include "bfd.h"
 #include "sysdep.h"
@@ -35,6 +33,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #define offsetof(type, identifier) (size_t) &(((type *) 0)->identifier) 
 #endif
 
+static boolean oasys_write_sections PARAMS ((bfd *));
+
 /* Read in all the section data and relocation stuff too */
 PROTO(static boolean,oasys_slurp_section_data,(bfd *CONST abfd));
 
@@ -101,7 +101,11 @@ DEFUN(oasys_slurp_symbol_table,(abfd),
 #else
   data->strings = bfd_alloc(abfd, data->symbol_string_length);
 #endif
-
+  if (!data->symbols || !data->strings)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
 
   dest_defined = data->symbols + abfd->symcount -1;
 
@@ -149,7 +153,7 @@ DEFUN(oasys_slurp_symbol_table,(abfd),
            }
            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:
@@ -168,7 +172,7 @@ DEFUN(oasys_slurp_symbol_table,(abfd),
          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] != '_') {
@@ -234,20 +238,18 @@ DEFUN(oasys_archive_p,(abfd),
   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
@@ -261,30 +263,31 @@ DEFUN(oasys_archive_p,(abfd),
       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;
 
+      if (!ar || !module)
+       {
+         bfd_error = no_memory;
+         return NULL;
+       }
 
       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);
+        bfd_seek(abfd, filepos, SEEK_SET);
 
        /* There are two ways of specifying the archive header */
 
@@ -292,16 +295,19 @@ DEFUN(oasys_archive_p,(abfd),
          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);
+         if (!module[i].name)
+           {
+             bfd_error = no_error;
+             return NULL;
+           }
 
          memcpy(module[i].name, record_ext.mod_name, 33);
          filepos +=
@@ -314,16 +320,20 @@ DEFUN(oasys_archive_p,(abfd),
          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);
+         if (!module[i].name)
+           {
+             bfd_error = no_error;
+             return NULL;
+           }
          bfd_read((PTR)module[i].name, 1, record.module_name_size, abfd);
          module[i].name[record.module_name_size] = 0;
          filepos +=
@@ -349,7 +359,7 @@ DEFUN(oasys_mkobject,(abfd),
 {
 
   abfd->tdata.oasys_obj_data =    (oasys_data_type*)bfd_alloc(abfd, sizeof(oasys_data_type));
-  return true;
+  return abfd->tdata.oasys_obj_data ? true : false;
 }
 
 #define MAX_SECS 16
@@ -402,6 +412,11 @@ DEFUN(oasys_object_p,(abfd),
                goto fail;
              }
          buffer = bfd_alloc(abfd, 3);
+         if (!buffer)
+           {
+             bfd_error = no_memory;
+             goto fail;
+           }
          section_number= record.section.relb & RELOCATION_SECT_BITS;
          sprintf(buffer,"%u", section_number);
          s = bfd_make_section(abfd,buffer);
@@ -415,8 +430,8 @@ DEFUN(oasys_object_p,(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;
        }
@@ -460,6 +475,17 @@ DEFUN(oasys_object_p,(abfd),
 }
 
 
+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
@@ -475,7 +501,6 @@ DEFUN(oasys_print_symbol,(ignore_abfd, afile, symbol, how),
     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;
@@ -496,10 +521,10 @@ DEFUN(oasys_print_symbol,(ignore_abfd, afile, symbol, how),
 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 */
@@ -534,22 +559,26 @@ DEFUN(oasys_slurp_section_data,(abfd),
        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) 
                  {
                    per->data = (bfd_byte *) bfd_zalloc(abfd, section->_raw_size);
+                   if (!per->data)
+                     {
+                       bfd_error = no_memory;
+                       return false;
+                     }
                    per->reloc_tail_ptr = (oasys_reloc_type **)&(section->relocation);
                    per->had_vma = false;
                    per->initialized = true;
@@ -560,15 +589,12 @@ DEFUN(oasys_slurp_section_data,(abfd),
              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;
@@ -577,8 +603,8 @@ DEFUN(oasys_slurp_section_data,(abfd),
                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) {
@@ -598,7 +624,7 @@ DEFUN(oasys_slurp_section_data,(abfd),
                      {
                        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:
@@ -612,6 +638,11 @@ DEFUN(oasys_slurp_section_data,(abfd),
                                      (oasys_reloc_type *)
                                        bfd_alloc(abfd,
                                                  sizeof(oasys_reloc_type));
+                                   if (!r)
+                                     {
+                                       bfd_error = no_memory;
+                                       return false;
+                                     }
                                    *(per->reloc_tail_ptr) = r;
                                    per->reloc_tail_ptr = &r->next;
                                    r->next= (oasys_reloc_type *)NULL;
@@ -627,7 +658,7 @@ DEFUN(oasys_slurp_section_data,(abfd),
                                                     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];
@@ -653,6 +684,11 @@ DEFUN(oasys_slurp_section_data,(abfd),
                                      (oasys_reloc_type *)
                                        bfd_alloc(abfd,
                                                  sizeof(oasys_reloc_type));
+                                   if (!r)
+                                     {
+                                       bfd_error = no_memory;
+                                       return false;
+                                     }
                                    *(per->reloc_tail_ptr) = r;
                                    per->reloc_tail_ptr = &r->next;
                                    r->next= (oasys_reloc_type *)NULL;
@@ -709,10 +745,6 @@ DEFUN(oasys_slurp_section_data,(abfd),
 
 }
 
-
-
-bfd_error_vector_type bfd_error_vector;
-
 static boolean
 DEFUN(oasys_new_section_hook,(abfd, newsect),
       bfd *abfd AND
@@ -720,6 +752,11 @@ DEFUN(oasys_new_section_hook,(abfd, newsect),
 {
   newsect->used_by_bfd = (PTR)
     bfd_alloc(abfd, sizeof(oasys_per_section_type));
+  if (!newsect->used_by_bfd)
+    {
+      bfd_error = no_memory;
+      return false;
+    }
   oasys_per_section( newsect)->data = (bfd_byte *)NULL;
   oasys_per_section(newsect)->section = newsect;
   oasys_per_section(newsect)->offset  = 0;
@@ -807,12 +844,13 @@ DEFUN(oasys_write_record,(abfd, type, record, size),
 {
   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++;
@@ -839,19 +877,19 @@ DEFUN(oasys_write_syms, (abfd),
     char *dst = symbol.name;
     unsigned int l = 0;
 
-    if (g->section == & bfd_com_section) {
+    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++;
     }
@@ -869,14 +907,18 @@ DEFUN(oasys_write_syms, (abfd),
       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] == '_')
+      dst[l++] = '.';
+#endif
     while (src[l]) {
       dst[l] = 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) {
@@ -897,28 +939,29 @@ DEFUN(oasys_write_syms, (abfd),
 
 
   /* Write a section header for each section */
-static void 
-DEFUN(oasys_write_sections, (abfd),
-      bfd *CONST abfd)
+static boolean
+oasys_write_sections (abfd)
+     bfd *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])) 
        {
-          bfd_error_vector.nonrepresentable_section(abfd,
-                                                   s->name);
+         bfd_error = nonrepresentable_section;
+         return false;
        }
     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,
                       (oasys_record_union_type *) &out,
                       sizeof(out));
   }
+  return true;
 }
 
 static void
@@ -955,11 +998,11 @@ DEFUN(oasys_write_end,(abfd),
       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,
@@ -988,13 +1031,13 @@ DEFUN(oasys_write_data, (abfd),
   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;
       arelent **p = s->orelocation;
       if (s->reloc_count != 0) {
-       /* Sort the reloc records so it's easy to insert the relocs into the
+/* Sort the reloc records so it's easy to insert the relocs into the
           data */
     
        qsort(s->orelocation,
@@ -1009,37 +1052,40 @@ DEFUN(oasys_write_data, (abfd),
          {
            /* 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 long_length = 128;
+           unsigned int i = 0;
+           *mod = 0;
 
 
-           bfd_h_put_32(abfd, s->vma + current_byte_index, processed_data.addr);
-           if ((size_t)(long_length + current_byte_index) > (size_t)(s->_cooked_size)) {
-             long_length = s->_cooked_size - current_byte_index;
-           }
-           while (long_length  > 0 &&  (dst - (uint8e_type*)&processed_data < 128)) {
-           
-             unsigned int length = long_length;
-             *mod =0;
-             if (length > 8)
-               length = 8;
+           bfd_h_put_32(abfd, s->vma + current_byte_index,
+                        processed_data.addr);
+
+           /* Don't start a relocation unless you're sure you can finish it
+              within the same data record.  The worst case relocation is a
+              4-byte relocatable value which is split across two modification
+              bytes (1 relocation byte + 2 symbol reference bytes + 2 data +
+              1 modification byte + 2 data = 8 bytes total).  That's where
+              the magic number 8 comes from.
+           */
+           while (current_byte_index < s->_raw_size && dst <=
+               &processed_data.data[sizeof(processed_data.data)-8]) {
+           
 
-             for (i = 0; i < length; i++) {
                if (relocs_to_go != 0) {        
                  arelent *r = *p;
-                 reloc_howto_type *CONST how=r->howto;
+                 const 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 */
@@ -1059,7 +1105,7 @@ DEFUN(oasys_write_data, (abfd),
                      rel_byte = 0;
                    }
                    if (how->size ==2) {
-                     rel_byte |= 0x40;
+                     rel_byte |= RELOCATION_32BIT_BIT;
                    }
                  
                    /* Is this a section relative relocation, or a symbol
@@ -1091,8 +1137,6 @@ DEFUN(oasys_write_data, (abfd),
                          }
                          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
@@ -1102,28 +1146,44 @@ DEFUN(oasys_write_data, (abfd),
                            *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,
+                      so we can assume that raw_data is not NULL
+                    */
+                   *dst++ = *raw_data++;
+                   ADVANCE
+                   *dst++ = *raw_data++;
+                   ADVANCE
+                   if (how->size == 2) {
+                     *dst++ = *raw_data++;
+                     ADVANCE
+                     *dst++ = *raw_data++;
+                     ADVANCE
+                   }
+                   continue;
                  }
                }
                /* If this is coming from an unloadable section then copy
                   zeros */
-               if (raw_data == (uint8e_type *)NULL) {
+               if (raw_data == NULL) {
                  *dst++ = 0;
                }
                else {
                  *dst++ = *raw_data++;
                }
-               current_byte_index++;
-             }
-             mod = dst++;
-             long_length -= length;
+               ADVANCE
+           }
+
+           /* Don't write a useless null modification byte */
+           if (dst == mod+1) {
+             --dst;
            }
 
            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);
                         
          }
     }
@@ -1131,11 +1191,12 @@ DEFUN(oasys_write_data, (abfd),
 }
 static boolean
 DEFUN(oasys_write_object_contents, (abfd),
-      bfd * CONST abfd)
+      bfd *abfd)
 {
   oasys_write_header(abfd);
   oasys_write_syms(abfd);
-  oasys_write_sections(abfd);
+  if (! oasys_write_sections(abfd))
+    return false;
   oasys_write_data(abfd);
   oasys_write_end(abfd);
   return true;
@@ -1162,6 +1223,11 @@ DEFUN(oasys_set_section_contents,(abfd, section, location, offset, count),
        {
          oasys_per_section(section)->data =
            (bfd_byte *)(bfd_alloc(abfd,section->_cooked_size));    
+         if (!   oasys_per_section(section)->data)
+           {
+             bfd_error = no_memory;
+             return false;
+           }
        }
     (void) memcpy((PTR)(oasys_per_section(section)->data + offset),
                  location,
@@ -1185,9 +1251,13 @@ DEFUN(oasys_make_empty_symbol,(abfd),
 
   oasys_symbol_type  *new =
     (oasys_symbol_type *)bfd_zalloc (abfd, sizeof (oasys_symbol_type));
+  if (!new)
+    {
+      bfd_error = no_memory;
+      return NULL;
+    }
   new->symbol.the_bfd = abfd;
   return &new->symbol;
-
 }
 
 
@@ -1288,6 +1358,14 @@ return 0;
 #define oasys_bfd_debug_info_end bfd_void
 #define oasys_bfd_debug_info_accumulate  (FOO(void, (*), (bfd *, asection *)))bfd_void
 #define oasys_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
+#define oasys_bfd_relax_section bfd_generic_relax_section
+#define oasys_bfd_reloc_type_lookup \
+  ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
+#define oasys_bfd_make_debug_symbol \
+  ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
+#define oasys_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
+#define oasys_bfd_link_add_symbols _bfd_generic_link_add_symbols
+#define oasys_bfd_final_link _bfd_generic_final_link
 
 /*SUPPRESS 460 */
 bfd_target oasys_vec =
@@ -1298,14 +1376,19 @@ bfd_target oasys_vec =
   true,                                /* target headers byte order */
   (HAS_RELOC | EXEC_P |                /* object flags */
    HAS_LINENO | HAS_DEBUG |
-   HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
+   HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
   (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
    |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
+   0,                          /* leading underscore */
   ' ',                         /* 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 */
@@ -1324,5 +1407,6 @@ bfd_target oasys_vec =
       _bfd_write_archive_contents,
       bfd_false,
     },
-  JUMP_TABLE(oasys)
+  JUMP_TABLE(oasys),
+  (PTR) 0
 };
This page took 0.050564 seconds and 4 git commands to generate.