[PATCH 8/9] x86-x32: fix it by defining a separate target for it

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

 



On x86-64, the x32 ABI was processed as a kind of special case
of the usual 32-bit variant. But this doesn't work very well.

Fix it and help avoiding possible future problems by defining
a separate target for it.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 target-x86.c | 32 ++++++++++++++++++++++++++++++++
 target.c     | 11 ++++++++---
 target.h     |  1 +
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/target-x86.c b/target-x86.c
index e69594edac0e..b7ff8f2ab4ed 100644
--- a/target-x86.c
+++ b/target-x86.c
@@ -67,6 +67,37 @@ const struct target target_i386 = {
 };
 
 
+static void init_x86_x32(const struct target *target)
+{
+	init_x86_common(target);
+
+	max_int_alignment = 8;
+
+	fast16_ctype = &int_ctype;
+	ufast16_ctype = &uint_ctype;
+	fast32_ctype = &int_ctype;
+	ufast32_ctype = &uint_ctype;
+	wchar_ctype = &long_ctype;
+}
+
+static const struct target target_x86_x32 = {
+	.mach = MACH_X86_64,
+	.bitness = ARCH_X32,
+	.big_endian = 0,
+	.unsigned_char = 0,
+	.has_int128 = 1,
+
+	.bits_in_longdouble = 128,
+	.max_fp_alignment = 16,
+
+	.target_32bit = &target_i386,
+	.target_64bit = &target_x86_64,
+
+	.init = init_x86_x32,
+	.predefine = predefine_x86_64,
+};
+
+
 static void init_x86_64(const struct target *target)
 {
 	init_x86_common(target);
@@ -124,6 +155,7 @@ const struct target target_x86_64 = {
 	.max_fp_alignment = 16,
 
 	.target_32bit = &target_i386,
+	.target_x32bit = &target_x86_x32,
 
 	.init = init_x86_64,
 	.predefine = predefine_x86_64,
diff --git a/target.c b/target.c
index 308386b8fa7d..8ae22d744f40 100644
--- a/target.c
+++ b/target.c
@@ -213,10 +213,17 @@ void target_init(void)
 	const struct target *target = arch_target;
 
 	switch (arch_m64) {
+	case ARCH_X32:
+		if (target->target_x32bit)
+			target = target->target_x32bit;
+		goto case_32bit;
+
 	case ARCH_LP32:
 		max_int_alignment = 4;
+		if (target->target_32bit)
+			target = target->target_32bit;
 		/* fallthrough */
-	case ARCH_X32:
+	case_32bit:
 		bits_in_long = 32;
 		bits_in_pointer = 32;
 		pointer_alignment = 4;
@@ -228,8 +235,6 @@ void target_init(void)
 		uintmax_ctype = &ullong_ctype;
 		fast64_ctype = &llong_ctype;
 		ufast64_ctype = &ullong_ctype;
-		if (target->target_32bit)
-			target = target->target_32bit;
 		break;
 
 	case ARCH_LLP64:
diff --git a/target.h b/target.h
index 8ffd8e882906..92b8af9169d7 100644
--- a/target.h
+++ b/target.h
@@ -92,6 +92,7 @@ struct target {
 	unsigned int	max_fp_alignment;
 
 	const struct target *target_32bit;
+	const struct target *target_x32bit;
 	const struct target *target_64bit;
 
 	const struct builtin_fn *builtins;
-- 
2.27.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