Skip to content

Commit 4d1d8a8

Browse files
committed
[dsymutil] Fix data race in input verification (NFC)
Dump verification errors to a local buffer instead of racing stdio and potentially showing interleaved output.
1 parent 7275734 commit 4d1d8a8

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
@@ -338,7 +338,7 @@ class DWARFLinker {
338338
Pub, ///< .debug_pubnames, .debug_pubtypes
339339
DebugNames ///< .debug_names.
340340
};
341-
typedef std::function<void(const DWARFFile &File)> inputVerificationHandler;
341+
typedef std::function<void(const DWARFFile &File, llvm::StringRef Output)> inputVerificationHandler;
342342
typedef std::function<ErrorOr<DWARFFile &>(StringRef ContainerName,
343343
StringRef Path)>
344344
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
@@ -3057,11 +3057,13 @@ Error DWARFLinker::cloneModuleUnit(LinkContext &Context, RefModuleUnit &Unit,
30573057
void DWARFLinker::verifyInput(const DWARFFile &File) {
30583058
assert(File.Dwarf);
30593059

3060-
raw_ostream &os = Options.Verbose ? errs() : nulls();
3060+
3061+
std::string Buffer;
3062+
raw_string_ostream OS(Buffer);
30613063
DIDumpOptions DumpOpts;
3062-
if (!File.Dwarf->verify(os, DumpOpts.noImplicitRecursion())) {
3064+
if (!File.Dwarf->verify(OS, DumpOpts.noImplicitRecursion())) {
30633065
if (Options.InputVerificationHandler)
3064-
Options.InputVerificationHandler(File);
3066+
Options.InputVerificationHandler(File, OS.str());
30653067
}
30663068
}
30673069

llvm/tools/dsymutil/DwarfLinkerForBinary.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,11 @@ bool DwarfLinkerForBinary::linkImpl(
638638
GeneralLinker->setNumThreads(Options.Threads);
639639
GeneralLinker->setPrependPath(Options.PrependPath);
640640
GeneralLinker->setKeepFunctionForStatic(Options.KeepFunctionForStatic);
641-
GeneralLinker->setInputVerificationHandler([&](const OutDwarfFile &File) {
642-
reportWarning("input verification failed", File.FileName);
641+
GeneralLinker->setInputVerificationHandler([&](const OutDwarfFile &File, llvm::StringRef Output) {
642+
std::lock_guard<std::mutex> Guard(ErrorHandlerMutex);
643+
if (Options.Verbose)
644+
errs() << Output;
645+
warn("input verification failed", File.FileName);
643646
HasVerificationErrors = true;
644647
});
645648
auto Loader = [&](StringRef ContainerName,

0 commit comments

Comments
 (0)