[compiler-rt] [compiler-rt][wasm] Compile atomic.c with atomics and bulk-memory features (PR #89049)
Yuta Saito via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 17 04:20:05 PDT 2024
https://github.com/kateinoigakukun created https://github.com/llvm/llvm-project/pull/89049
The bulitin object file for `atomic.c` is only referenced by user code when the atomics and bulk-memory features are enabled and libcall is required. However, the atomic.c itself was compiled without those features and it leads to a linker error because all objects have to have the feature when `--shared-memory` is enabled.
This patch compiles `atomic.c` with the atomics and bulk-memory features enabled.
This unlocks atomics with larger types than 64bit on WebAssembly.
>From e48f5c9e5a037c11cdd9bbe0e5c394d42f7bd82e Mon Sep 17 00:00:00 2001
From: Yuta Saito <kateinoigakukun at gmail.com>
Date: Sun, 14 Apr 2024 16:48:59 +0000
Subject: [PATCH] [compiler-rt][wasm] Compile atomic.c with atomics and
bulk-memory features
The bulitin object file for atomic.c is only referenced by user code
when the atomics and bulk-memory features are enabled and libcall is
required. However, the atomic.c itself was compiled without those
features and it leads to a linker error because all objects have to have
the feature when `--shared-memory` is enabled.
This patch compiles atomic.c with the atomics and bulk-memory features
enabled.
---
compiler-rt/lib/builtins/CMakeLists.txt | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index f9611574a562b4..f7ec04f246c149 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -854,11 +854,30 @@ else ()
list(APPEND BUILTIN_CFLAGS_${arch} -fforce-enable-int128)
endif()
+ set(BUILTIN_OBJECT_LIBS_${arch})
+ # For WebAssembly, we need to compile the atomic.c with different flags than the rest
+ # to enable atomics and bulk-memory features only for the object file.
+ if((arch STREQUAL "wasm32" OR arch STREQUAL "wasm64") AND "atomic.c" IN_LIST ${arch}_SOURCES)
+ set(BUILTIN_ATOMIC_CFLAGS_${arch} ${BUILTIN_CFLAGS_${arch}})
+ list(APPEND BUILTIN_ATOMIC_CFLAGS_${arch} -matomics -mbulk-memory)
+ add_compiler_rt_object_libraries(clang_rt.builtins.${arch}.atomic
+ ARCHS ${arch}
+ DEPS ${deps_${arch}}
+ SOURCES atomic.c
+ DEFS ${BUILTIN_DEFS}
+ CFLAGS ${BUILTIN_ATOMIC_CFLAGS_${arch}})
+ # Include the atomic object file in the builtins archive
+ list(APPEND BUILTIN_OBJECT_LIBS_${arch} clang_rt.builtins.${arch}.atomic)
+ # Remove atomic.c from the main list of sources
+ list(REMOVE_ITEM ${arch}_SOURCES atomic.c)
+ endif()
+
add_compiler_rt_runtime(clang_rt.builtins
STATIC
ARCHS ${arch}
DEPS ${deps_${arch}}
SOURCES ${${arch}_SOURCES}
+ OBJECT_LIBS ${BUILTIN_OBJECT_LIBS_${arch}}
DEFS ${BUILTIN_DEFS}
CFLAGS ${BUILTIN_CFLAGS_${arch}}
PARENT_TARGET builtins)
More information about the llvm-commits
mailing list