-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deadlock in exit(0) (LLD) #21
Comments
Thanks for your interest. 😂 Would you please provide some more detailed information (backtrace of each thread for example, which can be obtained using a debugger)? |
I posted a comment on SF. The first problem didn't seem reproducible. |
The first problem manifests itself on vanilla MSys2 gcc only. |
Fair enough. I am trying to build LLD in MSYS now. |
How did you overcome these errors?
|
I never built all targets, usually I build X86 and NVPTX only, but to debug LLD on mingw, X86 only would be enough, thus simply add Something like this would be OK I believe: |
Also paths like |
I followed the instruction here.
It didn't help. The same errors took place. |
I suspect the culprit is wrong paths story under MSys shell. Usually I build things with simple batch files with (roughly) the following structure:
|
The path problem still exists. But this time it is the Unix-y path that is causing the problem:
|
Did you ever tried to use vanilla command prompt ( |
Yes, neither worked. Since I am using the MSYS2
|
Ah, I use native cmake (mingw or precompiled package from cmake.org), absolutely no problems with it. |
There is another error now:
|
... You just missed |
Btw, Perhaps, it would be possible to test |
Yes I have reproduced the problem:
Then it hangs. |
Btw, |
That is because |
I attached LLD with a modified version of mcfgthread that would trigger a breakpoint if Note that inside a DLL, all destructors of static objects are called by There should indeed be threads sleeping on the condition variable before Full backtrace:
|
Briefly, the following happened:
|
Possible workaround: If there are no other threads, don't call ... But how can we tell there are no other threads? |
Another thread called ExitThread(), terminating the previous thread while it was sleeping Don't quite understand this. Why the "previous" thread is terminated? Because it was created by "another" thread or what? |
See text following 'When handling DLL_PROCESS_DETACH' in https://msdn.microsoft.com/en-us/library/windows/desktop/ms682583(v=vs.85).aspx . |
Oops it was a typo. It was |
Removing From your explanations I've understood that the deadlock can happen only if sleeping threads are killed by |
Please double check this for sure. In the case of DLL such handlers are run from the entry point function ( |
I even tried to put my own exit handler into an LLD code, which simply printed something to the console, and it completed successfully before the deadlock. Thus we have no problems with either mingw-w64 or FILO order. |
Actually GCC uses |
Again, it is not possible to register a callback that can be called before the pool's dtor without modifying LLD' source, as it requires registering it after the pool's ctor (for example, inside the |
I am not ready to investigate this right now, but this looks extremely strange. How could |
The C standard doesn't care about dynamic libraries, but it is true on almost every platform where there are dynamic libraries. The reason is simple, too: If you load a dynamic library which registers some exit callbacks and then unload it, those callbacks must be run and removed before the virtual memory of the dynamic library is unmapped. If those callbacks were deferred to the time when you realy call |
Please test the new branch. If this is OK I will port it to both branches. |
Thank goodness I found the function |
Looks like it does the trick for me! Thanks! |
Merged to |
Thanks for sharing you solution. @lhmouse I think it's fixed as a bug, but I can't expect every PC is patched. |
And is there any page describes "RtlDllShutdownInProgress" ? It's hard to find discussion about this function |
Since I was just reading lld code, if you want to learn more about lld+exit https://reviews.llvm.org/D58246 |
@wwc7654321 No. If a thread calls @MaskRay |
If you want to see yet more related to LLD exit (using MSVC static run-time), check out my experimental patch here: https://reviews.llvm.org/D40366. I agree that detached threads are not good. |
Specifically on Windows, if threads are detached then it is not safe to call |
First thanks for your wonderful library.
Here is a bit of prehistory.
Still, while
LLD
built with yourgcc
successfully completes allparallel_for
s, it deadlocks atexit(0)
.The text was updated successfully, but these errors were encountered: