This is the mail archive of the binutils-cvs@sourceware.org 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]

[binutils-gdb] Speed up objdump when displaying disassembly mixed with line number and source code information.


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cd6581da62c32a391f9a4c2c5d248a11aa6fa8f7

commit cd6581da62c32a391f9a4c2c5d248a11aa6fa8f7
Author: Nick Clifton <nickc@redhat.com>
Date:   Mon Jan 9 16:49:48 2017 +0000

    Speed up objdump when displaying disassembly mixed with line number and source code information.
    
    bfd	* dwarf2.c (lookup_address_in_function_table): Return early if
    	there are no functions in the given comp unit, or if the high
    	address of the last function in the comp unit is less than the
    	desired address.
    
    binutils * objdump.c (display_file): Add new parameter 'last_file'.  If
    	last_file is true, do not call bfd_close at the end of the
    	function.
    	(main): Set the value of the last_file parameter when calling
    	display_file.

Diff:
---
 bfd/ChangeLog      |  7 +++++++
 bfd/dwarf2.c       |  6 ++++++
 binutils/ChangeLog |  8 ++++++++
 binutils/objdump.c | 22 ++++++++++++++++++----
 4 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 933feba..83a7116 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,12 @@
 2017-01-09  Nick Clifton  <nickc@redhat.com>
 
+	* dwarf2.c (lookup_address_in_function_table): Return early if
+	there are no functions in the given comp unit, or if the high
+	address of the last function in the comp unit is less than the
+	desired address.
+
+2017-01-09  Nick Clifton  <nickc@redhat.com>
+
 	PR binutils/21013
 	* coffgen.c (_bfd_coff_get_external_symbols): Generate an error
 	message if there are too many symbols to load.
diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
index b477d27..40edd91 100644
--- a/bfd/dwarf2.c
+++ b/bfd/dwarf2.c
@@ -2336,9 +2336,15 @@ lookup_address_in_function_table (struct comp_unit *unit,
   bfd_size_type low, high, mid, first;
   struct arange *arange;
 
+  if (number_of_functions == 0)
+    return FALSE;
+
   if (!build_lookup_funcinfo_table (unit))
     return FALSE;
 
+  if (unit->lookup_funcinfo_table[number_of_functions - 1].high_addr < addr)
+    return FALSE;
+  
   /* Find the first function in the lookup table which may contain the
      specified address.  */
   low = 0;
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index b5e82fe..a37f56c 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,11 @@
+2017-01-09  Nick Clifton  <nickc@redhat.com>
+
+	* objdump.c (display_file): Add new parameter 'last_file'.  If
+	last_file is true, do not call bfd_close at the end of the
+	function.
+	(main): Set the value of the last_file parameter when calling
+	display_file.
+
 2017-01-09  Alan Modra  <amodra@gmail.com>
 
 	* readelf.c (process_section_headers): Correct .rel.dyn/.rela.dyn
diff --git a/binutils/objdump.c b/binutils/objdump.c
index f61968b..c03dfc5 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -3616,7 +3616,7 @@ display_any_bfd (bfd *file, int level)
 }
 
 static void
-display_file (char *filename, char *target)
+display_file (char *filename, char *target, bfd_boolean last_file)
 {
   bfd *file;
 
@@ -3635,7 +3635,18 @@ display_file (char *filename, char *target)
 
   display_any_bfd (file, 0);
 
-  bfd_close (file);
+  /* This is an optimization to improve the speed of objdump, especially when
+     dumping a file with lots of associated debug informatiom.  Calling
+     bfd_close on such a file can take a non-trivial amount of time as there
+     are lots of lists to walk and buffers to free.  This is only really
+     necessary however if we are about to load another file and we need the
+     memory back.  Otherwise, if we are about to exit, then we can save (a lot
+     of) time by only doing a quick close, and allowing the OS to reclaim the
+     memory for us.  */
+  if (! last_file)
+    bfd_close (file);
+  else
+    bfd_close_all_done (file);
 }
 
 int
@@ -3913,10 +3924,13 @@ main (int argc, char **argv)
   else
     {
       if (optind == argc)
-	display_file ("a.out", target);
+	display_file ("a.out", target, TRUE);
       else
 	for (; optind < argc;)
-	  display_file (argv[optind++], target);
+	  {
+	    display_file (argv[optind], target, optind == argc - 1);
+	    optind++;
+	  }
     }
 
   free_only_list ();


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