Chromium Code Reviews| Index: build/config/compiler/BUILD.gn |
| diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn |
| index c492356ce6bfafb24a056e2f7a89e1e0a7fdff48..253f6eb0c4e48196b1740e7f7b1c47d5de36d792 100644 |
| --- a/build/config/compiler/BUILD.gn |
| +++ b/build/config/compiler/BUILD.gn |
| @@ -7,6 +7,12 @@ if (cpu_arch == "arm") { |
| import("//build/config/arm.gni") |
| } |
| +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 |
| +} |
| + |
| # compiler --------------------------------------------------------------------- |
| # |
| # Base compiler configuration. |
| @@ -59,6 +65,12 @@ config("compiler") { |
| } else if (is_linux) { |
| cflags += [ "-fstack-protector", "--param=ssp-buffer-size=4" ] |
| } |
| + |
| + # Linker warnings. |
| + if (!is_chromeos || cpu_arch != "arm") { |
|
awong
2014/05/12 19:23:02
de morgan's?
!(is_chromeos && cpu_arch == "arm")
|
| + # TODO(jochen): Enable this on chromeos on arm. http://crbug.com/356580 |
| + ldflags += [ "-Wl,--fatal-warnings" ] |
| + } |
| } |
| # Mac-specific compiler flags setup. |
| @@ -131,16 +143,26 @@ config("compiler") { |
| } |
| } |
| - # Linux-specific compiler flags setup. |
| - # ------------------------------------ |
| - if (is_linux) { |
| + # Linux/Android common flags setup. |
|
scottmg
2014/05/12 16:33:58
or any of this
|
| + # --------------------------------- |
| + if (is_linux || is_android) { |
| cflags += [ |
| "-fPIC", |
|
awong
2014/05/12 19:23:02
Huh...do we actually build -fPIC for a static link
brettw
2014/05/12 21:00:08
Yes, I verified that this matches the GYP build.
cjhopman
2014/05/12 21:04:19
IDK about linux, but android doesn't build executa
awong
2014/05/12 21:34:23
Gotcha. I was worried about -fPIE more for the is_
|
| "-pipe", # Use pipes for communicating between sub-processes. Faster. |
| ] |
| - if (!is_android) { |
| - cflags += [ "-pthread" ] |
| - } |
| + |
| + ldflags += [ |
| + "-fPIC", |
| + "-Wl,-z,noexecstack", |
| + "-Wl,-z,now", |
|
awong
2014/05/12 19:23:02
Can we track down why we force immediate binding o
brettw
2014/05/12 21:00:08
I actually know very little about Linux dynamic lo
|
| + "-Wl,-z,relro", |
| + ] |
| + } |
| + |
| + # Linux-specific compiler flags setup. |
| + # ------------------------------------ |
| + if (is_linux) { |
| + cflags += [ "-pthread" ] |
| if (cpu_arch == "x64") { |
| # Use gold for linking on 64-bit Linux only (on 32-bit it runs out of |
| @@ -170,11 +192,7 @@ config("compiler") { |
| } |
| ldflags += [ |
| - "-fPIC", |
| "-pthread", |
| - "-Wl,-z,noexecstack", |
| - "-Wl,-z,now", |
| - "-Wl,-z,relro", |
| ] |
| } |
| @@ -225,6 +243,22 @@ config("compiler") { |
| defines += [ "HAVE_SYS_UIO_H" ] |
| } |
| + # Use gold for Android for most CPU architectures. |
| + if (cpu_arch == "x86" || cpu_arch == "x64" || |
| + (cpu_arch == "arm" && !is_clang)) { |
| + # These architectures support gold for linking. Apparently Clang has not |
| + # been made to work on x86 yet or we would probably need a -B option like |
| + # we do below for Clang-on-arm. |
|
awong
2014/05/12 19:23:02
Do you mean Clang has not been make to work on arm
brettw
2014/05/12 21:00:08
This matches the GYP file, but I changed it to mat
|
| + ldflags += [ "-fuse-ld=gold" ] |
| + } else if (cpu_arch == "arm") { |
| + # Clang does not support -fuse-ld to invoke the built-in gold linker, |
| + # so use the -B option which requires us to specify the path. |
|
awong
2014/05/12 19:23:02
Is this the long-term expected approach? Having fl
brettw
2014/05/12 21:00:08
I did some googleing and it seems clang doesn't su
|
| + ldflags += [ |
| + "-B" + rebase_path("//build/android/arm-linux-androideabi-gold", |
| + root_build_dir) |
| + ] |
| + } |
| + |
| ldflags += [ |
| "-Wl,--no-undefined", |
| # Don't export symbols from statically linked libraries. |
| @@ -322,10 +356,10 @@ config("runtime_library") { |
| ] |
| ldflags += [ |
| + "-Wl,--warn-shared-textrel", |
| "-nostdlib", |
| ] |
| - |
| # NOTE: The stlport header include paths below are specified in cflags |
| # rather than include_dirs because they need to come after include_dirs. |
| # Think of them like system headers, but don't use '-isystem' because the |
| @@ -335,8 +369,9 @@ config("runtime_library") { |
| if (use_system_stlport) { |
| cflags += [ |
| # For libstdc++/include, which is used by stlport. |
| - "-I$android_src/bionic", |
| - "-I$android_src/external/stlport/stlport", |
| + "-I" + rebase_path("$android_src/bionic", root_build_dir), |
|
awong
2014/05/12 19:23:02
I'm unconvinced this makes sense and the comment a
brettw
2014/05/12 21:00:08
I believe this is only the case on the WebView bui
cjhopman
2014/05/12 21:04:19
Bionic is the Android c library, stlport is the c+
awong
2014/05/12 21:34:23
Yep...so I've been messing a lot with the NDK c++
|
| + "-I" + rebase_path("$android_src/external/stlport/stlport", |
| + root_build_dir), |
| ] |
| libs += [ |
| "stlport", |
| @@ -344,7 +379,9 @@ config("runtime_library") { |
| } else { |
| android_stlport_root = "$android_ndk_root/sources/cxx-stl/stlport" |
| - cflags += [ "-I$android_stlport_root/stlport" ] |
| + cflags += [ |
| + "-I" + rebase_path("$android_stlport_root/stlport", root_build_dir) |
| + ] |
| lib_dirs += [ "$android_stlport_root/libs/$android_app_abi" ] |
| if (component_mode == "shared_library") { |
| @@ -353,6 +390,16 @@ config("runtime_library") { |
| libs += [ "stlport_static" ] |
| } |
| } |
| + |
| + libs += [ |
| + # Manually link the libgcc.a that the cross compiler uses. This is |
| + # absolute because the linker will look inside the sysroot if it's not. |
| + rebase_path(android_libgcc_file), |
| + "c", |
|
awong
2014/05/12 19:23:02
This seems incorrect to me. I think it's being cau
brettw
2014/05/12 21:00:08
GYP build does nostdlib and adds these libraries.
|
| + "dl", |
| + "m", |
| + ] |
| + |
| } |
| } |
| @@ -587,23 +634,60 @@ config("wexit_time_destructors") { |
| # configs -= default_optimization_config |
| # configs += [ "//build/config/compiler/optimize_max" ] |
| +# Shared settings for both "optimize" and "optimize_max" configs. |
| +if (is_win) { |
| + common_optimize_on_cflags = [ |
| + "/o2", |
| + "/ob2", # both explicit and auto inlining. |
| + "/oy-", # disable omitting frame pointers, must be after /o2. |
| + "/os", # favor size over speed. |
| + ] |
| + common_optimize_on_ldflags = [] |
| +} else { |
| + common_optimize_on_cflags = [ |
| + # Don't emit the GCC version ident directives, they just end up in the |
| + # .comment section taking up binary size. |
| + "-fno-ident", |
| + # Put data and code in their own sections, so that unused symbols |
| + # can be removed at link time with --gc-sections. |
| + "-fdata-sections", |
| + "-ffunction-sections", |
| + ] |
| + |
| + common_optimize_on_ldflags = [] |
| + if (is_mac) { |
| + if (symbol_level == 2) { |
| + # Mac dead code stripping requires symbols. |
| + common_optimize_on_ldflags += [ |
| + "-Wl,-dead_strip", |
| + ] |
| + } |
| + } else { |
| + # Non-Mac Posix linker flags. |
| + common_optimize_on_ldflags += [ |
| + # Specifically tell the linker to perform optimizations. |
| + # See http://lwn.net/Articles/192624/ . |
| + "-Wl,-O1", |
| + "-Wl,--as-needed", |
| + "-Wl,--gc-sections", |
| + ] |
| + } |
| + |
| + if (is_ios) { |
| + common_optimize_on_cflags += [ "-os" ] |
|
scottmg
2014/05/12 16:33:58
are these really lower case 'O's on iOS?
brettw
2014/05/12 18:06:41
Nope, I think an errant vi command lower-cased eve
awong
2014/05/12 19:23:02
Strange...does Android not compile -Os?
|
| + } else { |
| + common_optimize_on_cflags += [ "-o2" ] |
| + } |
| +} |
| + |
| # Default "optimization on" config. On Windows, this favors size over speed. |
| -# |
| -# IF YOU CHANGE THIS also consider whether optimize_max should be updated. |
| config("optimize") { |
| + cflags = common_optimize_on_cflags |
| + ldflags = common_optimize_on_ldflags |
| if (is_win) { |
| - cflags = [ |
| - "/O2", |
| - "/Ob2", # Both explicit and auto inlining. |
| - "/Oy-", # Disable omitting frame pointers, must be after /O2. |
| - "/Os", # Favor size over speed. |
| + cflags += [ |
| + "/os", # favor size over speed. |
|
scottmg
2014/05/12 16:33:58
/Os
|
| ] |
| - } else { |
| - if (is_ios) { |
| - cflags = [ "-Os" ] |
| - } else { |
| - cflags = [ "-O2" ] |
| - } |
| } |
| } |
| @@ -615,6 +699,20 @@ config("no_optimize") { |
| "/Ob0", # Disable all inlining (on by default). |
| "/RTC1", # Runtime checks for stack frame and uninitialized variables. |
| ] |
| + } else if (is_android && !android_full_debug) { |
| + # On Android we kind of optimize some things that don't affect debugging |
| + # much even when optimization is disabled to get the binary size down. |
| + cflags = [ |
| + "-O1", |
| + "-fomit-frame-pointer", |
| + "-fdata-sections", |
| + "-ffunction-sections", |
| + ] |
| + ldflags = [ |
| + "-Wl,-O1", |
|
awong
2014/05/12 19:23:02
This blob of linker flags is the same here as in 6
brettw
2014/05/12 21:00:08
I didn't do that because I didn't feel like this l
awong
2014/05/12 21:34:23
I think the fact that these 4 flags are used in co
brettw
2014/05/13 17:39:21
Will do this in a followup. I have green tries and
|
| + "-Wl,--as-needed", |
| + "-Wl,--gc-sections", |
| + ] |
| } else { |
| cflags = [ "-O0" ] |
| } |
| @@ -624,31 +722,18 @@ config("no_optimize") { |
| # optimization and link-time code generation which is very expensive and should |
| # be used sparingly. For non-Windows, this is the same as "optimize". |
| config("optimize_max") { |
| + cflags = common_optimize_on_cflags |
| + ldflags = common_optimize_on_ldflags |
| if (is_win) { |
| - cflags = [ |
| - "/O2", |
| - "/Ob2", # Both explicit and auto inlining. |
| - "/Oy-", # Disable omitting frame pointers, must be after /O2. |
| + cflags += [ |
| "/Ot", # Favor speed over size. |
| "/GL", # Whole program optimization. |
| ] |
| - } else { |
| - if (is_ios) { |
| - cflags = [ "-Os" ] |
| - } else { |
| - cflags = [ "-O2" ] |
| - } |
| } |
| } |
| # Symbols ---------------------------------------------------------------------- |
| -# TODO(brettw) Since this sets ldflags on Windows which is inherited across |
| -# static library boundaries, if you want to remove the default symbol config |
| -# and set a different one on a target, you also have to do it for all static |
| -# libraries that go into that target, which is messed up. Either we need a |
| -# more flexible system for defining linker flags, or we need to separate this |
| -# out into a "symbols_linker" config that is only applied to DLLs and EXEs. |
| config("symbols") { |
| if (is_win) { |
| cflags = [ "/Zi" ] # Produce PDB file, no edit and continue. |