public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PATCH: Support IMAGE_SCN_ALIGN_XXXXBYTES
@ 2007-07-26 22:17 H.J. Lu
  2007-08-01 17:12 ` Nick Clifton
  0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2007-07-26 22:17 UTC (permalink / raw)
  To: binutils; +Cc: cgf

This patch supports IMAGE_SCN_ALIGN_XXXXBYTES. OK to install?

Thanks.

H.J.
----
bfd/

2007-07-26  H.J. Lu  <hongjiu.lu@intel.com>

	* coffcode.h (ALIGN_SET): Removed.
	(ELIFALIGN_SET): Likewise.
	(coff_set_alignment_hook): Handle IMAGE_SCN_ALIGN_128BYTES,
	IMAGE_SCN_ALIGN_256BYTES, IMAGE_SCN_ALIGN_512BYTES,
	IMAGE_SCN_ALIGN_1024BYTES, IMAGE_SCN_ALIGN_2048BYTES,
	IMAGE_SCN_ALIGN_4096BYTES and IMAGE_SCN_ALIGN_8192BYTES.

include/coff/

2007-07-26  H.J. Lu  <hongjiu.lu@intel.com>

	* pe.h (IMAGE_SCN_ALIGN_128BYTES): New.
	(IMAGE_SCN_ALIGN_256BYTES): Likewise.
	(IMAGE_SCN_ALIGN_512BYTES): Likewise.
	(IMAGE_SCN_ALIGN_1024BYTES): Likewise.
	(IMAGE_SCN_ALIGN_2048BYTES): Likewise.
	(IMAGE_SCN_ALIGN_4096BYTES): Likewise.
	(IMAGE_SCN_ALIGN_8192BYTES): Likewise.

--- binutils/bfd/coffcode.h.align	2007-07-25 14:34:19.000000000 -0700
+++ binutils/bfd/coffcode.h	2007-07-26 14:01:29.000000000 -0700
@@ -1627,19 +1627,6 @@ coff_set_alignment_hook (bfd * abfd ATTR
 #else /* ! COFF_ALIGN_IN_SECTION_HEADER */
 #ifdef COFF_WITH_PE
 
-/* A couple of macros to help setting the alignment power field.  */
-#define ALIGN_SET(field, x, y) \
-  if (((field) & IMAGE_SCN_ALIGN_64BYTES) == x)\
-    {\
-      section->alignment_power = y;\
-    }
-
-#define ELIFALIGN_SET(field, x, y) \
-  else if (((field) & IMAGE_SCN_ALIGN_64BYTES) == x) \
-    {\
-      section->alignment_power = y;\
-    }
-
 static void
 coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED,
 			 asection * section,
@@ -1647,14 +1634,29 @@ coff_set_alignment_hook (bfd * abfd ATTR
 {
   struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
   bfd_size_type amt;
+  unsigned int alignment_power = hdr->s_flags & 0x00f00000;
 
-  ALIGN_SET     (hdr->s_flags, IMAGE_SCN_ALIGN_64BYTES, 6)
-  ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_32BYTES, 5)
-  ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_16BYTES, 4)
-  ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_8BYTES,  3)
-  ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_4BYTES,  2)
-  ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_2BYTES,  1)
-  ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_1BYTES,  0)
+  switch (alignment_power)
+    {
+    case IMAGE_SCN_ALIGN_8192BYTES:
+    case IMAGE_SCN_ALIGN_4096BYTES:
+    case IMAGE_SCN_ALIGN_2048BYTES:
+    case IMAGE_SCN_ALIGN_1024BYTES:
+    case IMAGE_SCN_ALIGN_512BYTES:
+    case IMAGE_SCN_ALIGN_256BYTES:
+    case IMAGE_SCN_ALIGN_128BYTES:
+    case IMAGE_SCN_ALIGN_64BYTES:
+    case IMAGE_SCN_ALIGN_32BYTES:
+    case IMAGE_SCN_ALIGN_16BYTES:
+    case IMAGE_SCN_ALIGN_8BYTES:
+    case IMAGE_SCN_ALIGN_4BYTES:
+    case IMAGE_SCN_ALIGN_2BYTES:
+    case IMAGE_SCN_ALIGN_1BYTES:
+      section->alignment_power = (alignment_power >> 20) - 1;
+      break;
+    default:
+      break;
+    }
 
   /* In a PE image file, the s_paddr field holds the virtual size of a
      section, while the s_size field holds the raw size.  We also keep
--- binutils/include/coff/pe.h.align	2007-07-24 14:01:56.000000000 -0700
+++ binutils/include/coff/pe.h	2007-07-25 15:02:42.000000000 -0700
@@ -73,6 +73,13 @@
 #define IMAGE_SCN_ALIGN_16BYTES              0x00500000  /* Default alignment if no others are specified. */
 #define IMAGE_SCN_ALIGN_32BYTES              0x00600000
 #define IMAGE_SCN_ALIGN_64BYTES              0x00700000
+#define IMAGE_SCN_ALIGN_128BYTES             0x00800000
+#define IMAGE_SCN_ALIGN_256BYTES             0x00900000
+#define IMAGE_SCN_ALIGN_512BYTES             0x00a00000
+#define IMAGE_SCN_ALIGN_1024BYTES            0x00b00000
+#define IMAGE_SCN_ALIGN_2048BYTES            0x00c00000
+#define IMAGE_SCN_ALIGN_4096BYTES            0x00d00000
+#define IMAGE_SCN_ALIGN_8192BYTES            0x00e00000
 
 #define IMAGE_SCN_LNK_NRELOC_OVFL            0x01000000  /* Section contains extended relocations. */
 #define IMAGE_SCN_MEM_NOT_CACHED             0x04000000  /* Section is not cachable.               */

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

* Re: PATCH: Support IMAGE_SCN_ALIGN_XXXXBYTES
  2007-07-26 22:17 PATCH: Support IMAGE_SCN_ALIGN_XXXXBYTES H.J. Lu
@ 2007-08-01 17:12 ` Nick Clifton
  2007-08-01 23:19   ` H.J. Lu
  0 siblings, 1 reply; 4+ messages in thread
From: Nick Clifton @ 2007-08-01 17:12 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils, cgf

Hi H.J.

> This patch supports IMAGE_SCN_ALIGN_XXXXBYTES. OK to install?

Not quite...

> +    case IMAGE_SCN_ALIGN_4BYTES:
> +    case IMAGE_SCN_ALIGN_2BYTES:
> +    case IMAGE_SCN_ALIGN_1BYTES:
> +      section->alignment_power = (alignment_power >> 20) - 1;

I like this, but I do not like the presence of the magic number 20.
I think that using a macro would be better. eg:

    section->alignment_power = IMAGE_SCN_ALIGN_NUMBER (alignment_power) - 1;

And then in pe.h....

    /* Bit position in the s_flags field where the alignment values start.  */
    #define IMAGE_SCN_ALIGN_BIT_POS       20
    #define IMAGE_SCN_ALIGN_NUMBER(val)   ((val) >> IMAGE_SCN_ALIGN_BIT_POS)
    #define IMAGE_SCN_ALIGN_CONSTANT(val) ((val) << IMAGE_SCN_ALIGN_BIT_POS)

    #define IMAGE_SCN_ALIGN_1BYTES IMAGE_SCN_ALIGN_CONSTANT(1)
    #define IMAGE_SCN_ALIGN_2BYTES IMAGE_SCN_ALIGN_CONSTANT(2)
    ...
    #define IMAGE_SCN_ALIGN_8129BYTES IMAGE_SCN_ALIGN_CONSTANT(15)

Cheers
   Nick



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

* Re: PATCH: Support IMAGE_SCN_ALIGN_XXXXBYTES
  2007-08-01 17:12 ` Nick Clifton
@ 2007-08-01 23:19   ` H.J. Lu
  2007-08-02 15:16     ` Nick Clifton
  0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2007-08-01 23:19 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils, cgf

On Wed, Aug 01, 2007 at 06:12:09PM +0100, Nick Clifton wrote:
> Hi H.J.
> 
> >This patch supports IMAGE_SCN_ALIGN_XXXXBYTES. OK to install?
> 
> Not quite...
> 
> >+    case IMAGE_SCN_ALIGN_4BYTES:
> >+    case IMAGE_SCN_ALIGN_2BYTES:
> >+    case IMAGE_SCN_ALIGN_1BYTES:
> >+      section->alignment_power = (alignment_power >> 20) - 1;
> 
> I like this, but I do not like the presence of the magic number 20.
> I think that using a macro would be better. eg:
> 
>    section->alignment_power = IMAGE_SCN_ALIGN_NUMBER (alignment_power) - 1;
> 
> And then in pe.h....
> 
>    /* Bit position in the s_flags field where the alignment values start.  
>    */
>    #define IMAGE_SCN_ALIGN_BIT_POS       20
>    #define IMAGE_SCN_ALIGN_NUMBER(val)   ((val) >> IMAGE_SCN_ALIGN_BIT_POS)
>    #define IMAGE_SCN_ALIGN_CONSTANT(val) ((val) << IMAGE_SCN_ALIGN_BIT_POS)
> 
>    #define IMAGE_SCN_ALIGN_1BYTES IMAGE_SCN_ALIGN_CONSTANT(1)
>    #define IMAGE_SCN_ALIGN_2BYTES IMAGE_SCN_ALIGN_CONSTANT(2)
>    ...
>    #define IMAGE_SCN_ALIGN_8129BYTES IMAGE_SCN_ALIGN_CONSTANT(15)
> 
> Cheers
>   Nick
> 

#define IMAGE_SCN_ALIGN_1BYTES IMAGE_SCN_ALIGN_CONSTANT(1)

doesn't make senses since 2**1 is 2. Here is the updated patch.
I used

#define IMAGE_SCN_ALIGN_1BYTES IMAGE_SCN_ALIGN_POWER_CONST (0)

since 2**0 is 1.  OK to install?


H.J.
----
bfd/

2007-08-01  H.J. Lu  <hongjiu.lu@intel.com>

	* coffcode.h (ALIGN_SET): Removed.
	(ELIFALIGN_SET): Likewise.
	(coff_set_alignment_hook): Handle IMAGE_SCN_ALIGN_128BYTES,
	IMAGE_SCN_ALIGN_256BYTES, IMAGE_SCN_ALIGN_512BYTES,
	IMAGE_SCN_ALIGN_1024BYTES, IMAGE_SCN_ALIGN_2048BYTES,
	IMAGE_SCN_ALIGN_4096BYTES and IMAGE_SCN_ALIGN_8192BYTES.

include/coff/

2007-08-01  H.J. Lu  <hongjiu.lu@intel.com>

	* pe.h (IMAGE_SCN_ALIGN_POWER_BIT_POS): New.
	(IMAGE_SCN_ALIGN_POWER_BIT_MASK): Likewise.
	(IMAGE_SCN_ALIGN_POWER_NUM): Likewise.
	(IMAGE_SCN_ALIGN_POWER_CONST): Likewise.
	(IMAGE_SCN_ALIGN_128BYTES): Likewise.
	(IMAGE_SCN_ALIGN_256BYTES): Likewise.
	(IMAGE_SCN_ALIGN_512BYTES): Likewise.
	(IMAGE_SCN_ALIGN_1024BYTES): Likewise.
	(IMAGE_SCN_ALIGN_2048BYTES): Likewise.
	(IMAGE_SCN_ALIGN_4096BYTES): Likewise.
	(IMAGE_SCN_ALIGN_8192BYTES): Likewise.
	(IMAGE_SCN_ALIGN_1BYTES): Redefined with
	IMAGE_SCN_ALIGN_POWER_CONST.
	(IMAGE_SCN_ALIGN_2BYTES): Likewise.
	(IMAGE_SCN_ALIGN_4BYTES): Likewise.
	(IMAGE_SCN_ALIGN_8BYTES): Likewise.
	(IMAGE_SCN_ALIGN_16BYTES): Likewise.
	(IMAGE_SCN_ALIGN_32BYTES): Likewise.
	(IMAGE_SCN_ALIGN_64BYTES): Likewise.

--- binutils/bfd/coffcode.h.align	2007-08-01 11:12:53.000000000 -0700
+++ binutils/bfd/coffcode.h	2007-08-01 16:04:27.000000000 -0700
@@ -1628,19 +1628,6 @@ coff_set_alignment_hook (bfd * abfd ATTR
 #else /* ! COFF_ALIGN_IN_SECTION_HEADER */
 #ifdef COFF_WITH_PE
 
-/* A couple of macros to help setting the alignment power field.  */
-#define ALIGN_SET(field, x, y) \
-  if (((field) & IMAGE_SCN_ALIGN_64BYTES) == x)\
-    {\
-      section->alignment_power = y;\
-    }
-
-#define ELIFALIGN_SET(field, x, y) \
-  else if (((field) & IMAGE_SCN_ALIGN_64BYTES) == x) \
-    {\
-      section->alignment_power = y;\
-    }
-
 static void
 coff_set_alignment_hook (bfd * abfd ATTRIBUTE_UNUSED,
 			 asection * section,
@@ -1648,14 +1635,31 @@ coff_set_alignment_hook (bfd * abfd ATTR
 {
   struct internal_scnhdr *hdr = (struct internal_scnhdr *) scnhdr;
   bfd_size_type amt;
+  unsigned int alignment_power_const
+    = hdr->s_flags & IMAGE_SCN_ALIGN_POWER_BIT_MASK;
 
-  ALIGN_SET     (hdr->s_flags, IMAGE_SCN_ALIGN_64BYTES, 6)
-  ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_32BYTES, 5)
-  ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_16BYTES, 4)
-  ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_8BYTES,  3)
-  ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_4BYTES,  2)
-  ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_2BYTES,  1)
-  ELIFALIGN_SET (hdr->s_flags, IMAGE_SCN_ALIGN_1BYTES,  0)
+  switch (alignment_power_const)
+    {
+    case IMAGE_SCN_ALIGN_8192BYTES:
+    case IMAGE_SCN_ALIGN_4096BYTES:
+    case IMAGE_SCN_ALIGN_2048BYTES:
+    case IMAGE_SCN_ALIGN_1024BYTES:
+    case IMAGE_SCN_ALIGN_512BYTES:
+    case IMAGE_SCN_ALIGN_256BYTES:
+    case IMAGE_SCN_ALIGN_128BYTES:
+    case IMAGE_SCN_ALIGN_64BYTES:
+    case IMAGE_SCN_ALIGN_32BYTES:
+    case IMAGE_SCN_ALIGN_16BYTES:
+    case IMAGE_SCN_ALIGN_8BYTES:
+    case IMAGE_SCN_ALIGN_4BYTES:
+    case IMAGE_SCN_ALIGN_2BYTES:
+    case IMAGE_SCN_ALIGN_1BYTES:
+      section->alignment_power
+	= IMAGE_SCN_ALIGN_POWER_NUM (alignment_power_const);
+      break;
+    default:
+      break;
+    }
 
   /* In a PE image file, the s_paddr field holds the virtual size of a
      section, while the s_size field holds the raw size.  We also keep
--- binutils/include/coff/pe.h.align	2006-12-05 11:27:59.000000000 -0800
+++ binutils/include/coff/pe.h	2007-08-01 16:06:12.000000000 -0700
@@ -66,13 +66,29 @@
 #define IMAGE_SCN_MEM_LOCKED                 0x00040000
 #define IMAGE_SCN_MEM_PRELOAD                0x00080000
 
-#define IMAGE_SCN_ALIGN_1BYTES               0x00100000
-#define IMAGE_SCN_ALIGN_2BYTES               0x00200000
-#define IMAGE_SCN_ALIGN_4BYTES               0x00300000
-#define IMAGE_SCN_ALIGN_8BYTES               0x00400000
-#define IMAGE_SCN_ALIGN_16BYTES              0x00500000  /* Default alignment if no others are specified. */
-#define IMAGE_SCN_ALIGN_32BYTES              0x00600000
-#define IMAGE_SCN_ALIGN_64BYTES              0x00700000
+/* Bit position in the s_flags field where the alignment values start. */
+#define IMAGE_SCN_ALIGN_POWER_BIT_POS	     20
+#define IMAGE_SCN_ALIGN_POWER_BIT_MASK	     0x00f00000
+#define IMAGE_SCN_ALIGN_POWER_NUM(val)	     \
+  (((val) >> IMAGE_SCN_ALIGN_POWER_BIT_POS) - 1)
+#define IMAGE_SCN_ALIGN_POWER_CONST(val)     \
+  (((val) + 1) << IMAGE_SCN_ALIGN_POWER_BIT_POS)
+
+#define IMAGE_SCN_ALIGN_1BYTES		     IMAGE_SCN_ALIGN_POWER_CONST (0)
+#define IMAGE_SCN_ALIGN_2BYTES		     IMAGE_SCN_ALIGN_POWER_CONST (1)
+#define IMAGE_SCN_ALIGN_4BYTES		     IMAGE_SCN_ALIGN_POWER_CONST (2)
+#define IMAGE_SCN_ALIGN_8BYTES		     IMAGE_SCN_ALIGN_POWER_CONST (3)
+/* Default alignment if no others are specified. */
+#define IMAGE_SCN_ALIGN_16BYTES		     IMAGE_SCN_ALIGN_POWER_CONST (4)
+#define IMAGE_SCN_ALIGN_32BYTES		     IMAGE_SCN_ALIGN_POWER_CONST (5)
+#define IMAGE_SCN_ALIGN_64BYTES		     IMAGE_SCN_ALIGN_POWER_CONST (6)
+#define IMAGE_SCN_ALIGN_128BYTES	     IMAGE_SCN_ALIGN_POWER_CONST (7)
+#define IMAGE_SCN_ALIGN_256BYTES	     IMAGE_SCN_ALIGN_POWER_CONST (8)
+#define IMAGE_SCN_ALIGN_512BYTES	     IMAGE_SCN_ALIGN_POWER_CONST (9)
+#define IMAGE_SCN_ALIGN_1024BYTES	     IMAGE_SCN_ALIGN_POWER_CONST (10)
+#define IMAGE_SCN_ALIGN_2048BYTES	     IMAGE_SCN_ALIGN_POWER_CONST (11)
+#define IMAGE_SCN_ALIGN_4096BYTES	     IMAGE_SCN_ALIGN_POWER_CONST (12)
+#define IMAGE_SCN_ALIGN_8192BYTES	     IMAGE_SCN_ALIGN_POWER_CONST (13)
 
 #define IMAGE_SCN_LNK_NRELOC_OVFL            0x01000000  /* Section contains extended relocations. */
 #define IMAGE_SCN_MEM_NOT_CACHED             0x04000000  /* Section is not cachable.               */

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

* Re: PATCH: Support IMAGE_SCN_ALIGN_XXXXBYTES
  2007-08-01 23:19   ` H.J. Lu
@ 2007-08-02 15:16     ` Nick Clifton
  0 siblings, 0 replies; 4+ messages in thread
From: Nick Clifton @ 2007-08-02 15:16 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils, cgf

Hi H.J.

> #define IMAGE_SCN_ALIGN_1BYTES IMAGE_SCN_ALIGN_CONSTANT(1)
> 
> doesn't make senses since 2**1 is 2.

Doh!

> bfd/
> 2007-08-01  H.J. Lu  <hongjiu.lu@intel.com>
> 
> 	* coffcode.h (ALIGN_SET): Removed.
> 	(ELIFALIGN_SET): Likewise.
> 	(coff_set_alignment_hook): Handle IMAGE_SCN_ALIGN_128BYTES,
> 	IMAGE_SCN_ALIGN_256BYTES, IMAGE_SCN_ALIGN_512BYTES,
> 	IMAGE_SCN_ALIGN_1024BYTES, IMAGE_SCN_ALIGN_2048BYTES,
> 	IMAGE_SCN_ALIGN_4096BYTES and IMAGE_SCN_ALIGN_8192BYTES.
> 
> include/coff/
> 2007-08-01  H.J. Lu  <hongjiu.lu@intel.com>
> 
> 	* pe.h (IMAGE_SCN_ALIGN_POWER_BIT_POS): New.
> 	(IMAGE_SCN_ALIGN_POWER_BIT_MASK): Likewise.
> 	(IMAGE_SCN_ALIGN_POWER_NUM): Likewise.
> 	(IMAGE_SCN_ALIGN_POWER_CONST): Likewise.
> 	(IMAGE_SCN_ALIGN_128BYTES): Likewise.
> 	(IMAGE_SCN_ALIGN_256BYTES): Likewise.
> 	(IMAGE_SCN_ALIGN_512BYTES): Likewise.
> 	(IMAGE_SCN_ALIGN_1024BYTES): Likewise.
> 	(IMAGE_SCN_ALIGN_2048BYTES): Likewise.
> 	(IMAGE_SCN_ALIGN_4096BYTES): Likewise.
> 	(IMAGE_SCN_ALIGN_8192BYTES): Likewise.
> 	(IMAGE_SCN_ALIGN_1BYTES): Redefined with
> 	IMAGE_SCN_ALIGN_POWER_CONST.
> 	(IMAGE_SCN_ALIGN_2BYTES): Likewise.
> 	(IMAGE_SCN_ALIGN_4BYTES): Likewise.
> 	(IMAGE_SCN_ALIGN_8BYTES): Likewise.
> 	(IMAGE_SCN_ALIGN_16BYTES): Likewise.
> 	(IMAGE_SCN_ALIGN_32BYTES): Likewise.
> 	(IMAGE_SCN_ALIGN_64BYTES): Likewise.

Approved - please apply.

Cheers
   Nick

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

end of thread, other threads:[~2007-08-02 15:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-26 22:17 PATCH: Support IMAGE_SCN_ALIGN_XXXXBYTES H.J. Lu
2007-08-01 17:12 ` Nick Clifton
2007-08-01 23:19   ` H.J. Lu
2007-08-02 15:16     ` Nick Clifton

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