@@ -491,22 +491,25 @@ static Error createBundleDir(StringRef BundleBase) {
491
491
}
492
492
493
493
static bool verifyOutput (StringRef OutputFile, StringRef Arch,
494
- DsymutilOptions Options) {
494
+ DsymutilOptions Options, std::mutex &Mutex ) {
495
495
496
496
if (OutputFile == " -" ) {
497
+ std::lock_guard<std::mutex> Guard (Mutex);
497
498
WithColor::warning () << " verification skipped for " << Arch
498
499
<< " because writing to stdout.\n " ;
499
500
return true ;
500
501
}
501
502
502
503
if (Options.LinkOpts .NoOutput ) {
504
+ std::lock_guard<std::mutex> Guard (Mutex);
503
505
WithColor::warning () << " verification skipped for " << Arch
504
506
<< " because --no-output was passed.\n " ;
505
507
return true ;
506
508
}
507
509
508
510
Expected<OwningBinary<Binary>> BinOrErr = createBinary (OutputFile);
509
511
if (!BinOrErr) {
512
+ std::lock_guard<std::mutex> Guard (Mutex);
510
513
WithColor::error () << OutputFile << " : " << toString (BinOrErr.takeError ());
511
514
return false ;
512
515
}
@@ -515,16 +518,27 @@ static bool verifyOutput(StringRef OutputFile, StringRef Arch,
515
518
if (auto *Obj = dyn_cast<MachOObjectFile>(&Binary)) {
516
519
std::unique_ptr<DWARFContext> DICtx = DWARFContext::create (*Obj);
517
520
if (DICtx->getMaxVersion () >= 5 ) {
521
+ std::lock_guard<std::mutex> Guard (Mutex);
518
522
WithColor::warning () << " verification skipped for " << Arch
519
523
<< " because DWARFv5 is not fully supported yet.\n " ;
520
524
return true ;
521
525
}
522
- raw_ostream &os = Options.LinkOpts .Verbose ? errs () : nulls ();
523
- os << " Verifying DWARF for architecture: " << Arch << " \n " ;
526
+
527
+ if (Options.LinkOpts .Verbose ) {
528
+ std::lock_guard<std::mutex> Guard (Mutex);
529
+ errs () << " Verifying DWARF for architecture: " << Arch << " \n " ;
530
+ }
531
+
532
+ std::string Buffer;
533
+ raw_string_ostream OS (Buffer);
534
+
524
535
DIDumpOptions DumpOpts;
525
- bool success = DICtx->verify (os, DumpOpts.noImplicitRecursion ());
526
- if (!success)
536
+ bool success = DICtx->verify (OS, DumpOpts.noImplicitRecursion ());
537
+ if (!success) {
538
+ std::lock_guard<std::mutex> Guard (Mutex);
539
+ errs () << OS.str ();
527
540
WithColor::error () << " output verification failed for " << Arch << ' \n ' ;
541
+ }
528
542
return success;
529
543
}
530
544
@@ -730,16 +744,16 @@ int dsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
730
744
!Options.DumpDebugMap && (Options.OutputFile != " -" ) &&
731
745
(DebugMapPtrsOrErr->size () != 1 || Options.LinkOpts .Update );
732
746
733
- // Set up a crash recovery context.
734
- CrashRecoveryContext::Enable ();
735
- CrashRecoveryContext CRC;
736
- CRC.DumpStackAndCleanupOnFailure = true ;
737
-
738
747
std::atomic_char AllOK (1 );
739
748
SmallVector<MachOUtils::ArchAndFile, 4 > TempFiles;
740
749
741
750
std::mutex ErrorHandlerMutex;
742
751
752
+ // Set up a crash recovery context.
753
+ CrashRecoveryContext::Enable ();
754
+ CrashRecoveryContext CRC;
755
+ CRC.DumpStackAndCleanupOnFailure = true ;
756
+
743
757
const bool Crashed = !CRC.RunSafely ([&]() {
744
758
for (auto &Map : *DebugMapPtrsOrErr) {
745
759
if (Options.LinkOpts .Verbose || Options.DumpDebugMap )
@@ -751,11 +765,13 @@ int dsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
751
765
if (!Options.SymbolMap .empty ())
752
766
Options.LinkOpts .Translator = SymMapLoader.Load (InputFile, *Map);
753
767
754
- if (Map->begin () == Map->end ())
768
+ if (Map->begin () == Map->end ()) {
769
+ std::lock_guard<std::mutex> Guard (ErrorHandlerMutex);
755
770
WithColor::warning ()
756
771
<< " no debug symbols in executable (-arch "
757
772
<< MachOUtils::getArchName (Map->getTriple ().getArchName ())
758
773
<< " )\n " ;
774
+ }
759
775
760
776
// Using a std::shared_ptr rather than std::unique_ptr because move-only
761
777
// types don't work with std::bind in the ThreadPool implementation.
@@ -767,6 +783,7 @@ int dsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
767
783
768
784
auto E = TempFiles.back ().createTempFile ();
769
785
if (E) {
786
+ std::lock_guard<std::mutex> Guard (ErrorHandlerMutex);
770
787
WithColor::error () << toString (std::move (E));
771
788
AllOK.fetch_and (false );
772
789
return ;
@@ -797,8 +814,9 @@ int dsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
797
814
if (flagIsSet (Options.Verify , DWARFVerify::Output) ||
798
815
(flagIsSet (Options.Verify , DWARFVerify::OutputOnValidInput) &&
799
816
!Linker.InputVerificationFailed ())) {
800
- AllOK.fetch_and (verifyOutput (
801
- OutputFile, Map->getTriple ().getArchName (), Options));
817
+ AllOK.fetch_and (verifyOutput (OutputFile,
818
+ Map->getTriple ().getArchName (),
819
+ Options, ErrorHandlerMutex));
802
820
}
803
821
};
804
822
0 commit comments