Skip to contentSkip to conversation

sparse warnings in overflow.h

PATCH New Miroslav Benes 4 participants 5 messages Jun 7, 2018 – Jun 8, 2018

lore
Share & tools
lore
#0 lore raw

Hi Kees,

sparse (make C=1) gives me this warnings today...

./include/linux/overflow.h:254:13: error: undefined identifier '__builtin_mul_overflow' ./include/linux/overflow.h:254:13: error: incorrect type in conditional
./include/linux/overflow.h:254:13: got void
./include/linux/overflow.h:256:13: error: undefined identifier '__builtin_add_overflow' ./include/linux/overflow.h:256:13: error: incorrect type in conditional
./include/linux/overflow.h:256:13: got void

This hunk obviously fixes it, but I'm really not sure if it is a proper fix.

include/linux/compiler-gcc.h +1 -1
index f1a7492a5cc8..15e55b89e952 100644
@@ -344,6 +344,6 @@
  */
 #define uninitialized_var(x) x = x
 
-#if GCC_VERSION >= 50100
+#if GCC_VERSION >= 50100 && !defined(__CHECKER__)
 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
 #endif

Any idea?

Regards,
Miroslav

#1 lore raw
Quoted 28 lines · Miroslav Benes

Hi Kees,

sparse (make C=1) gives me this warnings today...

./include/linux/overflow.h:254:13: error: undefined identifier '__builtin_mul_overflow' ./include/linux/overflow.h:254:13: error: incorrect type in conditional
./include/linux/overflow.h:254:13: got void
./include/linux/overflow.h:256:13: error: undefined identifier '__builtin_add_overflow' ./include/linux/overflow.h:256:13: error: incorrect type in conditional
./include/linux/overflow.h:256:13: got void

This hunk obviously fixes it, but I'm really not sure if it is a proper fix.

include/linux/compiler-gcc.h +1 -1
index f1a7492a5cc8..15e55b89e952 100644
@@ -344,6 +344,6 @@
  */
 #define uninitialized_var(x) x = x
 
-#if GCC_VERSION >= 50100
+#if GCC_VERSION >= 50100 && !defined(__CHECKER__)
 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
 #endif
Quoted 1 line

Any idea?

Hi! Yeah, that's probably the correct approach. If the checker doesn't have it, the builtins need to be disabled. :)

Can you send this with a Signed-off-by line, etc, and I'll take it for sending to Linus?

Thanks!

-Kees

Signature · 2 lines
Kees Cook
Pixel Security
#2 lore raw
Quoted 29 lines · Kees Cook
Quoted 28 lines · Miroslav Benes

Hi Kees,

sparse (make C=1) gives me this warnings today...

./include/linux/overflow.h:254:13: error: undefined identifier '__builtin_mul_overflow' ./include/linux/overflow.h:254:13: error: incorrect type in conditional
./include/linux/overflow.h:254:13: got void
./include/linux/overflow.h:256:13: error: undefined identifier '__builtin_add_overflow' ./include/linux/overflow.h:256:13: error: incorrect type in conditional
./include/linux/overflow.h:256:13: got void

This hunk obviously fixes it, but I'm really not sure if it is a proper fix.

include/linux/compiler-gcc.h +1 -1
index f1a7492a5cc8..15e55b89e952 100644
@@ -344,6 +344,6 @@
  */
 #define uninitialized_var(x) x = x
 
-#if GCC_VERSION >= 50100
+#if GCC_VERSION >= 50100 && !defined(__CHECKER__)
 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
 #endif
Quoted 4 lines
Quoted 1 line

Any idea?

Hi! Yeah, that's probably the correct approach. If the checker doesn't have it, the builtins need to be disabled. :)

IIRC, the problem is that sparse pretends to be the gcc sparse itself was built with, which is obviously entirely unrelated to the C dialect that that particular sparse version groks. Sigh. Ack to the fix above.

Rasmus

#3 lore raw
Quoted 4 lines · Rasmus Villemoes

IIRC, the problem is that sparse pretends to be the gcc sparse itself was built with, which is obviously entirely unrelated to the C dialect that that particular sparse version groks. Sigh. Ack to the fix above.

Yes, indeed, and it is sometimes a problem.
Ideal would be that sparse would pretend to be same GCC as the one used to compile the code being checked *and* to have exactly the same features.

Pretending to be an older version of GCC would maybe solve the present problem it's not really a general solution.

One good thing would be to not depend on GCC versions to enable some features (but GCC offers few facilities helping here).

Best regards,
-- Luc Van Oostenryck

#4 lore raw

PATCH 1/1 compiler-gcc.h: don't set COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW for sparse

In reply to Kees Cook

sparse errors out with

./include/linux/overflow.h:254:13: error: undefined identifier '__builtin_mul_overflow' ./include/linux/overflow.h:254:13: error: incorrect type in conditional
./include/linux/overflow.h:254:13: got void
./include/linux/overflow.h:256:13: error: undefined identifier '__builtin_add_overflow' ./include/linux/overflow.h:256:13: error: incorrect type in conditional
./include/linux/overflow.h:256:13: got void

Sparse has not acquired generic overflow builtins yet, so don't set COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW for it.

---
 include/linux/compiler-gcc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/compiler-gcc.h +1 -1
index f1a7492a5cc8..15e55b89e952 100644
@@ -344,6 +344,6 @@
  */
 #define uninitialized_var(x) x = x
 
-#if GCC_VERSION >= 50100
+#if GCC_VERSION >= 50100 && !defined(__CHECKER__)
 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
 #endif
Signature · 1 line
2.17.0