-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Remove special case JS function proxying from library_pthread.c #14912
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
Conversation
45f4468
to
de7c458
Compare
The normal `__proxy` method for JS functions works fine in these cases and avoiding the special cases reduces the dependies of `library_pthread.c` which is included in all threaded programs.
de7c458
to
518c8f9
Compare
Why call the builtin_malloc directly and not malloc? Doing that prevents people from providing their own malloc wrappers/implementations? |
The the Maybe we could provide default aliases that are used when the santizers are not enabled, that way folks would only need to include them in their custom allocator if they also want to use the santizers? |
Hmm, it looks like there has been an overloaded meaning added to the Originally those This way end users could implement However when asan & lsan support was added, it looks like they have "stolen" this use case from the user, and now Though even with this mutated meaning, it is not obvious to me why these calls would want to bypass asan&lsan? These all look like general memory allocation that would benefit from being taken through memory sanitizers as well? |
Isn't asan using the |
I think these two comments (one from compiler-rt and one from our code) describe why we don't/can't detect leaks in the low level pthread code: emscripten/system/lib/compiler-rt/lib/asan/asan_interceptors.cpp Lines 215 to 224 in 9a644e1
emscripten/system/lib/pthread/library_pthread.c Lines 162 to 171 in 9a644e1
|
Yes it is, but by doing that, it prevents the user from doing that. So asan & lsan are incompatible with users wrapping.
We can work around that problem by saying "asan/lsan" is not available for codebases that wrap to malloc/free on their own. But the bigger problem that results from this is that all these call sites that bypass regular calls to malloc/free to appease asan/lsan now also bypass calls to user-provided malloc & free. As result, it means that user-provided malloc & free cannot be wrapped when building with multithreading enabled, even if asan/lsan are disabled.
Hmm, I am not sure I understand the comments in those blocks. It seems that they are describing a cleanup issue rather than a tracking issue(?) E.g. since the worker lingers around in a pool, it might keep the thread stack alive? Although that sounds like a bug - the pthread stack should really be freed when a pthread quits, even if the worker is kept alive in the pool. |
I don't fully understand the details either but it seems clear the asan/lsan are not expecting to be able to track memory leaks that occur within pthread_create itself. Its also the case the emscripten already goes to some lengths to avoid this too. See the existing code we have today in emscripten: emscripten/system/lib/pthread/library_pthread.c Lines 162 to 176 in 28ca7fb
I don't think this PR is ready to land yet at least now without more research... |
I don't think its true that it prevents wrapping. What it means is that the wrapper interceptors won't see those particular allocations. Wrapping is still possible, and all the normal allocations/frees will still go through the wrappers. |
As an alternative, if you think its worth it, we could invent a new wrapping mechanism specifically for the sanitizers. But I think this would make wrapping more complicated. |
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant. |
The normal
__proxy
method for JS functions works fine in these casesand avoiding the special cases reduces the dependies of
library_pthread.c
which is included in all threaded programs.