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