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]

[PATCH,trunk+2.20.1] Extend COFF .section directive syntax to specify alignment.


    Hi gang,

  I propose to apply this patch on HEAD, after the usual day or two for
comments.  And unusual though it is to add new features on the release branch,
I'd like to ask permission to backport it there as well, the reason being that
it's going to be needed in order to be able to support LTO in GCC, and it
seems a long time to wait for the next major release.  If you look at the
code, you'll see it's tiny and pretty low risk, as none of it kicks in unless
you try and use a new syntax that would previously not have been valid.

  There's currently no way to specify the alignment of a section in the
assembler; it can only be done using the linker at present.  The underlying
COFF code in BFD does, however, have a default section alignment, and that is
what gets applied to all sections emitted in the assembler.  The attached
patch provides a trivial way to override this default section alignment by
supplying a power-of-two as a single ascii decimal digit in the section flags.

gas/ChangeLog:

	* NEWS: Mention new feature.
	* config/obj-coff.c (obj_coff_section): Accept digits and use
	to override default section alignment power if specified.
	* doc/as.texinfo (.section directive): Update documentation.

gas/testsuite/ChangeLog:

	* gas/pe/section-align-1.s: New test source file.
	* gas/pe/section-align-1.d: Likewise control script.
	* gas/pe/section-align-2.s: Likewise ...
	* gas/pe/section-align-2.d: ... and likewise.
	* gas/pe/pe.exp: Invoke new testcases.

  Tested on i686-pc-cygwin and cross to x86_64-w64-mingw32 with no regressions
and the new tests passing.

- Any comments before I apply on HEAD?

- Ok for the branch?

    cheers,
      DaveK

Index: gas/NEWS
===================================================================
RCS file: /cvs/src/src/gas/NEWS,v
retrieving revision 1.111
diff -p -u -r1.111 NEWS
--- gas/NEWS	29 Sep 2009 14:17:06 -0000	1.111
+++ gas/NEWS	17 Jan 2010 14:45:15 -0000
@@ -4,6 +4,9 @@
 
 Changes in 2.20:
 
+* GAS now understands an extended syntax in the .section directive flags
+  for COFF targets that allows the section's alignment to be specified.
+
 * GNU/Linux targets now supports "gnu_unique_object" as a value in the .type
   pseudo op.  It marks the symbol as being globally unique in the entire
   process.
Index: gas/config/obj-coff.c
===================================================================
RCS file: /cvs/src/src/gas/config/obj-coff.c,v
retrieving revision 1.103
diff -p -u -r1.103 obj-coff.c
--- gas/config/obj-coff.c	11 Dec 2009 13:42:10 -0000	1.103
+++ gas/config/obj-coff.c	17 Jan 2010 14:45:15 -0000
@@ -23,6 +23,7 @@
 #define OBJ_HEADER "obj-coff.h"
 
 #include "as.h"
+#include "safe-ctype.h"
 #include "obstack.h"
 #include "subsegs.h"
 
@@ -1540,6 +1541,7 @@ coff_frob_file_after_relocs (void)
   						 'r' for read-only data
   						 's' for shared data (PE)
 						 'y' for noread
+					   '0' - '9' for power-of-two alignment (GNU extension).
    But if the argument is not a quoted string, treat it as a
    subsegment number.
 
@@ -1551,7 +1553,7 @@ obj_coff_section (int ignore ATTRIBUTE_U
 {
   /* Strip out the section name.  */
   char *section_name;
-  char c;
+  char c, alignment = -1;
   char *name;
   unsigned int exp;
   flagword flags, oldflags;
@@ -1594,6 +1596,11 @@ obj_coff_section (int ignore ATTRIBUTE_U
 		 attr != '"'
 		 && ! is_end_of_line[attr])
 	    {
+	      if (ISDIGIT (attr))
+		{
+		  alignment = attr - '0';
+		  continue;
+		}
 	      switch (attr)
 		{
 		case 'b':
@@ -1670,6 +1677,8 @@ obj_coff_section (int ignore ATTRIBUTE_U
     }
 
   sec = subseg_new (name, (subsegT) exp);
+  if (alignment >= 0)
+    sec->alignment_power = alignment;
 
   oldflags = bfd_get_section_flags (stdoutput, sec);
   if (oldflags == SEC_NO_FLAGS)
Index: gas/doc/as.texinfo
===================================================================
RCS file: /cvs/src/src/gas/doc/as.texinfo,v
retrieving revision 1.214
diff -p -u -r1.214 as.texinfo
--- gas/doc/as.texinfo	29 Oct 2009 00:19:19 -0000	1.214
+++ gas/doc/as.texinfo	17 Jan 2010 14:45:17 -0000
@@ -5768,6 +5768,8 @@ shared section (meaningful for PE target
 ignored.  (For compatibility with the ELF version)
 @item y
 section is not readable (meaningful for PE targets)
+@item 0-9
+single-digit power-of-two section alignment (GNU extension)
 @end table
 
 If no flags are specified, the default flags depend upon the section name.  If
Index: gas/testsuite/gas/pe/pe.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/pe/pe.exp,v
retrieving revision 1.1
diff -p -u -r1.1 pe.exp
--- gas/testsuite/gas/pe/pe.exp	19 May 2009 16:08:07 -0000	1.1
+++ gas/testsuite/gas/pe/pe.exp	17 Jan 2010 14:45:17 -0000
@@ -32,3 +32,6 @@ run_dump_test "aligncomm-a"
 run_dump_test "aligncomm-b"
 run_dump_test "aligncomm-c"
 run_dump_test "aligncomm-d"
+
+run_dump_test "section-align-1"
+run_dump_test "section-align-3"
Index: gas/testsuite/gas/pe/section-align-1.d
===================================================================
RCS file: gas/testsuite/gas/pe/section-align-1.d
diff -N gas/testsuite/gas/pe/section-align-1.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gas/testsuite/gas/pe/section-align-1.d	17 Jan 2010 14:45:17 -0000
@@ -0,0 +1,29 @@
+#objdump: -h
+#name: section alignment
+
+# Test that alignment works in .section directives.
+
+.*: .*
+
+Sections:
+Idx Name          *Size      *VMA       *LMA       *File off  *Algn
+  0 \.text         0*0000000  0*0000000  0*0000000  0*0000000  2\*\*[24]
+                  ALLOC, LOAD, READONLY, CODE
+  1 \.data         0*0000000  0*0000000  0*0000000  0*0000000  2\*\*[24]
+                  ALLOC, LOAD, DATA
+  2 \.bss          0*0000000  0*0000000  0*0000000  0*0000000  2\*\*[24]
+                  ALLOC
+  3 \.none         0*0000000  0*0000000  0*0000000  0*0000000  2\*\*0
+                  ALLOC, LOAD, READONLY, DATA
+  4 \.zero         0*0000000  0*0000000  0*0000000  0*0000000  2\*\*0
+                  ALLOC, LOAD, READONLY, DATA
+  5 \.one          0*0000001  0*0000000  0*0000000  0*00001a4  2\*\*0
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
+  6 \.two          0*0000002  0*0000000  0*0000000  0*00001a5  2\*\*0
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
+  7 \.three        0*0000003  0*0000000  0*0000000  0*00001a7  2\*\*0
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
+  8 \.four         0*0000004  0*0000000  0*0000000  0*00001aa  2\*\*0
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
+  9 \.five         0*0000005  0*0000000  0*0000000  0*00001ae  2\*\*0
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
Index: gas/testsuite/gas/pe/section-align-1.s
===================================================================
RCS file: gas/testsuite/gas/pe/section-align-1.s
diff -N gas/testsuite/gas/pe/section-align-1.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gas/testsuite/gas/pe/section-align-1.s	17 Jan 2010 14:45:17 -0000
@@ -0,0 +1,15 @@
+
+	.section	.none,"dr0"
+	.section	.zero,"dr0"
+	.ascii	""
+	.section	.one,"dr0"
+	.ascii	"1"
+	.section	.two,"dr0"
+	.ascii	"12"
+	.section	.three,"dr0"
+	.ascii	"123"
+	.section	.four,"dr0"
+	.ascii	"1234"
+	.section	.five,"dr0"
+	.ascii	"12345"
+	.end
Index: gas/testsuite/gas/pe/section-align-3.d
===================================================================
RCS file: gas/testsuite/gas/pe/section-align-3.d
diff -N gas/testsuite/gas/pe/section-align-3.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gas/testsuite/gas/pe/section-align-3.d	17 Jan 2010 14:45:17 -0000
@@ -0,0 +1,39 @@
+#objdump: -h
+#name: section alignment
+
+# Test that alignment works in .section directives.
+
+.*: .*
+
+Sections:
+Idx Name          *Size      *VMA       *LMA       *File off  *Algn
+  0 \.text         0*0000000  0*0000000  0*0000000  0*0000000  2\*\*[24]
+                  ALLOC, LOAD, READONLY, CODE
+  1 \.data         0*0000000  0*0000000  0*0000000  0*0000000  2\*\*[24]
+                  ALLOC, LOAD, DATA
+  2 \.bss          0*0000000  0*0000000  0*0000000  0*0000000  2\*\*[24]
+                  ALLOC
+  3 \.none         0*0000000  0*0000000  0*0000000  0*0000000  2\*\*3
+                  ALLOC, LOAD, READONLY, DATA
+  4 \.zero         0*0000000  0*0000000  0*0000000  0*0000000  2\*\*3
+                  ALLOC, LOAD, READONLY, DATA
+  5 \.one          0*0000008  0*0000000  0*0000000  0*000026c  2\*\*3
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
+  6 \.two          0*0000008  0*0000000  0*0000000  0*0000274  2\*\*3
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
+  7 \.three        0*0000008  0*0000000  0*0000000  0*000027c  2\*\*3
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
+  8 \.four         0*0000008  0*0000000  0*0000000  0*0000284  2\*\*3
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
+  9 \.five         0*0000008  0*0000000  0*0000000  0*000028c  2\*\*3
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
+ 10 \.six          0*0000008  0*0000000  0*0000000  0*0000294  2\*\*3
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
+ 11 \.seven        0*0000008  0*0000000  0*0000000  0*000029c  2\*\*3
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
+ 12 \.eight        0*0000008  0*0000000  0*0000000  0*00002a4  2\*\*3
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
+ 13 \.nine         0*0000010  0*0000000  0*0000000  0*00002ac  2\*\*3
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
+ 14 \.ten          0*0000010  0*0000000  0*0000000  0*00002bc  2\*\*3
+                  CONTENTS, ALLOC, LOAD, READONLY, DATA
Index: gas/testsuite/gas/pe/section-align-3.s
===================================================================
RCS file: gas/testsuite/gas/pe/section-align-3.s
diff -N gas/testsuite/gas/pe/section-align-3.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gas/testsuite/gas/pe/section-align-3.s	17 Jan 2010 14:45:17 -0000
@@ -0,0 +1,25 @@
+
+	.section	.none,"dr3"
+	.section	.zero,"dr3"
+	.ascii	""
+	.section	.one,"dr3"
+	.ascii	"1"
+	.section	.two,"dr3"
+	.ascii	"12"
+	.section	.three,"dr3"
+	.ascii	"123"
+	.section	.four,"dr3"
+	.ascii	"1234"
+	.section	.five,"dr3"
+	.ascii	"12345"
+	.section	.six,"dr3"
+	.ascii	"123456"
+	.section	.seven,"dr3"
+	.ascii	"1234567"
+	.section	.eight,"dr3"
+	.ascii	"12345678"
+	.section	.nine,"dr3"
+	.ascii	"123456789"
+	.section	.ten,"dr3"
+	.ascii	"1234567890"
+	.end

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