Skip to content

Commit 629b2cf

Browse files
committed
[dsymutil] Add -q/--quiet flag to suppress warnings (llvm#91658)
Add a -q/--quiet flag to suppress dsymutil output. For now the flag is limited to dsymutil, though there might be other places in the DWARF linker that could be conditionalized by this flag. The motivation is having a way to silence the "no debug symbols in executable" warning. This is useful when we want to generate a dSYM for a binary not containing debug symbols, but still want a dSYM that can be indexed by spotlight. rdar://127843467 (cherry picked from commit 1e97d11)
1 parent 5345565 commit 629b2cf

File tree

6 files changed

+51
-15
lines changed

6 files changed

+51
-15
lines changed

llvm/docs/CommandGuide/dsymutil.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ OPTIONS
115115
Specifies an alternate ``path`` to place the dSYM bundle. The default dSYM
116116
bundle path is created by appending ``.dSYM`` to the executable name.
117117

118+
.. option:: -q, --quiet
119+
120+
Enable quiet mode and limit output.
121+
118122
.. option:: --remarks-drop-without-debug
119123

120124
Drop remarks without valid debug locations. Without this flags, all remarks are kept.

llvm/test/tools/dsymutil/ARM/empty-map.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# RUN: dsymutil -f -oso-prepend-path=%p/../Inputs -y %s -o - 2>&1 | FileCheck %s
2+
# RUN: dsymutil -q -f -oso-prepend-path=%p/../Inputs -y %s -o - 2>&1 | FileCheck %s --check-prefix QUIET
23

34
# RUN: dsymutil --linker parallel -f -oso-prepend-path=%p/../Inputs -y %s -o - 2>&1 | FileCheck %s
45

@@ -7,3 +8,4 @@ triple: 'thumbv7-apple-darwin'
78
...
89

910
# CHECK: warning: no debug symbols in executable (-arch armv7)
11+
# QUIET-NOT: no debug symbols in executable

llvm/test/tools/dsymutil/cmdline.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ CHECK: -object-prefix-map <prefix=remapped>
2323
CHECK: -oso-prepend-path <path>
2424
CHECK: -out <filename>
2525
CHECK: {{-o <filename>}}
26+
CHECK: -quiet
2627
CHECK: -remarks-drop-without-debug
2728
CHECK: -remarks-output-format <format>
2829
CHECK: -remarks-prepend-path <path>
@@ -47,3 +48,6 @@ NOINPUT: error: no input files specified
4748

4849
RUN: dsymutil -bogus -help 2>&1 | FileCheck --check-prefix=BOGUS %s
4950
BOGUS: warning: ignoring unknown option: -bogus
51+
52+
RUN: not dsymutil --quiet --verbose 2>&1 | FileCheck --check-prefix=CONFLICT %s
53+
CONFLICT: error: --quiet and --verbose cannot be specified together

llvm/tools/dsymutil/LinkUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ struct LinkOptions {
4040
/// Verbosity
4141
bool Verbose = false;
4242

43+
/// Quiet
44+
bool Quiet = false;
45+
4346
/// Statistics
4447
bool Statistics = false;
4548

llvm/tools/dsymutil/Options.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ def verbose: F<"verbose">,
2424
HelpText<"Enable verbose mode.">,
2525
Group<grp_general>;
2626

27+
def quiet: F<"quiet">,
28+
HelpText<"Enable quiet mode.">,
29+
Group<grp_general>;
30+
def: Flag<["-"], "q">,
31+
Alias<quiet>,
32+
HelpText<"Alias for --quiet">,
33+
Group<grp_general>;
34+
2735
def keep_func_for_static: F<"keep-function-for-static">,
2836
HelpText<"Make a static variable keep the enclosing function even if it would have been omitted otherwise.">,
2937
Group<grp_general>;

llvm/tools/dsymutil/dsymutil.cpp

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ static Expected<std::vector<std::string>> getInputs(opt::InputArgList &Args,
170170

171171
// Verify that the given combination of options makes sense.
172172
static Error verifyOptions(const DsymutilOptions &Options) {
173+
if (Options.LinkOpts.Verbose && Options.LinkOpts.Quiet) {
174+
return make_error<StringError>(
175+
"--quiet and --verbose cannot be specified together",
176+
errc::invalid_argument);
177+
}
178+
173179
if (Options.InputFiles.empty()) {
174180
return make_error<StringError>("no input files specified",
175181
errc::invalid_argument);
@@ -312,6 +318,7 @@ static Expected<DsymutilOptions> getOptions(opt::InputArgList &Args) {
312318
Options.LinkOpts.NoTimestamp = Args.hasArg(OPT_no_swiftmodule_timestamp);
313319
Options.LinkOpts.Update = Args.hasArg(OPT_update);
314320
Options.LinkOpts.Verbose = Args.hasArg(OPT_verbose);
321+
Options.LinkOpts.Quiet = Args.hasArg(OPT_quiet);
315322
Options.LinkOpts.Statistics = Args.hasArg(OPT_statistics);
316323
Options.LinkOpts.Fat64 = Args.hasArg(OPT_fat64);
317324
Options.LinkOpts.KeepFunctionForStatic =
@@ -490,16 +497,20 @@ static bool verifyOutput(StringRef OutputFile, StringRef Arch,
490497
DsymutilOptions Options, std::mutex &Mutex) {
491498

492499
if (OutputFile == "-") {
493-
std::lock_guard<std::mutex> Guard(Mutex);
494-
WithColor::warning() << "verification skipped for " << Arch
495-
<< " because writing to stdout.\n";
500+
if (!Options.LinkOpts.Quiet) {
501+
std::lock_guard<std::mutex> Guard(Mutex);
502+
WithColor::warning() << "verification skipped for " << Arch
503+
<< " because writing to stdout.\n";
504+
}
496505
return true;
497506
}
498507

499508
if (Options.LinkOpts.NoOutput) {
500-
std::lock_guard<std::mutex> Guard(Mutex);
501-
WithColor::warning() << "verification skipped for " << Arch
502-
<< " because --no-output was passed.\n";
509+
if (!Options.LinkOpts.Quiet) {
510+
std::lock_guard<std::mutex> Guard(Mutex);
511+
WithColor::warning() << "verification skipped for " << Arch
512+
<< " because --no-output was passed.\n";
513+
}
503514
return true;
504515
}
505516

@@ -514,10 +525,12 @@ static bool verifyOutput(StringRef OutputFile, StringRef Arch,
514525
if (auto *Obj = dyn_cast<MachOObjectFile>(&Binary)) {
515526
std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(*Obj);
516527
if (DICtx->getMaxVersion() > 5) {
517-
std::lock_guard<std::mutex> Guard(Mutex);
518-
WithColor::warning()
519-
<< "verification skipped for " << Arch
520-
<< " because DWARF standard greater than v5 is not supported yet.\n";
528+
if (!Options.LinkOpts.Quiet) {
529+
std::lock_guard<std::mutex> Guard(Mutex);
530+
WithColor::warning() << "verification skipped for " << Arch
531+
<< " because DWARF standard greater than v5 is "
532+
"not supported yet.\n";
533+
}
521534
return true;
522535
}
523536

@@ -766,11 +779,13 @@ int main(int argc, char **argv) {
766779
Options.LinkOpts.Translator = SymMapLoader.Load(InputFile, *Map);
767780

768781
if (Map->begin() == Map->end()) {
769-
std::lock_guard<std::mutex> Guard(ErrorHandlerMutex);
770-
WithColor::warning()
771-
<< "no debug symbols in executable (-arch "
772-
<< MachOUtils::getArchName(Map->getTriple().getArchName())
773-
<< ")\n";
782+
if (!Options.LinkOpts.Quiet) {
783+
std::lock_guard<std::mutex> Guard(ErrorHandlerMutex);
784+
WithColor::warning()
785+
<< "no debug symbols in executable (-arch "
786+
<< MachOUtils::getArchName(Map->getTriple().getArchName())
787+
<< ")\n";
788+
}
774789
}
775790

776791
// Using a std::shared_ptr rather than std::unique_ptr because move-only

0 commit comments

Comments
 (0)