I finally had time to investigate further.
Based on my understanding (with google help), here is the fix I propose:
/* TinyCC & gcc defines */
#if defined(TCC_TARGET_PE) && defined(TCC_TARGET_X86_64)
/* 64bit Windows. */
tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned long long");
tcc_define_symbol(s, "__PTRDIFF_TYPE__", "long long");
tcc_define_symbol(s, "__LLP64__", NULL);
#elif defined(TCC_TARGET_X86_64) || defined(TCC_TARGET_ARM64)
/* Other 64bit systems. */
tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned long");
tcc_define_symbol(s, "__PTRDIFF_TYPE__", "long");
tcc_define_symbol(s, "__LP64__", NULL);
#else
/* Other 32bit systems. */
tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned long");
tcc_define_symbol(s, "__PTRDIFF_TYPE__", "long");
tcc_define_symbol(s, "__ILP32__", NULL);
#endif
mob looks good on Windows 32 and 64, Linux x86_64, Linux arm and arm64. Can
you please review for other architectures/OS?
From: Christian Jullien [mailto:[email protected]]
Sent: dimanche 18 septembre 2016 14:15
To: '[email protected]'
Subject: RE: [Tinycc-devel] Why is __LP64__ defined for targets for 32bits
targets?
>From a commit:
author
<http://repo.or.cz/tinycc.git/search/9d679e391660e411d676b847ff4ce72beda6092
7?s=seyko;st=author> seyko
<http://repo.or.cz/tinycc.git/search/9d679e391660e411d676b847ff4ce72beda6092
[email protected];st=author> <[email protected]>
Sun, 15 May 2016 20:07:05 +0200 (15 21:07 +0300)
committer
<http://repo.or.cz/tinycc.git/search/9d679e391660e411d676b847ff4ce72beda6092
7?s=seyko;st=committer> seyko
<http://repo.or.cz/tinycc.git/search/9d679e391660e411d676b847ff4ce72beda6092
[email protected];st=committer> <[email protected]>
Sun, 15 May 2016 20:07:05 +0200 (15 21:07 +0300)
a patch from tcc bugzilla.
From: Reuben Thomas
Date: Thu, 31 Jul 2014 13:50:13 +0100
Subject: [PATCH] libtcc.c: add memory model macros __{L,}LP64__
<http://repo.or.cz/tinycc.git/blob/9d679e391660e411d676b847ff4ce72beda60927:
/libtcc.c> libtcc.c
patch
<http://repo.or.cz/tinycc.git/commitdiff/9d679e391660e411d676b847ff4ce72beda
60927?hp=7cfd21440b1b75c5ac78351ba02427983d1d20e6#patch1> | blob
<http://repo.or.cz/tinycc.git/blob/9d679e391660e411d676b847ff4ce72beda60927:
/libtcc.c> | blame
<http://repo.or.cz/tinycc.git/blame_incremental/9d679e391660e411d676b847ff4c
e72beda60927:/libtcc.c> | history
<http://repo.or.cz/tinycc.git/history/9d679e391660e411d676b847ff4ce72beda609
27:/libtcc.c>
diff --git a/libtcc.c
<http://repo.or.cz/tinycc.git/blob/7cfd21440b1b75c5ac78351ba02427983d1d20e6:
/libtcc.c> b/libtcc.c
<http://repo.or.cz/tinycc.git/blob/9d679e391660e411d676b847ff4ce72beda60927:
/libtcc.c>
index d63b86f
<http://repo.or.cz/tinycc.git/blob/7cfd21440b1b75c5ac78351ba02427983d1d20e6:
/libtcc.c> ..b0fcdf9
<http://repo.or.cz/tinycc.git/blob/9d679e391660e411d676b847ff4ce72beda60927:
/libtcc.c> 100644 (file)
--- a/libtcc.c
<http://repo.or.cz/tinycc.git/blob/7cfd21440b1b75c5ac78351ba02427983d1d20e6:
/libtcc.c>
+++ b/libtcc.c
<http://repo.or.cz/tinycc.git/blob/9d679e391660e411d676b847ff4ce72beda60927:
/libtcc.c>
@@
<http://repo.or.cz/tinycc.git/blob/7cfd21440b1b75c5ac78351ba02427983d1d20e6:
/libtcc.c#l1146> -1146,9
<http://repo.or.cz/tinycc.git/blob/9d679e391660e411d676b847ff4ce72beda60927:
/libtcc.c#l1146> +1146,11 @@ LIBTCCAPI TCCState *tcc_new(void)
#if defined TCC_TARGET_PE && defined TCC_TARGET_X86_64
tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned long long");
tcc_define_symbol(s, "__PTRDIFF_TYPE__", "long long");
+ tcc_define_symbol(s, "__LLP64__", NULL);
#else
tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned long");
tcc_define_symbol(s, "__PTRDIFF_TYPE__", "long");
+ tcc_define_symbol(s, "__LP64__", NULL);
#endif
From: Tinycc-devel [mailto:[email protected]]
On Behalf Of Christian Jullien
Sent: dimanche 18 septembre 2016 14:06
To: [email protected]
Subject: [Tinycc-devel] Why is __LP64__ defined for targets for 32bits
targets?
/* TinyCC & gcc defines */
#if defined TCC_TARGET_PE && defined TCC_TARGET_X86_64
tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned long long");
tcc_define_symbol(s, "__PTRDIFF_TYPE__", "long long");
tcc_define_symbol(s, "__LLP64__", NULL);
#else
tcc_define_symbol(s, "__SIZE_TYPE__", "unsigned long");
tcc_define_symbol(s, "__PTRDIFF_TYPE__", "long");
tcc_define_symbol(s, "__LP64__", NULL); // <= here?
#endif
Compiling tcc on native 32BITS Windows for example, it defines __LP64__
This variable is specified as (see
https://gcc.gnu.org/onlinedocs/gcc-4.9.2/cpp/Common-Predefined-Macros.html)
__LP64__
_LP64
These macros are defined, with value 1, if (and only if) the compilation is
for a target where long int and pointer both use 64-bits and int uses
32-bit.
Testing this macro in programs compiled with tcc 32bits returns wrong
behavior
#if defined(__LP64__)
#define MYPTR_SIZE_IN_BYTES 8
// Assume void* is a 64bits pointer which is false on Windows 32bit
#endif
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel