Re: FYI: SIGBUS with world built by clang

From: Konstantin Belousov <kostikbel_at_gmail.com>
Date: Thu, 5 Jul 2012 23:11:31 +0300
On Fri, Jul 06, 2012 at 04:15:18AM +0900, Taku YAMAMOTO wrote:
> On Thu, 5 Jul 2012 00:14:14 +0300
> Konstantin Belousov <kostikbel_at_gmail.com> wrote:
> 
> > On Thu, Jul 05, 2012 at 12:32:01AM +0900, Taku YAMAMOTO wrote:
> > > On Wed, 04 Jul 2012 17:08:30 +0200
> > > Dimitry Andric <dim_at_FreeBSD.org> wrote:
> > > 
> > > > On 2012-07-04 16:33, Taku YAMAMOTO wrote:
> > > > > For people having SIGBUS with clang-build world + gcc-build binaries,
> > > > > 
> > > > > 
> > > > > In short words, for any libraries (and never forget about rtld-elf!)
> > > > > which are potentially called from arbitrary binaries,
> > > > > compile them with either -mstackrealign or -mstack-alignment=8!
> > > > > 
> > > > > The detail is as follows.
> > > > > 
> > > > > I've observed that clang carelessly expects the stack being aligned at
> > > > > 16 byte boundary.
> > > > 
> > > > Eh, this is a requirement of the amd64 ABI.  Any compiler that *doesn't*
> > > > align the stack on 16-byte boundaries is basically broken.  Or are you
> > > > experiencing this on i386?  Even there, 16-byte alignment would be much
> > > > better in combination with SSE instructions (which arent' enabled by
> > > > default, btw).
> > > 
> > > Oops, I had to be clear about that!
> > > Yes, the experiment was took on i386 (actually -march=pentium4).
> > > 
> > > > Note that you would get the same issue with newer versions of gcc, which
> > > > will also assume this alignment.
> > > 
> > > Interesting, but the base gcc we currently have won't on i386, I think.
> > > (I occationally get bitten by similar problem when using -ftree-vectorize)
> > As far as I understand the rules, $esp % 16 must be zero before call
> > instruction is executed.
> 
> I googled and found that it is enforced by MacOS X ABI for IA32 but
> i386 SysV ABI defines otherwise (8 bytes instead of 16 bytes).
No, SysV ABI only requires 4-byte alignment for the stack on i386.

> 
> > i386 csu explicitely aligns the stack before calling into C land, everything
> > else should be the C compiler own offence :).
> 
> Unfortunately it is difficult when we have to deal with binaries produced by
> random compilers, such as Win32 app via wine, mplayer with win32-codecs, etc. ;)
> 
> JITs, like Java and mono, also have possibility to become victims if they
> emit native codes without paying attention to the stack alignment, though
> I'm not sure.
> 
> Just my random thoughts,
> -- 
> -|-__   YAMAMOTO, Taku
>  | __ <     <taku_at_tackymt.homeip.net>
> 
>       - A chicken is an egg's way of producing more eggs. -

Received on Thu Jul 05 2012 - 18:11:36 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:28 UTC