From 021e8dc6f09f2e77d368818ca8854e33063f2867 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 10 Oct 2024 10:27:25 -0700 Subject: [PATCH 1/3] Add Clang builtins for threads targets This change adds the `libclang_rt.builtins-wasm32.a` to the appropriate Clang directory for the threaded variants of the WASI targets (`lib/wasi-threads`, `lib/wasip1-threads`). This fixes #543. --- cmake/wasi-sdk-sysroot.cmake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/wasi-sdk-sysroot.cmake b/cmake/wasi-sdk-sysroot.cmake index 127ca62..7df4c73 100644 --- a/cmake/wasi-sdk-sysroot.cmake +++ b/cmake/wasi-sdk-sysroot.cmake @@ -93,10 +93,14 @@ add_custom_target(compiler-rt-post-build COMMAND ${CMAKE_COMMAND} -E copy_directory ${clang_resource_dir}/include ${wasi_resource_dir}/include - # Copy the `lib/wasi` folder to `libc/wasi{p1,p2}` to ensure that those - # OS-strings also work for looking up the compiler-rt.a file. + # Copy the `lib/wasi` folder to `libc/wasi{p1,p2}{-threads}?` to ensure that + # those OS-strings also work for looking up the compiler-rt.a file. + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${wasi_resource_dir}/lib/wasi ${wasi_resource_dir}/lib/wasi-threads COMMAND ${CMAKE_COMMAND} -E copy_directory ${wasi_resource_dir}/lib/wasi ${wasi_resource_dir}/lib/wasip1 + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${wasi_resource_dir}/lib/wasi ${wasi_resource_dir}/lib/wasip1-threads COMMAND ${CMAKE_COMMAND} -E copy_directory ${wasi_resource_dir}/lib/wasi ${wasi_resource_dir}/lib/wasip2 From 38ae65b565bea8be73a310109642cc14f8e0ba52 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 17 Oct 2024 10:03:18 -0700 Subject: [PATCH 2/3] Add test using a compiler builtin This uses the `__floatditf` function which was reported as an issue in [wasi-libc#543]. Compiling and running this test should prove that the builtins are available in the `wasm32-*-threads` targets as long as the tests use those targets (they do, right?). [wasi-libc#543]: https://github.com/WebAssembly/wasi-libc/issues/543 --- tests/general/builtin-floatditf.c | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/general/builtin-floatditf.c diff --git a/tests/general/builtin-floatditf.c b/tests/general/builtin-floatditf.c new file mode 100644 index 0000000..afbf06d --- /dev/null +++ b/tests/general/builtin-floatditf.c @@ -0,0 +1,10 @@ +// Primarily check that `libclang_rt.builtins-wasm32.a` functions are present +// and work as expected on all tested targets, not the builtin functionality. + +#include + +int main() { + tf_float f = __floatditf(0); + assert(f == 0.0); + return 0; +} From 24a7308c87666fc2ad361e482f472951b0a8e1ad Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 17 Oct 2024 17:05:50 -0700 Subject: [PATCH 3/3] Switch test to use `__floatdidf` The `__floatdidf` builtin uses a more conventional type--`double`--which means we don't have to guess at the representation of `tf_float`. --- tests/general/{builtin-floatditf.c => builtin-floatdidf.c} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/general/{builtin-floatditf.c => builtin-floatdidf.c} (87%) diff --git a/tests/general/builtin-floatditf.c b/tests/general/builtin-floatdidf.c similarity index 87% rename from tests/general/builtin-floatditf.c rename to tests/general/builtin-floatdidf.c index afbf06d..ddfd5c9 100644 --- a/tests/general/builtin-floatditf.c +++ b/tests/general/builtin-floatdidf.c @@ -4,7 +4,7 @@ #include int main() { - tf_float f = __floatditf(0); + double f = __floatdidf(0); assert(f == 0.0); return 0; }