-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Update libraries to LLVM 17.0.2 #20405
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
This updates compiler-rt, libcxx, libcxxabi, and libunwind to LLVM 17.0.2 (https://github.com/llvm/llvm-project/tree/llvmorg-17.0.2).
Awesome! Did you already push the latest local change to the emscripten-libs-16 branch? |
I can. Do I do that just by committing or creating a PR? By the way I did the squashing you recommended ( And I found I can't create a PR for new branch, which is |
Sounds good. Can you send a PR to the |
Done here: emscripten-core/llvm-project#7 |
Updating the 16 branch should just be question of commiting the result of the llvm_push_change.py script. |
PSTL was integrated in libc++ recently and we have to choose one out of three PSTL modes in many places, one of them being https://github.com/llvm/llvm-project/blob/373c343a77a7afaa07179db1754a52b620dfaf2e/libcxx/include/__algorithm/pstl_backends/cpu_backends/backend.h#L15-L23. This is supposed to set in `__config_site`, which is supposed to be generated from https://github.com/llvm/llvm-project/blob/main/libcxx/include/__config_site.in#L33-L36 from https://github.com/llvm/llvm-project/blob/main/libcxx/CMakeLists.txt. Given that we don't use CMake system in Emscripten, we need to hard-code this in this file. Note that this cannot be solved by just adding `-D_LIBCPP_PSTL_CPU_BACKEND_SERIAL` in `libcxx`'s `system_lib.py` flags, because this is needed in header files that are included in user code as well.
compiler-rt's `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. libcxx's `libdispatch.cpp` is related to PSTL's `LIBDISPATCH` mode, whatever that is, which doesn't seem to be necessary for us.
This was introduced in llvm/llvm-project@0a71e25, which makes Wasm backend error out.
Given that I started emscripten-core/emscripten#20405 and OOO for nearly a month and then in the meantime llvm 17.0.4 came out, I'd like to update to not 17.0.3 but 17.0.4, with the most recent downstream changes. These are the downstream changes happened during the last month.
`__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`.
Fixing the declaration added in d3e2c95. The return type should be void.
Given that I started emscripten-core/emscripten#20405 and OOO for nearly a month and then in the meantime llvm 17.0.4 came out, I'd like to update to not 17.0.3 but 17.0.4, with the most recent downstream changes. These are the downstream changes happened during the last month.
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.
Without these `lsan.test_pthread_dylink_main_module_1` fails with an undefined symbol error for `emscripten_builtin_pthread_exit`.
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.
The wasm code size in `other.test_minimal_runtime_code_Size_hello_embind_val` increased by 50% in LLVM 17 lib update, and the reason was because `__throw_***` functions in `libcxx/include/stdexcept` started using `_LIBCPP_VERBOSE_ABORT` in non-exception mode: https://github.com/llvm/llvm-project/blob/beb121f6322be466384ffaa68b913f58862ed14c/libc xx/include/stdexcept#L228-L305 Note that they used to just call abort() until LLVM 16: https://github.com/llvm/llvm-project/blob/7cbf1a2591520c2491aa35339f227775f4d3adf6/libc xx/include/stdexcept#L231-L305 And that _LIBCPP_VERBOSE_ABORT calls this: https://github.com/llvm/llvm-project/blob/beb121f6322be466384ffaa68b913f58862ed14c/libc xx/src/verbose_abort.cpp#L31-L75 which calls vfprintf and all that jazz, increasing code size a lot. So at the moment we define `_LIBCPP_AVAILABILITY_HAS_NO_VERBOSE_ABORT` so that we don't use the new verbose version of printing.
This represents +0.04% for wasm, which I think can be considered as misc. implementation changes.
This updates compiler-rt, libcxx, libcxxabi, and libunwind to LLVM 17.0.2 (https://github.com/llvm/llvm-project/tree/llvmorg-17.0.2).