Use the proper symbol table for and set linkage_name to symbol name

* src/abg-dwarf-reader.cc (find_symbol_table_section): Return the
	.symtab if we are looking at an executable or relocatable file and
	.dynsym if we are looking at a DSO.
	(find_symbol_table_section_index): Likewise.  Implement this in
	terms of find_symbol_table_section.
	(build_{function,var}_decl): Set the linkage_name to the symbol
	name, if the symbol name is not empty.
	* tests/data/test-diff-filter/test9-report.txt: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
Dodji Seketeli 2014-05-13 11:08:34 +02:00
parent 01269740b3
commit 61df20d749
2 changed files with 35 additions and 22 deletions

View File

@ -255,6 +255,11 @@ find_hash_table_section_index(Elf* elf_handle,
/// Find the symbol table.
///
/// If we are looking at a relocatable or executable file, this
/// function will return the .symtab symbol table (of type
/// SHT_SYMTAB). But if we are looking at a DSO it returns the
/// .dynsym symbol table (of type SHT_DYNSYM).
///
/// @param elf_handle the elf handle to consider.
///
/// @param symtab the symbol table found.
@ -263,16 +268,27 @@ find_hash_table_section_index(Elf* elf_handle,
static bool
find_symbol_table_section(Elf* elf_handle, Elf_Scn*& symtab)
{
Elf_Scn* section = 0;
Elf_Scn* section = 0, *dynsym = 0, *sym_tab = 0;
while ((section = elf_nextscn(elf_handle, section)) != 0)
{
GElf_Shdr header_mem, *header;
header = gelf_getshdr(section, &header_mem);
if (header->sh_type == SHT_SYMTAB)
{
symtab = section;
return true;
}
if (header->sh_type == SHT_DYNSYM)
dynsym = section;
else if (header->sh_type == SHT_SYMTAB)
sym_tab = section;
}
if (dynsym || sym_tab)
{
GElf_Ehdr eh_mem;
GElf_Ehdr* elf_header = gelf_getehdr(elf_handle, &eh_mem);
if (elf_header->e_type == ET_REL
|| elf_header->e_type == ET_EXEC)
symtab = sym_tab ? sym_tab : dynsym;
else
symtab = dynsym ? dynsym : sym_tab;
return true;
}
return false;
}
@ -280,6 +296,11 @@ find_symbol_table_section(Elf* elf_handle, Elf_Scn*& symtab)
/// Find the index (in the section headers table) of the symbol table
/// section.
///
/// If we are looking at a relocatable or executable file, this
/// function will return the index for the .symtab symbol table (of
/// type SHT_SYMTAB). But if we are looking at a DSO it returns the
/// index for the .dynsym symbol table (of type SHT_DYNSYM).
///
/// @param elf_handle the elf handle to use.
///
/// @param symtab_index the index of the symbol_table, that was found.
@ -290,17 +311,11 @@ find_symbol_table_section_index(Elf* elf_handle,
size_t& symtab_index)
{
Elf_Scn* section = 0;
while ((section = elf_nextscn(elf_handle, section)) != 0)
{
GElf_Shdr header_mem, *header;
header = gelf_getshdr(section, &header_mem);
if (header->sh_type == SHT_SYMTAB)
{
symtab_index = elf_ndxscn(section);
return true;
}
}
return false;
if (!find_symbol_table_section(elf_handle, section))
return false;
symtab_index = elf_ndxscn(section);
return true;
}
/// Find and return the .text section.
@ -4270,8 +4285,7 @@ build_var_decl(read_context& ctxt,
if (sym->is_variable() && sym->is_public())
{
result->set_symbol(sym);
if (result->get_linkage_name().empty())
result->set_linkage_name(sym->get_name());
result->set_linkage_name(sym->get_name());
result->set_is_in_public_symbol_table(true);
}
}
@ -4404,8 +4418,7 @@ build_function_decl(read_context& ctxt,
if (sym->is_function() && sym->is_public())
{
result->set_symbol(sym);
if (result->get_linkage_name().empty())
result->set_linkage_name(sym->get_name());
result->set_linkage_name(sym->get_name());
result->set_is_in_public_symbol_table(true);
}
}

View File

@ -14,7 +14,7 @@ Variables changes summary: 0 Removed, 0 Changed, 0 Added variable
2 Added functions:
'method int S::mem_fn1()'
'method S::S()'
'method int S::mem_fn1()'