This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch, rfc] Semantics of attribute (aligned), misscompilation of crtstuff
Hello,
as discussed in http://gcc.gnu.org/ml/gcc-patches/2007-10/msg00771.html,
aligned(sizeof(func_ptr)) on variables specifies only that the alignment
must be at least that of sizeof(func_ptr), so crtstuff should not
rely on that the alignment of such a variable is not increased above
this bound.
This patch makes crtstuff work even if the alignment is increased, which
makes gcc bootstrap with vectorization enabled on ppc64-linux. I have
also bootstrapped & regtested the patch on i686.
Zdenek
PR regression/32582
* crtstuff.c (__do_global_dtors_aux, __do_global_ctors_aux,
__do_global_ctors): Ignore padding for alignment at the end of
ctor/dtor lists.
Index: crtstuff.c
===================================================================
*** crtstuff.c (revision 129284)
--- crtstuff.c (working copy)
*************** __do_global_dtors_aux (void)
*** 298,303 ****
--- 298,308 ----
while (dtor_idx < max_idx)
{
f = __DTOR_LIST__[++dtor_idx];
+ /* If __DTOR_END__ is aligned to more than the pointer size,
+ NULL element(s) may appear at the end of the list. */
+ if (!f)
+ break;
+
f ();
}
}
*************** static void __attribute__((used))
*** 554,560 ****
__do_global_ctors_aux (void)
{
func_ptr *p;
! for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
(*p) ();
}
--- 559,569 ----
__do_global_ctors_aux (void)
{
func_ptr *p;
! /* If CTOR_END is aligned to more than the size of the pointer, NULL elements
! may appear at the end of the list. Skip them. */
! for (p = __CTOR_END__ - 1; !*p; p--)
! continue;
! for (; *p != (func_ptr) -1; p--)
(*p) ();
}
*************** __do_global_ctors (void)
*** 610,616 ****
#if defined(USE_EH_FRAME_REGISTRY) || defined(JCR_SECTION_NAME)
__do_global_ctors_1();
#endif
! for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
(*p) ();
}
--- 619,629 ----
#if defined(USE_EH_FRAME_REGISTRY) || defined(JCR_SECTION_NAME)
__do_global_ctors_1();
#endif
! /* If CTOR_END is aligned to more than the size of the pointer, NULL elements
! may appear at the end of the list. Skip them. */
! for (p = __CTOR_END__ - 1; !*p; p--)
! continue;
! for (; *p != (func_ptr) -1; p--)
(*p) ();
}