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

Re: PATCH: Cache the result of _bfd_elf_check_kept_section


On Mon, Apr 24, 2006 at 04:10:56PM -0700, H. J. Lu wrote:
> On Mon, Apr 24, 2006 at 10:52:53AM -0700, H. J. Lu wrote:
> > This patch addresses the link speed issue by caching the result of
> > _bfd_elf_check_kept_section.
> >  
> 
> Apparently, I didn't include the correct patch. Here is the right one.
> 

Here is a patch without adding a new field to ELF section.


H.J.
----
2006-04-24  Michael Matz  <matz@suse.de>
	    H.J. Lu  <hongjiu.lu@intel.com>

	* elf.c (_bfd_elf_new_section_hook): Initialize kept_section to
	(asection *) -1L.
	(assign_section_numbers): Check kept_section before calling
	_bfd_elf_check_kept_section.
	* elflink.c (elf_link_input_bfd): Likewise.

	* elflink.c (elf_link_add_object_symbols): Also check if
	kept_section isn't (asection *) -1L before using it.
	(elf_link_input_bfd): Likewise.
	(match_group_member): Correctly iterate group members.
	(_bfd_elf_check_kept_section): Cache the result in
	elf_kept_section.

--- bfd/elf.c.kept	2006-04-24 19:09:01.000000000 -0700
+++ bfd/elf.c	2006-04-24 19:16:14.000000000 -0700
@@ -2481,6 +2481,8 @@ _bfd_elf_new_section_hook (bfd *abfd, as
       if (sdata == NULL)
 	return FALSE;
       sec->used_by_bfd = sdata;
+      /* Initialized it with -1L so that it can be cached.  */
+      sec->kept_section = (asection *) -1L;
     }
 
   /* Indicate whether or not this section should use RELA relocations.  */
@@ -3131,7 +3133,11 @@ assign_section_numbers (bfd *abfd, struc
 			 s, s->owner);
 		      /* Point to the kept section if it has the same
 			 size as the discarded one.  */
-		      kept = _bfd_elf_check_kept_section (s);
+		      if (s->kept_section != NULL
+			  && s->kept_section != (asection *) -1L)
+			kept = _bfd_elf_check_kept_section (s);
+		      else
+			kept = NULL;
 		      if (kept == NULL)
 			{
 			  bfd_set_error (bfd_error_bad_value);
--- bfd/elflink.c.kept	2006-04-24 15:36:18.000000000 -0700
+++ bfd/elflink.c	2006-04-24 19:22:22.000000000 -0700
@@ -3587,7 +3587,8 @@ elf_link_add_object_symbols (bfd *abfd, 
 	  sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
 	  if (sec == NULL)
 	    sec = bfd_abs_section_ptr;
-	  else if (sec->kept_section)
+	  else if (sec->kept_section
+		   && sec->kept_section != (asection *) -1L)
 	    {
 	      /* Symbols from discarded section are undefined, and have
 		 default visibility.  */
@@ -6782,6 +6783,7 @@ match_group_member (asection *sec, asect
       if (bfd_elf_match_symbols_in_sections (s, sec))
 	return s;
 
+      s = elf_next_in_group (s);
       if (s == first)
 	break;
     }
@@ -6806,6 +6808,13 @@ _bfd_elf_check_kept_section (asection *s
       if (kept != NULL && sec->size != kept->size)
 	kept = NULL;
     }
+
+  /* kept_section is initialized to -1L.  */
+  if (kept == (asection *) -1L)
+    abort ();
+
+  sec->kept_section = kept;
+
   return kept;
 }
 
@@ -7157,7 +7166,9 @@ elf_link_input_bfd (struct elf_final_lin
 			 is that we warn in non-debug sections, and
 			 debug sections tend to come after other
 			 sections.  */
-		      if (action & PRETEND)
+		      if ((action & PRETEND)
+			  && sec->kept_section
+			  && sec->kept_section != (asection *) -1L)
 			{
 			  asection *kept;
 
@@ -7334,7 +7345,8 @@ elf_link_input_bfd (struct elf_final_lin
 			     case of discarded link-once and discarded
 			     SEC_MERGE sections, use the kept section.  */
 			  if (bfd_is_abs_section (osec)
-			      && sec->kept_section != NULL
+			      && sec->kept_section
+			      && sec->kept_section != (asection *) -1L 
 			      && sec->kept_section->output_section != NULL)
 			    {
 			      osec = sec->kept_section->output_section;


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