+ if ((filedata->file_header.e_machine == EM_ALPHA
+ || filedata->file_header.e_machine == EM_S390
+ || filedata->file_header.e_machine == EM_S390_OLD)
+ && filedata->file_header.e_ident[EI_CLASS] == ELFCLASS64)
+ hash_ent_size = 8;
+
+ if (fseek (filedata->handle,
+ (filedata->archive_file_offset
+ + offset_from_vma (filedata, filedata->dynamic_info[DT_HASH],
+ sizeof nb + sizeof nc)),
+ SEEK_SET))
+ {
+ error (_("Unable to seek to start of dynamic information\n"));
+ goto no_hash;
+ }
+
+ if (fread (nb, hash_ent_size, 1, filedata->handle) != 1)
+ {
+ error (_("Failed to read in number of buckets\n"));
+ goto no_hash;
+ }
+
+ if (fread (nc, hash_ent_size, 1, filedata->handle) != 1)
+ {
+ error (_("Failed to read in number of chains\n"));
+ goto no_hash;
+ }
+
+ filedata->nbuckets = byte_get (nb, hash_ent_size);
+ filedata->nchains = byte_get (nc, hash_ent_size);
+
+ if (filedata->nbuckets != 0 && filedata->nchains != 0)
+ {
+ filedata->buckets = get_dynamic_data (filedata, filedata->nbuckets,
+ hash_ent_size);
+ filedata->chains = get_dynamic_data (filedata, filedata->nchains,
+ hash_ent_size);
+
+ if (filedata->buckets != NULL && filedata->chains != NULL)
+ num_of_syms = filedata->nchains;
+ }
+ no_hash:
+ if (num_of_syms == 0)
+ {
+ free (filedata->buckets);
+ filedata->buckets = NULL;
+ free (filedata->chains);
+ filedata->chains = NULL;
+ filedata->nbuckets = 0;
+ }
+ }
+
+ if (filedata->dynamic_info_DT_GNU_HASH)
+ {
+ unsigned char nb[16];
+ bfd_vma i, maxchain = 0xffffffff, bitmaskwords;
+ bfd_vma buckets_vma;
+ unsigned long hn;
+
+ if (fseek (filedata->handle,
+ (filedata->archive_file_offset
+ + offset_from_vma (filedata,
+ filedata->dynamic_info_DT_GNU_HASH,
+ sizeof nb)),
+ SEEK_SET))
+ {
+ error (_("Unable to seek to start of dynamic information\n"));
+ goto no_gnu_hash;
+ }
+
+ if (fread (nb, 16, 1, filedata->handle) != 1)
+ {
+ error (_("Failed to read in number of buckets\n"));
+ goto no_gnu_hash;
+ }
+
+ filedata->ngnubuckets = byte_get (nb, 4);
+ filedata->gnusymidx = byte_get (nb + 4, 4);
+ bitmaskwords = byte_get (nb + 8, 4);
+ buckets_vma = filedata->dynamic_info_DT_GNU_HASH + 16;
+ if (is_32bit_elf)
+ buckets_vma += bitmaskwords * 4;
+ else
+ buckets_vma += bitmaskwords * 8;
+
+ if (fseek (filedata->handle,
+ (filedata->archive_file_offset
+ + offset_from_vma (filedata, buckets_vma, 4)),
+ SEEK_SET))
+ {
+ error (_("Unable to seek to start of dynamic information\n"));
+ goto no_gnu_hash;
+ }
+
+ filedata->gnubuckets
+ = get_dynamic_data (filedata, filedata->ngnubuckets, 4);
+
+ if (filedata->gnubuckets == NULL)
+ goto no_gnu_hash;
+
+ for (i = 0; i < filedata->ngnubuckets; i++)
+ if (filedata->gnubuckets[i] != 0)
+ {
+ if (filedata->gnubuckets[i] < filedata->gnusymidx)
+ goto no_gnu_hash;
+
+ if (maxchain == 0xffffffff || filedata->gnubuckets[i] > maxchain)
+ maxchain = filedata->gnubuckets[i];
+ }
+
+ if (maxchain == 0xffffffff)
+ goto no_gnu_hash;
+
+ maxchain -= filedata->gnusymidx;
+
+ if (fseek (filedata->handle,
+ (filedata->archive_file_offset
+ + offset_from_vma (filedata,
+ buckets_vma + 4 * (filedata->ngnubuckets
+ + maxchain),
+ 4)),
+ SEEK_SET))
+ {
+ error (_("Unable to seek to start of dynamic information\n"));
+ goto no_gnu_hash;
+ }
+
+ do
+ {
+ if (fread (nb, 4, 1, filedata->handle) != 1)
+ {
+ error (_("Failed to determine last chain length\n"));
+ goto no_gnu_hash;
+ }
+
+ if (maxchain + 1 == 0)
+ goto no_gnu_hash;
+
+ ++maxchain;
+ }
+ while ((byte_get (nb, 4) & 1) == 0);
+
+ if (fseek (filedata->handle,
+ (filedata->archive_file_offset
+ + offset_from_vma (filedata, (buckets_vma
+ + 4 * filedata->ngnubuckets),
+ 4)),
+ SEEK_SET))
+ {
+ error (_("Unable to seek to start of dynamic information\n"));
+ goto no_gnu_hash;
+ }
+
+ filedata->gnuchains = get_dynamic_data (filedata, maxchain, 4);
+ filedata->ngnuchains = maxchain;
+
+ if (filedata->gnuchains == NULL)
+ goto no_gnu_hash;
+
+ if (filedata->dynamic_info_DT_MIPS_XHASH)
+ {
+ if (fseek (filedata->handle,
+ (filedata->archive_file_offset
+ + offset_from_vma (filedata, (buckets_vma
+ + 4 * (filedata->ngnubuckets
+ + maxchain)), 4)),
+ SEEK_SET))
+ {
+ error (_("Unable to seek to start of dynamic information\n"));
+ goto no_gnu_hash;
+ }
+
+ filedata->mipsxlat = get_dynamic_data (filedata, maxchain, 4);
+ if (filedata->mipsxlat == NULL)
+ goto no_gnu_hash;
+ }
+
+ for (hn = 0; hn < filedata->ngnubuckets; ++hn)
+ if (filedata->gnubuckets[hn] != 0)
+ {
+ bfd_vma si = filedata->gnubuckets[hn];
+ bfd_vma off = si - filedata->gnusymidx;
+
+ do
+ {
+ if (filedata->dynamic_info_DT_MIPS_XHASH)
+ {
+ if (off < filedata->ngnuchains
+ && filedata->mipsxlat[off] >= num_of_syms)
+ num_of_syms = filedata->mipsxlat[off] + 1;
+ }
+ else
+ {
+ if (si >= num_of_syms)
+ num_of_syms = si + 1;
+ }
+ si++;
+ }
+ while (off < filedata->ngnuchains
+ && (filedata->gnuchains[off++] & 1) == 0);
+ }
+
+ if (num_of_syms == 0)
+ {
+ no_gnu_hash:
+ free (filedata->mipsxlat);
+ filedata->mipsxlat = NULL;
+ free (filedata->gnuchains);
+ filedata->gnuchains = NULL;
+ free (filedata->gnubuckets);
+ filedata->gnubuckets = NULL;
+ filedata->ngnubuckets = 0;
+ filedata->ngnuchains = 0;