+ 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;
+ }
+ }
+
+ return num_of_syms;
+}
+
+/* Parse and display the contents of the dynamic section. */
+
+static bfd_boolean
+process_dynamic_section (Filedata * filedata)
+{
+ Elf_Internal_Dyn * entry;
+
+ if (filedata->dynamic_size == 0)
+ {
+ if (do_dynamic)
+ printf (_("\nThere is no dynamic section in this file.\n"));
+
+ return TRUE;
+ }
+
+ if (is_32bit_elf)
+ {
+ if (! get_32bit_dynamic_section (filedata))
+ return FALSE;
+ }
+ else
+ {
+ if (! get_64bit_dynamic_section (filedata))
+ return FALSE;
+ }
+
+ /* Find the appropriate symbol table. */
+ if (filedata->dynamic_symbols == NULL || do_histogram)
+ {
+ unsigned long num_of_syms;
+
+ for (entry = filedata->dynamic_section;
+ entry < filedata->dynamic_section + filedata->dynamic_nent;
+ ++entry)
+ if (entry->d_tag == DT_SYMTAB)
+ filedata->dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
+ else if (entry->d_tag == DT_SYMENT)
+ filedata->dynamic_info[DT_SYMENT] = entry->d_un.d_val;
+ else if (entry->d_tag == DT_HASH)
+ filedata->dynamic_info[DT_HASH] = entry->d_un.d_val;
+ else if (entry->d_tag == DT_GNU_HASH)
+ filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
+ else if ((filedata->file_header.e_machine == EM_MIPS
+ || filedata->file_header.e_machine == EM_MIPS_RS3_LE)
+ && entry->d_tag == DT_MIPS_XHASH)
+ {
+ filedata->dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val;
+ filedata->dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
+ }
+
+ num_of_syms = get_num_dynamic_syms (filedata);
+
+ if (num_of_syms != 0
+ && filedata->dynamic_symbols == NULL
+ && filedata->dynamic_info[DT_SYMTAB]
+ && filedata->dynamic_info[DT_SYMENT])
+ {
+ Elf_Internal_Phdr *seg;
+ bfd_vma vma = filedata->dynamic_info[DT_SYMTAB];
+
+ if (! get_program_headers (filedata))
+ {
+ error (_("Cannot interpret virtual addresses "
+ "without program headers.\n"));
+ return FALSE;
+ }
+
+ for (seg = filedata->program_headers;
+ seg < filedata->program_headers + filedata->file_header.e_phnum;
+ ++seg)
+ {
+ if (seg->p_type != PT_LOAD)
+ continue;
+
+ if (seg->p_offset + seg->p_filesz > filedata->file_size)
+ {
+ /* See PR 21379 for a reproducer. */
+ error (_("Invalid PT_LOAD entry\n"));
+ return FALSE;
+ }
+
+ if (vma >= (seg->p_vaddr & -seg->p_align)
+ && vma < seg->p_vaddr + seg->p_filesz)
+ {
+ /* Since we do not know how big the symbol table is,
+ we default to reading in up to the end of PT_LOAD
+ segment and processing that. This is overkill, I
+ know, but it should work. */
+ Elf_Internal_Shdr section;
+ section.sh_offset = (vma - seg->p_vaddr
+ + seg->p_offset);
+ section.sh_size = (num_of_syms
+ * filedata->dynamic_info[DT_SYMENT]);
+ section.sh_entsize = filedata->dynamic_info[DT_SYMENT];
+
+ if (do_checks
+ && filedata->dynamic_symtab_section != NULL
+ && ((filedata->dynamic_symtab_section->sh_offset
+ != section.sh_offset)
+ || (filedata->dynamic_symtab_section->sh_size
+ != section.sh_size)
+ || (filedata->dynamic_symtab_section->sh_entsize
+ != section.sh_entsize)))
+ warn (_("\
+the .dynsym section doesn't match the DT_SYMTAB and DT_SYMENT tags\n"));
+
+ section.sh_name = filedata->string_table_length;
+ filedata->dynamic_symbols
+ = GET_ELF_SYMBOLS (filedata, §ion,
+ &filedata->num_dynamic_syms);
+ if (filedata->dynamic_symbols == NULL
+ || filedata->num_dynamic_syms != num_of_syms)
+ {
+ error (_("Corrupt DT_SYMTAB dynamic entry\n"));
+ return FALSE;
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ /* Similarly find a string table. */
+ if (filedata->dynamic_strings == NULL)
+ for (entry = filedata->dynamic_section;
+ entry < filedata->dynamic_section + filedata->dynamic_nent;
+ ++entry)
+ {
+ if (entry->d_tag == DT_STRTAB)
+ filedata->dynamic_info[DT_STRTAB] = entry->d_un.d_val;
+
+ if (entry->d_tag == DT_STRSZ)
+ filedata->dynamic_info[DT_STRSZ] = entry->d_un.d_val;
+
+ if (filedata->dynamic_info[DT_STRTAB]
+ && filedata->dynamic_info[DT_STRSZ])
+ {
+ unsigned long offset;
+ bfd_size_type str_tab_len = filedata->dynamic_info[DT_STRSZ];
+
+ offset = offset_from_vma (filedata,
+ filedata->dynamic_info[DT_STRTAB],
+ str_tab_len);
+ if (do_checks
+ && filedata->dynamic_strtab_section
+ && ((filedata->dynamic_strtab_section->sh_offset
+ != (file_ptr) offset)
+ || (filedata->dynamic_strtab_section->sh_size
+ != str_tab_len)))
+ warn (_("\
+the .dynstr section doesn't match the DT_STRTAB and DT_STRSZ tags\n"));
+
+ filedata->dynamic_strings
+ = (char *) get_data (NULL, filedata, offset, 1, str_tab_len,
+ _("dynamic string table"));
+ if (filedata->dynamic_strings == NULL)
+ {
+ error (_("Corrupt DT_STRTAB dynamic entry\n"));
+ break;
+ }
+
+ filedata->dynamic_strings_length = str_tab_len;
+ break;
+ }
+ }
+
+ /* And find the syminfo section if available. */
+ if (filedata->dynamic_syminfo == NULL)
+ {
+ unsigned long syminsz = 0;
+
+ for (entry = filedata->dynamic_section;
+ entry < filedata->dynamic_section + filedata->dynamic_nent;
+ ++entry)
+ {
+ if (entry->d_tag == DT_SYMINENT)
+ {
+ /* Note: these braces are necessary to avoid a syntax
+ error from the SunOS4 C compiler. */
+ /* PR binutils/17531: A corrupt file can trigger this test.
+ So do not use an assert, instead generate an error message. */
+ if (sizeof (Elf_External_Syminfo) != entry->d_un.d_val)
+ error (_("Bad value (%d) for SYMINENT entry\n"),
+ (int) entry->d_un.d_val);
+ }
+ else if (entry->d_tag == DT_SYMINSZ)
+ syminsz = entry->d_un.d_val;
+ else if (entry->d_tag == DT_SYMINFO)
+ filedata->dynamic_syminfo_offset
+ = offset_from_vma (filedata, entry->d_un.d_val, syminsz);
+ }
+
+ if (filedata->dynamic_syminfo_offset != 0 && syminsz != 0)
+ {
+ Elf_External_Syminfo * extsyminfo;
+ Elf_External_Syminfo * extsym;
+ Elf_Internal_Syminfo * syminfo;
+
+ /* There is a syminfo section. Read the data. */
+ extsyminfo = (Elf_External_Syminfo *)
+ get_data (NULL, filedata, filedata->dynamic_syminfo_offset,
+ 1, syminsz, _("symbol information"));
+ if (!extsyminfo)
+ return FALSE;
+
+ if (filedata->dynamic_syminfo != NULL)
+ {
+ error (_("Multiple dynamic symbol information sections found\n"));
+ free (filedata->dynamic_syminfo);
+ }
+ filedata->dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
+ if (filedata->dynamic_syminfo == NULL)