This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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: [4.5] PATCH: PR c/39323: MAX_OFILE_ALIGNMENT in elfos.h is too big


On Sat, Feb 28, 2009 at 12:00:40PM -0800, H.J. Lu wrote:
> We don't check if user specified alignment attribute will overflow.
> OK for 4.5 if there are no regressions on Linux/ia32, Linux/ia64
> and Linux/x86-64?
> 
> Thanks.
> 

This updated patch limits test to Linux since not all OSes support

int bar __attribute__ ((aligned(1 << 20))) =  20;


H.J.
-----
gcc/

2009-02-28  H.J. Lu  <hongjiu.lu@intel.com>

	PR c/39323
	* c-common.c (handle_aligned_attribute): Check alignment
	overlow.

	* tree.h (tree_decl_common): Add XXX_ALIGNMENT notes for the
	align field.

	* config/elfos.h (MAX_OFILE_ALIGNMENT): Change it to
	(((unsigned int) 1 << 20) * 8).

gcc/testsuite/

2009-02-28  H.J. Lu  <hongjiu.lu@intel.com>

	PR c/39323
	* gcc.dg/pr39323.c: New.

--- gcc/c-common.c.pr39323	2009-02-28 10:35:37.000000000 -0800
+++ gcc/c-common.c	2009-02-28 11:48:25.000000000 -0800
@@ -5977,7 +5977,13 @@ handle_aligned_attribute (tree *node, tr
   else
     {
       DECL_ALIGN (decl) = (1 << i) * BITS_PER_UNIT;
-      DECL_USER_ALIGN (decl) = 1;
+      if (DECL_ALIGN (decl) != (1 << i) * BITS_PER_UNIT)
+	{
+	  error ("requested alignment is too large");
+	  *no_add_attrs = true;
+	}
+      else
+	DECL_USER_ALIGN (decl) = 1;
     }
 
   return NULL_TREE;
--- gcc/config/elfos.h.pr39323	2007-08-03 06:25:48.000000000 -0700
+++ gcc/config/elfos.h	2009-02-28 11:42:43.000000000 -0800
@@ -41,13 +41,14 @@ along with GCC; see the file COPYING3.  
 
 /* The biggest alignment supported by ELF in bits. 32-bit ELF 
    supports section alignment up to (0x80000000 * 8), while 
-   64-bit ELF supports (0x8000000000000000 * 8). If this macro 
+   64-bit ELF supports (0x8000000000000000 * 8).  If this macro 
    is not defined, the default is the largest alignment supported 
-   by 32-bit ELF and representable on a 32-bit host. Use this
-   macro to limit the alignment which can be specified using
+   by 32-bit ELF and representable in struct tree_decl_common:
+  	 unsigned int align : 24;
+   Use this macro to limit the alignment which can be specified using
    the `__attribute__ ((aligned (N)))' construct.  */
 #ifndef MAX_OFILE_ALIGNMENT
-#define MAX_OFILE_ALIGNMENT (((unsigned int) 1 << 28) * 8)
+#define MAX_OFILE_ALIGNMENT (((unsigned int) 1 << 20) * 8)
 #endif
 
 /* Use periods rather than dollar signs in special g++ assembler names.  */
--- gcc/testsuite/gcc.dg/pr39323.c.pr39323	2009-02-28 11:53:45.000000000 -0800
+++ gcc/testsuite/gcc.dg/pr39323.c	2009-02-28 14:47:24.000000000 -0800
@@ -0,0 +1,6 @@
+/* PR c/39323 */
+/* { dg-do compile { target *-*-linux* } } */
+
+int bar __attribute__ ((aligned(1 << 20))) =  20;
+int foo __attribute__ ((aligned(1 << 21))) =  20; /* { dg-error "requested alignment is too large" } */
+
--- gcc/tree.h.pr39323	2009-02-28 10:35:37.000000000 -0800
+++ gcc/tree.h	2009-02-28 11:39:11.000000000 -0800
@@ -2724,6 +2724,9 @@ struct tree_decl_common GTY(())
   /* Padding so that 'align' can be on a 32-bit boundary.  */
   unsigned decl_common_unused : 2;
 
+  /* Need to make sure that all definitions of MAX_OFILE_ALIGNMENT,
+     MAX_STACK_ALIGNMENT, MAX_STACK_ALIGNMENT and BIGGEST_ALIGNMENT
+     will fit in this field.  */
   unsigned int align : 24;
   /* DECL_OFFSET_ALIGN, used only for FIELD_DECLs.  */
   unsigned int off_align : 8;


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