+ loop = FALSE;
+ }
+ }
+
+ return TRUE;
+
+}
+
+#define MAX_SECS 16
+
+static const bfd_target *
+oasys_object_p (bfd *abfd)
+{
+ oasys_data_type *oasys;
+ oasys_data_type *save = OASYS_DATA (abfd);
+ bfd_boolean loop = TRUE;
+ bfd_boolean had_usefull = FALSE;
+
+ abfd->tdata.oasys_obj_data = 0;
+ oasys_mkobject (abfd);
+ oasys = OASYS_DATA (abfd);
+ memset ((void *) oasys->sections, 0xff, sizeof (oasys->sections));
+
+ /* Point to the start of the file. */
+ if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
+ goto fail;
+ oasys->symbol_string_length = 0;
+
+ /* Inspect the records, but only keep the section info -
+ remember the size of the symbols. */
+ oasys->first_data_record = 0;
+ while (loop)
+ {
+ oasys_record_union_type record;
+ if (! oasys_read_record (abfd, &record))
+ goto fail;
+ if ((size_t) record.header.length < (size_t) sizeof (record.header))
+ goto fail;
+
+ switch ((oasys_record_enum_type) (record.header.type))
+ {
+ case oasys_record_is_header_enum:
+ had_usefull = TRUE;
+ break;
+ case oasys_record_is_symbol_enum:
+ case oasys_record_is_local_enum:
+ /* Count symbols and remember their size for a future malloc. */
+ abfd->symcount++;
+ oasys->symbol_string_length += 1 + oasys_string_length (&record);
+ had_usefull = TRUE;
+ break;
+ case oasys_record_is_section_enum:
+ {
+ asection *s;
+ char *buffer;
+ unsigned int section_number;
+
+ if (record.section.header.length != sizeof (record.section))
+ goto fail;
+
+ buffer = bfd_alloc (abfd, (bfd_size_type) 3);
+ if (!buffer)
+ goto fail;
+ section_number = record.section.relb & RELOCATION_SECT_BITS;
+ sprintf (buffer, "%u", section_number);
+ s = bfd_make_section (abfd, buffer);
+ oasys->sections[section_number] = s;
+ switch (record.section.relb & RELOCATION_TYPE_BITS)
+ {
+ case RELOCATION_TYPE_ABS:
+ case RELOCATION_TYPE_REL:
+ break;
+ case RELOCATION_TYPE_UND:
+ case RELOCATION_TYPE_COM:
+ BFD_FAIL ();
+ }
+
+ s->size = H_GET_32 (abfd, record.section.value);
+ s->vma = H_GET_32 (abfd, record.section.vma);
+ s->flags = 0;
+ had_usefull = TRUE;
+ }
+ break;
+ case oasys_record_is_data_enum:
+ oasys->first_data_record = bfd_tell (abfd) - record.header.length;
+ case oasys_record_is_debug_enum:
+ case oasys_record_is_module_enum:
+ case oasys_record_is_named_section_enum:
+ case oasys_record_is_end_enum:
+ if (! had_usefull)
+ goto fail;
+ loop = FALSE;
+ break;
+ default:
+ goto fail;