OLD | NEW |
1 -- Copyright 2011 the V8 project authors. All rights reserved. | 1 -- Copyright 2011 the V8 project authors. All rights reserved. |
2 -- Redistribution and use in source and binary forms, with or without | 2 -- Redistribution and use in source and binary forms, with or without |
3 -- modification, are permitted provided that the following conditions are | 3 -- modification, are permitted provided that the following conditions are |
4 -- met: | 4 -- met: |
5 -- | 5 -- |
6 -- * Redistributions of source code must retain the above copyright | 6 -- * Redistributions of source code must retain the above copyright |
7 -- notice, this list of conditions and the following disclaimer. | 7 -- notice, this list of conditions and the following disclaimer. |
8 -- * Redistributions in binary form must reproduce the above | 8 -- * Redistributions in binary form must reproduce the above |
9 -- copyright notice, this list of conditions and the following | 9 -- copyright notice, this list of conditions and the following |
10 -- disclaimer in the documentation and/or other materials provided | 10 -- disclaimer in the documentation and/or other materials provided |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 -- This is main driver for gcmole tool. See README for more details. | 28 -- This is main driver for gcmole tool. See README for more details. |
29 -- Usage: CLANG_BIN=clang-bin-dir lua tools/gcmole/gcmole.lua [arm|ia32|x64] | 29 -- Usage: CLANG_BIN=clang-bin-dir lua tools/gcmole/gcmole.lua [arm|ia32|x64] |
30 | 30 |
31 local DIR = arg[0]:match("^(.+)/[^/]+$") | 31 local DIR = arg[0]:match("^(.+)/[^/]+$") |
32 | 32 |
33 local FLAGS = { | 33 local FLAGS = { |
34 -- Do not build gcsuspects file and reuse previously generated one. | 34 -- Do not build gcsuspects file and reuse previously generated one. |
35 reuse_gcsuspects = false; | 35 reuse_gcsuspects = false; |
36 | 36 |
| 37 -- Don't use parallel python runner. |
| 38 sequential = false; |
| 39 |
37 -- Print commands to console before executing them. | 40 -- Print commands to console before executing them. |
38 verbose = false; | 41 verbose = false; |
39 | 42 |
40 -- Perform dead variable analysis (generates many false positives). | 43 -- Perform dead variable analysis (generates many false positives). |
41 -- TODO add some sort of whiteliste to filter out false positives. | 44 -- TODO add some sort of whiteliste to filter out false positives. |
42 dead_vars = false; | 45 dead_vars = false; |
43 | 46 |
44 -- When building gcsuspects whitelist certain functions as if they | 47 -- When building gcsuspects whitelist certain functions as if they |
45 -- can be causing GC. Currently used to reduce number of false | 48 -- can be causing GC. Currently used to reduce number of false |
46 -- positives in dead variables analysis. See TODO for WHITELIST | 49 -- positives in dead variables analysis. See TODO for WHITELIST |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 local CLANG_PLUGINS = os.getenv "CLANG_PLUGINS" | 86 local CLANG_PLUGINS = os.getenv "CLANG_PLUGINS" |
84 | 87 |
85 if not CLANG_BIN or CLANG_BIN == "" then | 88 if not CLANG_BIN or CLANG_BIN == "" then |
86 error "CLANG_BIN not set" | 89 error "CLANG_BIN not set" |
87 end | 90 end |
88 | 91 |
89 if not CLANG_PLUGINS or CLANG_PLUGINS == "" then | 92 if not CLANG_PLUGINS or CLANG_PLUGINS == "" then |
90 CLANG_PLUGINS = DIR | 93 CLANG_PLUGINS = DIR |
91 end | 94 end |
92 | 95 |
93 local function MakeClangCommandLine(plugin, plugin_args, triple, arch_define) | 96 local function MakeClangCommandLine( |
| 97 plugin, plugin_args, triple, arch_define, arch_options) |
94 if plugin_args then | 98 if plugin_args then |
95 for i = 1, #plugin_args do | 99 for i = 1, #plugin_args do |
96 plugin_args[i] = "-Xclang -plugin-arg-" .. plugin | 100 plugin_args[i] = "-Xclang -plugin-arg-" .. plugin |
97 .. " -Xclang " .. plugin_args[i] | 101 .. " -Xclang " .. plugin_args[i] |
98 end | 102 end |
99 plugin_args = " " .. table.concat(plugin_args, " ") | 103 plugin_args = " " .. table.concat(plugin_args, " ") |
100 end | 104 end |
101 return CLANG_BIN .. "/clang++ -std=c++11 -c " | 105 return CLANG_BIN .. "/clang++ -std=c++11 -c " |
102 .. " -Xclang -load -Xclang " .. CLANG_PLUGINS .. "/libgcmole.so" | 106 .. " -Xclang -load -Xclang " .. CLANG_PLUGINS .. "/libgcmole.so" |
103 .. " -Xclang -plugin -Xclang " .. plugin | 107 .. " -Xclang -plugin -Xclang " .. plugin |
104 .. (plugin_args or "") | 108 .. (plugin_args or "") |
105 .. " -Xclang -triple -Xclang " .. triple | 109 .. " -Xclang -triple -Xclang " .. triple |
106 .. " -D" .. arch_define | 110 .. " -D" .. arch_define |
107 .. " -DENABLE_DEBUGGER_SUPPORT" | 111 .. " -DENABLE_DEBUGGER_SUPPORT" |
108 .. " -DV8_I18N_SUPPORT" | 112 .. " -DV8_I18N_SUPPORT" |
109 .. " -I./" | 113 .. " -I./" |
110 .. " -Ithird_party/icu/source/common" | 114 .. " -Ithird_party/icu/source/common" |
111 .. " -Ithird_party/icu/source/i18n" | 115 .. " -Ithird_party/icu/source/i18n" |
| 116 .. " " .. arch_options |
| 117 end |
| 118 |
| 119 local function IterTable(t) |
| 120 return coroutine.wrap(function () |
| 121 for i, v in ipairs(t) do |
| 122 coroutine.yield(v) |
| 123 end |
| 124 end) |
| 125 end |
| 126 |
| 127 local function SplitResults(lines, func) |
| 128 -- Splits the output of parallel.py and calls func on each result. |
| 129 -- Bails out in case of an error in one of the executions. |
| 130 local current = {} |
| 131 local filename = "" |
| 132 for line in lines do |
| 133 local new_file = line:match "^______________ (.*)$" |
| 134 local code = line:match "^______________ finish (%d+) ______________$" |
| 135 if code then |
| 136 if tonumber(code) > 0 then |
| 137 log(table.concat(current, "\n")) |
| 138 log("Failed to examine " .. filename) |
| 139 return false |
| 140 end |
| 141 log("-- %s", filename) |
| 142 func(filename, IterTable(current)) |
| 143 elseif new_file then |
| 144 filename = new_file |
| 145 current = {} |
| 146 else |
| 147 table.insert(current, line) |
| 148 end |
| 149 end |
| 150 return true |
112 end | 151 end |
113 | 152 |
114 function InvokeClangPluginForEachFile(filenames, cfg, func) | 153 function InvokeClangPluginForEachFile(filenames, cfg, func) |
115 local cmd_line = MakeClangCommandLine(cfg.plugin, | 154 local cmd_line = MakeClangCommandLine(cfg.plugin, |
116 cfg.plugin_args, | 155 cfg.plugin_args, |
117 cfg.triple, | 156 cfg.triple, |
118 cfg.arch_define) | 157 cfg.arch_define, |
119 for _, filename in ipairs(filenames) do | 158 cfg.arch_options) |
120 log("-- %s", filename) | 159 if FLAGS.sequential then |
121 local action = cmd_line .. " " .. filename .. " 2>&1" | 160 log("** Sequential execution.") |
| 161 for _, filename in ipairs(filenames) do |
| 162 log("-- %s", filename) |
| 163 local action = cmd_line .. " " .. filename .. " 2>&1" |
| 164 if FLAGS.verbose then print('popen ', action) end |
| 165 local pipe = io.popen(action) |
| 166 func(filename, pipe:lines()) |
| 167 local success = pipe:close() |
| 168 if not success then error("Failed to run: " .. action) end |
| 169 end |
| 170 else |
| 171 log("** Parallel execution.") |
| 172 local action = "python tools/gcmole/parallel.py \"" |
| 173 .. cmd_line .. "\" " .. table.concat(filenames, " ") |
122 if FLAGS.verbose then print('popen ', action) end | 174 if FLAGS.verbose then print('popen ', action) end |
123 local pipe = io.popen(action) | 175 local pipe = io.popen(action) |
124 func(filename, pipe:lines()) | 176 local success = SplitResults(pipe:lines(), func) |
125 local success = pipe:close() | 177 local closed = pipe:close() |
126 if not success then error("Failed to run: " .. action) end | 178 if not (success and closed) then error("Failed to run: " .. action) end |
127 end | 179 end |
128 end | 180 end |
129 | 181 |
130 ------------------------------------------------------------------------------- | 182 ------------------------------------------------------------------------------- |
131 -- GYP file parsing | 183 -- GYP file parsing |
132 | 184 |
133 local function ParseGYPFile() | 185 local function ParseGYPFile() |
134 local gyp = "" | 186 local gyp = "" |
135 local gyp_files = { "tools/gyp/v8.gyp", "test/cctest/cctest.gyp" } | 187 local gyp_files = { "tools/gyp/v8.gyp", "test/cctest/cctest.gyp" } |
136 for i = 1, #gyp_files do | 188 for i = 1, #gyp_files do |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 246 |
195 function mtConfig:extend(t) | 247 function mtConfig:extend(t) |
196 local e = {} | 248 local e = {} |
197 for k, v in pairs(self) do e[k] = v end | 249 for k, v in pairs(self) do e[k] = v end |
198 for k, v in pairs(t) do e[k] = v end | 250 for k, v in pairs(t) do e[k] = v end |
199 return config(e) | 251 return config(e) |
200 end | 252 end |
201 | 253 |
202 local ARCHITECTURES = { | 254 local ARCHITECTURES = { |
203 ia32 = config { triple = "i586-unknown-linux", | 255 ia32 = config { triple = "i586-unknown-linux", |
204 arch_define = "V8_TARGET_ARCH_IA32" }, | 256 arch_define = "V8_TARGET_ARCH_IA32", |
| 257 arch_options = "-m32" }, |
205 arm = config { triple = "i586-unknown-linux", | 258 arm = config { triple = "i586-unknown-linux", |
206 arch_define = "V8_TARGET_ARCH_ARM" }, | 259 arch_define = "V8_TARGET_ARCH_ARM", |
| 260 arch_options = "-m32" }, |
207 x64 = config { triple = "x86_64-unknown-linux", | 261 x64 = config { triple = "x86_64-unknown-linux", |
208 arch_define = "V8_TARGET_ARCH_X64" }, | 262 arch_define = "V8_TARGET_ARCH_X64", |
| 263 arch_options = "" }, |
209 arm64 = config { triple = "x86_64-unknown-linux", | 264 arm64 = config { triple = "x86_64-unknown-linux", |
210 arch_define = "V8_TARGET_ARCH_ARM64" }, | 265 arch_define = "V8_TARGET_ARCH_ARM64", |
| 266 arch_options = "" }, |
211 } | 267 } |
212 | 268 |
213 ------------------------------------------------------------------------------- | 269 ------------------------------------------------------------------------------- |
214 -- GCSuspects Generation | 270 -- GCSuspects Generation |
215 | 271 |
216 local gc, gc_caused, funcs | 272 local gc, gc_caused, funcs |
217 | 273 |
218 local WHITELIST = { | 274 local WHITELIST = { |
219 -- The following functions call CEntryStub which is always present. | 275 -- The following functions call CEntryStub which is always present. |
220 "MacroAssembler.*CallExternalReference", | 276 "MacroAssembler.*CallExternalReference", |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 442 |
387 for _, arch in ipairs(ARCHS) do | 443 for _, arch in ipairs(ARCHS) do |
388 if not ARCHITECTURES[arch] then | 444 if not ARCHITECTURES[arch] then |
389 error ("Unknown arch: " .. arch) | 445 error ("Unknown arch: " .. arch) |
390 end | 446 end |
391 | 447 |
392 errors = SafeCheckCorrectnessForArch(arch, report) or errors | 448 errors = SafeCheckCorrectnessForArch(arch, report) or errors |
393 end | 449 end |
394 | 450 |
395 os.exit(errors and 1 or 0) | 451 os.exit(errors and 1 or 0) |
OLD | NEW |