-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix lsan
test suite
#15099
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
Merged
Merged
Fix lsan
test suite
#15099
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
002c1af
to
bb31177
Compare
kripken
reviewed
Sep 29, 2021
With this change the entire `lsan` suite passes.
OK, this change is a lot simpler now, and IMHO ready to land. |
tlively
approved these changes
Jan 12, 2022
aheejin
added a commit
to aheejin/emscripten
that referenced
this pull request
Nov 8, 2023
In LLVM 16, in `pthread_create` LSan interceptor, if `attr` is NULL, it calls `pthread_attr_init` and initializes the `attr` with it, and then calls `pthread_attr_getdetachstate`: https://github.com/llvm/llvm-project/blob/7cbf1a2591520c2491aa35339f227775f4d3adf6/compiler-rt/lib/lsan/lsan_interceptors.cpp#L450-L456 In Emscripten, emscripten-core#15099 changes the `if` condition so that even if `attr` is not NULL, if it is `__ATTRP_C11_THREAD`, we call `pthread_attr_init`. `__ATTRP_C11_THREAD` looks like something used from musl, and is defined as -1. https://github.com/emscripten-core/emscripten/blob/5ce75b8828e3f50494c956d42f2bac301e41253b/system/lib/compiler-rt/lib/lsan/lsan_interceptors.cpp#L465 In LLVM 17, somehow the order of the `pthread_attr_init` and `pthread_attr_getdetachstate` has swapped: https://github.com/llvm/llvm-project/blob/309d55140c46384b6de7a7573206cbeba3f7077f/compiler-rt/lib/lsan/lsan_interceptors.cpp#L444-L453 So we don't get to call `pthread_attr_init` before calling `pthread_attr_getdetachstate`. Even if the new code calls `pthread_attr_getdetachstate` only when `attr` is not NULL, in our case it didn't help because our `attr` was not NULL but `__ATTRP_C11_THREAD`. This swaps the code order back to what it was in LLVM 16.
aheejin
added a commit
to aheejin/emscripten
that referenced
this pull request
Nov 14, 2023
In LLVM 16, in `pthread_create` LSan interceptor, if `attr` is NULL, it calls `pthread_attr_init` and initializes the `attr` with it, and then calls `pthread_attr_getdetachstate`: https://github.com/llvm/llvm-project/blob/7cbf1a2591520c2491aa35339f227775f4d3adf6/compiler-rt/lib/lsan/lsan_interceptors.cpp#L450-L456 In Emscripten, emscripten-core#15099 changes the `if` condition so that even if `attr` is not NULL, if it is `__ATTRP_C11_THREAD`, we call `pthread_attr_init`. `__ATTRP_C11_THREAD` looks like something used from musl, and is defined as -1. https://github.com/emscripten-core/emscripten/blob/5ce75b8828e3f50494c956d42f2bac301e41253b/system/lib/compiler-rt/lib/lsan/lsan_interceptors.cpp#L465 In LLVM 17, somehow the order of the `pthread_attr_init` and `pthread_attr_getdetachstate` has swapped: https://github.com/llvm/llvm-project/blob/309d55140c46384b6de7a7573206cbeba3f7077f/compiler-rt/lib/lsan/lsan_interceptors.cpp#L444-L453 So we don't get to call `pthread_attr_init` before calling `pthread_attr_getdetachstate`. Even if the new code calls `pthread_attr_getdetachstate` only when `attr` is not NULL, in our case it didn't help because our `attr` was not NULL but `__ATTRP_C11_THREAD`. This swaps the code order back to what it was in LLVM 16. This is necessary to pass `lsan.test_pthread_c11_threads*`. Drive-by fix: This also guards `if (!attr || attr == __ATTRP_C11_THREAD)` condition with `SANITIZER_EMSCRIPTEN`, which was an Emscripten-specific fix added before.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After this change the entire
lsan
test suite now passes.