summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-02-02 22:04:02 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2019-02-07 21:49:45 +0100
commit949a29adb9f400ebdc15aed2dd874c17ffa839cb (patch)
treedfefa274a44ba25f08eb6013a6611a0be5b48c95
parente6e60e370f4309431de9d488f6dc1fe96a976879 (diff)
downloadsparse-949a29adb9f400ebdc15aed2dd874c17ffa839cb.tar.gz
predefs: add arch-specific predefines
Predefined macros like '__x86_64__', '__arm__', ... are used in systems headers (and surely at other places too). So, when appropriate, define the following symbols which seems to be somehow needed by glibc: m68k: __m68k__ mips: __mpis64, __mips ppc: __ppc64__, __powerpc, __ppc__ riscv: __riscv__, __riscv_xlen__ s390: __zarch__ sparc: __sparc_v9__, __sparcv9 x86-64: __x86_64__, __x86_64 Also, the following symbols, which were previously only defined in cgcc, are now defined in Sparse itself: i386 __i386, __i386__ sparc __sparc, __sparc__, __arch64__, __sparc64__, __sparcv9__ s390 __s390__, __s390x__ ppc __PPC__, __powerpc__, __PPC64__, __powerpc64__ arm __arm__ arm64 __aarch64__ Note: these are only tested on i386, x86-64, arm, arm64, mips64 (ABI O32), ppc, ppc64 (power7), ppc64el (power8) and sparc64, most of them on a not-so-new OS version. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rwxr-xr-xcgcc18
-rw-r--r--lib.c67
2 files changed, 68 insertions, 17 deletions
diff --git a/cgcc b/cgcc
index f3909ae8..a99a3a1c 100755
--- a/cgcc
+++ b/cgcc
@@ -287,16 +287,16 @@ sub add_specs {
" -D'__fastcall=__attribute__((__fastcall__))'" .
" -D'__declspec(x)=__attribute__((x))'";
} elsif ($spec eq 'i386') {
- return (' -D__i386=1 -D__i386__=1' .
+ return (
&float_types (1, 1, 21, [24,8], [53,11], [64,15]));
} elsif ($spec eq 'sparc') {
- return (' -D__sparc=1 -D__sparc__=1' .
+ return (
&integer_types (8, 16, 32, $m64 ? 64 : 32, 64) .
&float_types (1, 1, 33, [24,8], [53,11], [113,15]) .
&define_size_t ($m64 ? "long unsigned int" : "unsigned int") .
' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4'));
} elsif ($spec eq 'sparc64') {
- return (' -D__sparc=1 -D__sparc__=1 -D__sparcv9__=1 -D__sparc64__=1 -D__arch64__=1 -D__LP64__=1' .
+ return (
&integer_types (8, 16, 32, 64, 64, 128) .
&float_types (1, 1, 33, [24,8], [53,11], [113,15]) .
&define_size_t ("long unsigned int") .
@@ -304,25 +304,23 @@ sub add_specs {
} elsif ($spec eq 'x86_64') {
return &float_types (1, 1, 33, [24,8], [53,11], [113,15]);
} elsif ($spec eq 'ppc') {
- return (' -D__powerpc__=1 -D_BIG_ENDIAN -D_STRING_ARCH_unaligned=1' .
+ return (' -D_BIG_ENDIAN -D_STRING_ARCH_unaligned=1' .
&integer_types (8, 16, 32, $m64 ? 64 : 32, 64) .
&float_types (1, 1, 21, [24,8], [53,11], [113,15]) .
&define_size_t ($m64 ? "long unsigned int" : "unsigned int") .
' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4'));
} elsif ($spec eq 'ppc64') {
- return (' -D__powerpc__=1 -D__PPC__=1 -D_STRING_ARCH_unaligned=1' .
- ' -D__powerpc64__=1 -D__PPC64__=1' .
- ' -m64' .
+ return (' -D_STRING_ARCH_unaligned=1 -m64' .
&float_types (1, 1, 21, [24,8], [53,11], [113,15]));
} elsif ($spec eq 's390x') {
- return (' -D__s390x__ -D__s390__ -D_BIG_ENDIAN' .
+ return (' -D_BIG_ENDIAN' .
&integer_types (8, 16, 32, $m64 ? 64 : 32, 64) .
&float_types (1, 1, 36, [24,8], [53,11], [113,15]) .
&define_size_t ("long unsigned int") .
' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4'));
} elsif ($spec eq 'arm') {
chomp (my $gccmachine = `$cc -dumpmachine`);
- my $cppsymbols = ' -D__arm__=1 -m32';
+ my $cppsymbols = ' -m32';
if ($gccmachine eq 'arm-linux-gnueabihf') {
$cppsymbols .= ' -D__ARM_PCS_VFP=1';
@@ -331,7 +329,7 @@ sub add_specs {
return ($cppsymbols .
&float_types (1, 1, 36, [24,8], [53,11], [53, 11]));
} elsif ($spec eq 'aarch64') {
- return (' -D__aarch64__=1 -m64' .
+ return (' -m64' .
&float_types (1, 1, 36, [24,8], [53,11], [113,15]));
} elsif ($spec eq 'host_os_specs') {
my $os = `uname -s`;
diff --git a/lib.c b/lib.c
index ee439b5b..83e6a1e1 100644
--- a/lib.c
+++ b/lib.c
@@ -1314,20 +1314,73 @@ static void predefined_macros(void)
break;
}
- if (arch_m64 != ARCH_LP32) {
-#if defined(__x86_64__) || defined(__x86_64)
- predefine("__x86_64__", 1, "1");
- predefine("__x86_64", 1, "1");
-#endif
- }
-
switch (arch_mach) {
+ case MACH_ARM64:
+ predefine("__aarch64__", 1, "1");
+ break;
+ case MACH_ARM:
+ predefine("__arm__", 1, "1");
+ break;
+ case MACH_M68K:
+ predefine("__m68k__", 1, "1");
+ break;
case MACH_MIPS64:
+ if (arch_m64 == ARCH_LP64)
+ predefine("__mips64", 1, "64");
+ /* fall-through */
case MACH_MIPS32:
+ predefine("__mips", 1, "%d", ptr_ctype.bit_size);
predefine("_MIPS_SZINT", 1, "%d", int_ctype.bit_size);
predefine("_MIPS_SZLONG", 1, "%d", long_ctype.bit_size);
predefine("_MIPS_SZPTR", 1, "%d", ptr_ctype.bit_size);
break;
+ case MACH_PPC64:
+ if (arch_m64 == ARCH_LP64) {
+ predefine("__powerpc64__", 1, "1");
+ predefine("__ppc64__", 1, "1");
+ predefine("__PPC64__", 1, "1");
+ }
+ /* fall-through */
+ case MACH_PPC32:
+ predefine("__powerpc__", 1, "1");
+ predefine("__powerpc", 1, "1");
+ predefine("__ppc__", 1, "1");
+ predefine("__PPC__", 1, "1");
+ break;
+ case MACH_RISCV64:
+ case MACH_RISCV32:
+ predefine("__riscv", 1, "1");
+ predefine("__riscv_xlen", 1, "%d", ptr_ctype.bit_size);
+ break;
+ case MACH_S390X:
+ predefine("__zarch__", 1, "1");
+ predefine("__s390x__", 1, "1");
+ predefine("__s390__", 1, "1");
+ break;
+ case MACH_SPARC64:
+ if (arch_m64 == ARCH_LP64) {
+ predefine("__sparc_v9__", 1, "1");
+ predefine("__sparcv9__", 1, "1");
+ predefine("__sparcv9", 1, "1");
+ predefine("__sparc64__", 1, "1");
+ predefine("__arch64__", 1, "1");
+ }
+ /* fall-through */
+ case MACH_SPARC32:
+ predefine("__sparc__", 1, "1");
+ predefine("__sparc", 1, "1");
+ break;
+ case MACH_X86_64:
+ if (arch_m64 != ARCH_LP32) {
+ predefine("__x86_64__", 1, "1");
+ predefine("__x86_64", 1, "1");
+ break;
+ }
+ /* fall-through */
+ case MACH_I386:
+ predefine("__i386__", 1, "1");
+ predefine("__i386", 1, "1");
+ break;
}
}