+ header.version = H_GET_32 (abfd, header_ext.version);
+ header.mod_count = H_GET_32 (abfd, header_ext.mod_count);
+ header.mod_tbl_offset = H_GET_32 (abfd, header_ext.mod_tbl_offset);
+ header.sym_tbl_size = H_GET_32 (abfd, header_ext.sym_tbl_size);
+ header.sym_count = H_GET_32 (abfd, header_ext.sym_count);
+ header.sym_tbl_offset = H_GET_32 (abfd, header_ext.sym_tbl_offset);
+ header.xref_count = H_GET_32 (abfd, header_ext.xref_count);
+ header.xref_lst_offset = H_GET_32 (abfd, header_ext.xref_lst_offset);
+
+ /* There isn't a magic number in an Oasys archive, so the best we
+ can do to verify reasonableness is to make sure that the values in
+ the header are too weird. */
+
+ if (header.version > 10000
+ || header.mod_count > 10000
+ || header.sym_count > 100000
+ || header.xref_count > 100000)
+ return NULL;
+
+ /* That all worked, let's buy the space for the header and read in
+ the headers. */
+ {
+ oasys_ar_data_type *ar;
+ oasys_module_info_type *module;
+ oasys_module_table_type record;
+
+ amt = sizeof (oasys_ar_data_type);
+ ar = bfd_alloc (abfd, amt);
+
+ amt = header.mod_count;
+ amt *= sizeof (oasys_module_info_type);
+ module = bfd_alloc (abfd, amt);
+
+ if (!ar || !module)
+ 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++)
+ {
+ oasys_extmodule_table_type_b_type record_ext;
+
+ if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
+ return NULL;
+
+ /* There are two ways of specifying the archive header. */
+ amt = sizeof (record_ext);
+ if (bfd_bread ((void *) &record_ext, amt, abfd) != amt)
+ return NULL;
+
+ record.mod_size = H_GET_32 (abfd, record_ext.mod_size);
+ record.file_offset = H_GET_32 (abfd, record_ext.file_offset);
+
+ record.dep_count = H_GET_32 (abfd, record_ext.dep_count);
+ record.depee_count = H_GET_32 (abfd, record_ext.depee_count);
+ record.sect_count = H_GET_32 (abfd, record_ext.sect_count);
+ record.module_name_size = H_GET_32 (abfd,
+ record_ext.mod_name_length);
+
+ amt = record.module_name_size;
+ module[i].name = bfd_alloc (abfd, amt + 1);
+ if (!module[i].name)
+ return NULL;
+ if (bfd_bread ((void *) module[i].name, amt, abfd) != amt)
+ return NULL;
+ module[i].name[record.module_name_size] = 0;
+ filepos += (sizeof (record_ext)
+ + record.dep_count * 4
+ + record.module_name_size + 1);