From aba31cb69187d41c37c7fa832eb9c8270b8b7227 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 5 Feb 2015 01:36:53 +0000 Subject: [PATCH] Add -fwrapv to CFLAGS for the kernel. This essentially un-reverts r259045. The C standard undefines behavior when signed integers overflow. The compiler toolchain has become more adept at detecting this and taking advantage of faster undefined behavior. At the current time this has the unfortunate effect of the clock stopping after 24 days of uptime. clang makes no distinction between -fwrapv and -fno-strict-overflow. gcc does treat them differently but -fwrapv is mature in gcc and is the behavior are actually expecting. Obtained from: kib --- sys/conf/kern.mk | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sys/conf/kern.mk b/sys/conf/kern.mk index c031b3a37906..4317de56c65e 100644 --- a/sys/conf/kern.mk +++ b/sys/conf/kern.mk @@ -157,6 +157,14 @@ INLINE_LIMIT?= 8000 # CFLAGS+= -ffreestanding +# +# The C standard leaves signed integer overflow behavior undefined. +# gcc and clang opimizers take advantage of this. The kernel makes +# use of signed integer wraparound mechanics so we need the compiler +# to treat it as a wraparound and not take shortcuts. +# +CFLAGS+= -fwrapv + # # GCC SSP support #