-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
SANDYBRIDGE.gn
2585 lines (2335 loc) · 86.9 KB
/
SANDYBRIDGE.gn
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) 2021 The Chromium Authors and Alex313031. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/buildflag_header.gni")
import("//build/config/android/config.gni")
import("//build/config/c++/c++.gni")
import("//build/config/chrome_build.gni")
import("//build/config/chromecast_build.gni")
import("//build/config/chromeos/args.gni")
import("//build/config/chromeos/ui_mode.gni")
import("//build/config/clang/clang.gni")
import("//build/config/compiler/compiler.gni")
import("//build/config/coverage/coverage.gni")
import("//build/config/dcheck_always_on.gni")
import("//build/config/gclient_args.gni")
import("//build/config/host_byteorder.gni")
import("//build/config/rust.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/config/ui.gni")
import("//build/toolchain/cc_wrapper.gni")
import("//build/toolchain/goma.gni")
import("//build/toolchain/rbe.gni")
import("//build/toolchain/toolchain.gni")
import("//build_overrides/build.gni")
if (current_cpu == "arm" || current_cpu == "arm64") {
import("//build/config/arm.gni")
}
if (current_cpu == "mipsel" || current_cpu == "mips64el" ||
current_cpu == "mips" || current_cpu == "mips64") {
import("//build/config/mips.gni")
}
if (current_cpu == "x64") {
import("//build/config/x64.gni")
}
if (is_mac) {
import("//build/config/apple/symbols.gni")
}
if (is_ios) {
import("//build/config/ios/ios_sdk.gni")
}
if (is_nacl) {
# To keep NaCl variables out of builds that don't include NaCl, all
# variables defined in nacl/config.gni referenced here should be protected by
# is_nacl conditions.
import("//build/config/nacl/config.gni")
}
lld_path = ""
if (!is_clang) {
declare_args() {
# This allows overriding the location of lld.
lld_path = rebase_path("$clang_base_path/bin", root_build_dir)
}
} else {
# clang looks for lld next to it, no need for -B.
lld_path = ""
}
declare_args() {
# Normally, Android builds are lightly optimized, even for debug builds, to
# keep binary size down. Setting this flag to true disables such optimization
android_full_debug = false
# Compile in such a way as to make it possible for the profiler to unwind full
# stack frames. Setting this flag has a large effect on the performance of the
# generated code than just setting profiling, but gives the profiler more
# information to analyze.
# Requires profiling to be set to true.
enable_full_stack_frames_for_profiling = false
# When we are going to use gold we need to find it.
# This is initialized below, after use_gold might have been overridden.
gold_path = ""
# Enable fatal linker warnings. Building Chromium with certain versions
# of binutils can cause linker warning.
fatal_linker_warnings = true
# Build with C++ RTTI enabled. Chromium builds without RTTI by default,
# but some sanitizers are known to require it, like CFI diagnostics
# and UBsan variants.
use_rtti = use_cfi_diag || is_ubsan_vptr || is_ubsan_security
# AFDO (Automatic Feedback Directed Optimizer) is a form of profile-guided
# optimization that GCC supports. It used by ChromeOS in their official
# builds. To use it, set auto_profile_path to the path to a file containing
# the needed gcov profiling data.
auto_profile_path = ""
# Allow projects that wish to stay on C++11 to override Chromium's default.
use_cxx11 = false
# Path to an AFDO profile to use while building with clang, if any. Empty
# implies none.
clang_sample_profile_path = ""
# Some configurations have default sample profiles. If this is true and
# clang_sample_profile_path is empty, we'll fall back to the default.
#
# We currently only have default profiles for Chromium in-tree, so we disable
# this by default for all downstream projects, since these profiles are likely
# nonsensical for said projects.
clang_use_default_sample_profile =
chrome_pgo_phase == 0 && build_with_chromium && is_official_build &&
(is_android || chromeos_is_browser_only || is_chromecast)
# This configuration is used to select a default profile in Chrome OS based on
# the microarchitectures we are using. This is only used if
# clang_use_default_sample_profile is true and clang_sample_profile_path is
# empty.
chromeos_afdo_platform = "atom"
# Emit debug information for profiling wile building with clang.
clang_emit_debug_info_for_profiling = false
# Turn this on to have the compiler output extra timing information.
compiler_timing = false
# Turn this on to use ghash feature of lld for faster debug link on Windows.
# http://blog.llvm.org/2018/01/improving-link-time-on-windows-with.html
use_ghash = true
# Whether to enable ThinLTO optimizations. Turning ThinLTO optimizations on
# can substantially increase link time and binary size, but they generally
# also make binaries a fair bit faster.
#
# TODO(gbiv): We disable optimizations by default on most platforms because
# the space overhead is too great. We should use some mixture of profiles and
# optimization settings to better tune the size increase.
thin_lto_enable_optimizations =
(is_chromeos_ash || is_android || is_win || is_linux) && is_official_build
# Initialize all local variables with a pattern. This flag will fill
# uninitialized floating-point types (and 32-bit pointers) with 0xFF and the
# rest with 0xAA. This makes behavior of uninitialized memory bugs consistent,
# recognizable in the debugger, and crashes on memory accesses through
# uninitialized pointers.
#
# TODO(crbug.com/1131993): Enabling this when 'is_android' is true breaks
# content_shell_test_apk on both ARM and x86.
init_stack_vars = !is_android
# This argument is to control whether enabling text section splitting in the
# final binary. When enabled, the separated text sections with prefix
# '.text.hot', '.text.unlikely', '.text.startup' and '.text.exit' will not be
# merged to '.text' section. This allows us to identify the hot code section
# ('.text.hot') in the binary which may be mlocked or mapped to huge page to
# reduce TLB misses which gives performance improvement on cpu usage.
# The gold linker by default has text section splitting enabled.
use_text_section_splitting = false
# Token limits may not be accurate for build configs not covered by the CQ,
# so only enable them by default for mainstream build configs.
enable_wmax_tokens =
!is_official_build && !(is_component_build && !is_debug) &&
((is_mac && target_cpu == "x64" && !use_system_xcode) ||
(is_linux && !is_chromeos && target_cpu == "x64") ||
(is_win && target_cpu == "x86") || (is_win && target_cpu == "x64") ||
(is_android && target_cpu == "arm") ||
(is_android && target_cpu == "arm64"))
# Turn off the --call-graph-profile-sort flag for lld by default. Enable
# selectively for targets where it's beneficial.
enable_call_graph_profile_sort = chrome_pgo_phase == 2
# Enable DWARF v5.
use_dwarf5 = false
# Override this to put full paths to PDBs in Windows PE files. This helps
# windbg and Windows Performance Analyzer with finding the PDBs in some local-
# build scenarios. This is never needed for bots or official builds. Because
# this puts the output directory in the DLLs/EXEs it breaks build determinism.
# Bugs have been reported to the windbg/WPA teams and this workaround will be
# removed when they are fixed.
use_full_pdb_paths = false
# Enable -H, which prints the include tree during compilation.
# For use by tools/clang/scripts/analyze_includes.py
show_includes = false
}
declare_args() {
# Set to true to use icf, Identical Code Folding.
#
# icf=all is broken in older golds, see
# https://sourceware.org/bugzilla/show_bug.cgi?id=17704
# chromeos binutils has been patched with the fix, so always use icf there.
# The bug only affects x86 and x64, so we can still use ICF when targeting
# other architectures.
#
# lld doesn't have the bug.
use_icf =
(is_posix || is_fuchsia) && !is_debug && !using_sanitizer &&
!use_clang_coverage && current_os != "zos" &&
!(is_android && use_order_profiling) &&
(use_lld || (use_gold && (is_chromeos_ash || !(current_cpu == "x86" ||
current_cpu == "x64"))))
}
if (is_android || (is_chromeos_ash && is_chromeos_device)) {
# Set the path to use orderfile for linking Chrome
# Note that this is for using only one orderfile for linking
# the Chrome binary/library.
declare_args() {
chrome_orderfile_path = ""
if (defined(default_chrome_orderfile)) {
# Allow downstream tools to set orderfile path with
# another variable.
chrome_orderfile_path = default_chrome_orderfile
} else if (is_chromeos_ash && is_chromeos_device) {
chrome_orderfile_path = "//chromeos/profiles/chromeos.orderfile.txt"
}
}
}
assert(!(llvm_force_head_revision && use_goma),
"can't use goma with trunk clang")
assert(!(llvm_force_head_revision && use_remoteexec),
"can't use rbe with trunk clang")
# default_include_dirs ---------------------------------------------------------
#
# This is a separate config so that third_party code (which would not use the
# source root and might have conflicting versions of some headers) can remove
# this and specify their own include paths.
config("default_include_dirs") {
include_dirs = [
"//",
root_gen_dir,
]
}
# Compiler instrumentation can introduce dependencies in DSOs to symbols in
# the executable they are loaded into, so they are unresolved at link-time.
config("no_unresolved_symbols") {
if (!using_sanitizer &&
(is_linux || is_chromeos || is_android || is_fuchsia)) {
ldflags = [
"-Wl,-z,defs",
"-Wl,--as-needed",
]
}
}
# compiler ---------------------------------------------------------------------
#
# Base compiler configuration.
#
# See also "runtime_library" below for related stuff and a discussion about
# where stuff should go. Put warning related stuff in the "warnings" config.
config("compiler") {
asmflags = []
cflags = []
cflags_c = []
cflags_cc = []
cflags_objc = []
cflags_objcc = []
ldflags = []
defines = []
configs = []
# System-specific flags. If your compiler flags apply to one of the
# categories here, add it to the associated file to keep this shared config
# smaller.
if (is_win) {
configs += [ "//build/config/win:compiler" ]
} else if (is_android) {
configs += [ "//build/config/android:compiler" ]
} else if (is_linux || is_chromeos) {
configs += [ "//build/config/linux:compiler" ]
if (is_chromeos_ash) {
configs += [ "//build/config/chromeos:compiler" ]
}
} else if (is_nacl) {
configs += [ "//build/config/nacl:compiler" ]
} else if (is_mac) {
configs += [ "//build/config/mac:compiler" ]
} else if (is_ios) {
configs += [ "//build/config/ios:compiler" ]
} else if (is_fuchsia) {
configs += [ "//build/config/fuchsia:compiler" ]
} else if (current_os == "aix") {
configs += [ "//build/config/aix:compiler" ]
} else if (current_os == "zos") {
configs += [ "//build/config/zos:compiler" ]
}
configs += [
# See the definitions below.
":clang_revision",
":rustc_revision",
":compiler_cpu_abi",
":compiler_codegen",
":compiler_deterministic",
]
# Here we enable -fno-delete-null-pointer-checks, which makes various nullptr
# operations (e.g. dereferencing) into defined behavior. This avoids deletion
# of some security-critical code: see https://crbug.com/1139129.
# Nacl does not support the flag. And, we still want UBSAN to catch undefined
# behavior related to nullptrs, so do not add this flag if UBSAN is enabled.
# GCC seems to have some bugs compiling constexpr code when this is defined,
# so only enable it if using_clang. See: https://gcc.gnu.org/PR97913
# TODO(mpdenton): remove is_clang once GCC bug is fixed.
if (!is_nacl && !is_ubsan && is_clang) {
cflags += [ "-fno-delete-null-pointer-checks" ]
}
# Don't emit the GCC version ident directives, they just end up in the
# .comment section or debug info taking up binary size, and makes comparing
# .o files built with different compiler versions harder.
if (!is_win || is_clang) {
cflags += [ "-fno-ident" ]
}
# In general, Windows is totally different, but all the other builds share
# some common compiler and linker configuration.
if (!is_win) {
# Common POSIX compiler flags setup.
# --------------------------------
cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204
# Stack protection.
if (is_mac) {
# The strong variant of the stack protector significantly increases
# binary size, so only enable it in debug mode.
if (is_debug) {
cflags += [ "-fstack-protector-strong" ]
} else {
cflags += [ "-fstack-protector" ]
}
} else if ((is_posix && !is_chromeos_ash && !is_nacl) || is_fuchsia) {
# TODO(phajdan.jr): Use -fstack-protector-strong when our gcc supports it.
# See also https://crbug.com/533294
if (current_os != "zos") {
cflags += [ "--param=ssp-buffer-size=4" ]
}
# The x86 toolchain currently has problems with stack-protector.
if (is_android && current_cpu == "x86") {
cflags += [ "-fno-stack-protector" ]
} else if (current_os != "aix") {
# Not available on aix.
cflags += [ "-fstack-protector" ]
}
}
if (use_lld) {
ldflags += [ "-fuse-ld=lld" ]
if (lld_path != "") {
ldflags += [ "-B$lld_path" ]
}
}
# Linker warnings.
if (fatal_linker_warnings && !is_apple && current_os != "aix" &&
current_os != "zos") {
ldflags += [ "-Wl,--fatal-warnings" ]
}
if (fatal_linker_warnings && is_apple) {
ldflags += [ "-Wl,-fatal_warnings" ]
}
}
if (is_clang && is_debug) {
# Allow comparing the address of references and 'this' against 0
# in debug builds. Technically, these can never be null in
# well-defined C/C++ and Clang can optimize such checks away in
# release builds, but they may be used in asserts in debug builds.
cflags_cc += [
"-Wno-undefined-bool-conversion",
"-Wno-tautological-undefined-compare",
]
}
# Non-Mac Posix and Fuchsia compiler flags setup.
# -----------------------------------
if ((is_posix && !is_apple) || is_fuchsia) {
if (enable_profiling) {
if (!is_debug) {
cflags += [ "-g" ]
if (enable_full_stack_frames_for_profiling) {
cflags += [
"-fno-inline",
"-fno-optimize-sibling-calls",
]
}
}
}
# Explicitly pass --build-id to ld. Compilers used to always pass this
# implicitly but don't any more (in particular clang when built without
# ENABLE_LINKER_BUILD_ID=ON).
if (is_official_build) {
# The sha1 build id has lower risk of collision but is more expensive to
# compute, so only use it in the official build to avoid slowing down
# links.
ldflags += [ "-Wl,--build-id=sha1" ]
} else if (current_os != "aix" && current_os != "zos") {
ldflags += [ "-Wl,--build-id" ]
}
if (!is_android) {
defines += [
# _FILE_OFFSET_BITS=64 should not be set on Android in order to maintain
# the behavior of the Android NDK from earlier versions.
# See https://android-developers.googleblog.com/2017/09/introducing-android-native-development.html
"_FILE_OFFSET_BITS=64",
"_LARGEFILE_SOURCE",
"_LARGEFILE64_SOURCE",
]
}
if (!is_nacl) {
if (exclude_unwind_tables) {
cflags += [
"-fno-unwind-tables",
"-fno-asynchronous-unwind-tables",
]
defines += [ "NO_UNWIND_TABLES" ]
} else {
cflags += [ "-funwind-tables" ]
}
}
}
# Linux/Android/Fuchsia common flags setup.
# ---------------------------------
if (is_linux || is_chromeos || is_android || is_fuchsia) {
asmflags += [ "-fPIC" ]
cflags += [ "-fPIC" ]
ldflags += [ "-fPIC" ]
if (!is_clang) {
# Use pipes for communicating between sub-processes. Faster.
# (This flag doesn't do anything with Clang.)
cflags += [ "-pipe" ]
}
ldflags += [
"-Wl,-z,noexecstack",
"-Wl,-z,relro",
]
if (!is_component_build) {
ldflags += [ "-Wl,-z,now" ]
}
}
# Linux-specific compiler flags setup.
# ------------------------------------
if ((is_posix || is_fuchsia) && !is_apple && use_lld) {
if (current_cpu == "arm64") {
# Reduce the page size from 65536 in order to reduce binary size slightly
# by shrinking the alignment gap between segments. This also causes all
# segments to be mapped adjacently, which breakpad relies on.
ldflags += [ "-Wl,-z,max-page-size=4096" ]
}
} else if (use_gold) {
ldflags += [ "-fuse-ld=gold" ]
if (!is_android) {
# On Android, this isn't needed. gcc in the NDK knows to look next to
# it with -fuse-ld=gold, and clang gets a --gcc-toolchain flag passed
# above.
if (gold_path != "") {
ldflags += [ "-B$gold_path" ]
}
ldflags += [
# Experimentation found that using four linking threads
# saved ~20% of link time.
# https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/281527606915bb36
# Only apply this to the target linker, since the host
# linker might not be gold, but isn't used much anyway.
"-Wl,--threads",
"-Wl,--thread-count=4",
]
}
# TODO(thestig): Make this flag work with GN.
#if (!is_official_build && !is_chromeos && !(is_asan || is_lsan || is_tsan || is_msan)) {
# ldflags += [
# "-Wl,--detect-odr-violations",
# ]
#}
}
if (use_icf && (!is_apple || use_lld)) {
ldflags += [ "-Wl,--icf=all" ]
}
if (is_linux || is_chromeos) {
cflags += [ "-pthread" ]
# Do not use the -pthread ldflag here since it becomes a no-op
# when using -nodefaultlibs, which would cause an unused argument
# error. "-lpthread" is added in //build/config:default_libs.
}
# Clang-specific compiler flags setup.
# ------------------------------------
if (is_clang) {
cflags += [ "-fcolor-diagnostics" ]
# Enable -fmerge-all-constants. This used to be the default in clang
# for over a decade. It makes clang non-conforming, but is fairly safe
# in practice and saves some binary size. We might want to consider
# disabling this (https://bugs.llvm.org/show_bug.cgi?id=18538#c13),
# but for now it looks like our build might rely on it
# (https://crbug.com/829795).
cflags += [ "-fmerge-all-constants" ]
}
if (use_lld) {
# TODO(thakis): Make the driver pass --color-diagnostics to the linker
# if -fcolor-diagnostics is passed to it, and pass -fcolor-diagnostics
# in ldflags instead.
if (is_win) {
# On Windows, we call the linker directly, instead of calling it through
# the driver.
ldflags += [ "--color-diagnostics" ]
} else {
ldflags += [ "-Wl,--color-diagnostics" ]
}
}
# Enable text section splitting only on linux when using lld for now. Other
# platforms can be added later if needed.
if ((is_linux || is_chromeos) && use_lld && use_text_section_splitting) {
ldflags += [ "-Wl,-z,keep-text-section-prefix" ]
}
if (is_clang && !is_nacl && current_os != "zos") {
cflags += [ "-fcrash-diagnostics-dir=" + clang_diagnostic_dir ]
# TODO(hans): Remove this once Clang generates better optimized debug info
# by default. https://crbug.com/765793
cflags += [
"-mllvm",
"-instcombine-lower-dbg-declare=0",
]
if (!is_debug && use_thin_lto && is_a_target_toolchain) {
if (is_win) {
ldflags += [ "-mllvm:-instcombine-lower-dbg-declare=0" ]
} else {
ldflags += [ "-Wl,-mllvm,-instcombine-lower-dbg-declare=0" ]
}
}
# TODO(crbug.com/1235145): Investigate why/if this should be needed.
if (is_win) {
cflags += [ "/clang:-ffp-contract=off" ]
} else {
cflags += [ "-ffp-contract=off" ]
}
}
# C11/C++11 compiler flags setup.
# ---------------------------
if (is_linux || is_chromeos || is_android || (is_nacl && is_clang) ||
current_os == "aix") {
if (is_clang) {
standard_prefix = "c"
# Since we build with -std=c* and not -std=gnu*, _GNU_SOURCE will not be
# defined by the compiler. However, lots of code relies on the
# non-standard features that _GNU_SOURCE enables, so define it manually.
defines += [ "_GNU_SOURCE" ]
if (is_nacl) {
# Undefine __STRICT_ANSI__ to get non-standard features which would
# otherwise not be enabled by NaCl's sysroots.
cflags += [ "-U__STRICT_ANSI__" ]
}
} else {
# Gcc does not support ##__VA_ARGS__ when in standards-conforming mode,
# but we use this feature in several places in Chromium.
# TODO(thomasanderson): Replace usages of ##__VA_ARGS__ with the
# standard-compliant __VA_OPT__ added by C++20, and switch the gcc build
# to -std=c*.
standard_prefix = "gnu"
}
cflags_c += [ "-std=${standard_prefix}11" ]
if (is_nacl && !is_nacl_saigo) {
# This is for the pnacl_newlib toolchain. It's only used to build
# a few independent ppapi test files that don't pull in any other
# dependencies.
cflags_cc += [ "-std=${standard_prefix}++14" ]
if (is_clang) {
cflags_cc += [ "-fno-trigraphs" ]
}
} else {
cflags_cc += [ "-std=${standard_prefix}++17" ]
}
} else if (is_win) {
cflags_cc += [ "/std:c++17" ]
} else if (!is_nacl) {
# TODO(mcgrathr) - the NaCl GCC toolchain doesn't support either gnu11/gnu++11
# or c11/c++11; we technically don't need this toolchain any more, but there
# are still a few buildbots using it, so until those are turned off
# we need the !is_nacl clause and the (is_nacl && is_clang) clause, above.
cflags_c += [ "-std=c11" ]
cflags_cc += [ "-std=c++17" ]
}
if (is_clang && current_os != "zos") {
# C++17 removes trigraph support, but clang still warns that it ignores
# them when seeing them. Don't.
cflags_cc += [ "-Wno-trigraphs" ]
}
# Before C++17, an `alignas(N)` type would be N-aligned on the stack,
# but heap allocation would just return something aligned to whatever the
# default allocator happens to return. Starting with C++17, operator new
# called on aligned types with N > __STDCPP_DEFAULT_NEW_ALIGNMENT__ will
# call a special overload that hands in the desired alignment, and that will
# honor the alignas even for memory on the heap.
# However, that requires that operator new overload to exist. At least on
# macOS and iOS, they are in libc++abi, and system libc++abi has them as of
# "macOS 10.12, iOS 10.0" (https://reviews.llvm.org/D112921#3128089).
# However, we do statically link libc++abi, so maybe just explicitly passing
# -faligned-allocation is enough to make things work.
# For now, explicitly disable this feature though to keep the C++14 aligned
# allocation behavior (and do that on all platforms so that we have
# consistent behavior across platforms), to make the change more incremental.
if (!is_nacl || is_nacl_saigo) {
if (is_win) {
cflags_cc += [ "/Zc:alignedNew-" ]
} else {
cflags_cc += [ "-fno-aligned-new" ]
}
}
if (is_mac) {
# The system libc++ on Mac doesn't have aligned allocation in C++17.
defines += [ "_LIBCPP_HAS_NO_ALIGNED_ALLOCATION" ]
cflags_cc += [ "-stdlib=libc++" ]
ldflags += [ "-stdlib=libc++" ]
}
# Add flags for link-time optimization. These flags enable
# optimizations/transformations that require whole-program visibility at link
# time, so they need to be applied to all translation units, and we may end up
# with miscompiles if only part of the program is compiled with LTO flags. For
# that reason, we cannot allow targets to enable or disable these flags, for
# example by disabling the optimize configuration.
# TODO(pcc): Make this conditional on is_official_build rather than on gn
# flags for specific features.
if (!is_debug && use_thin_lto && is_a_target_toolchain) {
assert(use_lld, "LTO is only supported with lld")
cflags += [
"-flto=thin",
"-fsplit-lto-unit",
]
# Limit the size of the ThinLTO cache to the lesser of 10% of
# available disk space, 40GB and 100000 files.
# cache_policy = "cache_size=10%:cache_size_bytes=40g:cache_size_files=100000"
# TODO(gbiv): We ideally shouldn't need to specify this; ThinLTO
# should be able to better manage binary size increases on its own.
import_instr_limit = 100
if (is_win) {
ldflags += [
"/opt:lldltojobs=all",
"-mllvm:-import-instr-limit=$import_instr_limit",
# "/lldltocache:" +
# rebase_path("$root_out_dir/thinlto-cache", root_build_dir),
# "/lldltocachepolicy:$cache_policy",
]
} else {
ldflags += [ "-flto=thin" ]
# Enabling ThinLTO on Chrome OS too, in an effort to reduce the memory
# usage in crbug.com/1038040. Note this will increase build time in
# Chrome OS.
# In ThinLTO builds, we run at most one link process at a time,
# and let it use all cores.
# TODO(thakis): Check if '=0' (that is, number of cores, instead
# of "all" which means number of hardware threads) is faster.
ldflags += [ "-Wl,--thinlto-jobs=all" ]
if (is_mac) {
ldflags +=
[ "-Wl,-cache_path_lto," +
rebase_path("$root_out_dir/thinlto-cache", root_build_dir) ]
}
# ldflags += [ "-Wl,--thinlto-cache-policy=$cache_policy" ]
if (is_chromeos_ash) {
# Not much performance difference was noted between the default (100)
# and these. ARM was originally set lower than x86 to keep the size
# bloat of ThinLTO to <10%, but that's potentially no longer true.
# FIXME(inglorion): maybe tune these?
if (target_cpu == "arm" || target_cpu == "arm64") {
import_instr_limit = 20
} else {
import_instr_limit = 30
}
}
ldflags += [ "-Wl,-mllvm,-import-instr-limit=$import_instr_limit" ]
}
# TODO(https://crbug.com/1211155): investigate why this isn't effective on arm32.
if (!is_android || current_cpu == "arm64") {
cflags += [ "-fwhole-program-vtables" ]
if (!is_win) {
ldflags += [ "-fwhole-program-vtables" ]
}
}
# This flag causes LTO to create an .ARM.attributes section with the correct
# architecture. This is necessary because LLD will refuse to link a program
# unless the architecture revision in .ARM.attributes is sufficiently new.
# TODO(pcc): The contents of .ARM.attributes should be based on the
# -march flag passed at compile time (see llvm.org/pr36291).
if (current_cpu == "arm") {
ldflags += [ "-march=$arm_arch" ]
}
}
if (compiler_timing) {
if (is_clang && !is_nacl) {
cflags += [ "-ftime-trace" ]
} else if (is_win) {
cflags += [
# "Documented" here:
# http://aras-p.info/blog/2017/10/23/Best-unknown-MSVC-flag-d2cgsummary/
"/d2cgsummary",
]
}
}
# Pass flag to LLD so Android builds can allow debuggerd to properly symbolize
# stack crashes (http://crbug.com/919499).
if (use_lld && is_android) {
ldflags += [ "-Wl,--no-rosegment" ]
}
# LLD does call-graph-sorted binary layout by default when profile data is
# present. On Android this increases binary size due to more thinks for long
# jumps. Turn it off by default and enable selectively for targets where it's
# beneficial.
if (use_lld && !enable_call_graph_profile_sort) {
if (is_win) {
ldflags += [ "/call-graph-profile-sort:no" ]
} else if (!is_apple) {
# TODO(thakis): Once LLD's Mach-O port basically works, implement call
# graph profile sorting for it, add an opt-out flag, and pass it here.
ldflags += [ "-Wl,--no-call-graph-profile-sort" ]
}
}
if (is_clang && !is_nacl && show_includes) {
if (is_win) {
# TODO(crbug.com/1223741): Goma mixes the -H and /showIncludes output.
assert(!use_goma, "show_includes on Windows is not reliable with goma")
cflags += [
"/clang:-H",
"/clang:-fshow-skipped-includes",
]
} else {
cflags += [
"-H",
"-fshow-skipped-includes",
]
}
}
# This flag enforces that member pointer base types are complete. It helps
# prevent us from running into problems in the Microsoft C++ ABI (see
# https://crbug.com/847724).
# TODO(crbug/1052397): Remove is_chromeos_lacros once lacros-chrome switches
# to target_os="chromeos".
if (is_clang && !is_nacl && target_os != "chromeos" && !is_chromeos_lacros &&
(is_win || use_custom_libcxx)) {
cflags += [ "-fcomplete-member-pointers" ]
}
# Pass the same C/C++ flags to the objective C/C++ compiler.
cflags_objc += cflags_c
cflags_objcc += cflags_cc
# Assign any flags set for the C compiler to asmflags so that they are sent
# to the assembler. The Windows assembler takes different types of flags
# so only do so for posix platforms.
if (is_posix || is_fuchsia) {
asmflags += cflags
asmflags += cflags_c
}
# Rust compiler flags setup.
# ---------------------------
rustflags = [
# Overflow checks are optional in Rust, but even if switched
# off they do not cause undefined behavior (the overflowing
# behavior is defined). Because containers are bounds-checked
# in safe Rust, they also can't provoke buffer overflows.
# As such these checks may be less important in Rust than C++.
# But in (simplistic) testing they have negligible performance
# overhead, and this helps to provide consistent behavior
# between different configurations, so we'll keep them on until
# we discover a reason to turn them off.
"-Coverflow-checks=on",
# To make Rust .d files compatible with ninja
"-Z",
"dep-info-omit-d-target",
]
if (rust_abi_target != "") {
rustflags += [ "--target=$rust_abi_target" ]
}
if (use_lto_in_rustc_linking) {
rustflags += [ "-Clinker-plugin-lto" ]
}
if (!use_thin_lto) {
# Optimization - don't include bitcode if it won't be used.
rustflags += [ "-Cembed-bitcode=no" ]
}
}
# The BUILDCONFIG file sets this config on targets by default, which means when
# building with ThinLTO, no optimization is performed in the link step.
config("thinlto_optimize_default") {
if (!is_debug && use_thin_lto && is_a_target_toolchain) {
lto_opt_level = 3
if (is_win) {
ldflags = [ "/opt:lldlto=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
}
}
}
# Use this to enable optimization in the ThinLTO link step for select targets
# when thin_lto_enable_optimizations is set by doing:
#
# configs -= [ "//build/config/compiler:thinlto_optimize_default" ]
# configs += [ "//build/config/compiler:thinlto_optimize_max" ]
#
# Since it makes linking significantly slower and more resource intensive, only
# use it on important targets such as the main browser executable or dll.
config("thinlto_optimize_max") {
if (!is_debug && use_thin_lto && is_a_target_toolchain) {
if (thin_lto_enable_optimizations) {
lto_opt_level = 3
} else {
lto_opt_level = 3
}
if (is_win) {
ldflags = [ "/opt:lldlto=" + lto_opt_level ]
} else {
ldflags = [ "-Wl,--lto-O" + lto_opt_level ]
}
}
}
# This provides the basic options to select the target CPU and ABI.
# It is factored out of "compiler" so that special cases can use this
# without using everything that "compiler" brings in. Options that
# tweak code generation for a particular CPU do not belong here!
# See "compiler_codegen", below.
config("compiler_cpu_abi") {
cflags = []
ldflags = []
defines = []
if ((is_posix && !is_apple) || is_fuchsia) {
# CPU architecture. We may or may not be doing a cross compile now, so for
# simplicity we always explicitly set the architecture.
if (current_cpu == "x64") {
cflags += [
"-m64",
"-march=sandybridge",
]
ldflags += [ "-m64" ]
} else if (current_cpu == "x86") {
cflags += [ "-m32" ]
ldflags += [ "-m32" ]
if (!is_nacl) {
cflags += [
"-mfpmath=sse",
"-march=sandybridge",
]
}
} else if (current_cpu == "arm") {
if (is_clang && !is_android && !is_nacl) {
cflags += [ "--target=arm-linux-gnueabihf" ]
ldflags += [ "--target=arm-linux-gnueabihf" ]
}
if (!is_nacl) {
cflags += [
"-march=$arm_arch",
"-mfloat-abi=$arm_float_abi",
]
}
if (arm_tune != "") {
cflags += [ "-mtune=$arm_tune" ]
}
} else if (current_cpu == "arm64") {
if (is_clang && !is_android && !is_nacl && !is_fuchsia) {
cflags += [ "--target=aarch64-linux-gnu" ]
ldflags += [ "--target=aarch64-linux-gnu" ]
}
if (is_android) {
# Outline atomics crash on Exynos 9810. http://crbug.com/1272795
cflags += [ "-mno-outline-atomics" ]
}
} else if (current_cpu == "mipsel" && !is_nacl) {
ldflags += [ "-Wl,--hash-style=sysv" ]
if (custom_toolchain == "") {
if (is_clang) {
if (is_android) {
cflags += [ "--target=mipsel-linux-android" ]
ldflags += [ "--target=mipsel-linux-android" ]
} else {
cflags += [ "--target=mipsel-linux-gnu" ]
ldflags += [ "--target=mipsel-linux-gnu" ]
}
} else {
cflags += [ "-EL" ]
ldflags += [ "-EL" ]
}
}
if (mips_arch_variant == "r6") {
cflags += [ "-mno-odd-spreg" ]
ldflags += [ "-mips32r6" ]
if (is_clang) {
cflags += [
"-march=mipsel",
"-mcpu=mips32r6",
]
} else {
cflags += [
"-mips32r6",
"-Wa,-mips32r6",
]
if (is_android) {
ldflags += [ "-Wl,-melf32ltsmip" ]
}
}
if (mips_use_msa == true) {
cflags += [
"-mmsa",
"-mfp64",
]
}
} else if (mips_arch_variant == "r2") {
ldflags += [ "-mips32r2" ]
if (is_clang) {
cflags += [
"-march=mipsel",
"-mcpu=mips32r2",
]
} else {
cflags += [
"-mips32r2",
"-Wa,-mips32r2",
]
if (mips_float_abi == "hard" && mips_fpu_mode != "") {
cflags += [ "-m$mips_fpu_mode" ]
}
}
} else if (mips_arch_variant == "r1") {
ldflags += [ "-mips32" ]
if (is_clang) {
cflags += [
"-march=mipsel",
"-mcpu=mips32",
]
} else {
cflags += [
"-mips32",
"-Wa,-mips32",
]
}
} else if (mips_arch_variant == "loongson3") {
defines += [ "_MIPS_ARCH_LOONGSON" ]
cflags += [
"-march=loongson3a",
"-mno-branch-likely",
"-Wa,-march=loongson3a",
]
}
if (mips_dsp_rev == 1) {
cflags += [ "-mdsp" ]