[dsymutil] Add -q/--quiet flag to suppress warnings (#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
This commit is contained in:
Jonas Devlieghere
2024-05-09 15:55:36 -07:00
committed by GitHub
parent 8a3277acbc
commit 1e97d114b5
6 changed files with 51 additions and 15 deletions

View File

@@ -115,6 +115,10 @@ OPTIONS
Specifies an alternate ``path`` to place the dSYM bundle. The default dSYM
bundle path is created by appending ``.dSYM`` to the executable name.
.. option:: -q, --quiet
Enable quiet mode and limit output.
.. option:: --remarks-drop-without-debug
Drop remarks without valid debug locations. Without this flags, all remarks are kept.

View File

@@ -1,4 +1,5 @@
# RUN: dsymutil -f -oso-prepend-path=%p/../Inputs -y %s -o - 2>&1 | FileCheck %s
# RUN: dsymutil -q -f -oso-prepend-path=%p/../Inputs -y %s -o - 2>&1 | FileCheck %s --check-prefix QUIET
# RUN: dsymutil --linker parallel -f -oso-prepend-path=%p/../Inputs -y %s -o - 2>&1 | FileCheck %s
@@ -7,3 +8,4 @@ triple: 'thumbv7-apple-darwin'
...
# CHECK: warning: no debug symbols in executable (-arch armv7)
# QUIET-NOT: no debug symbols in executable

View File

@@ -23,6 +23,7 @@ CHECK: -object-prefix-map <prefix=remapped>
CHECK: -oso-prepend-path <path>
CHECK: -out <filename>
CHECK: {{-o <filename>}}
CHECK: -quiet
CHECK: -remarks-drop-without-debug
CHECK: -remarks-output-format <format>
CHECK: -remarks-prepend-path <path>
@@ -46,3 +47,6 @@ NOINPUT: error: no input files specified
RUN: dsymutil -bogus -help 2>&1 | FileCheck --check-prefix=BOGUS %s
BOGUS: warning: ignoring unknown option: -bogus
RUN: not dsymutil --quiet --verbose 2>&1 | FileCheck --check-prefix=CONFLICT %s
CONFLICT: error: --quiet and --verbose cannot be specified together

View File

@@ -38,6 +38,9 @@ struct LinkOptions {
/// Verbosity
bool Verbose = false;
/// Quiet
bool Quiet = false;
/// Statistics
bool Statistics = false;

View File

@@ -24,6 +24,14 @@ def verbose: F<"verbose">,
HelpText<"Enable verbose mode.">,
Group<grp_general>;
def quiet: F<"quiet">,
HelpText<"Enable quiet mode.">,
Group<grp_general>;
def: Flag<["-"], "q">,
Alias<quiet>,
HelpText<"Alias for --quiet">,
Group<grp_general>;
def keep_func_for_static: F<"keep-function-for-static">,
HelpText<"Make a static variable keep the enclosing function even if it would have been omitted otherwise.">,
Group<grp_general>;

View File

@@ -169,6 +169,12 @@ static Expected<std::vector<std::string>> getInputs(opt::InputArgList &Args,
// Verify that the given combination of options makes sense.
static Error verifyOptions(const DsymutilOptions &Options) {
if (Options.LinkOpts.Verbose && Options.LinkOpts.Quiet) {
return make_error<StringError>(
"--quiet and --verbose cannot be specified together",
errc::invalid_argument);
}
if (Options.InputFiles.empty()) {
return make_error<StringError>("no input files specified",
errc::invalid_argument);
@@ -311,6 +317,7 @@ static Expected<DsymutilOptions> getOptions(opt::InputArgList &Args) {
Options.LinkOpts.NoTimestamp = Args.hasArg(OPT_no_swiftmodule_timestamp);
Options.LinkOpts.Update = Args.hasArg(OPT_update);
Options.LinkOpts.Verbose = Args.hasArg(OPT_verbose);
Options.LinkOpts.Quiet = Args.hasArg(OPT_quiet);
Options.LinkOpts.Statistics = Args.hasArg(OPT_statistics);
Options.LinkOpts.Fat64 = Args.hasArg(OPT_fat64);
Options.LinkOpts.KeepFunctionForStatic =
@@ -483,16 +490,20 @@ static bool verifyOutput(StringRef OutputFile, StringRef Arch,
DsymutilOptions Options, std::mutex &Mutex) {
if (OutputFile == "-") {
std::lock_guard<std::mutex> Guard(Mutex);
WithColor::warning() << "verification skipped for " << Arch
<< " because writing to stdout.\n";
if (!Options.LinkOpts.Quiet) {
std::lock_guard<std::mutex> Guard(Mutex);
WithColor::warning() << "verification skipped for " << Arch
<< " because writing to stdout.\n";
}
return true;
}
if (Options.LinkOpts.NoOutput) {
std::lock_guard<std::mutex> Guard(Mutex);
WithColor::warning() << "verification skipped for " << Arch
<< " because --no-output was passed.\n";
if (!Options.LinkOpts.Quiet) {
std::lock_guard<std::mutex> Guard(Mutex);
WithColor::warning() << "verification skipped for " << Arch
<< " because --no-output was passed.\n";
}
return true;
}
@@ -507,10 +518,12 @@ static bool verifyOutput(StringRef OutputFile, StringRef Arch,
if (auto *Obj = dyn_cast<MachOObjectFile>(&Binary)) {
std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(*Obj);
if (DICtx->getMaxVersion() > 5) {
std::lock_guard<std::mutex> Guard(Mutex);
WithColor::warning()
<< "verification skipped for " << Arch
<< " because DWARF standard greater than v5 is not supported yet.\n";
if (!Options.LinkOpts.Quiet) {
std::lock_guard<std::mutex> Guard(Mutex);
WithColor::warning() << "verification skipped for " << Arch
<< " because DWARF standard greater than v5 is "
"not supported yet.\n";
}
return true;
}
@@ -751,11 +764,13 @@ int dsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
continue;
if (Map->begin() == Map->end()) {
std::lock_guard<std::mutex> Guard(ErrorHandlerMutex);
WithColor::warning()
<< "no debug symbols in executable (-arch "
<< MachOUtils::getArchName(Map->getTriple().getArchName())
<< ")\n";
if (!Options.LinkOpts.Quiet) {
std::lock_guard<std::mutex> Guard(ErrorHandlerMutex);
WithColor::warning()
<< "no debug symbols in executable (-arch "
<< MachOUtils::getArchName(Map->getTriple().getArchName())
<< ")\n";
}
}
// Using a std::shared_ptr rather than std::unique_ptr because move-only