Skip to content

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 1 commit into from
Jan 12, 2022
Merged

Fix lsan test suite #15099

merged 1 commit into from
Jan 12, 2022

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Sep 22, 2021

After this change the entire lsan test suite now passes.

@sbc100 sbc100 force-pushed the lsan_fixes branch 5 times, most recently from 002c1af to bb31177 Compare September 29, 2021 01:52
@sbc100 sbc100 requested review from kripken and tlively and removed request for kripken September 29, 2021 01:53
With this change the entire `lsan` suite passes.
@sbc100
Copy link
Collaborator Author

sbc100 commented Jan 12, 2022

OK, this change is a lot simpler now, and IMHO ready to land.

@sbc100 sbc100 merged commit 4950482 into main Jan 12, 2022
@sbc100 sbc100 deleted the lsan_fixes branch January 12, 2022 17:25
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants