Re: [RFC/PATCH 1/2] sparse: Fix including glibc headers on x86-64

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

 



Here is the patch I am purposing.

Please let me know if I handle the default size parsing wrong.

Chris

On Fri, Mar 23, 2012 at 2:13 AM, Christopher Li <sparse@xxxxxxxxxxx> wrote:
>
> We can start from -m32 parsing and work our way through the arch parsing.
>
From 95e614e382aaee4b6d1229aa8e9955eabb3f4756 Mon Sep 17 00:00:00 2001
From: Christopher Li <sparse@xxxxxxxxxxx>
Date: Fri, 23 Mar 2012 02:58:20 -0700
Subject: [PATCH] Adding default for m64/m32 handle

This is improved version of Pekka Enberg's patch
"Fix including glibc headers on x86-64".

To avoid setting 64 bit define in the -m32 case,
the 64 bit initialization needs to delay until all
arguments are handled.

Signed-off-by: Christopher Li <sparse@xxxxxxxxxxx>
---
 lib.c |   43 +++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/lib.c b/lib.c
index 396e9f1..fc06018 100644
--- a/lib.c
+++ b/lib.c
@@ -224,6 +224,15 @@ static enum { STANDARD_C89,
               STANDARD_GNU89,
               STANDARD_GNU99, } standard = STANDARD_GNU89;
 
+#ifdef __x86_64__
+#define ARCH_M64_DEFAULT 1
+#else
+#define ARCH_M64_DEFAULT 0
+#endif
+
+int arch_m64 = ARCH_M64_DEFAULT;
+int arch_msize_long = 0;
+
 #define CMDLINE_INCLUDE 20
 int cmdline_include_nr = 0;
 struct cmdline_include cmdline_include[CMDLINE_INCLUDE];
@@ -344,19 +353,47 @@ static char **handle_switch_M(char *arg, char **next)
 static char **handle_switch_m(char *arg, char **next)
 {
 	if (!strcmp(arg, "m64")) {
+		arch_m64 = 1;
+	} else if (!strcmp(arg, "m32")) {
+		arch_m64 = 0;
+	} else if (!strcmp(arg, "msize-long")) {
+		arch_msize_long = 1;
+	}
+	return next;
+}
+
+static void handle_arch_m64_finalize(void)
+{
+	if (arch_m64) {
 		bits_in_long = 64;
 		max_int_alignment = 8;
 		bits_in_pointer = 64;
 		pointer_alignment = 8;
 		size_t_ctype = &ulong_ctype;
 		ssize_t_ctype = &long_ctype;
-	} else if (!strcmp(arg, "msize-long")) {
+#ifdef __x86_64__
+		add_pre_buffer("#weak_define x86_64 1\n");
+		add_pre_buffer("#weak_define __x86_64 1\n");
+		add_pre_buffer("#weak_define __x86_64__ 1\n");
+#endif
+	}
+}
+
+static void handle_arch_msize_long_finalize(void)
+{
+	if (arch_msize_long) {
 		size_t_ctype = &ulong_ctype;
 		ssize_t_ctype = &long_ctype;
 	}
-	return next;
 }
 
+static void handle_arch_finalize(void)
+{
+	handle_arch_m64_finalize();
+	handle_arch_msize_long_finalize();
+}
+
+
 static char **handle_switch_o(char *arg, char **next)
 {
 	if (!strcmp (arg, "o")) {       // "-o foo"
@@ -931,6 +968,8 @@ struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list
 	handle_switch_W_finalize();
 	handle_switch_v_finalize();
 
+	handle_arch_finalize();
+
 	list = NULL;
 	if (!ptr_list_empty(filelist)) {
 		// Initialize type system
-- 
1.7.7.6


[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