Skip to content

Compiling Chrome using flto

Mohamad Barbar edited this page Jun 17, 2018 · 21 revisions

0 Install gold_plugin

Follow this guide

1 Install depot_tools

$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
$ export PATH="$PATH:/path/to/depot_tools"

2 Get the source code of Chrome

$ mkdir ~/chromium
$ cd ~/chromium
$ fetch --nohooks chromium
$ cd src

3 Install additional build dependencies

$ build/install-build-deps.sh

4 Run the hooks

$ gclient runhooks

5 Setting up the build (use gn)

5.1 Comment a few compiler options in config files to use local clang-7.0.0

In build/config/compiler/BUILD.gn, comment the following:

"-Wno-ignored-pragma-optimize",
cflags += [ "-fcolor-diagnostics" ]

In build/config/posix/BUILD.gn, comment the following:

ldflags += [ "-nostdlib++" ]

5.2 Create a build directory

$ gn args out/Default

This will bring up an editor (vi/vim). Enter the following options:

is_debug = false
is_component_build = true
symbol_level = 0
enable_nacl = false
clang_base_path = "PATH_TO_LLVM_BUILD"
clang_use_chrome_plugins = false
clang_version = "7.0.0"

Then save and quit the editor (:wq). "Default" can be replaced by any other name.

5.3 Add lto option (Optional)

Edit file out/Default/toolchain.ninja with the following changes to add options for "lto":

"${cflags}" ==> "-flto ${cflags}"
"${ldflags}" ==> "-flto ${ldflags}"

5.4 Change arguments to llvm-ar

Edit file out/Default/toolchain.ninja with the follow change:

"${arflags} -r -c -s -D" ==> "rcsT"

5.5 Set gold as the linker

Edit file build/config/compiler/BUILD.gn with the following changes:

"ldflags += [ "-fuse-ld=lld" ]" ==> "ldflags += [ "-fuse-ld=gold" ]"
"gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin", root_build_dir)"
   ==> "gold_path = "/usr/bin/ld""

Edit file build/config/compiler/compiler.gni with the following changes:

"use_lld = -long boolean expression-" ==> "use_lld = false"
"use_gold = -long boolean expression-" ==> "use_gold = true"

6 Build Chromium

Change to corresponding ninja version in the first line of out/Default/build.ninja, e.g., ninja_required_version = 1.5.1

Finally, run:

$ ninja -j 8 -C out/Default chrome

Browser benchmarks

dromaeo http://dromaeo.com/

jetstream http://browserbench.org/JetStream/

kraken http://krakenbenchmark.mozilla.org/

litebrite https://testdrive-archive.azurewebsites.net/Performance/LiteBrite/

octane https://developers.google.com/octane/

peacekeeper http://peacekeeper.futuremark.com/

sunspider https://webkit.org/perf/sunspider/sunspider.html

wirple-bmark https://www.wirple.com/bmark/

Clone this wiki locally