[cfe-dev] ILP32, -arch i386 and x86_64 Apple systems

Reid Kleckner via cfe-dev cfe-dev at lists.llvm.org
Tue Dec 1 11:26:17 PST 2015


Right. Clang's logic for defining the ILP macros is very simple:

  if (TI.getPointerWidth(0) == 64 && TI.getLongWidth() == 64
      && TI.getIntWidth() == 32) {
    Builder.defineMacro("_LP64");
    Builder.defineMacro("__LP64__");
  }

  if (TI.getPointerWidth(0) == 32 && TI.getLongWidth() == 32
      && TI.getIntWidth() == 32) {
    Builder.defineMacro("_ILP32");
    Builder.defineMacro("__ILP32__");
  }

It happens on all platforms, not just x86. I think this is reasonable
behavior and we should keep it, even if x86 gcc -m32 doesn't define this
macro. As David said, don't use ILP32 to detect x32. You'll have a bad time
on arm32.

On Tue, Dec 1, 2015 at 11:16 AM, Jeffrey Walton via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> On Tue, Dec 1, 2015 at 1:57 PM, Jeffrey Walton <noloader at gmail.com> wrote:
> > On Tue, Dec 1, 2015 at 1:47 PM, David Chisnall
> > <David.Chisnall at cl.cam.ac.uk> wrote:
> >> On 1 Dec 2015, at 18:36, Jeffrey Walton <noloader at gmail.com> wrote:
> >>>
> >>> When the i386 code is run on an x86_64 system (i.e., "arch i386
> >>> myprog.exe"), then we must interact with the stack using 64-bit values
> >>> and registers. Its an ABI requirement.
> >>
> >> When i386 code is run on an x86-64 system, it is using a different
> system call layer, but is otherwise a normal 386 extended mode
> environment.  Without an explicit switch to long mode, it can not use any
> of the long mode registers.  There is most definitely not an ABI
> requirement that i386 code use non-i386 instructions.
> >>
> > Thanks David.
> >
> > I just checked a 64-bit Fedora system using the -m32 option (which I
> > believe is equivalent to -arch i386; corrections please). Neither GCC
> > nor Clang define ILP32 and friends. So this appears to be limited to
> > Apple systems.
>
> My bad... I forgot the "-i" in my grep. It appears the issue is
> limited to Clang. GCC and Intel compilers do not define it:
>
> fedora-22 $ clang++ -x c++ -m32 -dM -E - < /dev/null | egrep -i "(ilp)"
> #define _ILP32 1
> #define __ILP32__ 1
>
> fedora-22 $ g++ -x c++ -m32 -dM -E - < /dev/null | egrep -i "(ilp)"
> $
>
> ubuntu-14 $ /opt/intel/bin/icpc -x c++ -m32 -dM -E - < /dev/null |
> egrep -i "(ilp)"
> $
>
> I'm not sure about Comeau's compiler because I do not have access to it.
>
> Jeff
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151201/f0b90cd0/attachment.html>


More information about the cfe-dev mailing list