public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PATCH: PR ld/2342: linkonce debug is broken
@ 2006-04-24 20:12 H. J. Lu
  2006-04-25 15:47 ` PATCH: Cache the result of _bfd_elf_check_kept_section H. J. Lu
  0 siblings, 1 reply; 4+ messages in thread
From: H. J. Lu @ 2006-04-24 20:12 UTC (permalink / raw)
  To: binutils; +Cc: matz

This patch addresses the link speed issue by caching the result of
_bfd_elf_check_kept_section.
 

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

	* elf-bfd.h (bfd_elf_section_data): Add kept_section.
	(elf_kept_section): New.

	* elf.c (_bfd_elf_new_section_hook): Initialize
	elf_kept_section to (asection *) -1L.

	* elflink.c (_bfd_elf_check_kept_section): Cache the result in
	elf_kept_section.

2006-02-17  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/2342
	* elflink.c (_bfd_elf_default_action_discarded): Undo the
	change made on 2006-02-16.
	(elf_link_input_bfd): Likewise.

Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.202
retrieving revision 1.201
diff -u -p -r1.202 -r1.201
--- bfd/elflink.c	15 Feb 2006 14:12:54 -0000	1.202
+++ bfd/elflink.c	17 Jan 2006 15:32:40 -0000	1.201
@@ -6691,7 +6691,7 @@ unsigned int
 _bfd_elf_default_action_discarded (asection *sec)
 {
   if (sec->flags & SEC_DEBUGGING)
-    return 0;
+    return PRETEND;
 
   if (strcmp (".eh_frame", sec->name) == 0)
     return 0;
@@ -7007,7 +7007,8 @@ elf_link_input_bfd (struct elf_final_lin
 	     from discarded sections and section symbols from
 	     removed link-once sections.  Complain about relocs
 	     against discarded sections.  Zero relocs against removed
-	     link-once sections.  */
+	     link-once sections.  Preserve debug information as much
+	     as we can.  */
 	  if (!elf_section_ignore_discarded_relocs (o))
 	    {
 	      Elf_Internal_Rela *rel, *relend;
@@ -7079,11 +7080,16 @@ elf_link_input_bfd (struct elf_final_lin
 			   sym_name, o, input_bfd, sec, sec->owner);
 
 		      /* Try to do the best we can to support buggy old
-			 versions of gcc.  Pretend that the symbol is
+			 versions of gcc.  If we've warned, or this is
+			 debugging info, pretend that the symbol is
 			 really defined in the kept linkonce section.
 			 FIXME: This is quite broken.  Modifying the
 			 symbol here means we will be changing all later
-			 uses of the symbol, not just in this section.  */
+			 uses of the symbol, not just in this section.
+			 The only thing that makes this half reasonable
+			 is that we warn in non-debug sections, and
+			 debug sections tend to come after other
+			 sections.  */
 		      if (action & PRETEND)
 			{
 			  asection *kept;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* PATCH: Cache the result of _bfd_elf_check_kept_section
  2006-04-24 20:12 PATCH: PR ld/2342: linkonce debug is broken H. J. Lu
@ 2006-04-25 15:47 ` H. J. Lu
  2006-04-25 16:11   ` H. J. Lu
  0 siblings, 1 reply; 4+ messages in thread
From: H. J. Lu @ 2006-04-25 15:47 UTC (permalink / raw)
  To: binutils; +Cc: matz

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.


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

	* elf-bfd.h (bfd_elf_section_data): Add kept_section.
	(elf_kept_section): New.

	* elf.c (_bfd_elf_new_section_hook): Initialize
	elf_kept_section to (asection *) -1L.

	* elflink.c (match_group_member): Correctly iterate group
	members.
	(_bfd_elf_check_kept_section): Cache the result in
	elf_kept_section.

--- bfd/elf-bfd.h.2342	2006-03-16 12:37:42.000000000 -0800
+++ bfd/elf-bfd.h	2006-04-24 10:23:41.000000000 -0700
@@ -1168,6 +1168,10 @@ struct bfd_elf_section_data
      the linker.  */
   asection *next_in_group;
 
+  /* The pointer to the real kept section. It is computed from the
+     kept_section field in asection due to section group.  */ 
+  asection *kept_section;
+
   /* A pointer used for various section optimizations.  */
   void *sec_info;
 };
@@ -1180,6 +1184,7 @@ struct bfd_elf_section_data
 #define elf_group_id(sec)      (elf_section_data(sec)->group.id)
 #define elf_next_in_group(sec) (elf_section_data(sec)->next_in_group)
 #define elf_sec_group(sec)	(elf_section_data(sec)->sec_group)
+#define elf_kept_section(sec) (elf_section_data(sec)->kept_section)
 
 /* Return TRUE if section has been discarded.  */
 #define elf_discarded_section(sec)				\
--- bfd/elf.c.2342	2006-04-21 16:15:41.000000000 -0700
+++ bfd/elf.c	2006-04-24 10:24:42.000000000 -0700
@@ -2481,6 +2481,7 @@ _bfd_elf_new_section_hook (bfd *abfd, as
       if (sdata == NULL)
 	return FALSE;
       sec->used_by_bfd = sdata;
+      elf_kept_section (sec) = (asection *) -1L;
     }
 
   /* Indicate whether or not this section should use RELA relocations.  */
--- bfd/elflink.c.2342	2006-04-05 11:10:51.000000000 -0700
+++ bfd/elflink.c	2006-04-24 10:28:31.000000000 -0700
@@ -6782,6 +6782,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;
     }
@@ -6798,6 +6799,10 @@ _bfd_elf_check_kept_section (asection *s
 {
   asection *kept;
 
+  kept = elf_kept_section (sec);
+  if (kept != (asection *) -1L)
+    return kept;
+
   kept = sec->kept_section;
   if (kept != NULL)
     {
@@ -6806,6 +6811,13 @@ _bfd_elf_check_kept_section (asection *s
       if (kept != NULL && sec->size != kept->size)
 	kept = NULL;
     }
+
+  /* elf_kept_section (sec) is initialized  to -1L.  */
+  if (kept == (asection *) -1L)
+    abort ();
+
+  elf_kept_section (sec) = kept;
+
   return kept;
 }
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: Cache the result of _bfd_elf_check_kept_section
  2006-04-25 15:47 ` PATCH: Cache the result of _bfd_elf_check_kept_section H. J. Lu
@ 2006-04-25 16:11   ` H. J. Lu
  2006-04-25 16:37     ` H. J. Lu
  0 siblings, 1 reply; 4+ messages in thread
From: H. J. Lu @ 2006-04-25 16:11 UTC (permalink / raw)
  To: binutils; +Cc: matz

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;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: Cache the result of _bfd_elf_check_kept_section
  2006-04-25 16:11   ` H. J. Lu
@ 2006-04-25 16:37     ` H. J. Lu
  0 siblings, 0 replies; 4+ messages in thread
From: H. J. Lu @ 2006-04-25 16:37 UTC (permalink / raw)
  To: binutils; +Cc: matz

On Mon, Apr 24, 2006 at 07:27:44PM -0700, H. J. Lu wrote:
> 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.
> 
> 

I think the new field in ELF section is useful to avoid setting
kept_section to -1L.



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

	* elf-bfd.h (bfd_elf_section_data): Add kept_section.
	(elf_kept_section): New.

	* elflink.c (match_group_member): Correctly iterate group
	members.
	(_bfd_elf_check_kept_section): Cache the result in
	elf_kept_section.

--- bfd/elf-bfd.h.kept	2006-03-16 12:37:42.000000000 -0800
+++ bfd/elf-bfd.h	2006-04-24 20:11:00.000000000 -0700
@@ -1168,6 +1168,10 @@ struct bfd_elf_section_data
      the linker.  */
   asection *next_in_group;
 
+  /* The pointer to the real kept section. It is computed from the
+     kept_section field in asection due to section group.  */ 
+  asection *kept_section;
+
   /* A pointer used for various section optimizations.  */
   void *sec_info;
 };
@@ -1180,6 +1184,7 @@ struct bfd_elf_section_data
 #define elf_group_id(sec)      (elf_section_data(sec)->group.id)
 #define elf_next_in_group(sec) (elf_section_data(sec)->next_in_group)
 #define elf_sec_group(sec)	(elf_section_data(sec)->sec_group)
+#define elf_kept_section(sec) (elf_section_data(sec)->kept_section)
 
 /* Return TRUE if section has been discarded.  */
 #define elf_discarded_section(sec)				\
--- bfd/elflink.c.kept	2006-04-24 15:36:18.000000000 -0700
+++ bfd/elflink.c	2006-04-24 20:18:03.000000000 -0700
@@ -6782,6 +6782,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;
     }
@@ -6798,7 +6799,14 @@ _bfd_elf_check_kept_section (asection *s
 {
   asection *kept;
 
+  kept = elf_kept_section (sec);
+  if (kept)
+    return kept;
+
   kept = sec->kept_section;
+  if (!kept)
+    return kept;
+
   if (kept != NULL)
     {
       if (elf_sec_group (sec) != NULL)
@@ -6806,6 +6814,12 @@ _bfd_elf_check_kept_section (asection *s
       if (kept != NULL && sec->size != kept->size)
 	kept = NULL;
     }
+
+  if (kept)
+    elf_kept_section (sec) = kept;
+  else
+    sec->kept_section = NULL;
+
   return kept;
 }
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-04-25  3:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-24 20:12 PATCH: PR ld/2342: linkonce debug is broken H. J. Lu
2006-04-25 15:47 ` PATCH: Cache the result of _bfd_elf_check_kept_section H. J. Lu
2006-04-25 16:11   ` H. J. Lu
2006-04-25 16:37     ` H. J. Lu

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).