From 71a43cab53042f33d77fe8eebe8c2463a92f9758 Mon Sep 17 00:00:00 2001 From: sebmarchand Date: Fri, 8 Jul 2016 15:03:35 -0700 Subject: [PATCH] Move the Syzygy scripts out of //chrome/ Also move the syzygy_optimize and syzygy_asan GN templates to //build/win/syzygy so they can be reused in //content (without adding a dependency with //chrome). BUG=619086 Review-Url: https://codereview.chromium.org/2126673002 Cr-Commit-Position: refs/heads/master@{#404503} --- BUILD.gn | 3 - build/win/syzygy/BUILD.gn | 23 +++ build/win/syzygy/OWNERS | 3 + .../build => build}/win/syzygy/instrument.py | 2 +- .../build => build}/win/syzygy/reorder.py | 2 +- .../win/syzygy/syzyasan-allocation-filter.txt | 0 .../syzyasan-instrumentation-filter.txt | 0 build/win/syzygy/syzygy.gni | 137 +++++++++++++++ chrome/installer/mini_installer/BUILD.gn | 2 +- chrome/tools/build/win/syzygy/BUILD.gn | 164 +----------------- third_party/kasko/BUILD.gn | 7 +- 11 files changed, 180 insertions(+), 163 deletions(-) create mode 100644 build/win/syzygy/BUILD.gn create mode 100644 build/win/syzygy/OWNERS rename {chrome/tools/build => build}/win/syzygy/instrument.py (99%) rename {chrome/tools/build => build}/win/syzygy/reorder.py (98%) rename {chrome/tools/build => build}/win/syzygy/syzyasan-allocation-filter.txt (100%) rename {chrome/tools/build => build}/win/syzygy/syzyasan-instrumentation-filter.txt (100%) create mode 100644 build/win/syzygy/syzygy.gni diff --git a/BUILD.gn b/BUILD.gn index 38e5b95047f8ff..ed2dcdd2642666 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -988,9 +988,6 @@ if (!is_ios && !is_android && !is_chromecast) { # TODO(GYP): Add this once it exists, https://crbug.com/619086 # "//content/shell:content_shell_syzyasan ] - if (is_multi_dll_chrome) { - deps += [ "//chrome/tools/build/win/syzygy:chrome_child_dll_syzygy" ] - } } } } diff --git a/build/win/syzygy/BUILD.gn b/build/win/syzygy/BUILD.gn new file mode 100644 index 00000000000000..1d26b5a6e7c188 --- /dev/null +++ b/build/win/syzygy/BUILD.gn @@ -0,0 +1,23 @@ +# Copyright 2016 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +copy("copy_syzyasan_binaries") { + visibility = [ + "//chrome/*", + "//content/*", + ] + + source_dir = "//third_party/syzygy/binaries/exe" + + sources = [ + "$source_dir/agent_logger.exe", + "$source_dir/minidump_symbolizer.py", + "$source_dir/syzyasan_rtl.dll", + "$source_dir/syzyasan_rtl.dll.pdb", + ] + + outputs = [ + "$root_out_dir/syzygy/{{source_file_part}}", + ] +} diff --git a/build/win/syzygy/OWNERS b/build/win/syzygy/OWNERS new file mode 100644 index 00000000000000..eb5a1c7c7efa10 --- /dev/null +++ b/build/win/syzygy/OWNERS @@ -0,0 +1,3 @@ +chrisha@chromium.org +sebmarchand@chromiun.org +siggi@chromium.org diff --git a/chrome/tools/build/win/syzygy/instrument.py b/build/win/syzygy/instrument.py similarity index 99% rename from chrome/tools/build/win/syzygy/instrument.py rename to build/win/syzygy/instrument.py index 5e98abf6af4eae..e103facf0dd6c5 100755 --- a/chrome/tools/build/win/syzygy/instrument.py +++ b/build/win/syzygy/instrument.py @@ -16,7 +16,7 @@ # The default directory containing the Syzygy toolchain. _DEFAULT_SYZYGY_DIR = os.path.abspath(os.path.join( - os.path.dirname(__file__), '../../../../..', + os.path.dirname(__file__), '../../..', 'third_party/syzygy/binaries/exe/')) # Basenames of various tools. diff --git a/chrome/tools/build/win/syzygy/reorder.py b/build/win/syzygy/reorder.py similarity index 98% rename from chrome/tools/build/win/syzygy/reorder.py rename to build/win/syzygy/reorder.py index 8cdd6d7ce6e572..ba62cc770626b3 100755 --- a/chrome/tools/build/win/syzygy/reorder.py +++ b/build/win/syzygy/reorder.py @@ -14,7 +14,7 @@ # The default relink executable to use to reorder binaries. _DEFAULT_RELINKER = os.path.join( - os.path.join(os.path.dirname(__file__), '../../../../..'), + os.path.join(os.path.dirname(__file__), '../../..'), 'third_party/syzygy/binaries/exe/relink.exe') _LOGGER = logging.getLogger() diff --git a/chrome/tools/build/win/syzygy/syzyasan-allocation-filter.txt b/build/win/syzygy/syzyasan-allocation-filter.txt similarity index 100% rename from chrome/tools/build/win/syzygy/syzyasan-allocation-filter.txt rename to build/win/syzygy/syzyasan-allocation-filter.txt diff --git a/chrome/tools/build/win/syzygy/syzyasan-instrumentation-filter.txt b/build/win/syzygy/syzyasan-instrumentation-filter.txt similarity index 100% rename from chrome/tools/build/win/syzygy/syzyasan-instrumentation-filter.txt rename to build/win/syzygy/syzyasan-instrumentation-filter.txt diff --git a/build/win/syzygy/syzygy.gni b/build/win/syzygy/syzygy.gni new file mode 100644 index 00000000000000..1ae2ebef828b47 --- /dev/null +++ b/build/win/syzygy/syzygy.gni @@ -0,0 +1,137 @@ +# Copyright 2016 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +assert(is_win) + +# Where the output binaries will be placed. +syzygy_dest_dir = "$root_out_dir/syzygy" + +# Generates a Syzygy optimize target. +# +# binary_name (required) +# Name of the binary to be instrumented, with no extension or path. This +# binary_name is assumed to be in the output directory and must be +# generated by a dependency of this target. +# +# deps (required) +# Normal meaning. +# +# data_deps +# Normal meaning. +template("syzygy_optimize") { + action(target_name) { + if (defined(invoker.visibility)) { + visibility = invoker.visibility + } + script = "//build/win/syzygy/reorder.py" + + binary_name = invoker.binary_name + input_dll = "$root_out_dir/$binary_name" + input_pdb = "$root_out_dir/$binary_name.pdb" + + inputs = [ + input_dll, + #input_pdb, + ] + + outputs = [ + "$syzygy_dest_dir/$binary_name", + "$syzygy_dest_dir/$binary_name.pdb", + ] + + args = [ + "--input_executable", + rebase_path(input_dll, root_build_dir), + "--input_symbol", + rebase_path(input_pdb, root_build_dir), + "--destination_dir", + rebase_path(syzygy_dest_dir, root_build_dir), + ] + + forward_variables_from(invoker, + [ + "deps", + "data_deps", + "public_deps", + ]) + } +} + +# Instruments a binary with SyzyAsan. +# +# binary_name (required) +# Name of the binary to be instrumented, with no extension or path. This +# binary_name is assumed to be in the output directory and must be +# generated by a dependency of this target. +# +# dest_dir (required) +# The destination directory where the instrumented image should be +# written. +# +# deps (required) +# Normal meaning. +# +# public_deps +# Normal meaning. +# +# data_deps +# Normal meaning. +template("syzygy_asan") { + action(target_name) { + if (defined(invoker.visibility)) { + visibility = invoker.visibility + } + script = "//build/win/syzygy/instrument.py" + + filter = "//build/win/syzygy/syzyasan-instrumentation-filter.txt" + + binary_name = invoker.binary_name + dest_dir = invoker.dest_dir + input_image = "$root_out_dir/$binary_name" + input_pdb = "$root_out_dir/$binary_name.pdb" + + inputs = [ + filter, + input_image, + + #input_pdb, + ] + + output_filter = "$dest_dir/win-syzyasan-filter-$binary_name.txt.json" + + outputs = [ + "$dest_dir/$binary_name", + "$dest_dir/$binary_name.pdb", + output_filter, + ] + + args = [ + "--mode", + "asan", + "--input_executable", + rebase_path(input_image, root_build_dir), + "--input_symbol", + rebase_path(input_pdb, root_build_dir), + "--filter", + rebase_path(filter, root_build_dir), + "--output-filter-file", + rebase_path(output_filter, root_build_dir), + "--destination_dir", + rebase_path(dest_dir, root_build_dir), + ] + + deps = [ + "//build/win/syzygy:copy_syzyasan_binaries", + ] + if (defined(invoker.deps)) { + deps += invoker.deps + } + forward_variables_from(invoker, + [ + "data_deps", + "public_deps", + "testonly", + ]) + } +} diff --git a/chrome/installer/mini_installer/BUILD.gn b/chrome/installer/mini_installer/BUILD.gn index 699f56f537d7da..842a0b539810ed 100644 --- a/chrome/installer/mini_installer/BUILD.gn +++ b/chrome/installer/mini_installer/BUILD.gn @@ -262,7 +262,7 @@ generate_mini_installer("mini_installer") { chrome_dll_target = "//chrome:main_dll" } -if (syzygy_optimize) { +if (syzygy_optimize || is_syzyasan) { generate_mini_installer("mini_installer_syzygy") { out_dir = "$root_out_dir/syzygy/" chrome_dll_file = "$root_out_dir/syzygy/chrome.dll" diff --git a/chrome/tools/build/win/syzygy/BUILD.gn b/chrome/tools/build/win/syzygy/BUILD.gn index 822a645f3e4886..0d065470b83e56 100644 --- a/chrome/tools/build/win/syzygy/BUILD.gn +++ b/chrome/tools/build/win/syzygy/BUILD.gn @@ -5,6 +5,7 @@ import("//build/config/chrome_build.gni") import("//build/config/compiler/compiler.gni") import("//build/config/sanitizers/sanitizers.gni") +import("//build/win/syzygy/syzygy.gni") assert(!syzygy_optimize || !is_syzyasan, "Don't do both syzygy_optimize and is_syzyasan") @@ -13,59 +14,8 @@ assert(!syzygy_optimize || !is_syzyasan, syzygy_dest_dir = "$root_out_dir/syzygy" if (syzygy_optimize) { - # Generates a Syzygy optimize target. - # - # dll_name (required) - # Name of the DLL to be instrumented, with no extension or path. This - # ${dll_name}.dll is assumed to be in the output directory and must be - # generated by a dependency of this target. - # - # deps (required) - # Normal meaning. - # - # data_deps - # Normal meaning. - template("syzygy_optimize") { - action(target_name) { - if (defined(invoker.visibility)) { - visibility = invoker.visibility - } - script = "//chrome/tools/build/win/syzygy/reorder.py" - - dll_name = invoker.dll_name - input_dll = "$root_out_dir/$dll_name.dll" - input_pdb = "$root_out_dir/$dll_name.dll.pdb" - - inputs = [ - input_dll, - #input_pdb, - ] - - outputs = [ - "$syzygy_dest_dir/$dll_name.dll", - "$syzygy_dest_dir/$dll_name.dll.pdb", - ] - - args = [ - "--input_executable", - rebase_path(input_dll, root_build_dir), - "--input_symbol", - rebase_path(input_pdb, root_build_dir), - "--destination_dir", - rebase_path(syzygy_dest_dir, root_build_dir), - ] - - forward_variables_from(invoker, - [ - "deps", - "data_deps", - "public_deps", - ]) - } - } - syzygy_optimize("chrome_dll_syzygy") { - dll_name = "chrome" + binary_name = "chrome.dll" deps = [ "//chrome:main_dll", ] @@ -78,96 +28,24 @@ if (syzygy_optimize) { if (is_multi_dll_chrome) { # Also instrument chrome_child.dll. syzygy_optimize("chrome_child_dll_syzygy") { - dll_name = "chrome_child" + binary_name = "chrome_child.dll" deps = [ "//chrome:chrome_child", ] } } } else if (is_syzyasan) { - # Instruments a binary with SyzyAsan. - # - # binary_name (required) - # Name of the binary to be instrumented, with no extension or path. This - # binary_name is assumed to be in the output directory and must be - # generated by a dependency of this target. - # - # dest_dir (required) - # The destination directory where the instrumented image should be - # written. - # - # deps (required) - # Normal meaning. - # - # public_deps - # Normal meaning. - # - # data_deps - # Normal meaning. - template("syzygy_asan") { - action(target_name) { - if (defined(invoker.visibility)) { - visibility = invoker.visibility - } - script = "//chrome/tools/build/win/syzygy/instrument.py" - - filter = "syzyasan-instrumentation-filter.txt" - - binary_name = invoker.binary_name - dest_dir = invoker.dest_dir - input_image = "$root_out_dir/$binary_name" - input_pdb = "$root_out_dir/$binary_name.pdb" - - inputs = [ - filter, - input_image, - - #input_pdb, - ] - - output_filter = "$dest_dir/win-syzyasan-filter-$binary_name.txt.json" - - outputs = [ - "$dest_dir/$input_image", - "$dest_dir/$input_image.pdb", - output_filter, - ] - - args = [ - "--mode", - "asan", - "--input_executable", - rebase_path(input_image, root_build_dir), - "--input_symbol", - rebase_path(input_pdb, root_build_dir), - "--filter", - rebase_path(filter, root_build_dir), - "--output-filter-file", - rebase_path(output_filter, root_build_dir), - "--destination_dir", - rebase_path(dest_dir, root_build_dir), - ] - - deps = [ - "//chrome/tools/build/win/syzygy:copy_syzyasan_binaries", - ] - if (defined(invoker.deps)) { - deps += invoker.deps - } - forward_variables_from(invoker, - [ - "data_deps", - "public_deps", - ]) - } - } - syzygy_asan("chrome_dll_syzygy") { binary_name = "chrome.dll" dest_dir = syzygy_dest_dir deps = [ "//chrome:main_dll", ] + if (is_multi_dll_chrome) { + data_deps = [ + ":chrome_child_dll_syzygy", + ] + } } if (is_multi_dll_chrome) { @@ -189,10 +67,6 @@ if (syzygy_optimize) { } else { dest_dir = syzygy_dest_dir } - - data_deps = [ - ":chrome_child_dll_syzygy", - ] } if (is_official_build) { @@ -201,10 +75,9 @@ if (syzygy_optimize) { copy("chrome_child_dll_syzygy_copy") { sources = [ "$root_out_dir/chrome_child.dll", - "$root_out_dir/chrome_child.dll.pdb", ] outputs = [ - "$dest_dir/{{source_file_part}}", + "$syzygy_dest_dir/{{source_file_part}}", ] deps = [ "//chrome:chrome_child", @@ -223,24 +96,5 @@ if (syzygy_optimize) { } } -if (is_syzyasan || syzygy_optimize) { - copy("copy_syzyasan_binaries") { - visibility = [ "//chrome/*" ] - - source_dir = "//third_party/syzygy/binaries/exe" - - sources = [ - "$source_dir/agent_logger.exe", - "$source_dir/minidump_symbolizer.py", - "$source_dir/syzyasan_rtl.dll", - "$source_dir/syzyasan_rtl.dll.pdb", - ] - - outputs = [ - "$syzygy_dest_dir/{{source_file_part}}", - ] - } -} - # Prevent unused variable warning for code paths where this is unused. assert(syzygy_dest_dir != "") diff --git a/third_party/kasko/BUILD.gn b/third_party/kasko/BUILD.gn index 3db51a1b255bd0..49a837d10a21c5 100644 --- a/third_party/kasko/BUILD.gn +++ b/third_party/kasko/BUILD.gn @@ -15,8 +15,11 @@ buildflag_header("kasko_features") { if (enable_kasko) { assert(is_win, "Kasko only support Windows.") assert(target_cpu == "x86", "Kasko only support 32 bits.") - assert(is_chrome_branded, - "The Kasko client is only initialized in Chrome-branded builds.") + + # TODO(sebmarchand): Fix this once the Kasko dependency in SyzyAsan has been + # removed for the non-official builds. + #assert(is_chrome_branded, + # "The Kasko client is only initialized in Chrome-branded builds.") config("kasko_config") { visibility = [ ":*" ]