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 Mon, Mar 2, 2009 at 3:52 PM, Ian Lance Taylor <iant@google.com> wrote:
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
>> 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;
>> ? ? ?}
>
> Use a local variable rather than repeating the expression.
>
>
>> --- 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
>
> I don't think this part of the change is a good idea.
> MAX_OFILE_ALIGNMENT should be the maximum alignment representable in the
> object file. ?It should not be affected by gcc's internal
> representation.
>
>> + ?/* 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;
>
> Let's not make the restriction in the comment.

I noticed this issue while working on

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39315

Its fix:

http://gcc.gnu.org/ml/gcc-patches/2009-02/msg01267.html

has been approved for 4.5.  Since MAX_OFILE_ALIGNMENT is
too big on Linux, in theory, expand_one_stack_var_at can overflow
DECL_ALIGN. In practice, it may never happen. I added a check

+  /* There should be no alignment overflow.  */
+  if (DECL_ALIGN (decl) != align)
+    gcc_unreachable ();

in expand_one_stack_var_at.  OK for 4.5?

Thanks.

-- 
H.J.
---
gcc/

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

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

	PR middle-end/39315
	* cfgexpand.c (expand_one_stack_var_at): Change alignment
	limit to MAX_SUPPORTED_STACK_ALIGNMENT and check alignment
	overflow.

gcc/testsuite/

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

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

	PR middle-end/39315
	* gcc.target/i386/pr39315-1.c: New.
	* gcc.target/i386/pr39315-2.c: Likewise.
	* gcc.target/i386/pr39315-3.c: Likewise.
	* gcc.target/i386/pr39315-4.c: Likewise.
	* gcc.target/i386/pr39315-check.c: Likewise.

Attachment: gcc-pr39315-6.patch
Description: Text document


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