Re: November 5th is Clang-Day

From: Konstantin Belousov <kostikbel_at_gmail.com>
Date: Sun, 4 Nov 2012 16:36:59 +0200
On Sun, Nov 04, 2012 at 03:29:42PM +0100, Dimitry Andric wrote:
> On 2012-11-04 14:18, Konstantin Belousov wrote:
> > On Sun, Nov 04, 2012 at 02:42:13PM +0200, David Naylor wrote:
> ...
> >> I tried building (using gcc) wine with your patch and now (at least) winecfg
> >> and regedit work with a clang built lib32.  I'll email Gerald (wine's
> >> maintainer) about including your patch in wine.
> >
> > The wine is the wrong place to fix. If system libraries suddenly started
> > requiring 16-byte stack alignment on i386, it is unacceptable breakage
> > of the ABI.
> 
> So we really must use 4 byte stack alignment on i386 by default?  I have
> attached a diff to llvm for this, but I would like to verify that it is
> really correct.  Apparently Darwin, Linux and Solaris all use 16 byte
> alignment.
No, this is a misunderstanding.

We must provide libraries that tolerate the 4-byte aligned stack.
Also, to be compatible with broken compilers (both older versions of gcc
and some versions of clang) we must provide the libraries which preserve
the %esp mod 0x10 across the functions entry/leave points.

The crt ensures that the stack is 16-byte aligned on entry to main.
> 
> The Sys V ABI seems to say only: "The stack is word aligned.  Although
> the architecture does not require any alignment of the stack, software
> convention and the operating system requires that the stack be aligned
> on a word boundary".
Right, this is ABI which some binaries follow. There are some other binaries,
generated by arguably broken compilers, which require 16-byte alignment.
The system shall support both.

> Index: contrib/llvm/lib/Target/X86/X86Subtarget.cpp
> ===================================================================
> --- contrib/llvm/lib/Target/X86/X86Subtarget.cpp	(revision 242480)
> +++ contrib/llvm/lib/Target/X86/X86Subtarget.cpp	(working copy)
> _at__at_ -416,12 +416,12 _at__at_ X86Subtarget::X86Subtarget(const std::string &TT,
>    assert((!In64BitMode || HasX86_64) &&
>           "64-bit code requested on a subtarget that doesn't support it!");
>  
> -  // Stack alignment is 16 bytes on Darwin, FreeBSD, Linux and Solaris (both
> -  // 32 and 64 bit) and for all 64-bit targets.
> +  // Stack alignment is 16 bytes on Darwin, Linux and Solaris (both 32 and 64
> +  // bit) and for all 64-bit targets.
>    if (StackAlignOverride)
> -    stackAlignment = StackAlignOverride;
> -  else if (isTargetDarwin() || isTargetFreeBSD() || isTargetLinux() ||
> -           isTargetSolaris() || In64BitMode)
> +	  stackAlignment = StackAlignOverride;
> +  else if (isTargetDarwin() || isTargetLinux() || isTargetSolaris() ||
> +           In64BitMode)
>      stackAlignment = 16;
>  }
>  


Received on Sun Nov 04 2012 - 13:37:03 UTC

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