Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Side by Side Diff: build/config/compiler/BUILD.gn

Issue 1841863002: Update monet. (Closed) Base URL: https://github.com/domokit/monet.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/config/clang/clang.gni ('k') | build/config/crypto.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import("//build/config/android/config.gni")
6 import("//build/config/chrome_build.gni")
7 if (current_cpu == "arm") {
8 import("//build/config/arm.gni")
9 }
10 if (current_cpu == "mipsel" || current_cpu == "mips64el") {
11 import("//build/config/mips.gni")
12 }
13 if (is_posix) {
14 import("//build/config/gcc/gcc_version.gni")
15 }
16 import("//build/config/nacl/config.gni")
17 import("//build/toolchain/ccache.gni")
18 import("//build/config/sanitizers/sanitizers.gni")
19
20 declare_args() {
21 # Normally, Android builds are lightly optimized, even for debug builds, to
22 # keep binary size down. Setting this flag to true disables such optimization
23 android_full_debug = false
24
25 # Whether to use the binary binutils checked into third_party/binutils.
26 # These are not multi-arch so cannot be used except on x86 and x86-64 (the
27 # only two architectures that are currently checked in). Turn this off when
28 # you are using a custom toolchain and need to control -B in cflags.
29 linux_use_bundled_binutils = is_linux && current_cpu == "x64"
30
31 # Compile in such a way as to enable profiling of the generated code. For
32 # example, don't omit the frame pointer and leave in symbols.
33 enable_profiling = false
34
35 # Compile in such a way as to make it possible for the profiler to unwind full
36 # stack frames. Setting this flag has a large effect on the performance of the
37 # generated code than just setting profiling, but gives the profiler more
38 # information to analyze.
39 # Requires profiling to be set to true.
40 enable_full_stack_frames_for_profiling = false
41
42 # Use gold for linking on 64-bit Linux only (on 32-bit it runs out of
43 # address space, and it doesn't support cross-compiling).
44 use_gold = is_linux && current_cpu == "x64"
45
46 # use_debug_fission: whether to use split DWARF debug info
47 # files. This can reduce link time significantly, but is incompatible
48 # with some utilities such as icecc and ccache. Requires gold and
49 # gcc >= 4.8 or clang.
50 # http://gcc.gnu.org/wiki/DebugFission
51 use_debug_fission = use_gold && linux_use_bundled_binutils && !use_ccache
52 }
53
54 # default_include_dirs ---------------------------------------------------------
55 #
56 # This is a separate config so that third_party code (which would not use the
57 # source root and might have conflicting versions of some headers) can remove
58 # this and specify their own include paths.
59 config("default_include_dirs") {
60 include_dirs = [
61 "//",
62 root_gen_dir,
63 ]
64 }
65
66 # TODO(GYP): is_ubsan, is_ubsan_vptr
67 using_sanitizer = is_asan || is_lsan || is_tsan || is_msan
68
69 # compiler ---------------------------------------------------------------------
70 #
71 # Base compiler configuration.
72 #
73 # See also "runtime_library" below for related stuff and a discussion about
74 # where stuff should go. Put warning related stuff in the "warnings" config.
75
76 config("compiler") {
77 asmflags = []
78 cflags = []
79 cflags_c = []
80 cflags_cc = []
81 ldflags = []
82 defines = []
83
84 # Common GCC compiler flags setup.
85 # --------------------------------
86 cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204
87 cflags_cc += [
88 # Not exporting C++ inline functions can generally be applied anywhere
89 # so we do so here. Normal function visibility is controlled by
90 # //build/config/gcc:symbol_visibility_hidden.
91 "-fvisibility-inlines-hidden",
92 ]
93
94 # Stack protection.
95 if (is_mac) {
96 cflags += [ "-fstack-protector-all" ]
97 } else if (is_linux) {
98 cflags += [
99 "-fstack-protector",
100 "--param=ssp-buffer-size=4",
101 ]
102 }
103
104 # Linker warnings.
105 if (!is_mac && !is_ios) {
106 ldflags += [ "-Wl,--fatal-warnings" ]
107 }
108
109 # Common options for AddressSanitizer, LeakSanitizer, ThreadSanitizer and
110 # MemorySanitizer
111 if (using_sanitizer) {
112 cflags += [
113 "-fno-omit-frame-pointer",
114 "-gline-tables-only",
115 ]
116 }
117 if (is_asan) {
118 asan_blacklist_path =
119 rebase_path("//tools/memory/asan/blacklist.txt", root_build_dir)
120 cflags += [
121 "-fsanitize=address",
122 "-fsanitize-blacklist=$asan_blacklist_path",
123 ]
124 if (is_mac) {
125 cflags += [ "-mllvm -asan-globals=0" ] # http://crbug.com/352073
126 # TODO(GYP): deal with mac_bundles.
127 }
128 }
129 if (is_lsan) {
130 cflags += [ "-fsanitize=leak" ]
131 }
132 if (is_tsan) {
133 tsan_blacklist_path =
134 rebase_path("//tools/memory/tsan_v2/ignores.txt", root_build_dir)
135 cflags += [
136 "-fsanitize=thread",
137 "-fsanitize-blacklist=$tsan_blacklist_path",
138 ]
139 }
140 if (is_msan) {
141 msan_blacklist_path =
142 rebase_path("//tools/msan/blacklist.txt", root_build_dir)
143 cflags += [
144 "-fsanitize=memory",
145 "-fsanitize-memory-track-origins=$msan_track_origins",
146 "-fsanitize-blacklist=$msan_blacklist_path",
147 ]
148 }
149
150 if (use_custom_libcxx) {
151 cflags_cc += [ "-nostdinc++" ]
152 include_dirs = [
153 "//buildtools/third_party/libc++/trunk/include",
154 "//buildtools/third_party/libc++abi/trunk/include",
155 ]
156 }
157
158 if (is_clang && is_debug) {
159 # Allow comparing the address of references and 'this' against 0
160 # in debug builds. Technically, these can never be null in
161 # well-defined C/C++ and Clang can optimize such checks away in
162 # release builds, but they may be used in asserts in debug builds.
163 cflags_cc += [
164 "-Wno-undefined-bool-conversion",
165 "-Wno-tautological-undefined-compare",
166 ]
167 }
168
169 if (is_clang && !is_nacl) {
170 # This is here so that all files get recompiled after a clang roll and
171 # when turning clang on or off. (defines are passed via the command line,
172 # and build system rebuild things when their commandline changes). Nothing
173 # should ever read this define.
174 defines +=
175 [ "CR_CLANG_REVISION=" + exec_script("//tools/clang/scripts/update.py",
176 [ "--print-revision" ],
177 "trim string") ]
178 }
179
180 # Mac-specific compiler flags setup.
181 # ----------------------------------
182 if (is_mac || is_ios) {
183 # These flags are shared between the C compiler and linker.
184 common_mac_flags = []
185
186 # CPU architecture.
187 if (current_cpu == "x64") {
188 common_mac_flags += [
189 "-arch",
190 "x86_64",
191 ]
192 } else if (current_cpu == "x86") {
193 common_mac_flags += [
194 "-arch",
195 "i386",
196 ]
197 } else if (current_cpu == "arm") {
198 common_mac_flags += [
199 "-arch",
200 "armv7",
201 ]
202 }
203
204 cflags += common_mac_flags
205
206 # Without this, the constructors and destructors of a C++ object inside
207 # an Objective C struct won't be called, which is very bad.
208 cflags_objcc = [ "-fobjc-call-cxx-cdtors" ]
209
210 cflags_c += [ "-std=c99" ]
211
212 ldflags += common_mac_flags
213 } else if (is_posix) {
214 # Non-Mac Posix compiler flags setup.
215 # -----------------------------------
216 if (enable_profiling && !is_debug) {
217 # The GYP build spams this define into every compilation unit, as we do
218 # here, but it only appears to be used in base and a couple other places.
219 # TODO(abarth): Should we move this define closer to where it's used?
220 defines += [ "ENABLE_PROFILING" ]
221
222 cflags += [
223 "-fno-omit-frame-pointer",
224 "-g",
225 ]
226
227 if (enable_full_stack_frames_for_profiling) {
228 cflags += [
229 "-fno-inline",
230 "-fno-optimize-sibling-calls",
231 ]
232 }
233 }
234
235 # CPU architecture. We may or may not be doing a cross compile now, so for
236 # simplicity we always explicitly set the architecture.
237 if (current_cpu == "x64") {
238 cflags += [
239 "-m64",
240 "-march=x86-64",
241 ]
242 ldflags += [ "-m64" ]
243 } else if (current_cpu == "x86") {
244 cflags += [ "-m32" ]
245 ldflags += [ "-m32" ]
246 if (is_clang) {
247 cflags += [
248 # Else building libyuv gives clang's register allocator issues,
249 # see llvm.org/PR15798 / crbug.com/233709
250 "-momit-leaf-frame-pointer",
251
252 # Align the stack on 16-byte boundaries, http://crbug.com/418554.
253 "-mstack-alignment=16",
254 "-mstackrealign",
255 ]
256 }
257 } else if (current_cpu == "arm") {
258 cflags += [
259 "-march=$arm_arch",
260 "-mfloat-abi=$arm_float_abi",
261 ]
262 if (arm_tune != "") {
263 cflags += [ "-mtune=$arm_tune" ]
264 }
265 if (arm_use_thumb) {
266 cflags += [ "-mthumb" ]
267 if (is_android && !is_clang) { # Clang doesn't support this option.
268 cflags += [ "-mthumb-interwork" ]
269 }
270 }
271 if (!is_clang) {
272 # Clang doesn't support these flags.
273 cflags += [
274 # The tree-sra optimization (scalar replacement for
275 # aggregates enabling subsequent optimizations) leads to
276 # invalid code generation when using the Android NDK's
277 # compiler (r5-r7). This can be verified using
278 # webkit_unit_tests' WTF.Checked_int8_t test.
279 "-fno-tree-sra",
280
281 # The following option is disabled to improve binary
282 # size and performance in gcc 4.9.
283 "-fno-caller-saves",
284 ]
285 }
286 } else if (current_cpu == "mipsel") {
287 if (mips_arch_variant == "r6") {
288 cflags += [
289 "-mips32r6",
290 "-Wa,-mips32r6",
291 ]
292 if (is_android) {
293 ldflags += [
294 "-mips32r6",
295 "-Wl,-melf32ltsmip",
296 ]
297 }
298 } else if (mips_arch_variant == "r2") {
299 cflags += [
300 "-mips32r2",
301 "-Wa,-mips32r2",
302 ]
303 if (mips_float_abi == "hard" && mips_fpu_mode != "") {
304 cflags += [ "-m$mips_fpu_mode" ]
305 }
306 } else if (mips_arch_variant == "r1") {
307 cflags += [
308 "-mips32",
309 "-Wa,-mips32",
310 ]
311 }
312
313 if (mips_dsp_rev == 1) {
314 cflags += [ "-mdsp" ]
315 } else if (mips_dsp_rev == 2) {
316 cflags += [ "-mdspr2" ]
317 }
318
319 cflags += [ "-m${mips_float_abi}-float" ]
320 } else if (current_cpu == "mips64el") {
321 if (mips_arch_variant == "r6") {
322 cflags += [
323 "-mips64r6",
324 "-Wa,-mips64r6",
325 ]
326 ldflags += [ "-mips64r6" ]
327 } else if (mips_arch_variant == "r2") {
328 cflags += [
329 "-mips64r2",
330 "-Wa,-mips64r2",
331 ]
332 ldflags += [ "-mips64r2" ]
333 }
334 }
335
336 defines += [ "_FILE_OFFSET_BITS=64" ]
337
338 if (!is_android) {
339 defines += [
340 "_LARGEFILE_SOURCE",
341 "_LARGEFILE64_SOURCE",
342 ]
343 }
344
345 # Omit unwind support in official builds to save space. We can use breakpad
346 # for these builds.
347 if (is_chrome_branded && is_official_build) {
348 cflags += [
349 "-fno-unwind-tables",
350 "-fno-asynchronous-unwind-tables",
351 ]
352 defines += [ "NO_UNWIND_TABLES" ]
353 } else {
354 cflags += [ "-funwind-tables" ]
355 }
356
357 if (is_clang && !is_nacl && !is_debug) {
358 # Non-unique section names appears to make linker dead stripping
359 # less effective. See http://crbug.com/483026#c20
360 # TODO(hans): Remove this if resolved upstream.
361 cflags += [ "-funique-section-names" ]
362 }
363 }
364
365 # Linux/Android common flags setup.
366 # ---------------------------------
367 if (is_linux || is_android) {
368 cflags += [
369 "-fPIC",
370 "-pipe", # Use pipes for communicating between sub-processes. Faster.
371 ]
372
373 ldflags += [
374 "-fPIC",
375 "-Wl,-z,noexecstack",
376 "-Wl,-z,now",
377 "-Wl,-z,relro",
378 ]
379 if (!using_sanitizer) {
380 ldflags += [ "-Wl,-z,defs" ]
381 }
382 }
383
384 # Linux-specific compiler flags setup.
385 # ------------------------------------
386 if (is_linux) {
387 cflags += [ "-pthread" ]
388 ldflags += [ "-pthread" ]
389 }
390 if (use_gold) {
391 gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
392 root_build_dir)
393 ldflags += [
394 "-B$gold_path",
395
396 # Newer gccs and clangs support -fuse-ld, use the flag to force gold
397 # selection.
398 # gcc -- http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Optimize-Options.html
399 "-fuse-ld=gold",
400
401 # Experimentation found that using four linking threads
402 # saved ~20% of link time.
403 # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_threa d/thread/281527606915bb36
404 # Only apply this to the target linker, since the host
405 # linker might not be gold, but isn't used much anyway.
406 # TODO(raymes): Disable threading because gold is frequently
407 # crashing on the bots: crbug.com/161942.
408 #"-Wl,--threads",
409 #"-Wl,--thread-count=4",
410 ]
411
412 if (!is_asan && !is_msan && !is_lsan && !is_tsan) {
413 # TODO(brettw) common.gypi has this only for target toolset.
414 if (current_cpu == "x64") {
415 # --icf=safe disables much more folding on x86_64 than elsewhere, see
416 # http://crbug.com/492177. Turning it on saves over 12 MB of binary
417 # size, but it seems to regress cold startup time by over a second
418 # (see http://crbug.com/492809).
419 # TODO(thakis): Check if disabling ICF would inmprove android cold start
420 # times by several seconds too.
421 ldflags += [ "-Wl,--icf=safe" ]
422 } else {
423 ldflags += [ "-Wl,--icf=all" ]
424 }
425 }
426 }
427
428 if (linux_use_bundled_binutils) {
429 binutils_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
430 root_build_dir)
431 cflags += [ "-B$binutils_path" ]
432 }
433
434 # Clang-specific compiler flags setup.
435 # ------------------------------------
436 if (is_clang) {
437 cflags += [ "-fcolor-diagnostics" ]
438 }
439
440 # C++11 compiler flags setup.
441 # ---------------------------
442 if (is_nacl) {
443 # gnu++11 instead of c++11 is needed because some code uses typeof() (a
444 # GNU extension).
445 # TODO(thakis): Eventually switch this to c++11 instead,
446 # http://crbug.com/427584
447 cflags_cc += [ "-std=gnu++11" ]
448 } else {
449 cflags_cc += [ "-std=c++11" ]
450 }
451
452 # Android-specific flags setup.
453 # -----------------------------
454 if (is_android) {
455 cflags += [
456 "-ffunction-sections",
457 "-funwind-tables",
458 "-fno-short-enums",
459 ]
460 if (!is_clang) {
461 # Clang doesn't support these flags.
462 cflags += [ "-finline-limit=64" ]
463 }
464 if (is_asan) {
465 # Android build relies on -Wl,--gc-sections removing unreachable code.
466 # ASan instrumentation for globals inhibits this and results in a library
467 # with unresolvable relocations.
468 # TODO(eugenis): find a way to reenable this.
469 cflags += [ "-mllvm -asan-globals=0" ]
470 }
471
472 defines += [ "ANDROID" ]
473
474 # The NDK has these things, but doesn't define the constants
475 # to say that it does. Define them here instead.
476 defines += [ "HAVE_SYS_UIO_H" ]
477
478 # Use gold for Android for most CPU architectures.
479 if (current_cpu == "x86" || current_cpu == "x64" || current_cpu == "arm") {
480 ldflags += [ "-fuse-ld=gold" ]
481 if (is_clang) {
482 # Let clang find the ld.gold in the NDK.
483 ldflags += [ "--gcc-toolchain=" +
484 rebase_path(android_toolchain_root, root_build_dir) ]
485 }
486 }
487
488 ldflags += [
489 "-Wl,--no-undefined",
490
491 # Don't allow visible symbols from libgcc or libc++ to be
492 # re-exported.
493 "-Wl,--exclude-libs=libgcc.a",
494 "-Wl,--exclude-libs=libc++_static.a",
495
496 # Don't allow visible symbols from libraries that contain
497 # assembly code with symbols that aren't hidden properly.
498 # http://crbug.com/448386
499 "-Wl,--exclude-libs=libvpx_assembly_arm.a",
500 ]
501 if (current_cpu == "arm") {
502 ldflags += [
503 # Enable identical code folding to reduce size.
504 "-Wl,--icf=safe",
505 ]
506 }
507
508 if (is_clang) {
509 if (current_cpu == "arm") {
510 cflags += [ "-target arm-linux-androideabi" ]
511 ldflags += [ "-target arm-linux-androideabi" ]
512 } else if (current_cpu == "x86") {
513 cflags += [ "-target x86-linux-androideabi" ]
514 ldflags += [ "-target x86-linux-androideabi" ]
515 }
516 }
517 }
518
519 # Assign any flags set for the C compiler to asmflags so that they are sent
520 # to the assembler.
521 asmflags += cflags
522 asmflags += cflags_c
523 }
524
525 # This provides the basic options to select the target CPU and ABI.
526 # It is factored out of "compiler" so that special cases can use this
527 # without using everything that "compiler" brings in. Options that
528 # tweak code generation for a particular CPU do not belong here!
529 # See "compiler_codegen", below.
530 config("compiler_cpu_abi") {
531 cflags = []
532 ldflags = []
533
534 if (is_posix && !(is_mac || is_ios)) {
535 # CPU architecture. We may or may not be doing a cross compile now, so for
536 # simplicity we always explicitly set the architecture.
537 if (current_cpu == "x64") {
538 cflags += [
539 "-m64",
540 "-march=x86-64",
541 ]
542 ldflags += [ "-m64" ]
543 } else if (current_cpu == "x86") {
544 cflags += [ "-m32" ]
545 ldflags += [ "-m32" ]
546 } else if (current_cpu == "arm") {
547 if (is_clang && !is_android && !is_nacl) {
548 cflags += [
549 "-target",
550 "arm-linux-gnueabihf",
551 ]
552 ldflags += [
553 "-target",
554 "arm-linux-gnueabihf",
555 ]
556 }
557 if (!is_nacl) {
558 cflags += [
559 "-march=$arm_arch",
560 "-mfloat-abi=$arm_float_abi",
561 ]
562 if (arm_use_thumb) {
563 cflags += [ "-mthumb" ]
564 if (is_android && !is_clang) {
565 # Clang doesn't support this option.
566 cflags += [ "-mthumb-interwork" ]
567 }
568 }
569 }
570 if (arm_tune != "") {
571 cflags += [ "-mtune=$arm_tune" ]
572 }
573 } else if (current_cpu == "mipsel") {
574 if (mips_arch_variant == "r6") {
575 cflags += [
576 "-mips32r6",
577 "-Wa,-mips32r6",
578 ]
579 if (is_android) {
580 ldflags += [
581 "-mips32r6",
582 "-Wl,-melf32ltsmip",
583 ]
584 }
585 } else if (mips_arch_variant == "r2") {
586 cflags += [
587 "-mips32r2",
588 "-Wa,-mips32r2",
589 ]
590 if (mips_float_abi == "hard" && mips_fpu_mode != "") {
591 cflags += [ "-m$mips_fpu_mode" ]
592 }
593 } else if (mips_arch_variant == "r1") {
594 cflags += [
595 "-mips32",
596 "-Wa,-mips32",
597 ]
598 }
599
600 if (mips_dsp_rev == 1) {
601 cflags += [ "-mdsp" ]
602 } else if (mips_dsp_rev == 2) {
603 cflags += [ "-mdspr2" ]
604 }
605
606 cflags += [ "-m${mips_float_abi}-float" ]
607 } else if (current_cpu == "mips64el") {
608 if (mips_arch_variant == "r6") {
609 cflags += [
610 "-mips64r6",
611 "-Wa,-mips64r6",
612 ]
613 ldflags += [ "-mips64r6" ]
614 } else if (mips_arch_variant == "r2") {
615 cflags += [
616 "-mips64r2",
617 "-Wa,-mips64r2",
618 ]
619 ldflags += [ "-mips64r2" ]
620 }
621 }
622 }
623
624 asmflags = cflags
625 }
626
627 config("compiler_arm_fpu") {
628 if (current_cpu == "arm" && !is_ios) {
629 cflags = [ "-mfpu=$arm_fpu" ]
630 asmflags = cflags
631 }
632 }
633
634 # runtime_library -------------------------------------------------------------
635 #
636 # Sets the runtime library and associated options.
637 #
638 # How do you determine what should go in here vs. "compiler" above? Consider if
639 # a target might choose to use a different runtime library (ignore for a moment
640 # if this is possible or reasonable on your system). If such a target would want
641 # to change or remove your option, put it in the runtime_library config. If a
642 # target wants the option regardless, put it in the compiler config.
643
644 config("runtime_library") {
645 cflags = []
646 defines = []
647 ldflags = []
648 lib_dirs = []
649 libs = []
650
651 if (is_component_build) {
652 # Component mode: dynamic CRT.
653 defines += [ "COMPONENT_BUILD" ]
654 }
655
656 # Android standard library setup.
657 if (is_android) {
658 if (is_clang) {
659 # Work around incompatibilities between bionic and clang headers.
660 defines += [
661 "__compiler_offsetof=__builtin_offsetof",
662 "nan=__builtin_nan",
663 ]
664 }
665
666 defines += [ "__GNU_SOURCE=1" ] # Necessary for clone().
667
668 # TODO(jdduke) Re-enable on mips after resolving linking
669 # issues with libc++ (crbug.com/456380).
670 if (current_cpu != "mipsel" && current_cpu != "mips64el") {
671 ldflags += [ "-Wl,--warn-shared-textrel" ]
672 }
673 ldflags += [ "-nostdlib" ]
674
675 # NOTE: The libc++ header include paths below are specified in cflags
676 # rather than include_dirs because they need to come after include_dirs.
677 # Think of them like system headers, but don't use '-isystem' because the
678 # arm-linux-androideabi-4.4.3 toolchain (circa Gingerbread) will exhibit
679 # strange errors. The include ordering here is important; change with
680 # caution.
681 android_libcpp_root = "$android_ndk_root/sources/cxx-stl/llvm-libc++"
682
683 cflags += [
684 "-isystem" +
685 rebase_path("$android_libcpp_root/libcxx/include", root_build_dir),
686 "-isystem" + rebase_path(
687 "$android_ndk_root/sources/cxx-stl/llvm-libc++abi/libcxxabi/includ e",
688 root_build_dir),
689 "-isystem" +
690 rebase_path("$android_ndk_root/sources/android/support/include",
691 root_build_dir),
692 ]
693
694 lib_dirs += [ "$android_libcpp_root/libs/$android_app_abi" ]
695
696 if (component_mode == "shared_library") {
697 android_libcpp_library = "c++_shared"
698 } else {
699 android_libcpp_library = "c++_static"
700 }
701
702 libs += [ "$android_libcpp_library" ]
703
704 if (current_cpu == "mipsel") {
705 libs += [
706 # ld linker is used for mips Android, and ld does not accept library
707 # absolute path prefixed by "-l"; Since libgcc does not exist in mips
708 # sysroot the proper library will be linked.
709 # TODO(gordanac): Remove once gold linker is used for mips Android.
710 "gcc",
711 ]
712 } else {
713 libs += [
714 # Manually link the libgcc.a that the cross compiler uses. This is
715 # absolute because the linker will look inside the sysroot if it's not.
716 rebase_path(android_libgcc_file),
717 ]
718 }
719
720 libs += [
721 "c",
722 "dl",
723 "m",
724 ]
725
726 # Clang with libc++ does not require an explicit atomic library reference.
727 if (!is_clang) {
728 libs += [ "atomic" ]
729 }
730 }
731 }
732
733 # default_warning_flags collects all warning flags that are used by default.
734 # This is in a variable instead of a config so that it can be used in
735 # both chromium_code and no_chromium_code. This way these flags are guaranteed
736 # to appear on the compile command line after -Wall.
737
738 default_warning_flags = []
739 default_warning_flags_cc = []
740
741 # Common GCC warning setup.
742 default_warning_flags += [
743 # Enables.
744 "-Wendif-labels", # Weird old-style text after an #endif.
745 "-Werror", # Warnings as errors.
746
747 # Disables.
748 "-Wno-missing-field-initializers", # "struct foo f = {0};"
749 ]
750
751 if (is_mac) {
752 if (!is_nacl) {
753 # When compiling Objective-C, warns if a method is used whose
754 # availability is newer than the deployment target. This is not
755 # required when compiling Chrome for iOS.
756 default_warning_flags += [ "-Wpartial-availability" ]
757 }
758 }
759
760 if (gcc_version >= 48) {
761 default_warning_flags_cc += [
762 # See comment for -Wno-c++11-narrowing.
763 "-Wno-narrowing",
764
765 # TODO(thakis): Remove, http://crbug.com/263960
766 "-Wno-literal-suffix",
767 ]
768 }
769
770 # Suppress warnings about ABI changes on ARM (Clang doesn't give this
771 # warning).
772 if (current_cpu == "arm" && !is_clang) {
773 default_warning_flags += [ "-Wno-psabi" ]
774 }
775
776 if (is_android) {
777 # Disable any additional warnings enabled by the Android build system but
778 # which chromium does not build cleanly with (when treating warning as
779 # errors).
780 default_warning_flags += [
781 "-Wno-extra",
782 "-Wno-ignored-qualifiers",
783 "-Wno-type-limits",
784 ]
785 default_warning_flags_cc += [
786 # Disabling c++0x-compat should be handled in WebKit, but
787 # this currently doesn't work because gcc_version is not set
788 # correctly when building with the Android build system.
789 # TODO(torne): Fix this in WebKit.
790 "-Wno-error=c++0x-compat",
791
792 # Other things unrelated to -Wextra:
793 "-Wno-non-virtual-dtor",
794 "-Wno-sign-promo",
795 ]
796 }
797
798 if (gcc_version >= 48) {
799 # Don't warn about the "typedef 'foo' locally defined but not used"
800 # for gcc 4.8.
801 # TODO: remove this flag once all builds work. See crbug.com/227506
802 default_warning_flags += [ "-Wno-unused-local-typedefs" ]
803 }
804
805 if (is_clang) {
806 default_warning_flags += [
807 # This warns on using ints as initializers for floats in
808 # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|),
809 # which happens in several places in chrome code. Not sure if
810 # this is worth fixing.
811 "-Wno-c++11-narrowing",
812
813 # Don't die on dtoa code that uses a char as an array index.
814 # This is required solely for base/third_party/dmg_fp/dtoa.cc.
815 # TODO(brettw) move this to that project then!
816 "-Wno-char-subscripts",
817
818 # Warns on switches on enums that cover all enum values but
819 # also contain a default: branch. Chrome is full of that.
820 "-Wno-covered-switch-default",
821
822 # Clang considers the `register` keyword as deprecated, but e.g.
823 # code generated by flex (used in angle) contains that keyword.
824 # http://crbug.com/255186
825 "-Wno-deprecated-register",
826 ]
827
828 # NaCl's Clang compiler and Chrome's hermetic Clang compiler will almost
829 # always have different versions. Certain flags may not be recognized by
830 # one version or the other.
831 if (!is_nacl) {
832 # Flags NaCl (Clang 3.7) does not recognize.
833 default_warning_flags += [
834 # TODO(smklein): Enable this, crbug.com/507717
835 "-Wno-shift-negative-value",
836 ]
837 }
838 }
839
840 # chromium_code ---------------------------------------------------------------
841 #
842 # Toggles between higher and lower warnings for code that is (or isn't)
843 # part of Chromium.
844
845 config("chromium_code") {
846 cflags = [
847 "-Wall",
848
849 # GCC turns on -Wsign-compare for C++ under -Wall, but clang doesn't,
850 # so we specify it explicitly.
851 # TODO(fischman): remove this if http://llvm.org/PR10448 obsoletes it.
852 # http://code.google.com/p/chromium/issues/detail?id=90453
853 "-Wsign-compare",
854 ]
855
856 # In Chromium code, we define __STDC_foo_MACROS in order to get the
857 # C99 macros on Mac and Linux.
858 defines = [
859 "__STDC_CONSTANT_MACROS",
860 "__STDC_FORMAT_MACROS",
861 ]
862
863 if (!is_debug && !using_sanitizer &&
864 (!is_linux || !is_clang || is_official_build)) {
865 # _FORTIFY_SOURCE isn't really supported by Clang now, see
866 # http://llvm.org/bugs/show_bug.cgi?id=16821.
867 # It seems to work fine with Ubuntu 12 headers though, so use it in
868 # official builds.
869 #
870 # Non-chromium code is not guaranteed to compile cleanly with
871 # _FORTIFY_SOURCE. Also, fortified build may fail when optimizations are
872 # disabled, so only do that for Release build.
873 defines += [ "_FORTIFY_SOURCE=2" ]
874 }
875
876 cflags += default_warning_flags
877 cflags_cc = default_warning_flags_cc
878 }
879 config("no_chromium_code") {
880 cflags = []
881 cflags_cc = []
882 defines = []
883
884 if (is_linux) {
885 # Don't warn about ignoring the return value from e.g. close(). This is
886 # off by default in some gccs but on by default in others. BSD systems do
887 # not support this option, since they are usually using gcc 4.2.1, which
888 # does not have this flag yet.
889 cflags += [
890 "-Wno-logical-not-parentheses",
891 "-Wno-unused-result",
892 ]
893 }
894
895 if (is_linux || is_android) {
896 cflags += [
897 # Don't warn about printf format problems. This is off by default in gcc
898 # but on in Ubuntu's gcc(!).
899 "-Wno-format",
900 ]
901 cflags_cc += [
902 # Don't warn about hash_map in third-party code.
903 "-Wno-deprecated",
904 ]
905 }
906
907 if (is_clang) {
908 cflags += [
909 # TODO(hans): Get this cleaned up.
910 "-Wno-inconsistent-missing-override",
911 ]
912 }
913
914 cflags += default_warning_flags
915 cflags_cc += default_warning_flags_cc
916
917 if (is_clang) {
918 cflags += [
919 # TODO(dalesat): Remove once not broken by third party (ffmpeg).
920 # See https://github.com/domokit/mojo/issues/692.
921 "-Wno-constant-conversion",
922 ]
923 }
924 }
925
926 # rtti ------------------------------------------------------------------------
927 #
928 # Allows turning Run-Time Type Identification on or off.
929
930 config("rtti") {
931 }
932 config("no_rtti") {
933 cflags_cc = [ "-fno-rtti" ]
934 }
935
936 # Warnings ---------------------------------------------------------------------
937
938 # This will generate warnings when using Clang if code generates exit-time
939 # destructors, which will slow down closing the program.
940 # TODO(thakis): Make this a blacklist instead, http://crbug.com/101600
941 config("wexit_time_destructors") {
942 if (is_clang) {
943 cflags = [ "-Wexit-time-destructors" ]
944 }
945 }
946
947 # On Windows compiling on x64, VC will issue a warning when converting
948 # size_t to int because it will truncate the value. Our code should not have
949 # these warnings and one should use a static_cast or a checked_cast for the
950 # conversion depending on the case. However, a lot of code still needs to be
951 # fixed. Apply this config to such targets to disable the warning.
952 #
953 # Note that this can be applied regardless of platform and architecture to
954 # clean up the call sites. This will only apply the flag when necessary.
955 #
956 # TODO(jschuh): crbug.com/167187 fix this and delete this config.
957 config("no_size_t_to_int_warning") {
958 }
959
960 # Some code presumes that pointers to structures/objects are compatible
961 # regardless of whether what they point to is already known to be valid.
962 config("no_incompatible_pointer_warnings") {
963 cflags = []
964 if (is_clang) {
965 cflags += [ "-Wno-incompatible-pointer-types" ]
966 }
967 }
968
969 # Optimization -----------------------------------------------------------------
970 #
971 # Note that BUILDCONFIG.gn sets up a variable "default_optimization_config"
972 # which it will assign to the config it implicitly applies to every target. If
973 # you want to override the optimization level for your target, remove this
974 # config (which will expand differently for debug or release builds), and then
975 # add back the one you want to override it with:
976 #
977 # configs -= default_optimization_config
978 # configs += [ "//build/config/compiler/optimize_max" ]
979
980 # Shared settings for both "optimize" and "optimize_max" configs.
981 common_optimize_on_cflags = [
982 # Don't emit the GCC version ident directives, they just end up in the
983 # .comment section taking up binary size.
984 "-fno-ident",
985
986 # Put data and code in their own sections, so that unused symbols
987 # can be removed at link time with --gc-sections.
988 "-fdata-sections",
989 "-ffunction-sections",
990 ]
991 common_optimize_on_ldflags = []
992
993 if (is_android) {
994 if (!using_sanitizer) {
995 common_optimize_on_cflags += [ "-fomit-frame-pointer" ]
996 }
997
998 # TODO(jdduke) Re-enable on mips after resolving linking
999 # issues with libc++ (crbug.com/456380).
1000 if (current_cpu != "mipsel" && current_cpu != "mips64el") {
1001 common_optimize_on_ldflags += [
1002 # Warn in case of text relocations.
1003 "-Wl,--warn-shared-textrel",
1004 ]
1005 }
1006 }
1007
1008 if (is_mac) {
1009 if (symbol_level == 2) {
1010 # Mac dead code stripping requires symbols.
1011 common_optimize_on_ldflags += [ "-Wl,-dead_strip" ]
1012 }
1013 } else {
1014 # Non-Mac Posix linker flags.
1015 common_optimize_on_ldflags += [
1016 # Specifically tell the linker to perform optimizations.
1017 # See http://lwn.net/Articles/192624/ .
1018 "-Wl,-O1",
1019 "-Wl,--gc-sections",
1020 ]
1021
1022 if (!using_sanitizer) {
1023 # Functions interposed by the sanitizers can make ld think
1024 # that some libraries aren't needed when they actually are,
1025 # http://crbug.com/234010. As workaround, disable --as-needed.
1026 common_optimize_on_ldflags += [ "-Wl,--as-needed" ]
1027 }
1028 }
1029
1030 # Default "optimization on" config. On Windows, this favors size over speed.
1031 config("optimize") {
1032 cflags = common_optimize_on_cflags
1033 ldflags = common_optimize_on_ldflags
1034 if (is_android || is_ios) {
1035 cflags += [ "-Os" ] # Favor size over speed.
1036 } else {
1037 cflags += [ "-O2" ]
1038 }
1039 }
1040
1041 # Turn off optimizations.
1042 config("no_optimize") {
1043 if (is_android && !android_full_debug) {
1044 # On Android we kind of optimize some things that don't affect debugging
1045 # much even when optimization is disabled to get the binary size down.
1046 cflags = [
1047 "-Os",
1048 "-fdata-sections",
1049 "-ffunction-sections",
1050 ]
1051 if (!using_sanitizer) {
1052 cflags += [ "-fomit-frame-pointer" ]
1053 }
1054 ldflags = common_optimize_on_ldflags
1055 } else if (is_pnacl) {
1056 # Linking and optimization is the slowest part of building code
1057 # using the PNaCl toolchain. Optimizing actually makes these passes faster,
1058 # and results in a smaller building/translation time.
1059 cflags = common_optimize_on_cflags
1060 cflags += [ "-Os" ]
1061 } else {
1062 cflags = [ "-O0" ]
1063 }
1064 }
1065
1066 # Turns up the optimization level. On Windows, this implies whole program
1067 # optimization and link-time code generation which is very expensive and should
1068 # be used sparingly.
1069 config("optimize_max") {
1070 cflags = common_optimize_on_cflags
1071 ldflags = common_optimize_on_ldflags
1072
1073 cflags += [ "-O2" ]
1074 }
1075
1076 # The default optimization applied to all targets. This will be equivalent to
1077 # either "optimize" or "no_optimize", depending on the build flags.
1078 config("default_optimization") {
1079 if (is_nacl_irt) {
1080 # The NaCl IRT is a special case and always wants its own config.
1081 # It gets optimized the same way regardless of the type of build.
1082 configs = [ "//build/config/nacl:irt_optimize" ]
1083 } else if (is_debug) {
1084 configs = [ ":no_optimize" ]
1085 } else {
1086 configs = [ ":optimize" ]
1087 }
1088 }
1089
1090 # Symbols ----------------------------------------------------------------------
1091
1092 config("symbols") {
1093 cflags = [ "-g2" ]
1094 if (use_debug_fission) {
1095 cflags += [ "-gsplit-dwarf" ]
1096 }
1097 asmflags = cflags
1098 ldflags = []
1099 }
1100
1101 config("minimal_symbols") {
1102 cflags = [ "-g1" ]
1103 if (use_debug_fission) {
1104 cflags += [ "-gsplit-dwarf" ]
1105 }
1106 asmflags = cflags
1107 ldflags = []
1108 }
1109
1110 config("no_symbols") {
1111 cflags = [ "-g0" ]
1112 asmflags = cflags
1113 }
1114
1115 # Default symbols.
1116 config("default_symbols") {
1117 if (symbol_level == 0) {
1118 configs = [ ":no_symbols" ]
1119 } else if (symbol_level == 1) {
1120 configs = [ ":minimal_symbols" ]
1121 } else if (symbol_level == 2) {
1122 configs = [ ":symbols" ]
1123 } else {
1124 assert(false)
1125 }
1126 }
OLDNEW
« no previous file with comments | « build/config/clang/clang.gni ('k') | build/config/crypto.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698