summaryrefslogtreecommitdiff
blob: a72d5beee9e15786f16b228a54f1891d1ee31c4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Taken from debian GNU/kFreeBSD.

Regretably, with GCC 4.4 or later this is the only flag combination
I could find that doesn't cause kernel panics CPU triple-faults or
other kind of severe breakage. This is Gentoo Bug #410945.

We restrict this to GCC so that Clang can use -O2.

--- a/sys/conf/kern.pre.mk
+++ b/sys/conf/kern.pre.mk
@@ -41,6 +41,9 @@
 .if !empty(COPTFLAGS:M-O[23s]) && empty(COPTFLAGS:M-fno-strict-aliasing)
 COPTFLAGS+= -fno-strict-aliasing
 .endif
+.if ${CC:T:Mgcc} == "gcc" && !empty(COPTFLAGS:M-O[23s])
+COPTFLAGS+= -O1
+.endif
 .if !defined(NO_CPU_COPTFLAGS)
 COPTFLAGS+= ${_CPUCFLAGS}
 .endif
--- a/sys/conf/kmod.mk
+++ b/sys/conf/kmod.mk
@@ -91,6 +91,9 @@
 .if !empty(CFLAGS:M-O[23s]) && empty(CFLAGS:M-fno-strict-aliasing)
 CFLAGS+=	-fno-strict-aliasing
 .endif
+.if ${CC:T:Mgcc} == "gcc" && !empty(CFLAGS:M-O[23s])
+CFLAGS+=	-O1
+.endif
 WERROR?=	-Werror
 CFLAGS+=	${WERROR}
 CFLAGS+=	-D_KERNEL