Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Jul 2012 23:11:31 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Taku YAMAMOTO <taku@tackymt.homeip.net>
Cc:        freebsd-current@freebsd.org
Subject:   Re: FYI: SIGBUS with world built by clang
Message-ID:  <20120705201131.GC2338@deviant.kiev.zoral.com.ua>
In-Reply-To: <20120706041518.de7e2ab5.taku@tackymt.homeip.net>
References:  <20120704233316.70ec8654.taku@tackymt.homeip.net> <4FF45C6E.1080000@FreeBSD.org> <20120705003201.bb297e8a.taku@tackymt.homeip.net> <20120704211414.GR2337@deviant.kiev.zoral.com.ua> <20120706041518.de7e2ab5.taku@tackymt.homeip.net>

next in thread | previous in thread | raw e-mail | index | archive | help

--3siQDZowHQqNOShm
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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@gmail.com> wrote:
>=20
> > 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@FreeBSD.org> wrote:
> > >=20
> > > > On 2012-07-04 16:33, Taku YAMAMOTO wrote:
> > > > > For people having SIGBUS with clang-build world + gcc-build binar=
ies,
> > > > >=20
> > > > >=20
> > > > > In short words, for any libraries (and never forget about rtld-el=
f!)
> > > > > which are potentially called from arbitrary binaries,
> > > > > compile them with either -mstackrealign or -mstack-alignment=3D8!
> > > > >=20
> > > > > The detail is as follows.
> > > > >=20
> > > > > I've observed that clang carelessly expects the stack being align=
ed at
> > > > > 16 byte boundary.
> > > >=20
> > > > Eh, this is a requirement of the amd64 ABI.  Any compiler that *doe=
sn'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).
> > >=20
> > > Oops, I had to be clear about that!
> > > Yes, the experiment was took on i386 (actually -march=3Dpentium4).
> > >=20
> > > > Note that you would get the same issue with newer versions of gcc, =
which
> > > > will also assume this alignment.
> > >=20
> > > Interesting, but the base gcc we currently have won't on i386, I thin=
k.
> > > (I occationally get bitten by similar problem when using -ftree-vecto=
rize)
> > As far as I understand the rules, $esp % 16 must be zero before call
> > instruction is executed.
>=20
> 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.

>=20
> > i386 csu explicitely aligns the stack before calling into C land, every=
thing
> > else should be the C compiler own offence :).
>=20
> 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. ;)
>=20
> 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.
>=20
> Just my random thoughts,
> --=20
> -|-__   YAMAMOTO, Taku
>  | __ <     <taku@tackymt.homeip.net>
>=20
>       - A chicken is an egg's way of producing more eggs. -

--3siQDZowHQqNOShm
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (FreeBSD)

iEYEARECAAYFAk/19PMACgkQC3+MBN1Mb4iEcACg718pKmwEUvCLhSqe7K3c7sFI
5lQAoLl5BwSokpjEHdm4FOmiomJ/lph/
=c8qA
-----END PGP SIGNATURE-----

--3siQDZowHQqNOShm--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120705201131.GC2338>