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

Dimitry Andric via cfe-dev cfe-dev at lists.llvm.org
Tue Dec 1 13:28:33 PST 2015


On 01 Dec 2015, at 22:04, Jeffrey Walton via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> On Tue, Dec 1, 2015 at 2:26 PM, Reid Kleckner <rnk at google.com> wrote:
>> 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.
> 
> Thanks. I also saw H.J. Lu's discussion related to ILP32 and
> ARM64/AARCH64 on LKML
> 
> If you don't mind helping with a strategy, how should I check for X32?
> The System V ABI only provides ILP32.

On my Debian Linux box, with gcc 4.9.2:

$ gcc -mx32 -dM -E -x c /dev/null | sort | grep -E "LP|amd64|i386|x86_64"
#define __amd64 1
#define __amd64__ 1
#define __ILP32__ 1
#define _ILP32 1
#define __x86_64 1
#define __x86_64__ 1

With clang 3.7.0:

$ clang -mx32 -dM -E -x c /dev/null | sort | grep -E "LP|amd64|i386|x86_64"
#define __amd64 1
#define __amd64__ 1
#define __ILP32__ 1
#define _ILP32 1
#define __x86_64 1
#define __x86_64__ 1

I get similar results on FreeBSD.  So you could check as follows:

#if defined __x86_64__ && defined __ILP32__

-Dimitry

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 194 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151201/a94c5205/attachment.sig>


More information about the cfe-dev mailing list