All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] teach sparse about endianness
@ 2017-06-20 20:19 Luc Van Oostenryck
  2017-06-20 20:19 ` [PATCH 1/3] teach sparse about -m{big,little}-endian Luc Van Oostenryck
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2017-06-20 20:19 UTC (permalink / raw)
  To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck

The goal of this series is to let sparse correctly
check macros, structures, ... endian-specific.
This is done by:
1) the introduction of a pair of option flags:
   -mbig-endian/-mlittle-endian 
2) a set of predefined macros:
   __{BIG,LITTLE}_ENDIAN__,
   __ORDER_{BIG,LITTLE}_ENDIAN__ &
   __BYTE_ORDER__

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] teach sparse about -m{big,little}-endian
  2017-06-20 20:19 [PATCH 0/3] teach sparse about endianness Luc Van Oostenryck
@ 2017-06-20 20:19 ` Luc Van Oostenryck
  2017-06-20 20:19 ` [PATCH 2/3] teach sparse about __{BIG,LITTLE}_ENDIAN__ Luc Van Oostenryck
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2017-06-20 20:19 UTC (permalink / raw)
  To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck

Some macros, structures definitions, ... depends on the
endianness and thus checking them with sparse demands
that sparse is endian-aware.

Give this information to sparse with two flags:
-mbig-endian/-mlittle-endian, and by default use
the endianness of the platform used to compile sparse.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 lib.c | 15 ++++++++++++++-
 lib.h |  1 +
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/lib.c b/lib.c
index eac84ee3f..a22635ecc 100644
--- a/lib.c
+++ b/lib.c
@@ -282,6 +282,14 @@ static enum { STANDARD_C89,
 int arch_m64 = ARCH_M64_DEFAULT;
 int arch_msize_long = 0;
 
+#ifdef __BIG_ENDIAN__
+#define ARCH_BIG_ENDIAN 1
+#else
+#define ARCH_BIG_ENDIAN 0
+#endif
+int arch_big_endian = ARCH_BIG_ENDIAN;
+
+
 #define CMDLINE_INCLUDE 20
 static int cmdline_include_nr = 0;
 static char *cmdline_include[CMDLINE_INCLUDE];
@@ -410,8 +418,13 @@ static char **handle_switch_m(char *arg, char **next)
 		arch_m64 = ARCH_LLP64;
 	} else if (!strcmp(arg, "msize-long")) {
 		arch_msize_long = 1;
-	} else if (!strcmp(arg, "multiarch-dir"))
+	} else if (!strcmp(arg, "multiarch-dir")) {
 		return handle_multiarch_dir(arg, next);
+	} else if (!strcmp(arg, "mbig-endian")) {
+		arch_big_endian = 1;
+	} else if (!strcmp(arg, "mlittle-endian")) {
+		arch_big_endian = 0;
+	}
 	return next;
 }
 
diff --git a/lib.h b/lib.h
index e09f47f12..3f8d3615a 100644
--- a/lib.h
+++ b/lib.h
@@ -150,6 +150,7 @@ extern int fdump_linearize;
 extern unsigned long long fmemcpy_max_count;
 
 extern int arch_m64;
+extern int arch_big_endian;
 
 extern void declare_builtin_functions(void);
 extern void create_builtin_stream(void);
-- 
2.13.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] teach sparse about __{BIG,LITTLE}_ENDIAN__
  2017-06-20 20:19 [PATCH 0/3] teach sparse about endianness Luc Van Oostenryck
  2017-06-20 20:19 ` [PATCH 1/3] teach sparse about -m{big,little}-endian Luc Van Oostenryck
@ 2017-06-20 20:19 ` Luc Van Oostenryck
  2017-06-20 20:19 ` [PATCH 3/3] teach sparse about __BYTE_ORDER__ & __ORDER_{BIG,LITTLE}_ENDIAN__ Luc Van Oostenryck
  2017-06-21  4:13 ` [PATCH 0/3] teach sparse about endianness Christopher Li
  3 siblings, 0 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2017-06-20 20:19 UTC (permalink / raw)
  To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck

Some macros, structures definitions, ... depends on the
endianness. This is generaly done via some header file
but these headers need information from the compiler via
the macros __{BIG,LITTLE}_ENDIAN__.

Let sparse predefine these macros like compilers do.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 lib.c                      |  3 +++
 validation/endian-big.c    | 11 +++++++++++
 validation/endian-little.c | 11 +++++++++++
 3 files changed, 25 insertions(+)
 create mode 100644 validation/endian-big.c
 create mode 100644 validation/endian-little.c

diff --git a/lib.c b/lib.c
index a22635ecc..daf7d0219 100644
--- a/lib.c
+++ b/lib.c
@@ -961,6 +961,9 @@ static void predefined_macros(void)
 	predefined_sizeof("FLOAT", bits_in_float);
 	predefined_sizeof("DOUBLE", bits_in_double);
 	predefined_sizeof("LONG_DOUBLE", bits_in_longdouble);
+
+	add_pre_buffer("#weak_define __%s_ENDIAN__ 1\n",
+		arch_big_endian ? "BIG" : "LITTLE");
 }
 
 void declare_builtin_functions(void)
diff --git a/validation/endian-big.c b/validation/endian-big.c
new file mode 100644
index 000000000..d535748cd
--- /dev/null
+++ b/validation/endian-big.c
@@ -0,0 +1,11 @@
+#if defined(__LITTLE_ENDIAN__)
+#error "__LITTLE_ENDIAN__ defined!"
+#endif
+#if (__BIG_ENDIAN__ != 1)
+#error "__BIG_ENDIAN__ not correctly defined!"
+#endif
+
+/*
+ * check-name: endian-big.c
+ * check-command: sparse -mbig-endian $file
+ */
diff --git a/validation/endian-little.c b/validation/endian-little.c
new file mode 100644
index 000000000..cc4a14f73
--- /dev/null
+++ b/validation/endian-little.c
@@ -0,0 +1,11 @@
+#if defined(__BIG_ENDIAN__)
+#error "__BIG_ENDIAN__ defined!"
+#endif
+#if (__LITTLE_ENDIAN__ != 1)
+#error "__LITTLE_ENDIAN__ not correctly defined!"
+#endif
+
+/*
+ * check-name: endian-little.c
+ * check-command: sparse -mlittle-endian $file
+ */
-- 
2.13.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] teach sparse about __BYTE_ORDER__ & __ORDER_{BIG,LITTLE}_ENDIAN__
  2017-06-20 20:19 [PATCH 0/3] teach sparse about endianness Luc Van Oostenryck
  2017-06-20 20:19 ` [PATCH 1/3] teach sparse about -m{big,little}-endian Luc Van Oostenryck
  2017-06-20 20:19 ` [PATCH 2/3] teach sparse about __{BIG,LITTLE}_ENDIAN__ Luc Van Oostenryck
@ 2017-06-20 20:19 ` Luc Van Oostenryck
  2017-06-21  4:13 ` [PATCH 0/3] teach sparse about endianness Christopher Li
  3 siblings, 0 replies; 5+ messages in thread
From: Luc Van Oostenryck @ 2017-06-20 20:19 UTC (permalink / raw)
  To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck

Some macros, structures definitions, ... depends on the
endianness. This is generaly done via some header file
but these headers need information from the compiler via
the macros __BYTE_ORDER__, itself being defined to
__ORDER_BIG_ENDIAN__ or __ORDER_LITTLE_ENDIAN__.

Let sparse predefine these macros like compilers do.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 lib.c                      | 6 ++++++
 validation/endian-big.c    | 3 +++
 validation/endian-little.c | 3 +++
 3 files changed, 12 insertions(+)

diff --git a/lib.c b/lib.c
index daf7d0219..de6350439 100644
--- a/lib.c
+++ b/lib.c
@@ -964,6 +964,12 @@ static void predefined_macros(void)
 
 	add_pre_buffer("#weak_define __%s_ENDIAN__ 1\n",
 		arch_big_endian ? "BIG" : "LITTLE");
+
+	add_pre_buffer("#weak_define __ORDER_LITTLE_ENDIAN__ 1234\n");
+	add_pre_buffer("#weak_define __ORDER_BIG_ENDIAN__ 4321\n");
+	add_pre_buffer("#weak_define __ORDER_PDP_ENDIAN__ 3412\n");
+	add_pre_buffer("#weak_define __BYTE_ORDER__ __ORDER_%s_ENDIAN__\n",
+		arch_big_endian ? "BIG" : "LITTLE");
 }
 
 void declare_builtin_functions(void)
diff --git a/validation/endian-big.c b/validation/endian-big.c
index d535748cd..ebf95df70 100644
--- a/validation/endian-big.c
+++ b/validation/endian-big.c
@@ -4,6 +4,9 @@
 #if (__BIG_ENDIAN__ != 1)
 #error "__BIG_ENDIAN__ not correctly defined!"
 #endif
+#if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__)
+#error "__BYTE_ORDER__ not correctly defined!"
+#endif
 
 /*
  * check-name: endian-big.c
diff --git a/validation/endian-little.c b/validation/endian-little.c
index cc4a14f73..57ef69866 100644
--- a/validation/endian-little.c
+++ b/validation/endian-little.c
@@ -4,6 +4,9 @@
 #if (__LITTLE_ENDIAN__ != 1)
 #error "__LITTLE_ENDIAN__ not correctly defined!"
 #endif
+#if (__BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__)
+#error "__BYTE_ORDER__ not correctly defined!"
+#endif
 
 /*
  * check-name: endian-little.c
-- 
2.13.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] teach sparse about endianness
  2017-06-20 20:19 [PATCH 0/3] teach sparse about endianness Luc Van Oostenryck
                   ` (2 preceding siblings ...)
  2017-06-20 20:19 ` [PATCH 3/3] teach sparse about __BYTE_ORDER__ & __ORDER_{BIG,LITTLE}_ENDIAN__ Luc Van Oostenryck
@ 2017-06-21  4:13 ` Christopher Li
  3 siblings, 0 replies; 5+ messages in thread
From: Christopher Li @ 2017-06-21  4:13 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: Linux-Sparse

On Tue, Jun 20, 2017 at 1:19 PM, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
> The goal of this series is to let sparse correctly
> check macros, structures, ... endian-specific.
> This is done by:
> 1) the introduction of a pair of option flags:
>    -mbig-endian/-mlittle-endian
> 2) a set of predefined macros:
>    __{BIG,LITTLE}_ENDIAN__,
>    __ORDER_{BIG,LITTLE}_ENDIAN__ &
>    __BYTE_ORDER__

This series looks good to me.

Signed-off-By: <sparse@chrisli.org>

Chris

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-06-21  4:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-20 20:19 [PATCH 0/3] teach sparse about endianness Luc Van Oostenryck
2017-06-20 20:19 ` [PATCH 1/3] teach sparse about -m{big,little}-endian Luc Van Oostenryck
2017-06-20 20:19 ` [PATCH 2/3] teach sparse about __{BIG,LITTLE}_ENDIAN__ Luc Van Oostenryck
2017-06-20 20:19 ` [PATCH 3/3] teach sparse about __BYTE_ORDER__ & __ORDER_{BIG,LITTLE}_ENDIAN__ Luc Van Oostenryck
2017-06-21  4:13 ` [PATCH 0/3] teach sparse about endianness Christopher Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.