This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[Patch]: Fix crash in gprof (SunOS 5.8 only)
- From: Tristan Gingold <gingold at adacore dot com>
- To: binutils Development <binutils at sourceware dot org>
- Date: Thu, 23 Feb 2012 16:14:56 +0100
- Subject: [Patch]: Fix crash in gprof (SunOS 5.8 only)
Hi,
bsearch is slightly bugged in Solaris 8, as it calls the comparator function even if the number of entries is 0.
There are two instances of such bsearch in gprof/corefile.c. Guarding them is very simple, and done in this patch.
Ok for trunk ?
Simply tested on an example as there is no gprof test suite.
PS: should we drop tahoe ?
PPS: should we drop '-c' ? It is supported by very few architectures (i386, alpha, tax, sparc, tahoe and mips) and looks broken at least on i386.
Tristan.
gprof/
2012-02-23 Tristan Gingold <gingold@adacore.com>
* corefile.c (core_create_function_syms): Do not call bsearch if
symbol_map_count is 0.
diff --git a/gprof/corefile.c b/gprof/corefile.c
index e25d19b..9f93cee 100644
--- a/gprof/corefile.c
+++ b/gprof/corefile.c
@@ -582,7 +582,7 @@ core_create_function_syms (void)
bfd_vma max_vma = 0;
int cxxclass;
long i;
- struct function_map * found;
+ struct function_map * found = NULL;
int core_has_func_syms = 0;
switch (core_bfd->xvec->flavour)
@@ -609,10 +609,14 @@ core_create_function_syms (void)
/* Don't create a symtab entry for a function that has
a mapping to a file, unless it's the first function
in the file. */
- found = (struct function_map *) bsearch (core_syms[i]->name, symbol_map,
- symbol_map_count,
- sizeof (struct function_map),
- search_mapped_symbol);
+ if (symbol_map_count != 0)
+ {
+ /* Note: some systems (SunOS 5.8) crash if bsearch base argument
+ is NULL. */
+ found = (struct function_map *) bsearch
+ (core_syms[i]->name, symbol_map, symbol_map_count,
+ sizeof (struct function_map), search_mapped_symbol);
+ }
if (found == NULL || found->is_first)
++symtab.len;
}
@@ -643,9 +647,14 @@ core_create_function_syms (void)
continue;
}
- found = (struct function_map *) bsearch (core_syms[i]->name, symbol_map,
- symbol_map_count,
- sizeof (struct function_map), search_mapped_symbol);
+ if (symbol_map_count != 0)
+ {
+ /* Note: some systems (SunOS 5.8) crash if bsearch base argument
+ is NULL. */
+ found = (struct function_map *) bsearch
+ (core_syms[i]->name, symbol_map, symbol_map_count,
+ sizeof (struct function_map), search_mapped_symbol);
+ }
if (found && ! found->is_first)
continue;