linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 8/9] x86-x32: fix it by defining a separate target for it
Date: Tue, 14 Jul 2020 00:33:02 +0200	[thread overview]
Message-ID: <20200713223304.83666-9-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20200713223304.83666-1-luc.vanoostenryck@gmail.com>

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@gmail.com>
---
 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


  parent reply	other threads:[~2020-07-13 22:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-13 22:32 [PATCH 0/9] arch specific predefines Luc Van Oostenryck
2020-07-13 22:32 ` [PATCH 1/9] sparc: add 'sparcv8' predefines for sparc32 Luc Van Oostenryck
2020-07-13 22:32 ` [PATCH 2/9] alpha: has 64-bit long double & int128 Luc Van Oostenryck
2020-07-13 22:32 ` [PATCH 3/9] ppc: add predefines __LONGDOUBLE128 & __LONG_DOUBLE_128__ Luc Van Oostenryck
2020-07-13 22:32 ` [PATCH 4/9] arch: add predefines __INT_LEAST${N}_TYPE__ Luc Van Oostenryck
2020-07-13 22:32 ` [PATCH 5/9] arch: add predefines __INT_FAST${N}_TYPE__ Luc Van Oostenryck
2020-07-13 22:33 ` [PATCH 6/9] predefine: teach sparse about __SIG_ATOMIC_TYPE__ Luc Van Oostenryck
2020-07-13 22:33 ` [PATCH 7/9] arch: allow target specific [u]intptr_t & ptrdiff_t Luc Van Oostenryck
2020-07-13 22:33 ` Luc Van Oostenryck [this message]
2020-07-13 22:33 ` [PATCH 9/9] predefine: let predefine_width() take the usual interface Luc Van Oostenryck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200713223304.83666-9-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).