]> git.proxmox.com Git - rustc.git/blame - src/libcompiler_builtins/compiler-rt/lib/builtins/CMakeLists.txt
New upstream version 1.25.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / lib / builtins / CMakeLists.txt
CommitLineData
1a4d82fc
JJ
1# This directory contains a large amount of C code which provides
2# generic implementations of the core runtime library along with optimized
3# architecture-specific code in various subdirectories.
4
5bcae85e
SL
5if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
6 cmake_minimum_required(VERSION 3.4.3)
7
8 project(CompilerRTBuiltins C ASM)
9 set(COMPILER_RT_STANDALONE_BUILD TRUE)
10 set(COMPILER_RT_BUILTINS_STANDALONE_BUILD TRUE)
11 list(INSERT CMAKE_MODULE_PATH 0
12 "${CMAKE_SOURCE_DIR}/../../cmake"
13 "${CMAKE_SOURCE_DIR}/../../cmake/Modules")
14 include(base-config-ix)
15 include(CompilerRTUtils)
7cac9316
XL
16
17 load_llvm_config()
18 construct_compiler_rt_default_triple()
19
5bcae85e
SL
20 if(APPLE)
21 include(CompilerRTDarwinUtils)
22 endif()
23 include(AddCompilerRT)
24endif()
25
26include(builtin-config-ix)
27
3157f602
XL
28# TODO: Need to add a mechanism for logging errors when builtin source files are
29# added to a sub-directory and not this CMakeLists file.
1a4d82fc
JJ
30set(GENERIC_SOURCES
31 absvdi2.c
32 absvsi2.c
33 absvti2.c
34 adddf3.c
35 addsf3.c
92a42be0 36 addtf3.c
1a4d82fc
JJ
37 addvdi3.c
38 addvsi3.c
39 addvti3.c
40 apple_versioning.c
41 ashldi3.c
42 ashlti3.c
43 ashrdi3.c
44 ashrti3.c
2c00a5a8
XL
45 bswapdi2.c
46 bswapsi2.c
1a4d82fc
JJ
47 clzdi2.c
48 clzsi2.c
49 clzti2.c
50 cmpdi2.c
51 cmpti2.c
52 comparedf2.c
53 comparesf2.c
54 ctzdi2.c
55 ctzsi2.c
56 ctzti2.c
57 divdc3.c
58 divdf3.c
59 divdi3.c
60 divmoddi4.c
61 divmodsi4.c
62 divsc3.c
63 divsf3.c
64 divsi3.c
5bcae85e 65 divtc3.c
1a4d82fc 66 divti3.c
92a42be0 67 divtf3.c
1a4d82fc 68 extendsfdf2.c
92a42be0 69 extendhfsf2.c
1a4d82fc 70 ffsdi2.c
2c00a5a8 71 ffssi2.c
1a4d82fc
JJ
72 ffsti2.c
73 fixdfdi.c
74 fixdfsi.c
75 fixdfti.c
76 fixsfdi.c
77 fixsfsi.c
78 fixsfti.c
79 fixunsdfdi.c
80 fixunsdfsi.c
81 fixunsdfti.c
82 fixunssfdi.c
83 fixunssfsi.c
84 fixunssfti.c
1a4d82fc
JJ
85 floatdidf.c
86 floatdisf.c
1a4d82fc
JJ
87 floatsidf.c
88 floatsisf.c
89 floattidf.c
90 floattisf.c
1a4d82fc
JJ
91 floatundidf.c
92 floatundisf.c
1a4d82fc
JJ
93 floatunsidf.c
94 floatunsisf.c
95 floatuntidf.c
96 floatuntisf.c
1a4d82fc
JJ
97 int_util.c
98 lshrdi3.c
99 lshrti3.c
100 moddi3.c
101 modsi3.c
102 modti3.c
103 muldc3.c
104 muldf3.c
105 muldi3.c
106 mulodi4.c
107 mulosi4.c
108 muloti4.c
109 mulsc3.c
110 mulsf3.c
111 multi3.c
92a42be0 112 multf3.c
1a4d82fc
JJ
113 mulvdi3.c
114 mulvsi3.c
115 mulvti3.c
1a4d82fc
JJ
116 negdf2.c
117 negdi2.c
118 negsf2.c
119 negti2.c
120 negvdi2.c
121 negvsi2.c
122 negvti2.c
2c00a5a8 123 os_version_check.c
1a4d82fc
JJ
124 paritydi2.c
125 paritysi2.c
126 parityti2.c
127 popcountdi2.c
128 popcountsi2.c
129 popcountti2.c
130 powidf2.c
131 powisf2.c
132 powitf2.c
1a4d82fc
JJ
133 subdf3.c
134 subsf3.c
135 subvdi3.c
136 subvsi3.c
137 subvti3.c
92a42be0 138 subtf3.c
1a4d82fc 139 trampoline_setup.c
92a42be0 140 truncdfhf2.c
1a4d82fc 141 truncdfsf2.c
92a42be0 142 truncsfhf2.c
1a4d82fc
JJ
143 ucmpdi2.c
144 ucmpti2.c
145 udivdi3.c
146 udivmoddi4.c
147 udivmodsi4.c
148 udivmodti4.c
149 udivsi3.c
150 udivti3.c
151 umoddi3.c
152 umodsi3.c
153 umodti3.c)
154
2c00a5a8
XL
155set(GENERIC_TF_SOURCES
156 comparetf2.c
157 extenddftf2.c
158 extendsftf2.c
159 fixtfdi.c
160 fixtfsi.c
161 fixtfti.c
162 fixunstfdi.c
163 fixunstfsi.c
164 fixunstfti.c
165 floatditf.c
166 floatsitf.c
167 floattitf.c
168 floatunditf.c
169 floatunsitf.c
170 floatuntitf.c
171 multc3.c
172 trunctfdf2.c
173 trunctfsf2.c)
174
7cac9316
XL
175option(COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN
176 "Skip the atomic builtin (this may be needed if system headers are unavailable)"
177 Off)
178
2c00a5a8
XL
179if(NOT FUCHSIA AND NOT COMPILER_RT_BAREMETAL_BUILD)
180 set(GENERIC_SOURCES
181 ${GENERIC_SOURCES}
182 emutls.c
183 enable_execute_stack.c
184 eprintf.c)
185endif()
186
7cac9316
XL
187if(COMPILER_RT_HAS_ATOMIC_KEYWORD AND NOT COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN)
188 set(GENERIC_SOURCES
189 ${GENERIC_SOURCES}
190 atomic.c)
191endif()
192
92a42be0
SL
193if(APPLE)
194 set(GENERIC_SOURCES
195 ${GENERIC_SOURCES}
196 atomic_flag_clear.c
197 atomic_flag_clear_explicit.c
198 atomic_flag_test_and_set.c
199 atomic_flag_test_and_set_explicit.c
200 atomic_signal_fence.c
201 atomic_thread_fence.c)
202endif()
1a4d82fc 203
92a42be0
SL
204if (HAVE_UNWIND_H)
205 set(GENERIC_SOURCES
206 ${GENERIC_SOURCES}
207 gcc_personality_v0.c)
208endif ()
209
2c00a5a8
XL
210if (NOT FUCHSIA)
211 set(GENERIC_SOURCES
212 ${GENERIC_SOURCES}
213 clear_cache.c)
214endif()
215
216# These sources work on all x86 variants, but only x86 variants.
217set(x86_ARCH_SOURCES
218 cpu_model.c
219 divxc3.c
220 fixxfdi.c
221 fixxfti.c
222 fixunsxfdi.c
223 fixunsxfsi.c
224 fixunsxfti.c
225 floatdixf.c
226 floattixf.c
227 floatundixf.c
228 floatuntixf.c
229 mulxc3.c
230 powixf2.c
231)
232
92a42be0
SL
233if (NOT MSVC)
234 set(x86_64_SOURCES
235 x86_64/floatdidf.c
236 x86_64/floatdisf.c
237 x86_64/floatdixf.c
238 x86_64/floatundidf.S
239 x86_64/floatundisf.S
2c00a5a8
XL
240 x86_64/floatundixf.S)
241 filter_builtin_sources(x86_64_SOURCES EXCLUDE x86_64_SOURCES "${x86_64_SOURCES};${GENERIC_SOURCES}")
92a42be0
SL
242 set(x86_64h_SOURCES ${x86_64_SOURCES})
243
244 if (WIN32)
245 set(x86_64_SOURCES
246 ${x86_64_SOURCES}
247 x86_64/chkstk.S
248 x86_64/chkstk2.S)
249 endif()
250
251 set(i386_SOURCES
252 i386/ashldi3.S
253 i386/ashrdi3.S
254 i386/divdi3.S
255 i386/floatdidf.S
256 i386/floatdisf.S
257 i386/floatdixf.S
258 i386/floatundidf.S
259 i386/floatundisf.S
260 i386/floatundixf.S
261 i386/lshrdi3.S
262 i386/moddi3.S
263 i386/muldi3.S
264 i386/udivdi3.S
2c00a5a8
XL
265 i386/umoddi3.S)
266 filter_builtin_sources(i386_SOURCES EXCLUDE i386_SOURCES "${i386_SOURCES};${GENERIC_SOURCES}")
92a42be0
SL
267
268 if (WIN32)
269 set(i386_SOURCES
270 ${i386_SOURCES}
271 i386/chkstk.S
272 i386/chkstk2.S)
273 endif()
92a42be0
SL
274else () # MSVC
275 # Use C versions of functions when building on MSVC
5bcae85e
SL
276 # MSVC's assembler takes Intel syntax, not AT&T syntax.
277 # Also use only MSVC compilable builtin implementations.
92a42be0
SL
278 set(x86_64_SOURCES
279 x86_64/floatdidf.c
280 x86_64/floatdisf.c
281 x86_64/floatdixf.c
2c00a5a8 282 ${GENERIC_SOURCES})
92a42be0 283 set(x86_64h_SOURCES ${x86_64_SOURCES})
2c00a5a8 284 set(i386_SOURCES ${GENERIC_SOURCES})
92a42be0 285endif () # if (NOT MSVC)
1a4d82fc 286
2c00a5a8
XL
287set(x86_64h_SOURCES ${x86_64h_SOURCES} ${x86_ARCH_SOURCES})
288set(x86_64_SOURCES ${x86_64_SOURCES} ${x86_ARCH_SOURCES})
289set(i386_SOURCES ${i386_SOURCES} ${x86_ARCH_SOURCES})
290set(i686_SOURCES ${i686_SOURCES} ${x86_ARCH_SOURCES})
291
5bcae85e 292set(arm_SOURCES
7cac9316
XL
293 arm/bswapdi2.S
294 arm/bswapsi2.S
295 arm/clzdi2.S
296 arm/clzsi2.S
297 arm/comparesf2.S
298 arm/divmodsi4.S
299 arm/divsi3.S
300 arm/modsi3.S
301 arm/sync_fetch_and_add_4.S
302 arm/sync_fetch_and_add_8.S
303 arm/sync_fetch_and_and_4.S
304 arm/sync_fetch_and_and_8.S
305 arm/sync_fetch_and_max_4.S
306 arm/sync_fetch_and_max_8.S
307 arm/sync_fetch_and_min_4.S
308 arm/sync_fetch_and_min_8.S
309 arm/sync_fetch_and_nand_4.S
310 arm/sync_fetch_and_nand_8.S
311 arm/sync_fetch_and_or_4.S
312 arm/sync_fetch_and_or_8.S
313 arm/sync_fetch_and_sub_4.S
314 arm/sync_fetch_and_sub_8.S
315 arm/sync_fetch_and_umax_4.S
316 arm/sync_fetch_and_umax_8.S
317 arm/sync_fetch_and_umin_4.S
318 arm/sync_fetch_and_umin_8.S
319 arm/sync_fetch_and_xor_4.S
320 arm/sync_fetch_and_xor_8.S
321 arm/udivmodsi4.S
322 arm/udivsi3.S
2c00a5a8
XL
323 arm/umodsi3.S)
324filter_builtin_sources(arm_SOURCES EXCLUDE arm_SOURCES "${arm_SOURCES};${GENERIC_SOURCES}")
325
326set(thumb1_SOURCES
327 arm/divsi3.S
328 arm/udivsi3.S
329 arm/comparesf2.S
330 arm/addsf3.S
7cac9316
XL
331 ${GENERIC_SOURCES})
332
333set(arm_EABI_SOURCES
92a42be0
SL
334 arm/aeabi_cdcmp.S
335 arm/aeabi_cdcmpeq_check_nan.c
336 arm/aeabi_cfcmp.S
337 arm/aeabi_cfcmpeq_check_nan.c
1a4d82fc 338 arm/aeabi_dcmp.S
92a42be0
SL
339 arm/aeabi_div0.c
340 arm/aeabi_drsub.c
1a4d82fc 341 arm/aeabi_fcmp.S
92a42be0 342 arm/aeabi_frsub.c
1a4d82fc
JJ
343 arm/aeabi_idivmod.S
344 arm/aeabi_ldivmod.S
345 arm/aeabi_memcmp.S
346 arm/aeabi_memcpy.S
347 arm/aeabi_memmove.S
348 arm/aeabi_memset.S
349 arm/aeabi_uidivmod.S
7cac9316 350 arm/aeabi_uldivmod.S)
2c00a5a8 351
7cac9316
XL
352set(arm_Thumb1_JT_SOURCES
353 arm/switch16.S
354 arm/switch32.S
355 arm/switch8.S
356 arm/switchu8.S)
357set(arm_Thumb1_SjLj_EH_SOURCES
358 arm/restore_vfp_d8_d15_regs.S
359 arm/save_vfp_d8_d15_regs.S)
360set(arm_Thumb1_VFPv2_SOURCES
361 arm/adddf3vfp.S
362 arm/addsf3vfp.S
54a0048b
SL
363 arm/divdf3vfp.S
364 arm/divsf3vfp.S
365 arm/eqdf2vfp.S
366 arm/eqsf2vfp.S
367 arm/extendsfdf2vfp.S
368 arm/fixdfsivfp.S
369 arm/fixsfsivfp.S
370 arm/fixunsdfsivfp.S
371 arm/fixunssfsivfp.S
372 arm/floatsidfvfp.S
373 arm/floatsisfvfp.S
374 arm/floatunssidfvfp.S
375 arm/floatunssisfvfp.S
376 arm/gedf2vfp.S
377 arm/gesf2vfp.S
378 arm/gtdf2vfp.S
379 arm/gtsf2vfp.S
380 arm/ledf2vfp.S
381 arm/lesf2vfp.S
382 arm/ltdf2vfp.S
383 arm/ltsf2vfp.S
384 arm/muldf3vfp.S
385 arm/mulsf3vfp.S
5bcae85e 386 arm/nedf2vfp.S
3157f602
XL
387 arm/negdf2vfp.S
388 arm/negsf2vfp.S
54a0048b 389 arm/nesf2vfp.S
54a0048b
SL
390 arm/subdf3vfp.S
391 arm/subsf3vfp.S
392 arm/truncdfsf2vfp.S
393 arm/unorddf2vfp.S
7cac9316
XL
394 arm/unordsf2vfp.S)
395set(arm_Thumb1_icache_SOURCES
396 arm/sync_synchronize.S)
397set(arm_Thumb1_SOURCES
398 ${arm_Thumb1_JT_SOURCES}
399 ${arm_Thumb1_SjLj_EH_SOURCES}
400 ${arm_Thumb1_VFPv2_SOURCES}
401 ${arm_Thumb1_icache_SOURCES})
402
403if(MINGW)
404 set(arm_SOURCES
405 arm/aeabi_idivmod.S
406 arm/aeabi_ldivmod.S
407 arm/aeabi_uidivmod.S
408 arm/aeabi_uldivmod.S
409 divmoddi4.c
410 divmodsi4.c
411 divdi3.c
412 divsi3.c
413 fixdfdi.c
414 fixsfdi.c
415 fixunsdfdi.c
416 fixunssfdi.c
417 floatdidf.c
418 floatdisf.c
419 floatundidf.c
420 floatundisf.c
421 mingw_fixfloat.c
422 moddi3.c
423 udivmoddi4.c
424 udivmodsi4.c
425 udivsi3.c
2c00a5a8
XL
426 umoddi3.c
427 emutls.c)
428 filter_builtin_sources(arm_SOURCES EXCLUDE arm_SOURCES "${arm_SOURCES};${GENERIC_SOURCES}")
7cac9316
XL
429elseif(NOT WIN32)
430 # TODO the EABI sources should only be added to EABI targets
431 set(arm_SOURCES
432 ${arm_SOURCES}
433 ${arm_EABI_SOURCES}
434 ${arm_Thumb1_SOURCES})
2c00a5a8
XL
435
436 set(thumb1_SOURCES
437 ${thumb1_SOURCES}
438 ${arm_EABI_SOURCES})
7cac9316 439endif()
3157f602 440
5bcae85e 441set(aarch64_SOURCES
2c00a5a8 442 ${GENERIC_TF_SOURCES}
5bcae85e
SL
443 ${GENERIC_SOURCES})
444
2c00a5a8
XL
445if (MINGW)
446 set(aarch64_SOURCES
447 ${aarch64_SOURCES}
448 aarch64/chkstk.S)
449endif()
450
5bcae85e
SL
451set(armhf_SOURCES ${arm_SOURCES})
452set(armv7_SOURCES ${arm_SOURCES})
453set(armv7s_SOURCES ${arm_SOURCES})
454set(armv7k_SOURCES ${arm_SOURCES})
92a42be0
SL
455set(arm64_SOURCES ${aarch64_SOURCES})
456
457# macho_embedded archs
2c00a5a8 458set(armv6m_SOURCES ${thumb1_SOURCES})
5bcae85e
SL
459set(armv7m_SOURCES ${arm_SOURCES})
460set(armv7em_SOURCES ${arm_SOURCES})
92a42be0
SL
461
462set(mips_SOURCES ${GENERIC_SOURCES})
463set(mipsel_SOURCES ${mips_SOURCES})
2c00a5a8
XL
464set(mips64_SOURCES ${GENERIC_TF_SOURCES}
465 ${mips_SOURCES})
466set(mips64el_SOURCES ${GENERIC_TF_SOURCES}
467 ${mips_SOURCES})
468
469set(powerpc64_SOURCES
470 ppc/divtc3.c
471 ppc/fixtfdi.c
472 ppc/fixunstfdi.c
473 ppc/floatditf.c
474 ppc/floatunditf.c
475 ppc/gcc_qadd.c
476 ppc/gcc_qdiv.c
477 ppc/gcc_qmul.c
478 ppc/gcc_qsub.c
479 ppc/multc3.c
480 ${GENERIC_SOURCES})
481set(powerpc64le_SOURCES ${powerpc64_SOURCES})
92a42be0 482
2c00a5a8
XL
483set(wasm32_SOURCES
484 ${GENERIC_TF_SOURCES}
485 ${GENERIC_SOURCES})
486set(wasm64_SOURCES
487 ${GENERIC_TF_SOURCES}
488 ${GENERIC_SOURCES})
3157f602 489
1a4d82fc 490add_custom_target(builtins)
5bcae85e 491set_target_properties(builtins PROPERTIES FOLDER "Compiler-RT Misc")
1a4d82fc 492
92a42be0
SL
493if (APPLE)
494 add_subdirectory(Darwin-excludes)
495 add_subdirectory(macho_embedded)
496 darwin_add_builtin_libraries(${BUILTIN_SUPPORTED_OS})
497else ()
7cac9316
XL
498 set(BUILTIN_CFLAGS "")
499
500 append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 BUILTIN_CFLAGS)
501
502 # These flags would normally be added to CMAKE_C_FLAGS by the llvm
503 # cmake step. Add them manually if this is a standalone build.
504 if(COMPILER_RT_STANDALONE_BUILD)
505 append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC BUILTIN_CFLAGS)
506 append_list_if(COMPILER_RT_HAS_FNO_BUILTIN_FLAG -fno-builtin BUILTIN_CFLAGS)
507 append_list_if(COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG -fvisibility=hidden BUILTIN_CFLAGS)
508 if(NOT COMPILER_RT_DEBUG)
509 append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fomit-frame-pointer BUILTIN_CFLAGS)
510 endif()
511 endif()
512
513 set(BUILTIN_DEFS "")
514
515 append_list_if(COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG VISIBILITY_HIDDEN BUILTIN_DEFS)
3157f602 516
92a42be0
SL
517 foreach (arch ${BUILTIN_SUPPORTED_ARCH})
518 if (CAN_TARGET_${arch})
2c00a5a8
XL
519 # NOTE: some architectures (e.g. i386) have multiple names. Ensure that
520 # we catch them all.
521 set(_arch ${arch})
522 if("${arch}" STREQUAL "armv6m")
523 set(_arch "arm|armv6m")
524 elseif("${arch}" MATCHES "^(armhf|armv7|armv7s|armv7k|armv7m|armv7em)$")
525 set(_arch "arm")
526 endif()
527
92a42be0
SL
528 # Filter out generic versions of routines that are re-implemented in
529 # architecture specific manner. This prevents multiple definitions of the
530 # same symbols, making the symbol selection non-deterministic.
531 foreach (_file ${${arch}_SOURCES})
2c00a5a8 532 if (${_file} MATCHES ${_arch}/*)
92a42be0
SL
533 get_filename_component(_name ${_file} NAME)
534 string(REPLACE ".S" ".c" _cname "${_name}")
535 list(REMOVE_ITEM ${arch}_SOURCES ${_cname})
536 endif ()
537 endforeach ()
538
7cac9316
XL
539 # Needed for clear_cache on debug mode, due to r7's usage in inline asm.
540 # Release mode already sets it via -O2/3, Debug mode doesn't.
541 if (${arch} STREQUAL "armhf")
2c00a5a8 542 list(APPEND BUILTIN_CFLAGS -fomit-frame-pointer -DCOMPILER_RT_ARMHF_TARGET)
7cac9316
XL
543 endif()
544
92a42be0
SL
545 add_compiler_rt_runtime(clang_rt.builtins
546 STATIC
547 ARCHS ${arch}
548 SOURCES ${${arch}_SOURCES}
7cac9316
XL
549 DEFS ${BUILTIN_DEFS}
550 CFLAGS ${BUILTIN_CFLAGS}
92a42be0
SL
551 PARENT_TARGET builtins)
552 endif ()
553 endforeach ()
554endif ()
1a4d82fc
JJ
555
556add_dependencies(compiler-rt builtins)