@@ -157,3 +157,111 @@ sh_test(
157157 },
158158 tags = ["manual" ],
159159)
160+
161+ # C++ compiler-rt builtins binary — exercises __int128 division to reference
162+ # the __divti3 symbol provided by libclang_rt.builtins.a (compiler-rt).
163+ # Build for aarch64:
164+ # bazel build //compile/test:test_compiler_rt --platforms=@toolchains_llvm//platforms:linux-aarch64
165+ # Build for x86_64:
166+ # bazel build //compile/test:test_compiler_rt --platforms=@toolchains_llvm//platforms:linux-x86_64
167+ cc_binary (
168+ name = "test_compiler_rt" ,
169+ srcs = ["test_compiler_rt.cc" ],
170+ copts = ["-Werror" ],
171+ )
172+
173+ # Cross-compilation compiler-rt tests.
174+ # These tests verify that the test_compiler_rt binary has libclang_rt.builtins.a
175+ # statically linked by checking for the defined __divti3 symbol (via llvm-nm)
176+ # and the absence of libgcc_s in dynamic NEEDED entries (via llvm-readelf).
177+ #
178+ # Run with:
179+ # bazel test //compile/test:cross_compile_aarch64_compiler_rt_test \
180+ # --platforms=@toolchains_llvm//platforms:linux-aarch64
181+ sh_test (
182+ name = "cross_compile_aarch64_compiler_rt_test" ,
183+ size = "small" ,
184+ srcs = ["check_compiler_rt.sh" ],
185+ data = [
186+ ":test_compiler_rt" ,
187+ "@llvm_toolchain_llvm//:nm" ,
188+ "@llvm_toolchain_llvm//:readelf" ,
189+ ],
190+ env = {
191+ "BINARY" : "$(rootpath :test_compiler_rt)" ,
192+ "EXPECT_COMPILER_RT" : "true" ,
193+ "EXPECTED_ARCH" : "AArch64" ,
194+ "LLVM_NM" : "$(rootpath @llvm_toolchain_llvm//:nm)" ,
195+ "LLVM_READELF" : "$(rootpath @llvm_toolchain_llvm//:readelf)" ,
196+ },
197+ tags = ["manual" ],
198+ )
199+
200+ # Run with:
201+ # bazel test //compile/test:cross_compile_x86_64_compiler_rt_test \
202+ # --platforms=@toolchains_llvm//platforms:linux-x86_64
203+ sh_test (
204+ name = "cross_compile_x86_64_compiler_rt_test" ,
205+ size = "small" ,
206+ srcs = ["check_compiler_rt.sh" ],
207+ data = [
208+ ":test_compiler_rt" ,
209+ "@llvm_toolchain_llvm//:nm" ,
210+ "@llvm_toolchain_llvm//:readelf" ,
211+ ],
212+ env = {
213+ "BINARY" : "$(rootpath :test_compiler_rt)" ,
214+ "EXPECT_COMPILER_RT" : "true" ,
215+ "EXPECTED_ARCH" : "X86-64" ,
216+ "LLVM_NM" : "$(rootpath @llvm_toolchain_llvm//:nm)" ,
217+ "LLVM_READELF" : "$(rootpath @llvm_toolchain_llvm//:readelf)" ,
218+ },
219+ tags = ["manual" ],
220+ )
221+
222+ # Negative compiler-rt tests — verify that compiler-rt builtins are NOT
223+ # statically linked when the flag is disabled. Run with:
224+ # bazel test //compile/test:cross_compile_aarch64_no_compiler_rt_test \
225+ # --platforms=@toolchains_llvm//platforms:linux-aarch64 \
226+ # --@toolchains_llvm//toolchain/config:compiler-rt=False
227+ sh_test (
228+ name = "cross_compile_aarch64_no_compiler_rt_test" ,
229+ size = "small" ,
230+ srcs = ["check_compiler_rt.sh" ],
231+ data = [
232+ ":test_compiler_rt" ,
233+ "@llvm_toolchain_llvm//:nm" ,
234+ "@llvm_toolchain_llvm//:readelf" ,
235+ ],
236+ env = {
237+ "BINARY" : "$(rootpath :test_compiler_rt)" ,
238+ "EXPECT_COMPILER_RT" : "false" ,
239+ "EXPECTED_ARCH" : "AArch64" ,
240+ "LLVM_NM" : "$(rootpath @llvm_toolchain_llvm//:nm)" ,
241+ "LLVM_READELF" : "$(rootpath @llvm_toolchain_llvm//:readelf)" ,
242+ },
243+ tags = ["manual" ],
244+ )
245+
246+ # Run with:
247+ # bazel test //compile/test:cross_compile_x86_64_no_compiler_rt_test \
248+ # --platforms=@toolchains_llvm//platforms:linux-x86_64 \
249+ # --@toolchains_llvm//toolchain/config:compiler-rt=False
250+ sh_test (
251+ name = "cross_compile_x86_64_no_compiler_rt_test" ,
252+ size = "small" ,
253+ srcs = ["check_compiler_rt.sh" ],
254+ data = [
255+ ":test_compiler_rt" ,
256+ "@llvm_toolchain_llvm//:nm" ,
257+ "@llvm_toolchain_llvm//:readelf" ,
258+ ],
259+ env = {
260+ "BINARY" : "$(rootpath :test_compiler_rt)" ,
261+ "EXPECT_COMPILER_RT" : "false" ,
262+ "EXPECTED_ARCH" : "X86-64" ,
263+ "LLVM_NM" : "$(rootpath @llvm_toolchain_llvm//:nm)" ,
264+ "LLVM_READELF" : "$(rootpath @llvm_toolchain_llvm//:readelf)" ,
265+ },
266+ tags = ["manual" ],
267+ )
0 commit comments