]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/conf/kern.mk
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / sys / conf / kern.mk
1 # $FreeBSD$
2
3 #
4 # Warning flags for compiling the kernel and components of the kernel:
5 #
6 CWARNFLAGS?=    -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes \
7                 -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual \
8                 -Wundef -Wno-pointer-sign ${FORMAT_EXTENSIONS} \
9                 -Wmissing-include-dirs -fdiagnostics-show-option \
10                 -Wno-unknown-pragmas \
11                 ${CWARNEXTRA}
12 #
13 # The following flags are next up for working on:
14 #       -Wextra
15
16 # Disable a few warnings for clang, since there are several places in the
17 # kernel where fixing them is more trouble than it is worth, or where there is
18 # a false positive.
19 .if ${COMPILER_TYPE} == "clang"
20 NO_WCONSTANT_CONVERSION=        -Wno-constant-conversion
21 NO_WSHIFT_COUNT_NEGATIVE=       -Wno-shift-count-negative
22 NO_WSHIFT_COUNT_OVERFLOW=       -Wno-shift-count-overflow
23 NO_WSELF_ASSIGN=                -Wno-self-assign
24 NO_WUNNEEDED_INTERNAL_DECL=     -Wno-unneeded-internal-declaration
25 NO_WSOMETIMES_UNINITIALIZED=    -Wno-error-sometimes-uninitialized
26 NO_WCAST_QUAL=                  -Wno-cast-qual
27 NO_WARRAY_BOUNDS=               -Wno-error-array-bounds
28 # Several other warnings which might be useful in some cases, but not severe
29 # enough to error out the whole kernel build.  Display them anyway, so there is
30 # some incentive to fix them eventually.
31 CWARNEXTRA?=    -Wno-error-tautological-compare -Wno-error-empty-body \
32                 -Wno-error-parentheses-equality -Wno-error-unused-function \
33                 -Wno-error-pointer-sign
34 .if ${COMPILER_VERSION} >= 30700
35 CWARNEXTRA+=    -Wno-error-shift-negative-value
36 .endif
37 .if ${COMPILER_VERSION} >= 40000
38 CWARNEXTRA+=    -Wno-error-address-of-packed-member
39 .endif
40
41 CLANG_NO_IAS= -no-integrated-as
42 .if ${COMPILER_VERSION} < 30500
43 # XXX: clang < 3.5 integrated-as doesn't grok .codeNN directives
44 CLANG_NO_IAS34= -no-integrated-as
45 .endif
46 .endif
47
48 .if ${COMPILER_TYPE} == "gcc"
49 .if ${COMPILER_VERSION} >= 40800
50 # Catch-all for all the things that are in our tree, but for which we're
51 # not yet ready for this compiler.
52 CWARNEXTRA?=    -Wno-error=address                              \
53                 -Wno-error=aggressive-loop-optimizations        \
54                 -Wno-error=array-bounds                         \
55                 -Wno-error=attributes                           \
56                 -Wno-error=cast-qual                            \
57                 -Wno-error=enum-compare                         \
58                 -Wno-error=inline                               \
59                 -Wno-error=maybe-uninitialized                  \
60                 -Wno-error=overflow                             \
61                 -Wno-error=sequence-point                       \
62                 -Wno-error=unused-but-set-variable
63 .if ${COMPILER_VERSION} >= 60100
64 CWARNEXTRA+=    -Wno-error=misleading-indentation               \
65                 -Wno-error=nonnull-compare                      \
66                 -Wno-error=shift-overflow                       \
67                 -Wno-error=tautological-compare
68 .endif
69 .else
70 # For gcc 4.2, eliminate the too-often-wrong warnings about uninitialized vars.
71 CWARNEXTRA?=    -Wno-uninitialized
72 .endif
73 .endif
74
75 # External compilers may not support our format extensions.  Allow them
76 # to be disabled.  WARNING: format checking is disabled in this case.
77 .if ${MK_FORMAT_EXTENSIONS} == "no"
78 FORMAT_EXTENSIONS=      -Wno-format
79 .elif ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 30600
80 FORMAT_EXTENSIONS=      -D__printf__=__freebsd_kprintf__
81 .else
82 FORMAT_EXTENSIONS=      -fformat-extensions
83 .endif
84
85 #
86 # On i386, do not align the stack to 16-byte boundaries.  Otherwise GCC 2.95
87 # and above adds code to the entry and exit point of every function to align the
88 # stack to 16-byte boundaries -- thus wasting approximately 12 bytes of stack
89 # per function call.  While the 16-byte alignment may benefit micro benchmarks,
90 # it is probably an overall loss as it makes the code bigger (less efficient
91 # use of code cache tag lines) and uses more stack (less efficient use of data
92 # cache tag lines).  Explicitly prohibit the use of FPU, SSE and other SIMD
93 # operations inside the kernel itself.  These operations are exclusively
94 # reserved for user applications.
95 #
96 # gcc:
97 # Setting -mno-mmx implies -mno-3dnow
98 # Setting -mno-sse implies -mno-sse2, -mno-sse3 and -mno-ssse3
99 #
100 # clang:
101 # Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
102 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
103 #
104 .if ${MACHINE_CPUARCH} == "i386"
105 CFLAGS.gcc+=    -mno-align-long-strings -mpreferred-stack-boundary=2
106 CFLAGS.clang+=  -mno-aes -mno-avx
107 CFLAGS+=        -mno-mmx -mno-sse -msoft-float
108 INLINE_LIMIT?=  8000
109 .endif
110
111 .if ${MACHINE_CPUARCH} == "arm"
112 INLINE_LIMIT?=  8000
113 .endif
114
115 .if ${MACHINE_CPUARCH} == "aarch64"
116 # We generally don't want fpu instructions in the kernel.
117 CFLAGS += -mgeneral-regs-only
118 # Reserve x18 for pcpu data
119 CFLAGS += -ffixed-x18
120 .endif
121
122 .if ${MACHINE_CPUARCH} == "riscv"
123 CFLAGS.gcc+=    -mcmodel=medany
124 INLINE_LIMIT?=  8000
125 .endif
126
127 #
128 # For sparc64 we want the medany code model so modules may be located
129 # anywhere in the 64-bit address space.  We also tell GCC to use floating
130 # point emulation.  This avoids using floating point registers for integer
131 # operations which it has a tendency to do.
132 #
133 .if ${MACHINE_CPUARCH} == "sparc64"
134 CFLAGS.clang+=  -mcmodel=large -fno-dwarf2-cfi-asm
135 CFLAGS.gcc+=    -mcmodel=medany -msoft-float
136 INLINE_LIMIT?=  15000
137 .endif
138
139 #
140 # For AMD64, we explicitly prohibit the use of FPU, SSE and other SIMD
141 # operations inside the kernel itself.  These operations are exclusively
142 # reserved for user applications.
143 #
144 # gcc:
145 # Setting -mno-mmx implies -mno-3dnow
146 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387
147 #
148 # clang:
149 # Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
150 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
151 # (-mfpmath= is not supported)
152 #
153 .if ${MACHINE_CPUARCH} == "amd64"
154 CFLAGS.clang+=  -mno-aes -mno-avx
155 CFLAGS+=        -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \
156                 -fno-asynchronous-unwind-tables
157 INLINE_LIMIT?=  8000
158 .endif
159
160 #
161 # For PowerPC we tell gcc to use floating point emulation.  This avoids using
162 # floating point registers for integer operations which it has a tendency to do.
163 # Also explicitly disable Altivec instructions inside the kernel.
164 #
165 .if ${MACHINE_CPUARCH} == "powerpc"
166 CFLAGS+=        -mno-altivec -msoft-float
167 INLINE_LIMIT?=  15000
168 .endif
169
170 #
171 # Use dot symbols on powerpc64 to make ddb happy
172 #
173 .if ${MACHINE_ARCH} == "powerpc64"
174 CFLAGS.gcc+=    -mcall-aixdesc
175 .endif
176
177 #
178 # For MIPS we also tell gcc to use floating point emulation
179 #
180 .if ${MACHINE_CPUARCH} == "mips"
181 CFLAGS+=        -msoft-float
182 INLINE_LIMIT?=  8000
183 .endif
184
185 #
186 # GCC 3.0 and above like to do certain optimizations based on the
187 # assumption that the program is linked against libc.  Stop this.
188 #
189 CFLAGS+=        -ffreestanding
190
191 #
192 # The C standard leaves signed integer overflow behavior undefined.
193 # gcc and clang opimizers take advantage of this.  The kernel makes
194 # use of signed integer wraparound mechanics so we need the compiler
195 # to treat it as a wraparound and not take shortcuts.
196 #
197 CFLAGS+=        -fwrapv
198
199 #
200 # GCC SSP support
201 #
202 .if ${MK_SSP} != "no" && \
203     ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
204 CFLAGS+=        -fstack-protector
205 .endif
206
207 #
208 # Retpoline speculative execution vulnerability mitigation (CVE-2017-5715)
209 #
210 .if defined(COMPILER_FEATURES) && ${COMPILER_FEATURES:Mretpoline} != "" && \
211     ${MK_KERNEL_RETPOLINE} != "no"
212 CFLAGS+=        -mretpoline
213 .endif
214
215 #
216 # Add -gdwarf-2 when compiling -g. The default starting in clang v3.4
217 # and gcc 4.8 is to generate DWARF version 4. However, our tools don't
218 # cope well with DWARF 4, so force it to genereate DWARF2, which they
219 # understand. Do this unconditionally as it is harmless when not needed,
220 # but critical for these newer versions.
221 #
222 .if ${CFLAGS:M-g} != "" && ${CFLAGS:M-gdwarf*} == ""
223 CFLAGS+=        -gdwarf-2
224 .endif
225
226 CFLAGS+= ${CWARNFLAGS:M*} ${CWARNFLAGS.${.IMPSRC:T}}
227 CFLAGS+= ${CFLAGS.${COMPILER_TYPE}} ${CFLAGS.${.IMPSRC:T}}
228
229 # Tell bmake not to mistake standard targets for things to be searched for
230 # or expect to ever be up-to-date.
231 PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \
232                 beforelinking build build-tools buildfiles buildincludes \
233                 checkdpadd clean cleandepend cleandir cleanobj configure \
234                 depend distclean distribute exe \
235                 html includes install installfiles installincludes lint \
236                 obj objlink objs objwarn \
237                 realinstall regress \
238                 tags whereobj
239
240 .PHONY: ${PHONY_NOTMAIN}
241 .NOTMAIN: ${PHONY_NOTMAIN}
242
243 CSTD=           c99
244
245 .if ${CSTD} == "k&r"
246 CFLAGS+=        -traditional
247 .elif ${CSTD} == "c89" || ${CSTD} == "c90"
248 CFLAGS+=        -std=iso9899:1990
249 .elif ${CSTD} == "c94" || ${CSTD} == "c95"
250 CFLAGS+=        -std=iso9899:199409
251 .elif ${CSTD} == "c99"
252 CFLAGS+=        -std=iso9899:1999
253 .else # CSTD
254 CFLAGS+=        -std=${CSTD}
255 .endif # CSTD
256
257 # Set target-specific linker emulation name. Used by ld -b binary to convert
258 # binary files into ELF objects.
259 LD_EMULATION_aarch64=aarch64elf
260 LD_EMULATION_amd64=elf_x86_64_fbsd
261 LD_EMULATION_arm=armelf_fbsd
262 LD_EMULATION_armeb=armelfb_fbsd
263 LD_EMULATION_armv6=armelf_fbsd
264 LD_EMULATION_i386=elf_i386_fbsd
265 LD_EMULATION_mips= elf32btsmip_fbsd
266 LD_EMULATION_mips64= elf64btsmip_fbsd
267 LD_EMULATION_mipsel= elf32ltsmip_fbsd
268 LD_EMULATION_mips64el= elf64ltsmip_fbsd
269 LD_EMULATION_mipsn32= elf32btsmipn32_fbsd
270 LD_EMULATION_mipsn32el= elf32btsmipn32_fbsd   # I don't think this is a thing that works
271 LD_EMULATION_powerpc= elf32ppc_fbsd
272 LD_EMULATION_powerpc64= elf64ppc_fbsd
273 LD_EMULATION_riscv64= elf64lriscv
274 LD_EMULATION_sparc64= elf64_sparc_fbsd
275 LD_EMULATION=${LD_EMULATION_${MACHINE_ARCH}}