diff options
Diffstat (limited to 'recipes-devtools/rust/rust-llvm/0001-sancov-Switch-to-OptTable-from-llvm-cl.patch')
-rw-r--r-- | recipes-devtools/rust/rust-llvm/0001-sancov-Switch-to-OptTable-from-llvm-cl.patch | 352 |
1 files changed, 0 insertions, 352 deletions
diff --git a/recipes-devtools/rust/rust-llvm/0001-sancov-Switch-to-OptTable-from-llvm-cl.patch b/recipes-devtools/rust/rust-llvm/0001-sancov-Switch-to-OptTable-from-llvm-cl.patch deleted file mode 100644 index e713dfa..0000000 --- a/recipes-devtools/rust/rust-llvm/0001-sancov-Switch-to-OptTable-from-llvm-cl.patch +++ /dev/null | |||
@@ -1,352 +0,0 @@ | |||
1 | From a8016e296e6ec161897e7421c5efbc25a6aa3a9f Mon Sep 17 00:00:00 2001 | ||
2 | From: =?UTF-8?q?Andr=C3=A9s=20Villegas?= <andresvi@google.com> | ||
3 | Date: Tue, 25 Jul 2023 23:38:09 +0000 | ||
4 | Subject: [PATCH] [sancov] Switch to OptTable from llvm::cl | ||
5 | |||
6 | Switch the parse of command line options from llvm::cl to OptTable. | ||
7 | |||
8 | The motivation for this change is to continue adding llvm based tools | ||
9 | to the llvm driver multicall. For more information about the proposal | ||
10 | and motivation, please see https://discourse.llvm.org/t/rfc-llvm-busybox-proposal/58494 | ||
11 | |||
12 | Reviewed By: leonardchan | ||
13 | |||
14 | Drop this patch when upgrading llvm in rust to 18.x or newer | ||
15 | |||
16 | Upstream-Status: Backport [https://github.com/llvm/llvm-project/commit/a8016e296e6ec161897e7421c5efbc25a6aa3a9f] | ||
17 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
18 | Differential Revision: https://reviews.llvm.org/D155119 | ||
19 | --- | ||
20 | llvm/tools/sancov/CMakeLists.txt | 8 ++ | ||
21 | llvm/tools/sancov/Opts.td | 58 +++++++++ | ||
22 | llvm/tools/sancov/sancov.cpp | 194 +++++++++++++++++++++---------- | ||
23 | 3 files changed, 196 insertions(+), 64 deletions(-) | ||
24 | create mode 100644 llvm/tools/sancov/Opts.td | ||
25 | |||
26 | --- a/tools/sancov/CMakeLists.txt | ||
27 | +++ b/tools/sancov/CMakeLists.txt | ||
28 | @@ -5,11 +5,19 @@ set(LLVM_LINK_COMPONENTS | ||
29 | MC | ||
30 | MCDisassembler | ||
31 | Object | ||
32 | + Option | ||
33 | Support | ||
34 | Symbolize | ||
35 | TargetParser | ||
36 | ) | ||
37 | |||
38 | +set(LLVM_TARGET_DEFINITIONS Opts.td) | ||
39 | +tablegen(LLVM Opts.inc -gen-opt-parser-defs) | ||
40 | +add_public_tablegen_target(SancovOptsTableGen) | ||
41 | + | ||
42 | add_llvm_tool(sancov | ||
43 | sancov.cpp | ||
44 | + | ||
45 | + DEPENDS | ||
46 | + SancovOptsTableGen | ||
47 | ) | ||
48 | --- /dev/null | ||
49 | +++ b/tools/sancov/Opts.td | ||
50 | @@ -0,0 +1,58 @@ | ||
51 | +include "llvm/Option/OptParser.td" | ||
52 | + | ||
53 | +class F<string name, string help> : Flag<["-", "--"], name>, HelpText<help>; | ||
54 | + | ||
55 | +multiclass B<string name, string help1, string help2> { | ||
56 | + def NAME: Flag<["-", "--"], name>, HelpText<help1>; | ||
57 | + def no_ # NAME: Flag<["-", "--"], "no-" # name>, HelpText<help2>; | ||
58 | +} | ||
59 | + | ||
60 | +multiclass Eq<string name, string help> { | ||
61 | + def NAME #_EQ : Joined<["-", "--"], name #"=">, | ||
62 | + HelpText<help>; | ||
63 | + def : Separate<["-", "--"], name>, Alias<!cast<Joined>(NAME #_EQ)>; | ||
64 | +} | ||
65 | + | ||
66 | +def generic_grp : OptionGroup<"Genric Options">, HelpText<"Generic Options">; | ||
67 | +def help : F<"help", "Display this help">, Group<generic_grp>; | ||
68 | +def : Flag<["-"], "h">, Alias<help>, HelpText<"Alias for --help">, Group<generic_grp>; | ||
69 | +def version : F<"version", "Display the version">, Group<generic_grp>; | ||
70 | +def : Flag<["-"], "v">, Alias<version>, HelpText<"Alias for --version">, Group<generic_grp>; | ||
71 | + | ||
72 | +def action_grp : OptionGroup<"Action">, HelpText<"Action (required)">; | ||
73 | +def print : F<"print", "Print coverage addresses">, | ||
74 | + Group<action_grp>; | ||
75 | +def printCoveragePcs : F<"print-coverage-pcs", "Print coverage instrumentation points addresses.">, | ||
76 | + Group<action_grp>; | ||
77 | +def coveredFunctions : F<"covered-functions", "Print all covered funcions.">, | ||
78 | + Group<action_grp>; | ||
79 | +def notCoveredFunctions : F<"not-covered-functions", "Print all not covered funcions.">, | ||
80 | + Group<action_grp>; | ||
81 | +def printCoverageStats : F<"print-coverage-stats", "Print coverage statistics.">, | ||
82 | + Group<action_grp>; | ||
83 | +def htmlReport : F<"html-report", "REMOVED. Use -symbolize & coverage-report-server.py.">, | ||
84 | + Group<action_grp>; | ||
85 | +def symbolize : F<"symbolize", "Produces a symbolized JSON report from binary report.">, | ||
86 | + Group<action_grp>; | ||
87 | +def merge : F<"merge", "Merges reports.">, | ||
88 | + Group<action_grp>; | ||
89 | + | ||
90 | +defm demangle : B<"demangle", "Demangle function names", "Do not demangle function names">; | ||
91 | +defm skipDeadFiles : B<"skip-dead-files", "Do not list dead source files in reports", | ||
92 | + "List dead source files in reports">; | ||
93 | +defm useDefaultIgnoreList : | ||
94 | + B<"use_default_ignorelist", "Use the default ignore list", "Don't use the default ignore list">, | ||
95 | + Flags<[HelpHidden]>; | ||
96 | + | ||
97 | +// Compatibility aliases | ||
98 | +def : Flag<["-"], "demangle=0">, Alias<no_demangle>, HelpText<"Alias for --no-demangle">; | ||
99 | +def : Flag<["-"], "skip-dead-files=0">, Alias<no_skipDeadFiles>, HelpText<"Alias for --no-skip-dead-files">; | ||
100 | +def : Flag<["-"], "use_default_ignorelist=0">, Alias<no_useDefaultIgnoreList>, HelpText<"Alias for --no-use_default_ignore_list">; | ||
101 | + | ||
102 | +defm stripPathPrefix | ||
103 | + : Eq<"strip_path_prefix", "Strip this prefix from files paths in reports">, | ||
104 | + MetaVarName<"<string>">; | ||
105 | + | ||
106 | +defm ignorelist | ||
107 | + : Eq<"ignorelist", "Ignorelist file (sanitizer ignorelist format)">, | ||
108 | + MetaVarName<"<string>">; | ||
109 | --- a/tools/sancov/sancov.cpp | ||
110 | +++ b/tools/sancov/sancov.cpp | ||
111 | @@ -29,6 +29,8 @@ | ||
112 | #include "llvm/Object/COFF.h" | ||
113 | #include "llvm/Object/MachO.h" | ||
114 | #include "llvm/Object/ObjectFile.h" | ||
115 | +#include "llvm/Option/ArgList.h" | ||
116 | +#include "llvm/Option/Option.h" | ||
117 | #include "llvm/Support/Casting.h" | ||
118 | #include "llvm/Support/CommandLine.h" | ||
119 | #include "llvm/Support/Errc.h" | ||
120 | @@ -55,9 +57,44 @@ using namespace llvm; | ||
121 | |||
122 | namespace { | ||
123 | |||
124 | -// --------- COMMAND LINE FLAGS --------- | ||
125 | +// Command-line option boilerplate. | ||
126 | +namespace { | ||
127 | +using namespace llvm::opt; | ||
128 | +enum ID { | ||
129 | + OPT_INVALID = 0, // This is not an option ID. | ||
130 | +#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ | ||
131 | + HELPTEXT, METAVAR, VALUES) \ | ||
132 | + OPT_##ID, | ||
133 | +#include "Opts.inc" | ||
134 | +#undef OPTION | ||
135 | +}; | ||
136 | |||
137 | -cl::OptionCategory Cat("sancov Options"); | ||
138 | +#define PREFIX(NAME, VALUE) \ | ||
139 | + static constexpr StringLiteral NAME##_init[] = VALUE; \ | ||
140 | + static constexpr ArrayRef<StringLiteral> NAME(NAME##_init, \ | ||
141 | + std::size(NAME##_init) - 1); | ||
142 | +#include "Opts.inc" | ||
143 | +#undef PREFIX | ||
144 | + | ||
145 | +static constexpr opt::OptTable::Info InfoTable[] = { | ||
146 | +#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ | ||
147 | + HELPTEXT, METAVAR, VALUES) \ | ||
148 | + { \ | ||
149 | + PREFIX, NAME, HELPTEXT, \ | ||
150 | + METAVAR, OPT_##ID, opt::Option::KIND##Class, \ | ||
151 | + PARAM, FLAGS, OPT_##GROUP, \ | ||
152 | + OPT_##ALIAS, ALIASARGS, VALUES}, | ||
153 | +#include "Opts.inc" | ||
154 | +#undef OPTION | ||
155 | +}; | ||
156 | + | ||
157 | +class SancovOptTable : public opt::GenericOptTable { | ||
158 | +public: | ||
159 | + SancovOptTable() : GenericOptTable(InfoTable) {} | ||
160 | +}; | ||
161 | +} // namespace | ||
162 | + | ||
163 | +// --------- COMMAND LINE FLAGS --------- | ||
164 | |||
165 | enum ActionType { | ||
166 | CoveredFunctionsAction, | ||
167 | @@ -70,53 +107,13 @@ enum ActionType { | ||
168 | SymbolizeAction | ||
169 | }; | ||
170 | |||
171 | -cl::opt<ActionType> Action( | ||
172 | - cl::desc("Action (required)"), cl::Required, | ||
173 | - cl::values( | ||
174 | - clEnumValN(PrintAction, "print", "Print coverage addresses"), | ||
175 | - clEnumValN(PrintCovPointsAction, "print-coverage-pcs", | ||
176 | - "Print coverage instrumentation points addresses."), | ||
177 | - clEnumValN(CoveredFunctionsAction, "covered-functions", | ||
178 | - "Print all covered funcions."), | ||
179 | - clEnumValN(NotCoveredFunctionsAction, "not-covered-functions", | ||
180 | - "Print all not covered funcions."), | ||
181 | - clEnumValN(StatsAction, "print-coverage-stats", | ||
182 | - "Print coverage statistics."), | ||
183 | - clEnumValN(HtmlReportAction, "html-report", | ||
184 | - "REMOVED. Use -symbolize & coverage-report-server.py."), | ||
185 | - clEnumValN(SymbolizeAction, "symbolize", | ||
186 | - "Produces a symbolized JSON report from binary report."), | ||
187 | - clEnumValN(MergeAction, "merge", "Merges reports.")), | ||
188 | - cl::cat(Cat)); | ||
189 | - | ||
190 | -static cl::list<std::string> | ||
191 | - ClInputFiles(cl::Positional, cl::OneOrMore, | ||
192 | - cl::desc("<action> <binary files...> <.sancov files...> " | ||
193 | - "<.symcov files...>"), | ||
194 | - cl::cat(Cat)); | ||
195 | - | ||
196 | -static cl::opt<bool> ClDemangle("demangle", cl::init(true), | ||
197 | - cl::desc("Print demangled function name"), | ||
198 | - cl::cat(Cat)); | ||
199 | - | ||
200 | -static cl::opt<bool> | ||
201 | - ClSkipDeadFiles("skip-dead-files", cl::init(true), | ||
202 | - cl::desc("Do not list dead source files in reports"), | ||
203 | - cl::cat(Cat)); | ||
204 | - | ||
205 | -static cl::opt<std::string> | ||
206 | - ClStripPathPrefix("strip_path_prefix", cl::init(""), | ||
207 | - cl::desc("Strip this prefix from file paths in reports"), | ||
208 | - cl::cat(Cat)); | ||
209 | - | ||
210 | -static cl::opt<std::string> | ||
211 | - ClIgnorelist("ignorelist", cl::init(""), | ||
212 | - cl::desc("Ignorelist file (sanitizer ignorelist format)"), | ||
213 | - cl::cat(Cat)); | ||
214 | - | ||
215 | -static cl::opt<bool> ClUseDefaultIgnorelist( | ||
216 | - "use_default_ignorelist", cl::init(true), cl::Hidden, | ||
217 | - cl::desc("Controls if default ignorelist should be used"), cl::cat(Cat)); | ||
218 | +static ActionType Action; | ||
219 | +static std::vector<std::string> ClInputFiles; | ||
220 | +static bool ClDemangle; | ||
221 | +static bool ClSkipDeadFiles; | ||
222 | +static bool ClUseDefaultIgnorelist; | ||
223 | +static std::string ClStripPathPrefix; | ||
224 | +static std::string ClIgnorelist; | ||
225 | |||
226 | static const char *const DefaultIgnorelistStr = "fun:__sanitizer_.*\n" | ||
227 | "src:/usr/include/.*\n" | ||
228 | @@ -699,8 +696,7 @@ findSanitizerCovFunctions(const object:: | ||
229 | // Ported from | ||
230 | // compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h:GetPreviousInstructionPc | ||
231 | // GetPreviousInstructionPc. | ||
232 | -static uint64_t getPreviousInstructionPc(uint64_t PC, | ||
233 | - Triple TheTriple) { | ||
234 | +static uint64_t getPreviousInstructionPc(uint64_t PC, Triple TheTriple) { | ||
235 | if (TheTriple.isARM()) | ||
236 | return (PC - 3) & (~1); | ||
237 | if (TheTriple.isMIPS() || TheTriple.isSPARC()) | ||
238 | @@ -1145,31 +1141,101 @@ readSymbolizeAndMergeCmdArguments(std::v | ||
239 | |||
240 | } // namespace | ||
241 | |||
242 | +static void parseArgs(int Argc, char **Argv) { | ||
243 | + SancovOptTable Tbl; | ||
244 | + llvm::BumpPtrAllocator A; | ||
245 | + llvm::StringSaver Saver{A}; | ||
246 | + opt::InputArgList Args = | ||
247 | + Tbl.parseArgs(Argc, Argv, OPT_UNKNOWN, Saver, [&](StringRef Msg) { | ||
248 | + llvm::errs() << Msg << '\n'; | ||
249 | + std::exit(1); | ||
250 | + }); | ||
251 | + | ||
252 | + if (Args.hasArg(OPT_help)) { | ||
253 | + Tbl.printHelp( | ||
254 | + llvm::outs(), | ||
255 | + "sancov [options] <action> <binary files...> <.sancov files...> " | ||
256 | + "<.symcov files...>", | ||
257 | + "Sanitizer Coverage Processing Tool (sancov)\n\n" | ||
258 | + " This tool can extract various coverage-related information from: \n" | ||
259 | + " coverage-instrumented binary files, raw .sancov files and their " | ||
260 | + "symbolized .symcov version.\n" | ||
261 | + " Depending on chosen action the tool expects different input files:\n" | ||
262 | + " -print-coverage-pcs - coverage-instrumented binary files\n" | ||
263 | + " -print-coverage - .sancov files\n" | ||
264 | + " <other actions> - .sancov files & corresponding binary " | ||
265 | + "files, .symcov files\n"); | ||
266 | + std::exit(0); | ||
267 | + } | ||
268 | + | ||
269 | + if (Args.hasArg(OPT_version)) { | ||
270 | + cl::PrintVersionMessage(); | ||
271 | + std::exit(0); | ||
272 | + } | ||
273 | + | ||
274 | + if (Args.hasMultipleArgs(OPT_action_grp)) { | ||
275 | + fail("Only one action option is allowed"); | ||
276 | + } | ||
277 | + | ||
278 | + for (const opt::Arg *A : Args.filtered(OPT_INPUT)) { | ||
279 | + ClInputFiles.emplace_back(A->getValue()); | ||
280 | + } | ||
281 | + | ||
282 | + if (const llvm::opt::Arg *A = Args.getLastArg(OPT_action_grp)) { | ||
283 | + switch (A->getOption().getID()) { | ||
284 | + case OPT_print: | ||
285 | + Action = ActionType::PrintAction; | ||
286 | + break; | ||
287 | + case OPT_printCoveragePcs: | ||
288 | + Action = ActionType::PrintCovPointsAction; | ||
289 | + break; | ||
290 | + case OPT_coveredFunctions: | ||
291 | + Action = ActionType::CoveredFunctionsAction; | ||
292 | + break; | ||
293 | + case OPT_notCoveredFunctions: | ||
294 | + Action = ActionType::NotCoveredFunctionsAction; | ||
295 | + break; | ||
296 | + case OPT_printCoverageStats: | ||
297 | + Action = ActionType::StatsAction; | ||
298 | + break; | ||
299 | + case OPT_htmlReport: | ||
300 | + Action = ActionType::HtmlReportAction; | ||
301 | + break; | ||
302 | + case OPT_symbolize: | ||
303 | + Action = ActionType::SymbolizeAction; | ||
304 | + break; | ||
305 | + case OPT_merge: | ||
306 | + Action = ActionType::MergeAction; | ||
307 | + break; | ||
308 | + default: | ||
309 | + fail("Invalid Action"); | ||
310 | + } | ||
311 | + } | ||
312 | + | ||
313 | + ClDemangle = Args.hasFlag(OPT_demangle, OPT_no_demangle, true); | ||
314 | + ClSkipDeadFiles = Args.hasFlag(OPT_skipDeadFiles, OPT_no_skipDeadFiles, true); | ||
315 | + ClUseDefaultIgnorelist = | ||
316 | + Args.hasFlag(OPT_useDefaultIgnoreList, OPT_no_useDefaultIgnoreList, true); | ||
317 | + | ||
318 | + ClStripPathPrefix = Args.getLastArgValue(OPT_stripPathPrefix_EQ); | ||
319 | + ClIgnorelist = Args.getLastArgValue(OPT_ignorelist_EQ); | ||
320 | +} | ||
321 | + | ||
322 | int main(int Argc, char **Argv) { | ||
323 | llvm::InitLLVM X(Argc, Argv); | ||
324 | - cl::HideUnrelatedOptions(Cat); | ||
325 | |||
326 | llvm::InitializeAllTargetInfos(); | ||
327 | llvm::InitializeAllTargetMCs(); | ||
328 | llvm::InitializeAllDisassemblers(); | ||
329 | |||
330 | - cl::ParseCommandLineOptions(Argc, Argv, | ||
331 | - "Sanitizer Coverage Processing Tool (sancov)\n\n" | ||
332 | - " This tool can extract various coverage-related information from: \n" | ||
333 | - " coverage-instrumented binary files, raw .sancov files and their " | ||
334 | - "symbolized .symcov version.\n" | ||
335 | - " Depending on chosen action the tool expects different input files:\n" | ||
336 | - " -print-coverage-pcs - coverage-instrumented binary files\n" | ||
337 | - " -print-coverage - .sancov files\n" | ||
338 | - " <other actions> - .sancov files & corresponding binary " | ||
339 | - "files, .symcov files\n" | ||
340 | - ); | ||
341 | + parseArgs(Argc, Argv); | ||
342 | |||
343 | // -print doesn't need object files. | ||
344 | if (Action == PrintAction) { | ||
345 | readAndPrintRawCoverage(ClInputFiles, outs()); | ||
346 | return 0; | ||
347 | - } else if (Action == PrintCovPointsAction) { | ||
348 | + } | ||
349 | + if (Action == PrintCovPointsAction) { | ||
350 | // -print-coverage-points doesn't need coverage files. | ||
351 | for (const std::string &ObjFile : ClInputFiles) { | ||
352 | printCovPoints(ObjFile, outs()); | ||