Skip to content

Commit 7c71610

Browse files
JDevliegherefelipepiovezan
authored andcommitted
[dsymutil] Fix data race in input verification (NFC)
Dump verification errors to a local buffer instead of racing stdio and potentially showing interleaved output. (cherry picked from commit 4d1d8a8)
1 parent f82a39c commit 7c71610

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

llvm/include/llvm/DWARFLinker/DWARFLinker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class DWARFLinker {
357357
Pub, ///< .debug_pubnames, .debug_pubtypes
358358
DebugNames ///< .debug_names.
359359
};
360-
typedef std::function<void(const DWARFFile &File)> inputVerificationHandler;
360+
typedef std::function<void(const DWARFFile &File, llvm::StringRef Output)> inputVerificationHandler;
361361
typedef std::function<ErrorOr<DWARFFile &>(StringRef ContainerName,
362362
StringRef Path)>
363363
objFileLoader;

llvm/include/llvm/DWARFLinkerParallel/DWARFLinker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class DWARFLinker {
134134
const Twine &Warning, StringRef Context, const DWARFDie *DIE)>;
135135
using ObjFileLoaderTy = std::function<ErrorOr<DWARFFile &>(
136136
StringRef ContainerName, StringRef Path)>;
137-
using InputVerificationHandlerTy = std::function<void(const DWARFFile &File)>;
137+
using InputVerificationHandlerTy = std::function<void(const DWARFFile &File, llvm::StringRef Output)>;
138138
using ObjectPrefixMapTy = std::map<std::string, std::string>;
139139
using CompileUnitHandlerTy = function_ref<void(const DWARFUnit &Unit)>;
140140
using TranslatorFuncTy = std::function<StringRef(StringRef)>;

llvm/lib/DWARFLinker/DWARFLinker.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,11 +3037,13 @@ Error DWARFLinker::cloneModuleUnit(LinkContext &Context, RefModuleUnit &Unit,
30373037
void DWARFLinker::verifyInput(const DWARFFile &File) {
30383038
assert(File.Dwarf);
30393039

3040-
raw_ostream &os = Options.Verbose ? errs() : nulls();
3040+
3041+
std::string Buffer;
3042+
raw_string_ostream OS(Buffer);
30413043
DIDumpOptions DumpOpts;
3042-
if (!File.Dwarf->verify(os, DumpOpts.noImplicitRecursion())) {
3044+
if (!File.Dwarf->verify(OS, DumpOpts.noImplicitRecursion())) {
30433045
if (Options.InputVerificationHandler)
3044-
Options.InputVerificationHandler(File);
3046+
Options.InputVerificationHandler(File, OS.str());
30453047
}
30463048
}
30473049

llvm/tools/dsymutil/DwarfLinkerForBinary.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,11 @@ bool DwarfLinkerForBinary::linkImpl(
689689
GeneralLinker->setNumThreads(Options.Threads);
690690
GeneralLinker->setPrependPath(Options.PrependPath);
691691
GeneralLinker->setKeepFunctionForStatic(Options.KeepFunctionForStatic);
692-
GeneralLinker->setInputVerificationHandler([&](const OutDwarfFile &File) {
693-
reportWarning("input verification failed", File.FileName);
692+
GeneralLinker->setInputVerificationHandler([&](const OutDwarfFile &File, llvm::StringRef Output) {
693+
std::lock_guard<std::mutex> Guard(ErrorHandlerMutex);
694+
if (Options.Verbose)
695+
errs() << Output;
696+
warn("input verification failed", File.FileName);
694697
HasVerificationErrors = true;
695698
});
696699
auto Loader = [&](StringRef ContainerName,

0 commit comments

Comments
 (0)