Fix the PNaCl translator to lock the dump stream when printing errors.
The previous code did not do this. Also localizes the lock to when
the error is actually printed.
Note: requires https://codereview.chromium.org/865963002
BUG=None
R=stichnot@chromium.org
Review URL: https://codereview.chromium.org/864383002
diff --git a/src/PNaClTranslator.cpp b/src/PNaClTranslator.cpp
index 33dda4b..01ba264 100644
--- a/src/PNaClTranslator.cpp
+++ b/src/PNaClTranslator.cpp
@@ -165,14 +165,7 @@
NaClBitstreamCursor &Cursor, bool &ErrorStatus)
: NaClBitcodeParser(Cursor), Translator(Translator), Header(Header),
ErrorStatus(ErrorStatus), NumErrors(0), NumFunctionIds(0),
- NumFunctionBlocks(0), BlockParser(nullptr) {
- // Note: This gives the reader uncontrolled access to the dump
- // stream, which it can then use without locking. TODO(kschimpf):
- // Consider reworking the LLVM side to use e.g. a callback for
- // errors.
- Ice::OstreamLocker L(Translator.getContext());
- setErrStream(Translator.getContext()->getStrDump());
- }
+ NumFunctionBlocks(0), BlockParser(nullptr) {}
~TopLevelParser() override {}
@@ -437,7 +430,11 @@
bool TopLevelParser::Error(const std::string &Message) {
ErrorStatus = true;
++NumErrors;
+ Ice::GlobalContext *Context = Translator.getContext();
+ Ice::OstreamLocker L(Context);
+ raw_ostream &OldErrStream = setErrStream(Context->getStrDump());
NaClBitcodeParser::Error(Message);
+ setErrStream(OldErrStream);
if (!Translator.getFlags().AllowErrorRecovery)
report_fatal_error("Unable to continue");
return true;