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

Removing empty sections


See http://sources.redhat.com/bugzilla/show_bug.cgi?id=797

ld/
	* scripttempt/elf.sc (.bss): Align tail in a way that allows
	empty section pruning.
ld/testsuite/
	* ld-scripts/empty-aligned.t: Adjust alignment expressions so
	that no .text? section is kept.  Also check setting vma and
	lma.
	* ld-scripts/empty-aligned.d: Update.

Index: ld/scripttempl/elf.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/elf.sc,v
retrieving revision 1.58
diff -u -p -r1.58 elf.sc
--- ld/scripttempl/elf.sc	29 May 2005 23:16:09 -0000	1.58
+++ ld/scripttempl/elf.sc	10 Jun 2005 00:29:49 -0000
@@ -398,7 +398,7 @@ cat <<EOF
    /* Align here to ensure that the .bss section occupies space up to
       _end.  Align after .bss to ensure correct alignment even if the
       .bss section disappears because there are no input sections.  */
-   ${RELOCATING+. = ALIGN(${ALIGNMENT});}
+   ${RELOCATING+. = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
   }
   ${OTHER_BSS_SECTIONS}
   ${RELOCATING+. = ALIGN(${ALIGNMENT});}
Index: ld/testsuite/ld-scripts/empty-aligned.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-scripts/empty-aligned.d,v
retrieving revision 1.2
diff -u -p -r1.2 empty-aligned.d
--- ld/testsuite/ld-scripts/empty-aligned.d	9 Jun 2005 02:06:58 -0000	1.2
+++ ld/testsuite/ld-scripts/empty-aligned.d	10 Jun 2005 00:29:49 -0000
@@ -6,9 +6,7 @@
 Program Headers:
  +Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg +Align
  +LOAD +0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ [RWE ]+ +0x[0-9a-f]+
- +LOAD +0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ 0x[0-9a-f]+ [RWE ]+ +0x[0-9a-f]+
 
  Section to Segment mapping:
  +Segment Sections\.\.\.
- +00.*\.text.*\.text2.*
- +01.*.data.*
+ +00.*\.text.*\.data.*
Index: ld/testsuite/ld-scripts/empty-aligned.t
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-scripts/empty-aligned.t,v
retrieving revision 1.1
diff -u -p -r1.1 empty-aligned.t
--- ld/testsuite/ld-scripts/empty-aligned.t	17 May 2005 16:42:54 -0000	1.1
+++ ld/testsuite/ld-scripts/empty-aligned.t	10 Jun 2005 00:29:49 -0000
@@ -1,15 +1,29 @@
 SECTIONS
 {
   .text : { *(.text) }
-  .text2 :
+  /* Alignment at beginning shouldn't result in empty section being kept.  */
+  .text1 ALIGN (4096) :
   {
-    . = ALIGN(4096);
-    *(.text2)
+    *(.text1)
   }
-  .text3 :
+  /* Same for alignment at beginning and end.  */
+  .text2 ALIGN (4096) :
   {
-    *(.text3)
-    . = ALIGN(4096);
+    *(.text2)
+    . = ALIGN (4096);
+  }
+  /* Same for alignment just at end, although we need to be careful in
+     the expression used to align.  */
+  .text3 :
+  {
+    *(.text3)
+    . = ALIGN (. != 0 ? 4096 : 1);
+  }
+  /* Same when setting vma and lma.  This also shouldn't result in
+     .text3 being kept.  */
+  .text4 ADDR (.text3) + SIZEOF (.text3) + 8192 : AT (LOADADDR (.text3))
+  {
+    *(.text4)
   }
   .data : { *(.data) }
   .bss : { *(.bss) }

-- 
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]