+ 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;
+ }
+ }
+