]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/conf/kern.mk
ofw_graph: Add functions for graph bindings
[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 -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-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-error-unneeded-internal-declaration
25 NO_WSOMETIMES_UNINITIALIZED=    -Wno-error-sometimes-uninitialized
26 NO_WCAST_QUAL=                  -Wno-error-cast-qual
27 NO_WTAUTOLOGICAL_POINTER_COMPARE= -Wno-tautological-pointer-compare
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-address-of-packed-member
39 .endif
40
41 CLANG_NO_IAS= -no-integrated-as
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 NO_WUNUSED_BUT_SET_VARIABLE = -Wno-unused-but-set-variable
49 CWARNEXTRA?=    -Wno-error=address                              \
50                 -Wno-error=aggressive-loop-optimizations        \
51                 -Wno-error=array-bounds                         \
52                 -Wno-error=attributes                           \
53                 -Wno-error=cast-qual                            \
54                 -Wno-error=enum-compare                         \
55                 -Wno-error=inline                               \
56                 -Wno-error=maybe-uninitialized                  \
57                 -Wno-error=overflow                             \
58                 -Wno-error=sequence-point                       \
59                 -Wno-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 .if ${COMPILER_VERSION} >= 70200
67 CWARNEXTRA+=    -Wno-error=memset-elt-size
68 .endif
69 .if ${COMPILER_VERSION} >= 80000
70 CWARNEXTRA+=    -Wno-error=packed-not-aligned
71 .endif
72 .else
73 # For gcc 4.2, eliminate the too-often-wrong warnings about uninitialized vars.
74 CWARNEXTRA?=    -Wno-uninitialized
75 # GCC 4.2 doesn't have -Wno-error=cast-qual, so just disable the warning for
76 # the few files that are already known to generate cast-qual warnings.
77 NO_WCAST_QUAL= -Wno-cast-qual
78 .endif
79 .endif
80
81 # External compilers may not support our format extensions.  Allow them
82 # to be disabled.  WARNING: format checking is disabled in this case.
83 .if ${MK_FORMAT_EXTENSIONS} == "no"
84 FORMAT_EXTENSIONS=      -Wno-format
85 .elif ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 30600
86 FORMAT_EXTENSIONS=      -D__printf__=__freebsd_kprintf__
87 .else
88 FORMAT_EXTENSIONS=      -fformat-extensions
89 .endif
90
91 #
92 # On i386, do not align the stack to 16-byte boundaries.  Otherwise GCC 2.95
93 # and above adds code to the entry and exit point of every function to align the
94 # stack to 16-byte boundaries -- thus wasting approximately 12 bytes of stack
95 # per function call.  While the 16-byte alignment may benefit micro benchmarks,
96 # it is probably an overall loss as it makes the code bigger (less efficient
97 # use of code cache tag lines) and uses more stack (less efficient use of data
98 # cache tag lines).  Explicitly prohibit the use of FPU, SSE and other SIMD
99 # operations inside the kernel itself.  These operations are exclusively
100 # reserved for user applications.
101 #
102 # gcc:
103 # Setting -mno-mmx implies -mno-3dnow
104 # Setting -mno-sse implies -mno-sse2, -mno-sse3 and -mno-ssse3
105 #
106 # clang:
107 # Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
108 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
109 #
110 .if ${MACHINE_CPUARCH} == "i386"
111 CFLAGS.gcc+=    -mno-align-long-strings -mpreferred-stack-boundary=2
112 CFLAGS.clang+=  -mno-aes -mno-avx
113 CFLAGS+=        -mno-mmx -mno-sse -msoft-float
114 INLINE_LIMIT?=  8000
115 .endif
116
117 .if ${MACHINE_CPUARCH} == "arm"
118 INLINE_LIMIT?=  8000
119 .endif
120
121 .if ${MACHINE_CPUARCH} == "aarch64"
122 # We generally don't want fpu instructions in the kernel.
123 CFLAGS += -mgeneral-regs-only
124 # Reserve x18 for pcpu data
125 CFLAGS += -ffixed-x18
126 INLINE_LIMIT?=  8000
127 .endif
128
129 .if ${MACHINE_CPUARCH} == "riscv"
130 CFLAGS.gcc+=    -mcmodel=medany -march=rv64imafdc -mabi=lp64
131 INLINE_LIMIT?=  8000
132 .endif
133
134 #
135 # For sparc64 we want the medany code model so modules may be located
136 # anywhere in the 64-bit address space.  We also tell GCC to use floating
137 # point emulation.  This avoids using floating point registers for integer
138 # operations which it has a tendency to do.
139 #
140 .if ${MACHINE_CPUARCH} == "sparc64"
141 CFLAGS.clang+=  -mcmodel=large -fno-dwarf2-cfi-asm
142 CFLAGS.gcc+=    -mcmodel=medany -msoft-float
143 INLINE_LIMIT?=  15000
144 .endif
145
146 #
147 # For AMD64, we explicitly prohibit the use of FPU, SSE and other SIMD
148 # operations inside the kernel itself.  These operations are exclusively
149 # reserved for user applications.
150 #
151 # gcc:
152 # Setting -mno-mmx implies -mno-3dnow
153 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387
154 #
155 # clang:
156 # Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
157 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
158 # (-mfpmath= is not supported)
159 #
160 .if ${MACHINE_CPUARCH} == "amd64"
161 CFLAGS.clang+=  -mno-aes -mno-avx
162 CFLAGS+=        -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \
163                 -fno-asynchronous-unwind-tables
164 INLINE_LIMIT?=  8000
165 .endif
166
167 #
168 # For PowerPC we tell gcc to use floating point emulation.  This avoids using
169 # floating point registers for integer operations which it has a tendency to do.
170 # Also explicitly disable Altivec instructions inside the kernel.
171 #
172 .if ${MACHINE_CPUARCH} == "powerpc"
173 CFLAGS+=        -mno-altivec -msoft-float
174 INLINE_LIMIT?=  15000
175 .endif
176
177 .if ${MACHINE_ARCH} == "powerpcspe"
178 CFLAGS.gcc+=    -mno-spe
179 .endif
180
181 #
182 # Use dot symbols (or, better, the V2 ELF ABI) on powerpc64 to make
183 # DDB happy. ELFv2, if available, has some other efficiency benefits.
184 #
185 .if ${MACHINE_ARCH} == "powerpc64"
186 .if ${COMPILER_VERSION} >= 40900
187 CFLAGS.gcc+=    -mabi=elfv2
188 .else
189 CFLAGS.gcc+=    -mcall-aixdesc
190 .endif
191 CFLAGS.clang+=  -mabi=elfv2
192 .endif
193
194 #
195 # For MIPS we also tell gcc to use floating point emulation
196 #
197 .if ${MACHINE_CPUARCH} == "mips"
198 CFLAGS+=        -msoft-float
199 INLINE_LIMIT?=  8000
200 .endif
201
202 #
203 # GCC 3.0 and above like to do certain optimizations based on the
204 # assumption that the program is linked against libc.  Stop this.
205 #
206 CFLAGS+=        -ffreestanding
207
208 #
209 # The C standard leaves signed integer overflow behavior undefined.
210 # gcc and clang opimizers take advantage of this.  The kernel makes
211 # use of signed integer wraparound mechanics so we need the compiler
212 # to treat it as a wraparound and not take shortcuts.
213 #
214 CFLAGS+=        -fwrapv
215
216 #
217 # GCC SSP support
218 #
219 .if ${MK_SSP} != "no" && \
220     ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
221 CFLAGS+=        -fstack-protector
222 .endif
223
224 #
225 # Retpoline speculative execution vulnerability mitigation (CVE-2017-5715)
226 #
227 .if defined(COMPILER_FEATURES) && ${COMPILER_FEATURES:Mretpoline} != "" && \
228     ${MK_KERNEL_RETPOLINE} != "no"
229 CFLAGS+=        -mretpoline
230 .endif
231
232 #
233 # Add -gdwarf-2 when compiling -g. The default starting in clang v3.4
234 # and gcc 4.8 is to generate DWARF version 4. However, our tools don't
235 # cope well with DWARF 4, so force it to genereate DWARF2, which they
236 # understand. Do this unconditionally as it is harmless when not needed,
237 # but critical for these newer versions.
238 #
239 .if ${CFLAGS:M-g} != "" && ${CFLAGS:M-gdwarf*} == ""
240 CFLAGS+=        -gdwarf-2
241 .endif
242
243 CFLAGS+= ${CWARNFLAGS:M*} ${CWARNFLAGS.${.IMPSRC:T}}
244 CFLAGS+= ${CFLAGS.${COMPILER_TYPE}} ${CFLAGS.${.IMPSRC:T}}
245
246 # Tell bmake not to mistake standard targets for things to be searched for
247 # or expect to ever be up-to-date.
248 PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \
249                 beforelinking build build-tools buildfiles buildincludes \
250                 checkdpadd clean cleandepend cleandir cleanobj configure \
251                 depend distclean distribute exe \
252                 html includes install installfiles installincludes \
253                 obj objlink objs objwarn \
254                 realinstall regress \
255                 tags whereobj
256
257 .PHONY: ${PHONY_NOTMAIN}
258 .NOTMAIN: ${PHONY_NOTMAIN}
259
260 CSTD=           c99
261
262 .if ${CSTD} == "k&r"
263 CFLAGS+=        -traditional
264 .elif ${CSTD} == "c89" || ${CSTD} == "c90"
265 CFLAGS+=        -std=iso9899:1990
266 .elif ${CSTD} == "c94" || ${CSTD} == "c95"
267 CFLAGS+=        -std=iso9899:199409
268 .elif ${CSTD} == "c99"
269 CFLAGS+=        -std=iso9899:1999
270 .else # CSTD
271 CFLAGS+=        -std=${CSTD}
272 .endif # CSTD
273
274 # Set target-specific linker emulation name.
275 LD_EMULATION_aarch64=aarch64elf
276 LD_EMULATION_amd64=elf_x86_64_fbsd
277 LD_EMULATION_arm=armelf_fbsd
278 LD_EMULATION_armv6=armelf_fbsd
279 LD_EMULATION_armv7=armelf_fbsd
280 LD_EMULATION_i386=elf_i386_fbsd
281 LD_EMULATION_mips= elf32btsmip_fbsd
282 LD_EMULATION_mipshf= elf32btsmip_fbsd
283 LD_EMULATION_mips64= elf64btsmip_fbsd
284 LD_EMULATION_mips64hf= elf64btsmip_fbsd
285 LD_EMULATION_mipsel= elf32ltsmip_fbsd
286 LD_EMULATION_mipselhf= elf32ltsmip_fbsd
287 LD_EMULATION_mips64el= elf64ltsmip_fbsd
288 LD_EMULATION_mips64elhf= elf64ltsmip_fbsd
289 LD_EMULATION_mipsn32= elf32btsmipn32_fbsd
290 LD_EMULATION_mipsn32el= elf32btsmipn32_fbsd   # I don't think this is a thing that works
291 LD_EMULATION_powerpc= elf32ppc_fbsd
292 LD_EMULATION_powerpcspe= elf32ppc_fbsd
293 LD_EMULATION_powerpc64= elf64ppc_fbsd
294 LD_EMULATION_riscv64= elf64lriscv
295 LD_EMULATION_sparc64= elf64_sparc_fbsd
296 LD_EMULATION=${LD_EMULATION_${MACHINE_ARCH}}