aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib.c
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-04-27 11:52:21 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-05-01 14:09:21 +0200
commite517edeb7cac6ecda0a951b776fae8d640df5fb2 (patch)
treec75edfaa7a76f9f36ce73c01318a27f190058dd0 /lib.c
parent08482b36803bbd896fb2a429b35a75629b23e067 (diff)
downloadsparse-dev-e517edeb7cac6ecda0a951b776fae8d640df5fb2.tar.gz
add a flag -mx32 ILP32 env on 64 bit archs
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@gmail.com> Acked-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index 5aa958ee..37766d30 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