Add '-fwrapv' to gcc CFLAGS
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 19 Mar 2009 18:10:17 +0000 (11:10 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 19 Mar 2009 18:10:17 +0000 (11:10 -0700)
This makes sure that gcc doesn't try to optimize away wrapping
arithmetic, which the kernel occasionally uses for overflow testing, ie
things like

if (ptr + offset < ptr)

which technically is undefined for non-unsigned types. See

http://bugzilla.kernel.org/show_bug.cgi?id=12597

for details.

Not all versions of gcc support it, so we need to make it conditional
(it looks like it was introduced in gcc-3.4).

Reminded-by: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Makefile

index 2e2f4a4324af777e66ffd333f7b3e44c8d5e243b..f607658ac896b710ed1d144b415c3873d097bede 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -347,6 +347,7 @@ KBUILD_CPPFLAGS := -D__KERNEL__
 KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
                   -fno-strict-aliasing -fno-common \
                   -Werror-implicit-function-declaration
+KBUILD_CFLAGS  += $(call cc-option,-fwrapv)
 KBUILD_AFLAGS   := -D__ASSEMBLY__
 
 # Read KERNELRELEASE from include/config/kernel.release (if it exists)