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

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

Issue 275703003: Make GN Android build link executables (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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
OLDNEW
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import("//build/config/android/config.gni") 5 import("//build/config/android/config.gni")
6 if (cpu_arch == "arm") { 6 if (cpu_arch == "arm") {
7 import("//build/config/arm.gni") 7 import("//build/config/arm.gni")
8 } 8 }
9 9
10 declare_args() {
11 # Normally, Android builds are lightly optimized, even for debug builds, to
12 # keep binary size down. Setting this flag to true disables such optimization
13 android_full_debug = false
14 }
15
10 # compiler --------------------------------------------------------------------- 16 # compiler ---------------------------------------------------------------------
11 # 17 #
12 # Base compiler configuration. 18 # Base compiler configuration.
13 # 19 #
14 # See also "runtime_library" below for related stuff and a discusison about 20 # See also "runtime_library" below for related stuff and a discusison about
15 # where stuff should go. Put warning related stuff in the "warnings" config. 21 # where stuff should go. Put warning related stuff in the "warnings" config.
16 22
17 config("compiler") { 23 config("compiler") {
18 cflags = [] 24 cflags = []
19 cflags_c = [] 25 cflags_c = []
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 # //build/config/gcc:symbol_visibility_hidden. 58 # //build/config/gcc:symbol_visibility_hidden.
53 "-fvisibility-inlines-hidden", 59 "-fvisibility-inlines-hidden",
54 ] 60 ]
55 61
56 # Stack protection. 62 # Stack protection.
57 if (is_mac) { 63 if (is_mac) {
58 cflags += [ "-fstack-protector-all" ] 64 cflags += [ "-fstack-protector-all" ]
59 } else if (is_linux) { 65 } else if (is_linux) {
60 cflags += [ "-fstack-protector", "--param=ssp-buffer-size=4" ] 66 cflags += [ "-fstack-protector", "--param=ssp-buffer-size=4" ]
61 } 67 }
68
69 # Linker warnings.
70 if (!is_chromeos || cpu_arch != "arm") {
71 # TODO(jochen): Enable this on chromeos on arm. http://crbug.com/356580
72 ldflags += [ "-Wl,--fatal-warnings" ]
73 }
62 } 74 }
63 75
64 # Mac-specific compiler flags setup. 76 # Mac-specific compiler flags setup.
65 # ---------------------------------- 77 # ----------------------------------
66 if (is_mac || is_ios) { 78 if (is_mac || is_ios) {
67 # These flags are shared between the C compiler and linker. 79 # These flags are shared between the C compiler and linker.
68 common_mac_flags = [] 80 common_mac_flags = []
69 81
70 # CPU architecture. 82 # CPU architecture.
71 if (cpu_arch == "x64") { 83 if (cpu_arch == "x64") {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 if (is_chrome_branded && is_official_build) { 136 if (is_chrome_branded && is_official_build) {
125 cflags += [ 137 cflags += [
126 "-fno-unwind-tables", 138 "-fno-unwind-tables",
127 "-fno-asynchronous-unwind-tables", 139 "-fno-asynchronous-unwind-tables",
128 ] 140 ]
129 } else { 141 } else {
130 cflags += [ "-funwind-tables" ] 142 cflags += [ "-funwind-tables" ]
131 } 143 }
132 } 144 }
133 145
146 # Linux/Android common flags setup.
147 # ---------------------------------
148 if (is_linux || is_android) {
149 cflags += [
150 "-fPIC",
151 "-pipe", # Use pipes for communicating between sub-processes. Faster.
152 ]
153
154 ldflags += [
155 "-fPIC",
156 "-Wl,-z,noexecstack",
157 "-Wl,-z,now",
158 "-Wl,-z,relro",
159 ]
160 }
161
134 # Linux-specific compiler flags setup. 162 # Linux-specific compiler flags setup.
135 # ------------------------------------ 163 # ------------------------------------
136 if (is_linux) { 164 if (is_linux) {
137 cflags += [ 165 cflags += [ "-pthread" ]
138 "-fPIC",
139 "-pipe", # Use pipes for communicating between sub-processes. Faster.
140 ]
141 if (!is_android) {
142 cflags += [ "-pthread" ]
143 }
144 166
145 if (cpu_arch == "x64") { 167 if (cpu_arch == "x64") {
146 # Use gold for linking on 64-bit Linux only (on 32-bit it runs out of 168 # Use gold for linking on 64-bit Linux only (on 32-bit it runs out of
147 # address space, and it doesn't support cross-compiling). 169 # address space, and it doesn't support cross-compiling).
148 gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin", 170 gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin",
149 root_build_dir) 171 root_build_dir)
150 ldflags += [ 172 ldflags += [
151 "-B$gold_path", 173 "-B$gold_path",
152 174
153 # There seems to be a conflict of --icf and -pie in gold which can 175 # There seems to be a conflict of --icf and -pie in gold which can
154 # generate crashy binaries. As a security measure, -pie takes 176 # generate crashy binaries. As a security measure, -pie takes
155 # precendence for now. 177 # precendence for now.
156 # TODO(brettw) common.gypi has this only for target toolset. 178 # TODO(brettw) common.gypi has this only for target toolset.
157 #"-Wl,--icf=safe", 179 #"-Wl,--icf=safe",
158 "-Wl,--icf=none", 180 "-Wl,--icf=none",
159 181
160 # Experimentation found that using four linking threads 182 # Experimentation found that using four linking threads
161 # saved ~20% of link time. 183 # saved ~20% of link time.
162 # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thr ead/thread/281527606915bb36 184 # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thr ead/thread/281527606915bb36
163 # Only apply this to the target linker, since the host 185 # Only apply this to the target linker, since the host
164 # linker might not be gold, but isn't used much anyway. 186 # linker might not be gold, but isn't used much anyway.
165 # TODO(raymes): Disable threading because gold is frequently 187 # TODO(raymes): Disable threading because gold is frequently
166 # crashing on the bots: crbug.com/161942. 188 # crashing on the bots: crbug.com/161942.
167 #"-Wl,--threads", 189 #"-Wl,--threads",
168 #"-Wl,--thread-count=4", 190 #"-Wl,--thread-count=4",
169 ] 191 ]
170 } 192 }
171 193
172 ldflags += [ 194 ldflags += [
173 "-fPIC",
174 "-pthread", 195 "-pthread",
175 "-Wl,-z,noexecstack",
176 "-Wl,-z,now",
177 "-Wl,-z,relro",
178 ] 196 ]
179 } 197 }
180 198
181 # Clang-specific compiler flags setup. 199 # Clang-specific compiler flags setup.
182 # ------------------------------------ 200 # ------------------------------------
183 if (is_clang) { 201 if (is_clang) {
184 cflags += [ 202 cflags += [
185 "-fcolor-diagnostics", 203 "-fcolor-diagnostics",
186 ] 204 ]
187 cflags_cc += [ 205 cflags_cc += [
(...skipping 30 matching lines...) Expand all
218 cflags += [ "-mllvm -asan-globals=0" ] 236 cflags += [ "-mllvm -asan-globals=0" ]
219 } 237 }
220 238
221 defines += [ "ANDROID" ] 239 defines += [ "ANDROID" ]
222 if (!is_android_webview_build) { 240 if (!is_android_webview_build) {
223 # The NDK has these things, but doesn't define the constants 241 # The NDK has these things, but doesn't define the constants
224 # to say that it does. Define them here instead. 242 # to say that it does. Define them here instead.
225 defines += [ "HAVE_SYS_UIO_H" ] 243 defines += [ "HAVE_SYS_UIO_H" ]
226 } 244 }
227 245
246 # Use gold for Android for most CPU architectures.
247 if (cpu_arch == "x86" || cpu_arch == "x64" ||
248 (cpu_arch == "arm" && !is_clang)) {
249 # These architectures support gold for linking. Apparently Clang has not
250 # been made to work on x86 yet or we would probably need a -B option like
251 # we do below for Clang-on-arm.
252 ldflags += [ "-fuse-ld=gold" ]
253 } else if (cpu_arch == "arm") {
254 # Clang does not support -fuse-ld to invoke the built-in gold linker,
255 # so use the -B option which requires us to specify the path.
256 ldflags += [
257 "-B" + rebase_path("//build/android/arm-linux-androideabi-gold",
258 root_build_dir)
259 ]
260 }
261
228 ldflags += [ 262 ldflags += [
229 "-Wl,--no-undefined", 263 "-Wl,--no-undefined",
230 # Don't export symbols from statically linked libraries. 264 # Don't export symbols from statically linked libraries.
231 "-Wl,--exclude-libs=ALL", 265 "-Wl,--exclude-libs=ALL",
232 ] 266 ]
233 if (cpu_arch == "arm") { 267 if (cpu_arch == "arm") {
234 ldflags += [ 268 ldflags += [
235 # Enable identical code folding to reduce size. 269 # Enable identical code folding to reduce size.
236 "-Wl,--icf=safe", 270 "-Wl,--icf=safe",
237 ] 271 ]
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 ] 349 ]
316 } 350 }
317 351
318 defines += [ 352 defines += [
319 "USE_STLPORT=1", 353 "USE_STLPORT=1",
320 "_STLP_USE_PTR_SPECIALIZATIONS=1", 354 "_STLP_USE_PTR_SPECIALIZATIONS=1",
321 "__GNU_SOURCE=1", # Necessary for clone(). 355 "__GNU_SOURCE=1", # Necessary for clone().
322 ] 356 ]
323 357
324 ldflags += [ 358 ldflags += [
359 "-Wl,--warn-shared-textrel",
325 "-nostdlib", 360 "-nostdlib",
326 ] 361 ]
327 362
328
329 # NOTE: The stlport header include paths below are specified in cflags 363 # NOTE: The stlport header include paths below are specified in cflags
330 # rather than include_dirs because they need to come after include_dirs. 364 # rather than include_dirs because they need to come after include_dirs.
331 # Think of them like system headers, but don't use '-isystem' because the 365 # Think of them like system headers, but don't use '-isystem' because the
332 # arm-linux-androideabi-4.4.3 toolchain (circa Gingerbread) will exhibit 366 # arm-linux-androideabi-4.4.3 toolchain (circa Gingerbread) will exhibit
333 # strange errors. The include ordering here is important; change with 367 # strange errors. The include ordering here is important; change with
334 # caution. 368 # caution.
335 if (use_system_stlport) { 369 if (use_system_stlport) {
336 cflags += [ 370 cflags += [
337 # For libstdc++/include, which is used by stlport. 371 # For libstdc++/include, which is used by stlport.
338 "-I$android_src/bionic", 372 "-I" + rebase_path("$android_src/bionic", root_build_dir),
339 "-I$android_src/external/stlport/stlport", 373 "-I" + rebase_path("$android_src/external/stlport/stlport",
374 root_build_dir),
340 ] 375 ]
341 libs += [ 376 libs += [
342 "stlport", 377 "stlport",
343 ] 378 ]
344 } else { 379 } else {
345 android_stlport_root = "$android_ndk_root/sources/cxx-stl/stlport" 380 android_stlport_root = "$android_ndk_root/sources/cxx-stl/stlport"
346 381
347 cflags += [ "-I$android_stlport_root/stlport" ] 382 cflags += [
383 "-I" + rebase_path("$android_stlport_root/stlport", root_build_dir)
384 ]
348 lib_dirs += [ "$android_stlport_root/libs/$android_app_abi" ] 385 lib_dirs += [ "$android_stlport_root/libs/$android_app_abi" ]
349 386
350 if (component_mode == "shared_library") { 387 if (component_mode == "shared_library") {
351 libs += [ "stlport_shared" ] 388 libs += [ "stlport_shared" ]
352 } else { 389 } else {
353 libs += [ "stlport_static" ] 390 libs += [ "stlport_static" ]
354 } 391 }
355 } 392 }
393
394 libs += [
395 # Manually link the libgcc.a that the cross compiler uses. This is
396 # absolute because the linker will look inside the sysroot if it's not.
397 rebase_path(android_libgcc_file),
398 "c",
399 "dl",
400 "m",
401 ]
402
356 } 403 }
357 } 404 }
358 405
359 # chromium_code --------------------------------------------------------------- 406 # chromium_code ---------------------------------------------------------------
360 # 407 #
361 # Toggles between higher and lower warnings for code that is (or isn't) 408 # Toggles between higher and lower warnings for code that is (or isn't)
362 # part of Chromium. 409 # part of Chromium.
363 410
364 config("chromium_code") { 411 config("chromium_code") {
365 if (is_win) { 412 if (is_win) {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 # 627 #
581 # Note that BUILDCONFIG.gn sets up a variable "default_optimization_config" 628 # Note that BUILDCONFIG.gn sets up a variable "default_optimization_config"
582 # which it will assign to the config it implicitly applies to every target. If 629 # which it will assign to the config it implicitly applies to every target. If
583 # you want to override the optimization level for your target, remove this 630 # you want to override the optimization level for your target, remove this
584 # config (which will expand differently for debug or release builds), and then 631 # config (which will expand differently for debug or release builds), and then
585 # add back the one you want to override it with: 632 # add back the one you want to override it with:
586 # 633 #
587 # configs -= default_optimization_config 634 # configs -= default_optimization_config
588 # configs += [ "//build/config/compiler/optimize_max" ] 635 # configs += [ "//build/config/compiler/optimize_max" ]
589 636
590 # Default "optimization on" config. On Windows, this favors size over speed. 637 # Shared settings for both "optimize" and "optimize_max" configs.
591 # 638 if (is_win) {
592 # IF YOU CHANGE THIS also consider whether optimize_max should be updated. 639 common_optimize_on_cflags = [
scottmg 2014/05/12 18:10:21 more o->O here
593 config("optimize") { 640 "/o2",
594 if (is_win) { 641 "/ob2", # both explicit and auto inlining.
595 cflags = [ 642 "/oy-", # disable omitting frame pointers, must be after /o2.
596 "/O2", 643 "/os", # favor size over speed.
597 "/Ob2", # Both explicit and auto inlining. 644 ]
598 "/Oy-", # Disable omitting frame pointers, must be after /O2. 645 common_optimize_on_ldflags = []
599 "/Os", # Favor size over speed. 646 } else {
647 common_optimize_on_cflags = [
648 # Don't emit the GCC version ident directives, they just end up in the
649 # .comment section taking up binary size.
650 "-fno-ident",
651 # Put data and code in their own sections, so that unused symbols
652 # can be removed at link time with --gc-sections.
653 "-fdata-sections",
654 "-ffunction-sections",
655 ]
656
657 common_optimize_on_ldflags = []
658 if (is_mac) {
659 if (symbol_level == 2) {
660 # Mac dead code stripping requires symbols.
661 common_optimize_on_ldflags += [
662 "-Wl,-dead_strip",
663 ]
664 }
665 } else {
666 # Non-Mac Posix linker flags.
667 common_optimize_on_ldflags += [
668 # Specifically tell the linker to perform optimizations.
669 # See http://lwn.net/Articles/192624/ .
670 "-Wl,-O1",
671 "-Wl,--as-needed",
672 "-Wl,--gc-sections",
600 ] 673 ]
674 }
675
676 if (is_ios) {
677 common_optimize_on_cflags += [ "-Os" ]
cjhopman 2014/05/12 18:37:17 Android also uses -Os for release/optimized builds
601 } else { 678 } else {
602 if (is_ios) { 679 common_optimize_on_cflags += [ "-O2" ]
603 cflags = [ "-Os" ]
604 } else {
605 cflags = [ "-O2" ]
606 }
607 } 680 }
608 } 681 }
609 682
683 # Default "optimization on" config. On Windows, this favors size over speed.
684 config("optimize") {
685 cflags = common_optimize_on_cflags
686 ldflags = common_optimize_on_ldflags
687 if (is_win) {
688 cflags += [
689 "/Os", # favor size over speed.
690 ]
691 }
692 }
693
610 # Turn off optimizations. 694 # Turn off optimizations.
611 config("no_optimize") { 695 config("no_optimize") {
612 if (is_win) { 696 if (is_win) {
613 cflags = [ 697 cflags = [
614 "/Od", # Disable optimization. 698 "/Od", # Disable optimization.
615 "/Ob0", # Disable all inlining (on by default). 699 "/Ob0", # Disable all inlining (on by default).
616 "/RTC1", # Runtime checks for stack frame and uninitialized variables. 700 "/RTC1", # Runtime checks for stack frame and uninitialized variables.
617 ] 701 ]
702 } else if (is_android && !android_full_debug) {
703 # On Android we kind of optimize some things that don't affect debugging
704 # much even when optimization is disabled to get the binary size down.
705 cflags = [
706 "-O1",
cjhopman 2014/05/12 18:37:17 This is -Os in this case in common.gypi
707 "-fomit-frame-pointer",
708 "-fdata-sections",
709 "-ffunction-sections",
710 ]
711 ldflags = [
712 "-Wl,-O1",
713 "-Wl,--as-needed",
714 "-Wl,--gc-sections",
715 ]
618 } else { 716 } else {
619 cflags = [ "-O0" ] 717 cflags = [ "-O0" ]
620 } 718 }
621 } 719 }
622 720
623 # On Windows, turns up the optimization level. This implies whole program 721 # On Windows, turns up the optimization level. This implies whole program
624 # optimization and link-time code generation which is very expensive and should 722 # optimization and link-time code generation which is very expensive and should
625 # be used sparingly. For non-Windows, this is the same as "optimize". 723 # be used sparingly. For non-Windows, this is the same as "optimize".
626 config("optimize_max") { 724 config("optimize_max") {
725 cflags = common_optimize_on_cflags
726 ldflags = common_optimize_on_ldflags
627 if (is_win) { 727 if (is_win) {
628 cflags = [ 728 cflags += [
629 "/O2",
630 "/Ob2", # Both explicit and auto inlining.
631 "/Oy-", # Disable omitting frame pointers, must be after /O2.
632 "/Ot", # Favor speed over size. 729 "/Ot", # Favor speed over size.
633 "/GL", # Whole program optimization. 730 "/GL", # Whole program optimization.
634 ] 731 ]
635 } else {
636 if (is_ios) {
637 cflags = [ "-Os" ]
638 } else {
639 cflags = [ "-O2" ]
640 }
641 } 732 }
642 } 733 }
643 734
644 # Symbols ---------------------------------------------------------------------- 735 # Symbols ----------------------------------------------------------------------
645 736
646 # TODO(brettw) Since this sets ldflags on Windows which is inherited across
647 # static library boundaries, if you want to remove the default symbol config
648 # and set a different one on a target, you also have to do it for all static
649 # libraries that go into that target, which is messed up. Either we need a
650 # more flexible system for defining linker flags, or we need to separate this
651 # out into a "symbols_linker" config that is only applied to DLLs and EXEs.
652 config("symbols") { 737 config("symbols") {
653 if (is_win) { 738 if (is_win) {
654 cflags = [ "/Zi" ] # Produce PDB file, no edit and continue. 739 cflags = [ "/Zi" ] # Produce PDB file, no edit and continue.
655 ldflags = [ "/DEBUG" ] 740 ldflags = [ "/DEBUG" ]
656 } else { 741 } else {
657 cflags = [ "-g2" ] 742 cflags = [ "-g2" ]
658 } 743 }
659 } 744 }
660 745
661 config("minimal_symbols") { 746 config("minimal_symbols") {
662 if (is_win) { 747 if (is_win) {
663 # Linker symbols for backtraces only. 748 # Linker symbols for backtraces only.
664 ldflags = [ "/DEBUG" ] 749 ldflags = [ "/DEBUG" ]
665 } else { 750 } else {
666 cflags = [ "-g1" ] 751 cflags = [ "-g1" ]
667 } 752 }
668 } 753 }
669 754
670 config("no_symbols") { 755 config("no_symbols") {
671 if (!is_win) { 756 if (!is_win) {
672 cflags = [ "-g0" ] 757 cflags = [ "-g0" ]
673 } 758 }
674 } 759 }
675 760
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698