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]

PR ld/3107


On Fri, Sep 15, 2006 at 11:01:25PM +0930, Alan Modra wrote:
> On Fri, Sep 15, 2006 at 09:48:58AM -0000, nickc@sourceware.org wrote:
> > Log message:
> > 	PR ld/3107
> > 	* ldlang.c (lang_size_sections_1): Do not abort when encountering a non-empty
> > 	section that is ignored.  Instead produce a warning message.
> 
> Eh?  Something is fishy here

I believe this is how arm should handle its glue sections.  (Or at
least, this is a minimal change.)  There were two bugs leading to
PR ld/3107:  The most serious one (I think I introduced with the initial
attempt at stripping unused sections) was to run the standard
ELF linker before_allocation function too early, before
bfd_elf32_arm_process_before_allocation had a chance to size the glue
sections.  The other was that record_arm_to_thumb_glue and
record_thumb_to_arm_glue were not updating the actual glue section sizes.
Even if the glue section sizes were calculated early enough the
generic linker saw them as being zero size at the time empty sections
were stripped.  This meant their output section could be marked
"ignored", but later found to not in fact be empty.

bfd/
	* elf32-arm.c (bfd_elf32_arm_allocate_interworking_sect): Check,
	don't set, glue section size.
	(record_arm_to_thumb_glue): Set glue section size here.
	(record_thumb_to_arm_glue): Likewise.
	(bfd_elf32_arm_add_glue_sections_to_bfd): Formatting.
	(bfd_elf32_arm_process_before_allocation): Ignore exluded sections.

ld/
	* emultempl/armelf.em (arm_elf_before_allocation): Run
	gld${EMULATION_NAME}_before_allocation later.
	* ldlang.c (lang_size_sections_1): Revert 2006-09-15 change.

OK?

Index: bfd/elf32-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.c,v
retrieving revision 1.93
diff -u -p -r1.93 elf32-arm.c
--- bfd/elf32-arm.c	17 Oct 2006 13:41:47 -0000	1.93
+++ bfd/elf32-arm.c	17 Oct 2006 14:56:14 -0000
@@ -2566,7 +2566,7 @@ bfd_elf32_arm_allocate_interworking_sect
 
       foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size);
 
-      s->size = globals->arm_glue_size;
+      BFD_ASSERT (s->size == globals->arm_glue_size);
       s->contents = foo;
     }
 
@@ -2581,7 +2581,7 @@ bfd_elf32_arm_allocate_interworking_sect
 
       foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size);
 
-      s->size = globals->thumb_glue_size;
+      BFD_ASSERT (s->size == globals->thumb_glue_size);
       s->contents = foo;
     }
 
@@ -2601,6 +2601,7 @@ record_arm_to_thumb_glue (struct bfd_lin
   struct bfd_link_hash_entry * bh;
   struct elf32_arm_link_hash_table * globals;
   bfd_vma val;
+  bfd_size_type size;
 
   globals = elf32_arm_hash_table (link_info);
 
@@ -2644,9 +2645,12 @@ record_arm_to_thumb_glue (struct bfd_lin
   free (tmp_name);
 
   if ((link_info->shared || globals->root.is_relocatable_executable))
-    globals->arm_glue_size += ARM2THUMB_PIC_GLUE_SIZE;
+    size = ARM2THUMB_PIC_GLUE_SIZE;
   else
-    globals->arm_glue_size += ARM2THUMB_STATIC_GLUE_SIZE;
+    size = ARM2THUMB_STATIC_GLUE_SIZE;
+
+  s->size += size;
+  globals->arm_glue_size += size;
 
   return myh;
 }
@@ -2722,6 +2726,7 @@ record_thumb_to_arm_glue (struct bfd_lin
 
   free (tmp_name);
 
+  s->size += THUMB2ARM_GLUE_SIZE;
   hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
 
   return;
@@ -2749,7 +2754,8 @@ bfd_elf32_arm_add_glue_sections_to_bfd (
       /* Note: we do not include the flag SEC_LINKER_CREATED, as this
 	 will prevent elf_link_input_bfd() from processing the contents
 	 of this section.  */
-      flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY;
+      flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
+	       | SEC_CODE | SEC_READONLY);
 
       sec = bfd_make_section_with_flags (abfd,
 					 ARM2THUMB_GLUE_SECTION_NAME,
@@ -2768,8 +2774,8 @@ bfd_elf32_arm_add_glue_sections_to_bfd (
 
   if (sec == NULL)
     {
-      flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
-	| SEC_CODE | SEC_READONLY;
+      flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
+	       | SEC_CODE | SEC_READONLY);
 
       sec = bfd_make_section_with_flags (abfd,
 					 THUMB2ARM_GLUE_SECTION_NAME,
@@ -2866,6 +2872,9 @@ bfd_elf32_arm_process_before_allocation 
       if (sec->reloc_count == 0)
 	continue;
 
+      if ((sec->flags & SEC_EXCLUDE) != 0)
+	continue;
+
       symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
 
       /* Load the relocs.  */
Index: ld/emultempl/armelf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/armelf.em,v
retrieving revision 1.50
diff -u -p -r1.50 armelf.em
--- ld/emultempl/armelf.em	18 Aug 2006 15:00:18 -0000	1.50
+++ ld/emultempl/armelf.em	17 Oct 2006 14:59:50 -0000
@@ -123,9 +123,6 @@ arm_elf_before_allocation (void)
     }
   /* We should be able to set the size of the interworking stub section.  */
 
-  /* Call the standard elf routine.  */
-  gld${EMULATION_NAME}_before_allocation ();
-
   /* Here we rummage through the found bfds to collect glue information.  */
   /* FIXME: should this be based on a command line option? krk@cygnus.com  */
   {
@@ -140,6 +137,9 @@ arm_elf_before_allocation (void)
       }
   }
 
+  /* Call the standard elf routine.  */
+  gld${EMULATION_NAME}_before_allocation ();
+
   /* We have seen it all. Allocate it, and carry on.  */
   bfd_elf32_arm_allocate_interworking_sections (& link_info);
 }
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.242
diff -u -p -r1.242 ldlang.c
--- ld/ldlang.c	17 Oct 2006 13:41:48 -0000	1.242
+++ ld/ldlang.c	17 Oct 2006 15:20:22 -0000
@@ -4368,18 +4368,7 @@ lang_size_sections_1
 	    os->processed_vma = TRUE;
 
 	    if (bfd_is_abs_section (os->bfd_section) || os->ignored)
-	      {
-		if (os->bfd_section->size > 0)
-		  {
-		    /* PR ld/3107:  Do not abort when a buggy linker script
-		       causes a non-empty section to be discarded.  */
-		    if (bfd_is_abs_section (os->bfd_section))
-		      einfo (_("%P%X: internal error: attempting to take the size of the non-section *ABS*\n"));
-		    else
-		      einfo (_("%P: warning: discarding non-empty, well known section %A\n"),
-			     os->bfd_section);
-		  }
-	      }
+	      ASSERT (os->bfd_section->size == 0);
 	    else
 	      {
 		dot = os->bfd_section->vma;

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


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