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: Linker relaxation and SEC_EXCLUDE issue.


On Thu, Oct 25, 2012 at 11:10:34AM +0100, Andrew Burgess wrote:
> However, if we have linker relaxation turned on then it is possible that
> section 'A' might shrink (or maybe even grow, do any 'relaxation' passes 
> grow sections?), in any case, if 'A' changes size then as we loop round
> in ldlang.c:lang_relax_sections the ALIGN statement in 'B' now needs to
> come into play to provide the required alignment; section 'B' is no longer
> empty, and so having is marked SEC_EXCLUDE is incorrect.

Yes, some relax passes grow sections.  elf32-ppc.c:ppc_elf_relax_section
is an example.  I don't think we can fix your align in an otherwise
empty section testcase.  Empty output sections need to be removed
(or at least the decision made to remove them) before the linker emits
dynamic symbols for output sections.

> The funny side of this bug is the result, as we perform linker relaxation 
> we *set* the size of the output section based on the input sections, and we
> *increase* the size of the output section to add any required padding if we
> see an ALIGN statement.  However, the code in ldlang.c:size_input_section
> that sets the size of the output section is not hit if the output section
> is marked as SEC_EXCLUDE, the result is the size of the output section is
> not reset each time round the linker relaxation loop, and as the ALIGN is
> now adding some padding, out section 'B' continues to grow for each linker
> relaxation pass; this in turn pushes output section 'C' to higher and higher
> addresses.

This will be a bug in insert_pad.

	* ldlang.c (insert_pad): Correct output section size calculation.
	(lang_size_sections_1): Likewise for lang_data_statement and
	lang_reloc_statement.

Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.400
diff -u -p -r1.400 ldlang.c
--- ld/ldlang.c	6 Aug 2012 22:27:52 -0000	1.400
+++ ld/ldlang.c	1 Nov 2012 04:07:30 -0000
@@ -4594,7 +4594,8 @@ insert_pad (lang_statement_union_type **
     }
   pad->padding_statement.output_offset = dot - output_section->vma;
   pad->padding_statement.size = alignment_needed;
-  output_section->size += alignment_needed;
+  output_section->size = TO_SIZE (dot + TO_ADDR (alignment_needed)
+				  - output_section->vma);
 }
 
 /* Work out how much this section will move the dot point.  */
@@ -5159,7 +5160,9 @@ lang_size_sections_1
 	    if (size < TO_SIZE ((unsigned) 1))
 	      size = TO_SIZE ((unsigned) 1);
 	    dot += TO_ADDR (size);
-	    output_section_statement->bfd_section->size += size;
+	    output_section_statement->bfd_section->size
+	      = TO_SIZE (dot - output_section_statement->bfd_section->vma);
+
 	  }
 	  break;
 
@@ -5173,7 +5176,8 @@ lang_size_sections_1
 	      output_section_statement->bfd_section;
 	    size = bfd_get_reloc_size (s->reloc_statement.howto);
 	    dot += TO_ADDR (size);
-	    output_section_statement->bfd_section->size += size;
+	    output_section_statement->bfd_section->size
+	      = TO_SIZE (dot - output_section_statement->bfd_section->vma);
 	  }
 	  break;
 
-- 
Alan Modra
Australia Development Lab, IBM


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