Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / chrome / tools / build / win / syzygy / BUILD.gn
blob116318b9ab7dfa1473a9ebb3ef7438e1f8a023ec
1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import("//build/config/chrome_build.gni")
6 import("//build/config/compiler/compiler.gni")
7 import("//build/config/sanitizers/sanitizers.gni")
9 declare_args() {
10   # Generate Syzygy optimized binaries. Syzygy optimize mode is a profile
11   # guided optimization that reorders code for better locality.
12   syzygy_optimize =
13       is_win && is_official_build && !is_clang && symbol_level == 2
16 assert(!syzygy_optimize || !is_syzyasan,
17        "Don't do both syzygy_optimize and is_syzyasan")
19 # Where the output binaries will be placed.
20 syzygy_dest_dir = "$root_out_dir/syzygy"
22 if (syzygy_optimize) {
23   # Generates a Syzygy optimize target.
24   #
25   #   dll_name (required)
26   #     Name of the DLL to be instrumented, with no extension or path. This
27   #     ${dll_name}.dll is assumed to be in the output directory and must be
28   #     generated by a dependency of this target.
29   #
30   #   deps (required)
31   #     Normal meaning.
32   template("syzygy_optimize") {
33     action(target_name) {
34       if (defined(invoker.visibility)) {
35         visibility = invoker.visibility
36       }
37       script = "//chrome/tools/build/win/syzygy/reorder.py"
39       dll_name = invoker.dll_name
40       input_dll = "$root_out_dir/$dll_name.dll"
41       input_pdb = "$root_out_dir/$dll_name.dll.pdb"
43       inputs = [
44         input_dll,
45         #input_pdb,
46       ]
48       outputs = [
49         "$syzygy_dest_dir/$dll_name.dll",
50         "$syzygy_dest_dir/$dll_name.dll.pdb",
51       ]
53       args = [
54         "--input_executable",
55         rebase_path(input_dll, root_build_dir),
56         "--input_symbol",
57         rebase_path(input_pdb, root_build_dir),
58         "--destination_dir",
59         rebase_path(syzygy_dest_dir, root_build_dir),
60       ]
62       if (defined(invoker.deps)) {
63         deps = invoker.deps
64       }
65     }
66   }
68   syzygy_optimize("chrome_dll_syzygy") {
69     dll_name = "chrome"
70     deps = [
71       "//chrome:main_dll",
72     ]
73   }
74   if (is_multi_dll_chrome) {
75     # Also instrument chrome_child.dll.
76     syzygy_optimize("chrome_child_dll_syzygy") {
77       dll_name = "chrome_child"
78       deps = [
79         "//chrome:chrome_child",
80       ]
81     }
82   }
83 } else if (is_syzyasan) {
84   # Instruments a binary with SyzyAsan.
85   #
86   #   dll_name (required)
87   #     Name of the DLL to be instrumented, with no extension or path. This
88   #     ${dll_name}.dll is assumed to be in the output directory and must be
89   #     generated by a dependency of this target.
90   #
91   #   deps (required)
92   #     Normal meaning.
93   template("syzygy_asan") {
94     action(target_name) {
95       if (defined(invoker.visibility)) {
96         visibility = invoker.visibility
97       }
98       script = "//chrome/tools/build/win/syzygy/instrument.py"
100       filter = "syzyasan-instrumentation-filter.txt"
101       input_dll = "$root_out_dir/$dll_name.dll"
102       input_pdb = "$root_out_dir/$dll_name.dll.pdb"
104       inputs = [
105         filter,
106         input_dll,
108         #input_pdb,
109       ]
111       output_filter = "$syzygy_dest_dir/win-syzyasan-filter-$dll_name.txt.json"
113       outputs = [
114         "$syzygy_dest_dir/$dll_name.dll",
115         "$syzygy_dest_dir/$dll_name.dll.pdb",
116         output_filter,
117       ]
119       args = [
120         "--mode",
121         "asan",
122         "--input_executable",
123         rebase_path(input_dll, root_build_dir),
124         "--input_symbol",
125         rebase_path(input_pdb, root_build_dir),
126         "--filter",
127         rebase_path(filter, root_build_dir),
128         "--output-filter-file",
129         rebase_path(output_filter, root_build_dir),
130         "--destination_dir",
131         rebase_path(syzygy_dest_dir, root_build_dir),
132       ]
134       deps = [
135         "//chrome/tools/build/win/syzygy:copy_syzyasan_binaries",
136       ]
137       if (defined(invoker.deps)) {
138         deps += invoker.deps
139       }
140       if (defined(invoker.public_deps)) {
141         public_deps = invoker.public_deps
142       }
143     }
144   }
146   syzygy_asan("chrome_dll_syzygy") {
147     dll_name = "chrome"
148     deps = [
149       "//chrome:main_dll",
150     ]
151   }
153   if (is_multi_dll_chrome) {
154     # Also instrument chrome_child.dll.
155     #
156     # For official builds, the instrumented version will be put into an
157     # "instrumented" subdirectory and the regular output will be
158     # uninstrumented. Otherwise, chrome_child is also instrumented to the
159     # normal place.
160     syzygy_asan("chrome_child_dll_syzygy") {
161       dll_name = "chrome_child"
162       deps = [
163         "//chrome:chrome_child",
164       ]
166       if (is_official_build) {
167         dest_dir = "$syzygy_dest_dir/instrumented"
168         deps += [ ":chrome_child_dll_syzygy_copy" ]
169       } else {
170         dest_dir = syzygy_dest_dir
171       }
172     }
174     if (is_official_build) {
175       # Copies the uninstrumented chrome_child.dll.
176       # GYP version: chrome/chrome_syzygy.gyp:chrome_child_dll_syzygy_copy
177       copy("chrome_child_dll_syzygy_copy") {
178         sources = [
179           "$root_out_dir/chrome_child.dll",
180           "$root_out_dir/chrome_child.dll.pdb",
181         ]
182         outputs = [
183           "$syzygy_dest_dir/{{source_file_part}}",
184         ]
185         deps = [
186           "//chrome:chrome_child",
187         ]
188       }
189     }
190   }
191 } else {
192   # No syzygy. Generate dummy targets so other targets can unconditionally
193   # depend on these without having to duplicate our conditions.
194   group("chrome_dll_syzygy") {
195   }
196   if (is_multi_dll_chrome) {
197     group("chrome_child_dll_syzygy") {
198     }
199   }
202 if (is_syzyasan || syzygy_optimize) {
203   copy("copy_syzyasan_binaries") {
204     visibility = [ "//chrome/*" ]
206     source_dir = "//third_party/syzygy/binaries/exe"
208     sources = [
209       "$source_dir/agent_logger.exe",
210       "$source_dir/minidump_symbolizer.py",
211       "$source_dir/syzyasan_rtl.dll",
212       "$source_dir/syzyasan_rtl.dll.pdb",
213     ]
215     outputs = [
216       "$syzygy_dest_dir/{{source_file_part}}",
217     ]
218   }
221 # Prevent unused variable warning for code paths where this is unused.
222 assert(syzygy_dest_dir != "")