In ErrorHandler::error(), rearrange code to avoid calling exitLld with
the mutex locked. Acquire mutex lock when flushing the output streams in
exitLld.
Details
- Reviewers
ruiu MaskRay - Commits
- rGde2dfc8b203f: [LLD] Avoid exiting with a locked mutex NFC
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
lld/Common/ErrorHandler.cpp | ||
---|---|---|
66 | it does not seem that exitLld can be invoked concurrently. |
It is generally not good practice to hold a lock whilst exiting, as this has the potential to cause deadlocks. I don't believe that this situation can occur currently with LLD. However, after some recent observations, it appears that on Windows, in particular when using the static run-time, the only guaranteed way to not intermittently crash on exit is to wait for all threads to terminate (see related review D70447). Doing so would enable this deadlock situation to occur.
lld/Common/ErrorHandler.cpp | ||
---|---|---|
66 | Yes, indeed that is another potential problem that exists and I believe that multiple threads calling _exit is also undefined behaviour. However, this change is really to protect against flushing the streams whilst some other thread could be writing to them. |
it does not seem that exitLld can be invoked concurrently.