[lld] r192250 - Fix flaky elf/X86_64/dynlib-search.test.
Rui Ueyama
ruiu at google.com
Tue Oct 8 16:01:52 PDT 2013
Author: ruiu
Date: Tue Oct 8 18:01:52 2013
New Revision: 192250
URL: http://llvm.org/viewvc/llvm-project?rev=192250&view=rev
Log:
Fix flaky elf/X86_64/dynlib-search.test.
Output to llvm::err() is not guaranteed to be thread-safe, so it needs
to be guarded with a lock.
Differential Revision: http://llvm-reviews.chandlerc.com/D1862
Modified:
lld/trunk/lib/Driver/Driver.cpp
Modified: lld/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Driver.cpp?rev=192250&r1=192249&r2=192250&view=diff
==============================================================================
--- lld/trunk/lib/Driver/Driver.cpp (original)
+++ lld/trunk/lib/Driver/Driver.cpp Tue Oct 8 18:01:52 2013
@@ -25,6 +25,8 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
+#include <mutex>
+
namespace lld {
/// This is where the link is actually performed.
@@ -49,13 +51,26 @@ bool Driver::link(LinkingContext &contex
ScopedTask readTask(getDefaultDomain(), "Read Args");
TaskGroup tg;
int index = 0;
+ std::mutex diagnosticsMutex;
for (auto &ie : inputGraph.inputElements()) {
tg.spawn([&, index] {
- if (error_code ec = ie->parse(context, diagnostics)) {
- FileNode *fileNode = (llvm::dyn_cast<FileNode>)(ie.get());
- diagnostics << fileNode->errStr(ec) << "\n";
+ // Writes to the same output stream is not guaranteed to be thread-safe.
+ // We buffer the diagnostics output to a separate string-backed output
+ // stream, acquire the lock, and then print it out.
+ std::string buf;
+ llvm::raw_string_ostream stream(buf);
+
+ if (error_code ec = ie->parse(context, stream)) {
+ FileNode *fileNode = llvm::dyn_cast<FileNode>(ie.get());
+ stream << fileNode->errStr(ec) << "\n";
fail = true;
}
+
+ stream.flush();
+ if (!buf.empty()) {
+ std::lock_guard<std::mutex> lock(diagnosticsMutex);
+ diagnostics << buf;
+ }
});
++index;
}
More information about the llvm-commits
mailing list