[PATCH] add arch-specific predefines

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Predefined macros like '__x86_64__', '__arm__', ... are used
in systems headers (and surely at other places too).

So, add them for all archs known to sparse.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---

Note: from what I see in glic's code, at least part of these
      are needed for recent versions.
Note: these  are only tested on i386, x86-64, arm, arm64,
      mips64 (ABI O32), ppc, ppc64 (power7), ppc64el (power8)
      and sparc64.

 lib.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 54 insertions(+), 7 deletions(-)

diff --git a/lib.c b/lib.c
index ee439b5b9..b8c0e8a5a 100644
--- a/lib.c
+++ b/lib.c
@@ -1314,20 +1314,67 @@ 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");
+		}
+		/* fall-through */
+	case MACH_PPC32:
+		predefine("__powerpc__", 1, "1");
+		predefine("__powerpc", 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("__s390x__", 1, "1");
+		predefine("__zarch__", 1, "1");
+		break;
+	case MACH_SPARC64:
+		if (arch_m64 == ARCH_LP64) {
+			predefine("__sparc_v9__", 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;
 	}
 }
 
-- 
2.20.0




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux