Update compiler-rt to LLVM 17.0.4#20708
Merged
Merged
Conversation
`crtbegin.c` and `crtend.c` were originally in `compiler-rt/lib/crt`, the directory we don't maintain, and moved to `compiler-rt/lib/builtins` recently. So they were included in the `excludes` list.
This was introduced in llvm/llvm-project@0a71e25, which makes Wasm backend error out.
- lsan_common_emscripten.cpp: Function name changes - lsan_common.cpp: The function structure has changed. Previously we had separate `ProcessRootRegion` and `ProcessRootRegions`, and Emscripten modified `ProcessRootRegion`. But in LLVM 17 `ProcessRootRegion` was deleted and merged into `ProcessRootRegions`. This fixes the code according to the new semantics.
These interceptors was added in LLVM 17, but it looks they have a wrong return type. I submitted llvm/llvm-project#71253 to fix that upstream, but in the meantime we should fix this to pass our tests.
We need these after `pthread_exit` LSan interceptor was added in llvm/llvm-project@da7943b.
`__sanitizer::internal_mprotect` symbol produces a link-time error in `MprotectReadWrite`, which was added in LLVM 17. While I am not very familiar with this part of the code, it looks we're already avoiding running it like these in the same file: https://github.com/emscripten-core/emscripten/blob/8ecbdb3fc694f659aadb85a00d80777b20477281/system/lib/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp#L148-L152 https://github.com/emscripten-core/emscripten/blob/8ecbdb3fc694f659aadb85a00d80777b20477281/system/lib/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp#L156-L160 This does the same thing for `MprotectReadWrite`.
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.
Member
Author
|
Ping 😀 |
sbc100
approved these changes
Nov 16, 2023
| ENSURE_LSAN_INITED; | ||
| EnsureMainThreadIDIsCorrect(); | ||
|
|
||
| #if !SANITIZER_EMSCRIPTEN |
Collaborator
There was a problem hiding this comment.
I wonder if could just have a single if at the top of this function?
#if !SANITIZER_EMSCRIPTEN
// Treat __ATTRP_C11_THREAD like the null attr
if (attr == __ATTRP_C11_THREAD) attr = nullptr;
#endif
Member
Author
There was a problem hiding this comment.
That's a good idea. Btw you meant #if SANITIZER_EMSCRIPTEN (without !), right?
Collaborator
|
Oh, I forgot to say we should add something to the ChangeLog for this (and the libc++ change). |
Member
Author
Done in #20736 |
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
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.
On top of the main library code changes, each fix that was necessary for Emscripten was committed separately with its own commit message.