#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
-#define GET_ELF_SYMBOLS(file, section, sym_count) \
- (is_32bit_elf ? get_32bit_elf_symbols (file, section, sym_count) \
- : get_64bit_elf_symbols (file, section, sym_count))
-
#define VALID_SYMBOL_NAME(strtab, strtab_size, offset) \
(strtab != NULL && offset < strtab_size)
#define VALID_DYNAMIC_NAME(filedata, offset) \
if (shdrs == NULL)
return false;
- free (filedata->section_headers);
filedata->section_headers = (Elf_Internal_Shdr *)
cmalloc (num, sizeof (Elf_Internal_Shdr));
if (filedata->section_headers == NULL)
if (shdrs == NULL)
return false;
- free (filedata->section_headers);
filedata->section_headers = (Elf_Internal_Shdr *)
cmalloc (num, sizeof (Elf_Internal_Shdr));
if (filedata->section_headers == NULL)
return true;
}
+static bool
+get_section_headers (Filedata *filedata, bool probe)
+{
+ if (filedata->section_headers != NULL)
+ return true;
+
+ if (filedata->file_header.e_shoff == 0)
+ return true;
+
+ if (is_32bit_elf)
+ return get_32bit_section_headers (filedata, probe);
+ else
+ return get_64bit_section_headers (filedata, probe);
+}
+
static Elf_Internal_Sym *
get_32bit_elf_symbols (Filedata * filedata,
Elf_Internal_Shdr * section,
return isyms;
}
+static Elf_Internal_Sym *
+get_elf_symbols (Filedata *filedata,
+ Elf_Internal_Shdr *section,
+ unsigned long *num_syms_return)
+{
+ if (is_32bit_elf)
+ return get_32bit_elf_symbols (filedata, section, num_syms_return);
+ else
+ return get_64bit_elf_symbols (filedata, section, num_syms_return);
+}
+
static const char *
get_elf_section_flags (Filedata * filedata, bfd_vma sh_flags)
{
Elf_Internal_Shdr * section;
unsigned int i;
- free (filedata->section_headers);
- filedata->section_headers = NULL;
- free (filedata->dynamic_symbols);
- filedata->dynamic_symbols = NULL;
- filedata->num_dynamic_syms = 0;
- free (filedata->dynamic_strings);
- filedata->dynamic_strings = NULL;
- filedata->dynamic_strings_length = 0;
- free (filedata->dynamic_syminfo);
- filedata->dynamic_syminfo = NULL;
- while (filedata->symtab_shndx_list != NULL)
- {
- elf_section_list *next = filedata->symtab_shndx_list->next;
- free (filedata->symtab_shndx_list);
- filedata->symtab_shndx_list = next;
- }
-
if (filedata->file_header.e_shnum == 0)
{
/* PR binutils/12467. */
(unsigned long) filedata->file_header.e_shoff);
}
- if (is_32bit_elf)
- {
- if (! get_32bit_section_headers (filedata, false))
- return false;
- }
- else
- {
- if (! get_64bit_section_headers (filedata, false))
- return false;
- }
+ if (!get_section_headers (filedata, false))
+ return false;
/* Read in the string table, so that we have names to display. */
if (filedata->file_header.e_shstrndx != SHN_UNDEF
CHECK_ENTSIZE (section, i, Sym);
filedata->dynamic_symbols
- = GET_ELF_SYMBOLS (filedata, section, &filedata->num_dynamic_syms);
+ = get_elf_symbols (filedata, section, &filedata->num_dynamic_syms);
filedata->dynamic_symtab_section = section;
break;
{
*strtab = NULL;
*strtablen = 0;
- *symtab = GET_ELF_SYMBOLS (filedata, symsec, nsyms);
+ *symtab = get_elf_symbols (filedata, symsec, nsyms);
if (*symtab == NULL)
return false;
{
symtab_sec = sec;
free (symtab);
- symtab = GET_ELF_SYMBOLS (filedata, symtab_sec, & num_syms);
+ symtab = get_elf_symbols (filedata, symtab_sec, & num_syms);
}
if (symtab == NULL)
return true;
}
+static bool
+get_dynamic_section (Filedata *filedata)
+{
+ if (filedata->dynamic_section)
+ return true;
+
+ if (is_32bit_elf)
+ return get_32bit_dynamic_section (filedata);
+ else
+ return get_64bit_dynamic_section (filedata);
+}
+
static void
print_dynamic_flags (bfd_vma flags)
{
return true;
}
- if (is_32bit_elf)
- {
- if (! get_32bit_dynamic_section (filedata))
- return false;
- }
- else
- {
- if (! get_64bit_dynamic_section (filedata))
- return false;
- }
+ if (!get_dynamic_section (filedata))
+ return false;
/* Find the appropriate symbol table. */
if (filedata->dynamic_symbols == NULL || do_histogram)
section.sh_name = filedata->string_table_length;
filedata->dynamic_symbols
- = GET_ELF_SYMBOLS (filedata, §ion,
+ = get_elf_symbols (filedata, §ion,
&filedata->num_dynamic_syms);
if (filedata->dynamic_symbols == NULL
|| filedata->num_dynamic_syms != num_of_syms)
found = true;
- symbols = GET_ELF_SYMBOLS (filedata, link_section, & num_syms);
+ symbols = get_elf_symbols (filedata, link_section, & num_syms);
if (symbols == NULL)
break;
else
printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
- symtab = GET_ELF_SYMBOLS (filedata, section, & num_syms);
+ symtab = get_elf_symbols (filedata, section, & num_syms);
if (symtab == NULL)
continue;
if (filedata->file_header.e_machine == EM_SH)
is_rela = false;
- symtab = GET_ELF_SYMBOLS (filedata, symsec, & num_syms);
+ symtab = get_elf_symbols (filedata, symsec, & num_syms);
for (rp = relocs; rp < relocs + num_relocs; ++rp)
{
filedata->file_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
}
- if (filedata->file_header.e_shoff)
- {
- /* There may be some extensions in the first section header. Don't
- bomb if we can't read it. */
- if (is_32bit_elf)
- get_32bit_section_headers (filedata, true);
- else
- get_64bit_section_headers (filedata, true);
- }
-
return true;
}
if (! get_file_header (filedata))
goto fail;
- if (filedata->file_header.e_shoff)
- {
- bool res;
-
- /* Read the section headers again, this time for real. */
- if (is_32bit_elf)
- res = get_32bit_section_headers (filedata, false);
- else
- res = get_64bit_section_headers (filedata, false);
-
- if (!res)
- goto fail;
- }
+ if (!get_section_headers (filedata, false))
+ goto fail;
return filedata;
initialise_dump_sects (filedata);
+ /* There may be some extensions in the first section header. Don't
+ bomb if we can't read it. */
+ get_section_headers (filedata, true);
+
if (! process_file_header (filedata))
- return false;
+ {
+ res = false;
+ goto out;
+ }
if (! process_section_headers (filedata))
{
if (! process_arch_specific (filedata))
res = false;
+ out:
free_filedata (filedata);
free_debug_memory ();