This is the mail archive of the gcc@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: unable to detect exception model


On Mon, 26 Jun 2006, Richard Guenther wrote:

> On Mon, 26 Jun 2006, Andrew Pinski wrote:
> 
> > 
> > On Jun 26, 2006, at 2:07 AM, Richard Guenther wrote:
> > 
> > >So even
> > >(len + sizeof (struct tree_string)) & ~__alignof__(struct tree_string)
> > >might magically work in every case.
> > 
> > Of course using __alignof__ is wrong in GCC sources since that would mean
> > you have to use GCC to bootstrap with which is not documented.
> > 
> > But this does not explain PPC-Darwin's problem as PPC is not a
> > STRICT_ALIGNMENT target.
> > So either we are allocating too little or someone is going past an array
> > bounds somewhere.
> 
> I'll currently investigate "fixing" build_string, which interestingly
> fails and may hint at a problem elsewhere.  Of course alignof is wrong, 
> but one can use
> 
>   /* Make sure to request aligned storage and do not waste bytes
>      provided by padding of struct tree_string.  */
>   length = ((len + sizeof (struct tree_string))
>             & ~(sizeof (struct tree_string)
>                 - offsetof (struct tree_string, str) - 1));
> 
> instead (not pretty, but works).

Though it will not fix the alignment problem, only not waste the
bytes from the padding (which is why using __alignof__ didn't work,
it was wrong).  A fix that also fixes the alignment problem would
look like

  /* Make sure to request aligned storage and do not waste bytes
     provided by padding of struct tree_string.  */
  length = ((len + sizeof (struct tree_string))
            & ~(sizeof (struct tree_string)
                - offsetof (struct tree_string, str) - 1));
  length = ((length + __alignof__ (struct tree_string) - 1)
            & ~(__alignof__ (struct tree_string) - 1));

that is, align length - I don't know how to avoid using __alignof__
here, though, other than using a fake struct like

 struct foo_align_for_tree_string {
   char c;
   struct tree_string s;
 }

and offsetof (struct foo_align_for_tree_string, s).  Which would make it
as ugly as

  struct dummy_to_get_alignof_tree_string {
    char c;
    struct tree_string s;
  };
 
  /* Make sure to request aligned storage and do not waste bytes
     provided by padding of struct tree_string.  */
  length = ((len + sizeof (struct tree_string))
            & ~(sizeof (struct tree_string)
                - offsetof (struct tree_string, str) - 1));
  length = ((length + offsetof (struct dummy_to_get_alignof_tree_string, 
s) - 1)
            & ~(offsetof (struct dummy_to_get_alignof_tree_string, s) - 
1));

:/

I'll go ahead and revert the ggc-page.c patch now.

Richard.

--
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs


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