Don't discard weak symbols.

2007-10-22  Soren Sandmann <sandmann@daimi.au.dk>

	* elfparser.c (read_table): Don't discard weak symbols.

	* elfparser.c (elf_parser_lookup_symbol): If the symbol has
	unknown size, don't check that the address is in range.


svn path=/trunk/; revision=381
This commit is contained in:
Soren Sandmann
2007-10-22 04:41:27 +00:00
committed by Søren Sandmann Pedersen
parent e33a7f9a2f
commit a7b39cf517
2 changed files with 48 additions and 19 deletions

View File

@ -353,19 +353,24 @@ const BinSymbol *
bin_file_lookup_symbol (BinFile *bin_file, bin_file_lookup_symbol (BinFile *bin_file,
gulong address) gulong address)
{ {
#if 0
g_print ("-=-=-=- \n");
#endif
if (bin_file->elf) if (bin_file->elf)
{ {
#if 0 #if 0
g_print ("bin file lookup lookup %d\n", address); g_print ("bin file lookup lookup %d\n", address);
#endif #endif
address -= bin_file->text_offset;
const ElfSym *sym = elf_parser_lookup_symbol (bin_file->elf, address); address -= bin_file->text_offset;
#if 0 #if 0
g_print ("lookup %d in %s\n", address, bin_file->filename); g_print ("lookup %d in %s\n", address, bin_file->filename);
#endif #endif
const ElfSym *sym = elf_parser_lookup_symbol (bin_file->elf, address);
if (sym) if (sym)
{ {
#if 0 #if 0

View File

@ -160,6 +160,10 @@ elf_parser_new_from_data (const guchar *data,
parser = g_new0 (ElfParser, 1); parser = g_new0 (ElfParser, 1);
#if 0
g_print (" new parser : %p\n", parser);
#endif
parser->parser = bin_parser_new (data, length); parser->parser = bin_parser_new (data, length);
if (is_big_endian) if (is_big_endian)
@ -239,6 +243,10 @@ elf_parser_new (const char *filename,
parser = elf_parser_new_from_data (data, length); parser = elf_parser_new_from_data (data, length);
#if 0
g_print ("Parser for %s: %p\n", filename, parser);
#endif
if (!parser) if (!parser)
{ {
g_mapped_file_free (file); g_mapped_file_free (file);
@ -437,23 +445,35 @@ read_table (ElfParser *parser,
parser->parser, parser->sym_format, "st_value"); parser->parser, parser->sym_format, "st_value");
offset = bin_parser_get_offset (parser->parser); offset = bin_parser_get_offset (parser->parser);
if (addr != 0 &&
(info & 0xf) == STT_FUNC &&
((info >> 4) == STB_GLOBAL ||
(info >> 4) == STB_LOCAL))
{
parser->symbols[n_functions].address = addr;
parser->symbols[n_functions].offset = offset;
n_functions++;
}
#if 0 #if 0
g_print ("read symbol: %s\n", get_string_indirect (parser->parser, g_print ("read symbol: %s\n", get_string_indirect (parser->parser,
parser->sym_format, "st_name", parser->sym_format, "st_name",
str_table->offset)); str_table->offset));
#endif #endif
if (addr != 0 &&
(info & 0xf) == STT_FUNC &&
((info >> 4) == STB_GLOBAL ||
(info >> 4) == STB_LOCAL ||
(info >> 4) == STB_WEAK)
)
{
parser->symbols[n_functions].address = addr;
parser->symbols[n_functions].offset = offset;
#if 0
g_print (" symbol: %s: %d\n", get_string_indirect (parser->parser,
parser->sym_format, "st_name",
str_table->offset), addr);
#endif
n_functions++;
}
#if 0
else if (addr != 0)
{
g_print ("rejecting %d in %p (info: %d:%d) (func:global %d:%d)\n", addr, parser, info & 0xf, info >> 4, STT_FUNC, STB_GLOBAL);
}
#endif
bin_parser_seek_record (parser->parser, parser->sym_format, 1); bin_parser_seek_record (parser->parser, parser->sym_format, 1);
} }
@ -546,7 +566,7 @@ elf_parser_lookup_symbol (ElfParser *parser,
address += parser->text_section->load_address; address += parser->text_section->load_address;
#if 0 #if 0
g_print ("the address we are looking up is %p\n", address); g_print ("elf: the address we are looking up is %p\n", address);
#endif #endif
result = do_lookup (parser->symbols, address, 0, parser->n_symbols - 1); result = do_lookup (parser->symbols, address, 0, parser->n_symbols - 1);
@ -554,7 +574,11 @@ elf_parser_lookup_symbol (ElfParser *parser,
#if 0 #if 0
if (result) if (result)
{ {
g_print ("found %s at %lx\n", elf_parser_get_sym_name (parser, result), result->address); g_print (" elf: found %s at %lx\n", elf_parser_get_sym_name (parser, result), result->address);
}
else
{
g_print ("elf: not found\n");
} }
#endif #endif
@ -567,7 +591,7 @@ elf_parser_lookup_symbol (ElfParser *parser,
size = bin_parser_get_uint_field ( size = bin_parser_get_uint_field (
parser->parser, parser->sym_format, "st_size"); parser->parser, parser->sym_format, "st_size");
if (result->address + size <= address) if (size > 0 && result->address + size <= address)
result = NULL; result = NULL;
} }