From a7b39cf5177f4816c22ac3b39111537e87a39d99 Mon Sep 17 00:00:00 2001 From: Soren Sandmann Date: Mon, 22 Oct 2007 04:41:27 +0000 Subject: [PATCH] Don't discard weak symbols. 2007-10-22 Soren Sandmann * 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 --- binfile.c | 9 +++++++-- elfparser.c | 58 +++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/binfile.c b/binfile.c index bffa39f8..d8d335c7 100644 --- a/binfile.c +++ b/binfile.c @@ -353,19 +353,24 @@ const BinSymbol * bin_file_lookup_symbol (BinFile *bin_file, gulong address) { +#if 0 + g_print ("-=-=-=- \n"); +#endif + if (bin_file->elf) { #if 0 g_print ("bin file lookup lookup %d\n", address); #endif + address -= bin_file->text_offset; - const ElfSym *sym = elf_parser_lookup_symbol (bin_file->elf, address); - #if 0 g_print ("lookup %d in %s\n", address, bin_file->filename); #endif + const ElfSym *sym = elf_parser_lookup_symbol (bin_file->elf, address); + if (sym) { #if 0 diff --git a/elfparser.c b/elfparser.c index 86a3f342..53e0e322 100644 --- a/elfparser.c +++ b/elfparser.c @@ -157,9 +157,13 @@ elf_parser_new_from_data (const guchar *data, /* FIXME: set error */ return NULL; } - + parser = g_new0 (ElfParser, 1); +#if 0 + g_print (" new parser : %p\n", parser); +#endif + parser->parser = bin_parser_new (data, length); if (is_big_endian) @@ -239,6 +243,10 @@ elf_parser_new (const char *filename, parser = elf_parser_new_from_data (data, length); +#if 0 + g_print ("Parser for %s: %p\n", filename, parser); +#endif + if (!parser) { g_mapped_file_free (file); @@ -437,23 +445,35 @@ read_table (ElfParser *parser, parser->parser, parser->sym_format, "st_value"); 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 g_print ("read symbol: %s\n", get_string_indirect (parser->parser, parser->sym_format, "st_name", str_table->offset)); #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); } @@ -546,7 +566,7 @@ elf_parser_lookup_symbol (ElfParser *parser, address += parser->text_section->load_address; #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 result = do_lookup (parser->symbols, address, 0, parser->n_symbols - 1); @@ -554,7 +574,11 @@ elf_parser_lookup_symbol (ElfParser *parser, #if 0 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 @@ -566,8 +590,8 @@ elf_parser_lookup_symbol (ElfParser *parser, size = bin_parser_get_uint_field ( parser->parser, parser->sym_format, "st_size"); - - if (result->address + size <= address) + + if (size > 0 && result->address + size <= address) result = NULL; }