Compile Chromium with custom -march, optimizations

651 views
Skip to first unread message

GabeA

unread,
Aug 28, 2016, 10:07:43 PM8/28/16
to Chromium-dev
Hello all,

This may be a common question, but I was unable to turn up anything modern with a simple search. 

I want to specify explicitly the architecture of my processor in a -march flag (-march=knl) and an optimization flag (-Ofast), and enable LTO + profiling. From what I've researched thus far:

- To set CFLAGS, modify "cflags" GN variable 
- To modify a GN variable, have to edit a BUILD.gn
- To add to cflags, have to trace what happens from root BUILD.gn
- Root BUILD.gn invokes /build/config/compiler/BUILD.gn
- compiler's BUILD.gn contains recipes for "optimize_max" which looks like a good place to start tweaking
- compiler BUILD.gn states: # You can override the optimization level on a per-target basis by removing the
# default config and then adding the named one you want:
#
#   configs -= [ "//build/config/compiler:default_optimization" ]
#   configs += [ "//build/config/compiler:optimize_max" ]
- I try to uncomment the lines: error. I realize "configs" is not in this scope. 
- Each config block is an object that must have a target (apparently can be an "executable" according to the example in the docs) -- no mention which executable is global/controlling/the one to set for a chromium build
- Docs say I can also specify config via commandline -- no mention what commandline (I only see "gn args out/Default") or how to add "configs -= [ "//build/config/compiler:default_optimization" ]" to such commandline
- Finally stumped after this wild goose chase -- I can't figure out what to do to add these simple CFLAGS. 

If Chromium already has a way to do profiled optimization (I see there's some stuff in the optimization configs for bootstrapping and LTO), it's not clear how to apply it instead of manually appending the CFLAGS. Apparently nobody is compiling Chromium with anything but the default settings on standard machines nowadays because it's an information wasteland out there -- or I'm just a bad scourer. 

Thanks for any help,
Gabe

Dirk Pranke

unread,
Aug 29, 2016, 1:17:16 PM8/29/16
to algh...@umn.edu, Chromium-dev
Hi Gabe,

You may have luck getting some of these questions answered on the chromium-packagers@ list as well, but I'll try to answer things here.

In general, we've recently switched from the GYP meta-build system to the GN meta-build system, and we're still working on the best
ways to allow for configuration tweaking like what you want to do, so you'll definitely be hitting rough patches.

In general, you can't just set CFLAGS= in the environment, as I'm sure you've discovered. That doesn't actually work at all at the moment,
and even if it did, it would be tricky to make it work correctly. There is a long discussion of some of the issues that arise in crbug.com/595653 ,
and I've filed crbug.com/642016 to track the need for further improvements.

On Sun, Aug 28, 2016 at 7:07 PM, GabeA <algh...@umn.edu> wrote:
Hello all,

This may be a common question, but I was unable to turn up anything modern with a simple search. 

I want to specify explicitly the architecture of my processor in a -march flag (-march=knl) and an optimization flag (-Ofast), and enable LTO + profiling. From what I've researched thus far:

- To set CFLAGS, modify "cflags" GN variable 
- To modify a GN variable, have to edit a BUILD.gn
- To add to cflags, have to trace what happens from root BUILD.gn
- Root BUILD.gn invokes /build/config/compiler/BUILD.gn
- compiler's BUILD.gn contains recipes for "optimize_max" which looks like a good place to start tweaking

Yup, this is all more-or-less correct.
 
- compiler BUILD.gn states: # You can override the optimization level on a per-target basis by removing the
# default config and then adding the named one you want:
#
#   configs -= [ "//build/config/compiler:default_optimization" ]
#   configs += [ "//build/config/compiler:optimize_max" ]
- I try to uncomment the lines: error. I realize "configs" is not in this scope. 
- Each config block is an object that must have a target (apparently can be an "executable" according to the example in the docs) -- no mention which executable is global/controlling/the one to set for a chromium build

Right, that's not how you add or change configs globally, that example is how you control the flags for a given target.
 
- Docs say I can also specify config via commandline -- no mention what commandline (I only see "gn args out/Default") or how to add "configs -= [ "//build/config/compiler:default_optimization" ]" to such commandline

I'm not sure what documentation you're referring to here? 
 
- Finally stumped after this wild goose chase -- I can't figure out what to do to add these simple CFLAGS. 

You can't currently change the -march values via a command line setting, but if you were to modify the build files directly, you'd add the flag here-ish:


To set -Ofast, you'd probably modify some combination of:


depending on which targets you wanted to optimize (only some of them that were really speed-sensitive, or all of them). 

The way we control optimization settings is currently awkward and I plan to rework it; see crbug.com/621335.
 

If Chromium already has a way to do profiled optimization (I see there's some stuff in the optimization configs for bootstrapping and LTO), it's not clear how to apply it instead of manually appending the CFLAGS.

We do build on linux w/ LTO, but we don't do any sort of profile-guided optimization yet. We do do that on Windows, but that's probably not helpful. CrOS does some static profile-based optimization (using AFDO) using a bunch of extra hooks that we have for them (see some of the stuff in //build/toolchain/cros/BUILD.gn), but that's not easily reused.

Hope that's at least a start,

-- Dirk
 
Apparently nobody is compiling Chromium with anything but the default settings on standard machines nowadays because it's an information wasteland out there -- or I'm just a bad scourer. 

Thanks for any help,
Gabe

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

Reply all
Reply to author
Forward
0 new messages