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