public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H. J. Lu" <hjl@lucon.org>
To: binutils@sources.redhat.com
Subject: PATCH: Speed up _bfd_elf_make_section_from_shdr
Date: Sun, 08 May 2005 20:12:00 -0000	[thread overview]
Message-ID: <20050508190903.GA22587@lucon.org> (raw)

We are checking SEC_DEBUGGING for all sections and we call strlen on
const strings. This patch avoids those. For ranlib on libgcj.a, I got:

Before

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls   s/call   s/call  name
 13.82      0.55     0.55     4860     0.00     0.00 bfd_hash_table_init_n
 12.31      1.04     0.49   102374     0.00     0.00 _bfd_elf_make_section_from_shdr
 11.18      1.49     0.45     2429     0.00     0.00 bfd_elf32_slurp_symbol_table

After

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls   s/call   s/call  name
 18.33      0.44     0.44     4860     0.00     0.00 bfd_hash_table_init_n
 10.42      0.69     0.25     2429     0.00     0.00 bfd_elf32_slurp_symbol_table
  9.17      0.91     0.22  2171203     0.00     0.00  bfd_getl32
  7.50      1.09     0.18   102374     0.00     0.00 _bfd_elf_make_section_from_shdr


H.J.
---
2005-05-08  H.J. Lu  <hongjiu.lu@intel.com>

	* elf.c (_bfd_elf_make_section_from_shdr): Only check debug
	section if SEC_ALLOC isn't set.

--- bfd/elf.c.debug	2005-05-07 06:58:09.000000000 -0700
+++ bfd/elf.c	2005-05-08 12:03:25.000000000 -0700
@@ -750,25 +750,45 @@ _bfd_elf_make_section_from_shdr (bfd *ab
   if ((hdr->sh_flags & SHF_TLS) != 0)
     flags |= SEC_THREAD_LOCAL;
 
-  /* The debugging sections appear to be recognized only by name, not
-     any sort of flag.  */
-  {
-    static const char *debug_sec_names [] =
+  if ((flags & SEC_ALLOC) == 0)
     {
-      ".debug",
-      ".gnu.linkonce.wi.",
-      ".line",
-      ".stab"
-    };
-    int i;
-
-    for (i = ARRAY_SIZE (debug_sec_names); i--;)
-      if (strncmp (name, debug_sec_names[i], strlen (debug_sec_names[i])) == 0)
-	break;
-
-    if (i >= 0)
-      flags |= SEC_DEBUGGING;
-  }
+      /* The debugging sections appear to be recognized only by name,
+	 not any sort of flag.  Their SEC_ALLOC bits are cleared.  */
+      static const struct
+	{
+	  const char *name;
+	  int len;
+	} debug_sections [] =
+	{
+	  { "debug",		 5  },	/* 'd' */
+	  { NULL,		 0  },	/* 'e' */
+	  { NULL,		 0  },	/* 'f' */
+	  { "gnu.linkonce.wi.", 17 },	/* 'g' */
+	  { NULL,		 0  },	/* 'h' */
+	  { NULL,		 0  },	/* 'i' */
+	  { NULL,		 0  },	/* 'j' */
+	  { NULL,		 0  },	/* 'k' */
+	  { "line",		 4  },	/* 'l' */
+	  { NULL,		 0  },	/* 'm' */
+	  { NULL,		 0  },	/* 'n' */
+	  { NULL,		 0  },	/* 'o' */
+	  { NULL,		 0  },	/* 'p' */
+	  { NULL,		 0  },	/* 'q' */
+	  { NULL,		 0  },	/* 'r' */
+	  { "stab",		 4  }	/* 's' */
+	};
+      
+      if (name [0] == '.')
+	{
+	  int i = name [1] - 'd';
+	  if (i >= 0
+	      && i < (int) ARRAY_SIZE (debug_sections)
+	      && debug_sections [i].name != NULL
+	      && strncmp (&name [1], debug_sections [i].name,
+			  debug_sections [i].len) == 0)
+	    flags |= SEC_DEBUGGING;
+	}
+    }
 
   /* As a GNU extension, if the name begins with .gnu.linkonce, we
      only link a single copy of the section.  This is used to support

             reply	other threads:[~2005-05-08 19:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-08 20:12 H. J. Lu [this message]
2005-05-11  1:27 ` Alan Modra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050508190903.GA22587@lucon.org \
    --to=hjl@lucon.org \
    --cc=binutils@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).