This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

objdump -d --line-numbers performance question


Hello all,

In one project I work on there's some scripts which we use to do
debugging that use objdump to get at debugging symbol info to decode
backtrace dumps from the program.  The application binary is ~50MB when
built with debugging info, and when we moved from developing on RedHat
7.3 to RH 9 or later, the objdump time went through the roof.

I grabbed a binutils-2.14 tarball, and spent a little time digging. 
oprofile reports that some huge proportion of the time is spent in the
bfd/elf.c:elf_find_function() call, which is being called (with some
intermediates) by binutils/objdump.c:show_line().

Looking at elf_find_function() it jumps out that it's doing a linear
search through the entire set of symbols every time it's called.  But
show_line() has access to find_symbol_for_address which does a binary
search on a sorted set of symbols.

So.  The attached patch uses find_symbol_for_address() in show_line(),
and then passes down a fake asymbol** list consisting of just the found
symbol and a null end marker.  So far it always produces identical
'objdump -d --line-numbers' output for me as the stock objdump, but my
run time on one representative file has gone from ~2 hours to ~4
minutes.

Does this look right?  If not, can anyone give me some pointers on the
right way to try to optimize things?

Thanks,
-emile


+----------------------------------------------------------------------
this wine is particularly heavy, and is mostly recommended for
hand-to-hand combat. -- Eric Idle 
+----------------------------------------------------------------------
diff -Naur binutils-2.14/binutils/objdump.c binutils-2.14-modified/binutils/objdump.c
--- binutils-2.14/binutils/objdump.c	2003-03-31 16:32:47.000000000 -0800
+++ binutils-2.14-modified/binutils/objdump.c	2005-02-25 12:02:43.617595584 -0800
@@ -980,13 +980,22 @@
   const char *filename;
   const char *functionname;
   unsigned int line;
+  asymbol *foundsym;
+  asymbol *mocksyms[2];
+  long symplace;
 
   if (! with_line_numbers && ! with_source_code)
     return;
 
-  if (! bfd_find_nearest_line (abfd, section, syms, addr_offset, &filename,
-			       &functionname, &line))
-    return;
+  foundsym = find_symbol_for_address(abfd, section, 
+                                     section->vma + addr_offset, 
+                                     FALSE, &symplace);
+  mocksyms[0] = foundsym;
+  mocksyms[1] = NULL;
+
+  if (! bfd_find_nearest_line (abfd, section, mocksyms, addr_offset, &filename,
+  			       &functionname, &line))
+      return;
 
   if (filename != NULL && *filename == '\0')
     filename = NULL;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]