[PATCH 2/8] add a flag -mx32 ILP32 env on 64 bit archs

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

 



Currently, we have the -m32 & -m64 flags to force sparse to
behave as a 32 or 64 bit arch, independently of the arch used
to build sparse. Good.

However, on x86-64, '-m32' is there to force the 32 bit instructions
& ABI but there is another flag '-mx32' for the x32 ABI which use the
x86-64 instructions / 64 bit registers but where the pointers and
long ints are 32 bit.

Add the same flag, '-mx32', to support this ABI with the proper size
alignment for pointers and longs and to predefine __ILP32__ as it is
done by 'GCC -mx32'.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 lib.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lib.c b/lib.c
index 5aa958ee1..37766d30f 100644
--- a/lib.c
+++ b/lib.c
@@ -278,12 +278,15 @@ static enum { STANDARD_C89,
 
 enum {
 	ARCH_LP32,
+	ARCH_X32,
 	ARCH_LP64,
 	ARCH_LLP64,
 };
 
 #ifdef __LP64__
 #define ARCH_M64_DEFAULT ARCH_LP64
+#elif defined(__x86_64__)
+#define ARCH_M64_DEFAULT ARCH_X32
 #else
 #define ARCH_M64_DEFAULT ARCH_LP32
 #endif
@@ -427,6 +430,8 @@ static char **handle_switch_m(char *arg, char **next)
 		arch_m64 = ARCH_LP64;
 	} else if (!strcmp(arg, "m32")) {
 		arch_m64 = ARCH_LP32;
+	} else if (!strcmp(arg, "mx32")) {
+		arch_m64 = ARCH_X32;
 	} else if (!strcmp(arg, "msize-llp64")) {
 		arch_m64 = ARCH_LLP64;
 	} else if (!strcmp(arg, "msize-long")) {
@@ -444,6 +449,11 @@ static char **handle_switch_m(char *arg, char **next)
 static void handle_arch_m64_finalize(void)
 {
 	switch (arch_m64) {
+	case ARCH_X32:
+		max_int_alignment = 8;
+		add_pre_buffer("#weak_define __ILP32__ 1\n");
+		add_pre_buffer("#weak_define _ILP32 1\n");
+		goto case_x86_64;
 	case ARCH_LP32:
 		/* default values */
 		return;
@@ -465,6 +475,8 @@ static void handle_arch_m64_finalize(void)
 	case_64bit_common:
 		bits_in_pointer = 64;
 		pointer_alignment = 8;
+		/* fall through */
+	case_x86_64:
 #ifdef __x86_64__
 		add_pre_buffer("#weak_define __x86_64__ 1\n");
 #endif
-- 
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[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