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 5if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) 6 cmake_minimum_required(VERSION 3.20.0) 7 8 set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) 9 project(CompilerRTBuiltins C ASM) 10 set(COMPILER_RT_STANDALONE_BUILD TRUE) 11 set(COMPILER_RT_BUILTINS_STANDALONE_BUILD TRUE) 12 13 set(COMPILER_RT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..") 14 15 set(LLVM_COMMON_CMAKE_UTILS "${COMPILER_RT_SOURCE_DIR}/../cmake") 16 17 # Add path for custom modules 18 list(INSERT CMAKE_MODULE_PATH 0 19 "${COMPILER_RT_SOURCE_DIR}/cmake" 20 "${COMPILER_RT_SOURCE_DIR}/cmake/Modules" 21 "${LLVM_COMMON_CMAKE_UTILS}" 22 "${LLVM_COMMON_CMAKE_UTILS}/Modules" 23 ) 24 25 include(base-config-ix) 26 include(CompilerRTUtils) 27 28 if (NOT LLVM_RUNTIMES_BUILD) 29 load_llvm_config() 30 endif() 31 construct_compiler_rt_default_triple() 32 33 include(SetPlatformToolchainTools) 34 if(APPLE) 35 include(CompilerRTDarwinUtils) 36 endif() 37 if(APPLE) 38 include(UseLibtool) 39 endif() 40 include(AddCompilerRT) 41 42 if(MINGW) 43 # Simplified version of what's set in cmake/config-ix.cmake; not including 44 # builtins, which are linked separately. 45 set(MINGW_LIBRARIES mingw32 moldname mingwex msvcrt advapi32 shell32 46 user32 kernel32 mingw32 moldname mingwex msvcrt) 47 endif() 48endif() 49 50if (COMPILER_RT_STANDALONE_BUILD) 51 # When compiler-rt is being built standalone, possibly as a cross-compilation 52 # target, the target may or may not want position independent code. This 53 # option provides an avenue through which the flag may be controlled when an 54 # LLVM configuration is not being utilized. 55 option(COMPILER_RT_BUILTINS_ENABLE_PIC 56 "Turns on or off -fPIC for the builtin library source" 57 ON) 58endif() 59 60include(builtin-config-ix) 61include(CMakeDependentOption) 62include(CMakePushCheckState) 63 64option(COMPILER_RT_BUILTINS_HIDE_SYMBOLS 65 "Do not export any symbols from the static library." ON) 66 67# TODO: Need to add a mechanism for logging errors when builtin source files are 68# added to a sub-directory and not this CMakeLists file. 69set(GENERIC_SOURCES 70 absvdi2.c 71 absvsi2.c 72 absvti2.c 73 adddf3.c 74 addsf3.c 75 addvdi3.c 76 addvsi3.c 77 addvti3.c 78 apple_versioning.c 79 ashldi3.c 80 ashlti3.c 81 ashrdi3.c 82 ashrti3.c 83 bswapdi2.c 84 bswapsi2.c 85 clzdi2.c 86 clzsi2.c 87 clzti2.c 88 cmpdi2.c 89 cmpti2.c 90 comparedf2.c 91 comparesf2.c 92 ctzdi2.c 93 ctzsi2.c 94 ctzti2.c 95 divdc3.c 96 divdf3.c 97 divdi3.c 98 divmoddi4.c 99 divmodsi4.c 100 divmodti4.c 101 divsc3.c 102 divsf3.c 103 divsi3.c 104 divti3.c 105 extendsfdf2.c 106 extendhfsf2.c 107 ffsdi2.c 108 ffssi2.c 109 ffsti2.c 110 fixdfdi.c 111 fixdfsi.c 112 fixdfti.c 113 fixsfdi.c 114 fixsfsi.c 115 fixsfti.c 116 fixunsdfdi.c 117 fixunsdfsi.c 118 fixunsdfti.c 119 fixunssfdi.c 120 fixunssfsi.c 121 fixunssfti.c 122 floatdidf.c 123 floatdisf.c 124 floatsidf.c 125 floatsisf.c 126 floattidf.c 127 floattisf.c 128 floatundidf.c 129 floatundisf.c 130 floatunsidf.c 131 floatunsisf.c 132 floatuntidf.c 133 floatuntisf.c 134 fp_mode.c 135 int_util.c 136 lshrdi3.c 137 lshrti3.c 138 moddi3.c 139 modsi3.c 140 modti3.c 141 muldc3.c 142 muldf3.c 143 muldi3.c 144 mulodi4.c 145 mulosi4.c 146 muloti4.c 147 mulsc3.c 148 mulsf3.c 149 multi3.c 150 mulvdi3.c 151 mulvsi3.c 152 mulvti3.c 153 negdf2.c 154 negdi2.c 155 negsf2.c 156 negti2.c 157 negvdi2.c 158 negvsi2.c 159 negvti2.c 160 os_version_check.c 161 paritydi2.c 162 paritysi2.c 163 parityti2.c 164 popcountdi2.c 165 popcountsi2.c 166 popcountti2.c 167 powidf2.c 168 powisf2.c 169 subdf3.c 170 subsf3.c 171 subvdi3.c 172 subvsi3.c 173 subvti3.c 174 trampoline_setup.c 175 truncdfhf2.c 176 truncdfsf2.c 177 truncsfhf2.c 178 ucmpdi2.c 179 ucmpti2.c 180 udivdi3.c 181 udivmoddi4.c 182 udivmodsi4.c 183 udivmodti4.c 184 udivsi3.c 185 udivti3.c 186 umoddi3.c 187 umodsi3.c 188 umodti3.c 189) 190 191# We only build BF16 files when "__bf16" is available. 192set(BF16_SOURCES 193 extendbfsf2.c 194 truncdfbf2.c 195 truncxfbf2.c 196 truncsfbf2.c 197 trunctfbf2.c 198) 199 200set(GENERIC_TF_SOURCES 201 addtf3.c 202 comparetf2.c 203 divtc3.c 204 divtf3.c 205 extenddftf2.c 206 extendhftf2.c 207 extendsftf2.c 208 fixtfdi.c 209 fixtfsi.c 210 fixtfti.c 211 fixunstfdi.c 212 fixunstfsi.c 213 fixunstfti.c 214 floatditf.c 215 floatsitf.c 216 floattitf.c 217 floatunditf.c 218 floatunsitf.c 219 floatuntitf.c 220 multc3.c 221 multf3.c 222 powitf2.c 223 subtf3.c 224 trunctfdf2.c 225 trunctfhf2.c 226 trunctfsf2.c 227) 228 229option(COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN 230 "Skip the atomic builtin (these should normally be provided by a shared library)" 231 On) 232 233if(NOT FUCHSIA AND NOT COMPILER_RT_BAREMETAL_BUILD AND NOT COMPILER_RT_GPU_BUILD) 234 set(GENERIC_SOURCES 235 ${GENERIC_SOURCES} 236 emutls.c 237 enable_execute_stack.c 238 eprintf.c 239 ) 240endif() 241 242option(COMPILER_RT_LIBATOMIC_USE_PTHREAD 243 "Whether libatomic should use pthreads if available." 244 Off) 245 246if(COMPILER_RT_LIBATOMIC_USE_PTHREAD) 247 add_compile_definitions(_LIBATOMIC_USE_PTHREAD) 248endif() 249 250if(COMPILER_RT_HAS_ATOMIC_KEYWORD AND NOT COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN) 251 set(GENERIC_SOURCES 252 ${GENERIC_SOURCES} 253 atomic.c 254 ) 255endif() 256 257if(APPLE) 258 set(GENERIC_SOURCES 259 ${GENERIC_SOURCES} 260 atomic_flag_clear.c 261 atomic_flag_clear_explicit.c 262 atomic_flag_test_and_set.c 263 atomic_flag_test_and_set_explicit.c 264 atomic_signal_fence.c 265 atomic_thread_fence.c 266 ) 267endif() 268 269if (HAVE_UNWIND_H) 270 set(GENERIC_SOURCES 271 ${GENERIC_SOURCES} 272 gcc_personality_v0.c 273 ) 274endif () 275 276if (NOT FUCHSIA) 277 set(GENERIC_SOURCES 278 ${GENERIC_SOURCES} 279 clear_cache.c 280 ) 281endif() 282 283# These files are used on 32-bit and 64-bit x86. 284set(x86_ARCH_SOURCES 285 cpu_model/x86.c 286 ) 287 288if (NOT MSVC) 289 set(x86_ARCH_SOURCES 290 ${x86_ARCH_SOURCES} 291 i386/fp_mode.c 292 ) 293endif () 294 295# Implement extended-precision builtins, assuming long double is 80 bits. 296# long double is not 80 bits on Android or MSVC. 297set(x86_80_BIT_SOURCES 298 divxc3.c 299 extendhfxf2.c 300 extendxftf2.c 301 fixxfdi.c 302 fixxfti.c 303 fixunsxfdi.c 304 fixunsxfsi.c 305 fixunsxfti.c 306 floatdixf.c 307 floattixf.c 308 floatundixf.c 309 floatuntixf.c 310 mulxc3.c 311 powixf2.c 312 trunctfxf2.c 313 truncxfhf2.c 314) 315 316if (NOT MSVC) 317 set(x86_64_SOURCES 318 ${GENERIC_SOURCES} 319 ${GENERIC_TF_SOURCES} 320 ${x86_ARCH_SOURCES} 321 x86_64/floatdidf.c 322 x86_64/floatdisf.c 323 ) 324 if (NOT WIN32) 325 set(x86_64_SOURCES 326 ${x86_64_SOURCES} 327 x86_64/floatundidf.S 328 x86_64/floatundisf.S 329 ) 330 endif() 331 332 if (NOT ANDROID) 333 set(x86_64_SOURCES 334 ${x86_64_SOURCES} 335 ${x86_80_BIT_SOURCES} 336 x86_64/floatdixf.c 337 ) 338 if (NOT WIN32) 339 set(x86_64_SOURCES 340 ${x86_64_SOURCES} 341 x86_64/floatundixf.S 342 ) 343 endif() 344 endif() 345 346 # Darwin x86_64 Haswell 347 set(x86_64h_SOURCES ${x86_64_SOURCES}) 348 349 if (WIN32) 350 set(x86_64_SOURCES 351 ${x86_64_SOURCES} 352 x86_64/chkstk.S 353 ) 354 endif() 355 356 set(i386_SOURCES 357 ${GENERIC_SOURCES} 358 ${x86_ARCH_SOURCES} 359 i386/ashldi3.S 360 i386/ashrdi3.S 361 i386/divdi3.S 362 i386/floatdidf.S 363 i386/floatdisf.S 364 i386/floatundidf.S 365 i386/floatundisf.S 366 i386/lshrdi3.S 367 i386/moddi3.S 368 i386/muldi3.S 369 i386/udivdi3.S 370 i386/umoddi3.S 371 ) 372 373 if (NOT ANDROID) 374 set(i386_SOURCES 375 ${i386_SOURCES} 376 ${x86_80_BIT_SOURCES} 377 i386/floatdixf.S 378 i386/floatundixf.S 379 ) 380 endif() 381 382 if (WIN32) 383 set(i386_SOURCES 384 ${i386_SOURCES} 385 i386/chkstk.S 386 ) 387 endif() 388else () # MSVC 389 # Use C versions of functions when building on MSVC 390 # MSVC's assembler takes Intel syntax, not AT&T syntax. 391 # Also use only MSVC compilable builtin implementations. 392 set(x86_64_SOURCES 393 ${GENERIC_SOURCES} 394 ${x86_ARCH_SOURCES} 395 x86_64/floatdidf.c 396 x86_64/floatdisf.c 397 ) 398 set(i386_SOURCES ${GENERIC_SOURCES} ${x86_ARCH_SOURCES}) 399endif () # if (NOT MSVC) 400 401 402# builtin support for Targets that have Arm state or have Thumb2 403set(arm_or_thumb2_base_SOURCES 404 arm/fp_mode.c 405 arm/bswapdi2.S 406 arm/bswapsi2.S 407 arm/clzdi2.S 408 arm/clzsi2.S 409 arm/comparesf2.S 410 arm/divmodsi4.S 411 arm/divsi3.S 412 arm/modsi3.S 413 arm/udivmodsi4.S 414 arm/udivsi3.S 415 arm/umodsi3.S 416 ${GENERIC_SOURCES} 417) 418 419set(arm_sync_SOURCES 420 arm/sync_fetch_and_add_4.S 421 arm/sync_fetch_and_add_8.S 422 arm/sync_fetch_and_and_4.S 423 arm/sync_fetch_and_and_8.S 424 arm/sync_fetch_and_max_4.S 425 arm/sync_fetch_and_max_8.S 426 arm/sync_fetch_and_min_4.S 427 arm/sync_fetch_and_min_8.S 428 arm/sync_fetch_and_nand_4.S 429 arm/sync_fetch_and_nand_8.S 430 arm/sync_fetch_and_or_4.S 431 arm/sync_fetch_and_or_8.S 432 arm/sync_fetch_and_sub_4.S 433 arm/sync_fetch_and_sub_8.S 434 arm/sync_fetch_and_umax_4.S 435 arm/sync_fetch_and_umax_8.S 436 arm/sync_fetch_and_umin_4.S 437 arm/sync_fetch_and_umin_8.S 438 arm/sync_fetch_and_xor_4.S 439 arm/sync_fetch_and_xor_8.S 440) 441 442# builtin support for Thumb-only targets with very limited Thumb2 technology, 443# such as v6-m and v8-m.baseline 444set(thumb1_base_SOURCES 445 arm/divsi3.S 446 arm/udivsi3.S 447 arm/comparesf2.S 448 arm/addsf3.S 449 ${GENERIC_SOURCES} 450) 451 452set(arm_EABI_SOURCES 453 arm/aeabi_cdcmp.S 454 arm/aeabi_cdcmpeq_check_nan.c 455 arm/aeabi_cfcmp.S 456 arm/aeabi_cfcmpeq_check_nan.c 457 arm/aeabi_dcmp.S 458 arm/aeabi_div0.c 459 arm/aeabi_drsub.c 460 arm/aeabi_fcmp.S 461 arm/aeabi_frsub.c 462 arm/aeabi_idivmod.S 463 arm/aeabi_ldivmod.S 464 arm/aeabi_memcmp.S 465 arm/aeabi_memcpy.S 466 arm/aeabi_memmove.S 467 arm/aeabi_memset.S 468 arm/aeabi_uidivmod.S 469 arm/aeabi_uldivmod.S 470) 471 472set(arm_Thumb1_JT_SOURCES 473 arm/switch16.S 474 arm/switch32.S 475 arm/switch8.S 476 arm/switchu8.S 477) 478set(arm_Thumb1_SjLj_EH_SOURCES 479 arm/restore_vfp_d8_d15_regs.S 480 arm/save_vfp_d8_d15_regs.S 481) 482set(arm_Thumb1_VFPv2_DP_SOURCES 483 arm/adddf3vfp.S 484 arm/divdf3vfp.S 485 arm/eqdf2vfp.S 486 arm/extendsfdf2vfp.S 487 arm/fixdfsivfp.S 488 arm/fixunsdfsivfp.S 489 arm/floatsidfvfp.S 490 arm/floatunssidfvfp.S 491 arm/gedf2vfp.S 492 arm/gtdf2vfp.S 493 arm/ledf2vfp.S 494 arm/ltdf2vfp.S 495 arm/muldf3vfp.S 496 arm/nedf2vfp.S 497 arm/negdf2vfp.S 498 arm/subdf3vfp.S 499 arm/truncdfsf2vfp.S 500 arm/unorddf2vfp.S 501) 502set(arm_Thumb1_VFPv2_SP_SOURCES 503 arm/addsf3vfp.S 504 arm/divsf3vfp.S 505 arm/eqsf2vfp.S 506 arm/fixsfsivfp.S 507 arm/fixunssfsivfp.S 508 arm/floatsisfvfp.S 509 arm/floatunssisfvfp.S 510 arm/gesf2vfp.S 511 arm/gtsf2vfp.S 512 arm/lesf2vfp.S 513 arm/ltsf2vfp.S 514 arm/mulsf3vfp.S 515 arm/negsf2vfp.S 516 arm/nesf2vfp.S 517 arm/subsf3vfp.S 518 arm/unordsf2vfp.S 519) 520set(arm_Thumb1_icache_SOURCES 521 arm/sync_synchronize.S 522) 523 524# thumb1 calling into Arm to cover support 525set(arm_Thumb1_SOURCES 526 ${arm_Thumb1_JT_SOURCES} 527 ${arm_Thumb1_SjLj_EH_SOURCES} 528 ${arm_Thumb1_VFPv2_DP_SOURCES} 529 ${arm_Thumb1_VFPv2_SP_SOURCES} 530 ${arm_Thumb1_icache_SOURCES} 531) 532 533# base functionality for Arm Targets prior to Arm v7-a and Armv6-m such as v6, 534# v5t, v4t 535set(arm_min_SOURCES 536 ${arm_or_thumb2_base_SOURCES} 537 ${arm_EABI_SOURCES} 538) 539 540if(MINGW) 541 set(arm_SOURCES 542 arm/aeabi_idivmod.S 543 arm/aeabi_ldivmod.S 544 arm/aeabi_uidivmod.S 545 arm/aeabi_uldivmod.S 546 arm/chkstk.S 547 ${arm_or_thumb2_base_SOURCES} 548 ${arm_sync_SOURCES} 549 ) 550 551 set(thumb1_SOURCES 552 ${thumb1_base_SOURCES} 553 ) 554elseif(NOT WIN32) 555 # TODO the EABI sources should only be added to EABI targets 556 set(arm_SOURCES 557 ${arm_or_thumb2_base_SOURCES} 558 ${arm_sync_SOURCES} 559 ${arm_EABI_SOURCES} 560 ${arm_Thumb1_SOURCES} 561 ) 562 563 set(thumb1_SOURCES 564 ${thumb1_base_SOURCES} 565 ${arm_EABI_SOURCES} 566 ) 567endif() 568 569set(aarch64_SOURCES 570 ${GENERIC_TF_SOURCES} 571 ${GENERIC_SOURCES} 572 cpu_model/aarch64.c 573 aarch64/fp_mode.c 574) 575 576set(COMPILER_RT_AARCH64_FMV_USES_GLOBAL_CONSTRUCTOR NOT(FUCHSIA OR APPLE)) 577 578if (COMPILER_RT_HAS_AARCH64_SME) 579 if (APPLE) 580 list(APPEND aarch64_SOURCES aarch64/arm_apple_sme_abi.s) 581 set_source_files_properties(aarch64/arm_apple_sme_abi.s PROPERTIES COMPILE_FLAGS -march=armv8a+sme) 582 message(STATUS "AArch64 Apple SME ABI routines enabled") 583 elseif (NOT COMPILER_RT_DISABLE_AARCH64_FMV AND COMPILER_RT_HAS_FNO_BUILTIN_FLAG AND COMPILER_RT_AARCH64_FMV_USES_GLOBAL_CONSTRUCTOR) 584 list(APPEND aarch64_SOURCES aarch64/sme-abi.S aarch64/sme-libc-mem-routines.S aarch64/sme-abi-assert.c aarch64/sme-libc-routines.c) 585 message(STATUS "AArch64 SME ABI routines enabled") 586 set_source_files_properties(aarch64/sme-libc-routines.c PROPERTIES COMPILE_FLAGS "-fno-builtin") 587 else() 588 if(COMPILER_RT_DISABLE_AARCH64_FMV) 589 message(WARNING "AArch64 SME ABI routines require function multiversioning support.") 590 endif() 591 if(NOT COMPILER_RT_HAS_FNO_BUILTIN_FLAG) 592 message(WARNING "AArch64 SME ABI routines require '-fno-builtin'") 593 endif() 594 if(NOT (COMPILER_RT_HAS_AUXV OR COMPILER_RT_BAREMETAL_BUILD)) 595 message(WARNING "AArch64 SME ABI routines requires sys/auxv.h or COMPILER_RT_BAREMETAL_BUILD flag") 596 endif() 597 message(STATUS "AArch64 SME ABI routines disabled") 598 endif() 599endif() 600 601# Generate outline atomics helpers from lse.S base 602set(OA_HELPERS_DIR "${CMAKE_CURRENT_BINARY_DIR}/outline_atomic_helpers.dir") 603file(MAKE_DIRECTORY "${OA_HELPERS_DIR}") 604 605if(CMAKE_HOST_UNIX) 606 set(COMPILER_RT_LINK_OR_COPY create_symlink) 607else() 608 set(COMPILER_RT_LINK_OR_COPY copy) 609endif() 610 611foreach(pat cas swp ldadd ldclr ldeor ldset) 612 foreach(size 1 2 4 8 16) 613 foreach(model 1 2 3 4 5) 614 if(pat STREQUAL "cas" OR NOT size STREQUAL "16") 615 set(source_asm "${CMAKE_CURRENT_SOURCE_DIR}/aarch64/lse.S") 616 set(helper_asm "${OA_HELPERS_DIR}/outline_atomic_${pat}${size}_${model}.S") 617 add_custom_command( 618 OUTPUT "${helper_asm}" 619 COMMAND ${CMAKE_COMMAND} -E ${COMPILER_RT_LINK_OR_COPY} "${source_asm}" "${helper_asm}" 620 DEPENDS "${source_asm}" 621 ) 622 set_source_files_properties("${helper_asm}" 623 PROPERTIES 624 COMPILE_DEFINITIONS "L_${pat};SIZE=${size};MODEL=${model}" 625 INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}" 626 ) 627 list(APPEND aarch64_SOURCES "${helper_asm}") 628 endif() 629 endforeach(model) 630 endforeach(size) 631endforeach(pat) 632 633if (MINGW) 634 set(aarch64_SOURCES 635 ${aarch64_SOURCES} 636 aarch64/chkstk.S 637 ) 638endif() 639 640set(amdgcn_SOURCES ${GENERIC_SOURCES}) 641 642set(armv4t_SOURCES ${arm_min_SOURCES}) 643set(armv5te_SOURCES ${arm_min_SOURCES}) 644set(armv6_SOURCES ${arm_min_SOURCES}) 645set(armhf_SOURCES ${arm_SOURCES}) 646set(armv7_SOURCES ${arm_SOURCES}) 647set(armv7s_SOURCES ${arm_SOURCES}) 648set(armv7k_SOURCES ${arm_SOURCES}) 649set(arm64_SOURCES ${aarch64_SOURCES}) 650set(arm64e_SOURCES ${aarch64_SOURCES}) 651set(arm64_32_SOURCES ${aarch64_SOURCES}) 652 653# macho_embedded archs 654set(armv6m_SOURCES ${thumb1_SOURCES}) 655set(armv7m_SOURCES ${arm_SOURCES}) 656set(armv7em_SOURCES ${arm_SOURCES}) 657set(armv8m.base_SOURCES ${thumb1_SOURCES}) 658set(armv8m.main_SOURCES ${arm_SOURCES}) 659set(armv8.1m.main_SOURCES ${arm_SOURCES}) 660 661# 8-bit AVR MCU 662set(avr_SOURCES 663 avr/mulqi3.S 664 avr/mulhi3.S 665 avr/exit.S 666 avr/divmodhi4.S 667 avr/udivmodhi4.S 668 avr/divmodqi4.S 669 avr/udivmodqi4.S 670 ${GENERIC_SOURCES} 671) 672 673# hexagon arch 674set(hexagon_SOURCES 675 hexagon/common_entry_exit_abi1.S 676 hexagon/common_entry_exit_abi2.S 677 hexagon/common_entry_exit_legacy.S 678 hexagon/dfaddsub.S 679 hexagon/dfdiv.S 680 hexagon/dffma.S 681 hexagon/dfminmax.S 682 hexagon/dfmul.S 683 hexagon/dfsqrt.S 684 hexagon/divdi3.S 685 hexagon/divsi3.S 686 hexagon/fastmath2_dlib_asm.S 687 hexagon/fastmath2_ldlib_asm.S 688 hexagon/fastmath_dlib_asm.S 689 hexagon/memcpy_forward_vp4cp4n2.S 690 hexagon/memcpy_likely_aligned.S 691 hexagon/moddi3.S 692 hexagon/modsi3.S 693 hexagon/sfdiv_opt.S 694 hexagon/sfsqrt_opt.S 695 hexagon/udivdi3.S 696 hexagon/udivmoddi4.S 697 hexagon/udivmodsi4.S 698 hexagon/udivsi3.S 699 hexagon/umoddi3.S 700 hexagon/umodsi3.S 701 ${GENERIC_SOURCES} 702 ${GENERIC_TF_SOURCES} 703) 704 705set(loongarch_SOURCES 706 loongarch/fp_mode.c 707 ${GENERIC_SOURCES} 708 ${GENERIC_TF_SOURCES} 709) 710set(loongarch64_SOURCES 711 ${loongarch_SOURCES} 712) 713 714set(mips_SOURCES ${GENERIC_SOURCES}) 715set(mipsel_SOURCES ${mips_SOURCES}) 716set(mips64_SOURCES ${GENERIC_TF_SOURCES} 717 ${mips_SOURCES}) 718set(mips64el_SOURCES ${GENERIC_TF_SOURCES} 719 ${mips_SOURCES}) 720 721set(nvptx64_SOURCES ${GENERIC_SOURCES}) 722 723set(powerpc_SOURCES ${GENERIC_SOURCES}) 724 725set(powerpcspe_SOURCES ${GENERIC_SOURCES}) 726 727set(powerpc64_SOURCES 728 ppc/divtc3.c 729 ppc/fixtfdi.c 730 ppc/fixunstfdi.c 731 ppc/floatditf.c 732 ppc/floatunditf.c 733 ppc/gcc_qadd.c 734 ppc/gcc_qdiv.c 735 ppc/gcc_qmul.c 736 ppc/gcc_qsub.c 737 ppc/multc3.c 738 ${GENERIC_SOURCES} 739) 740# These routines require __int128, which isn't supported on AIX. 741if (NOT OS_NAME MATCHES "AIX") 742 set(powerpc64_SOURCES 743 ppc/floattitf.c 744 ppc/fixtfti.c 745 ppc/fixunstfti.c 746 ${powerpc64_SOURCES} 747 ) 748endif() 749set(powerpc64le_SOURCES ${powerpc64_SOURCES}) 750 751set(riscv_SOURCES 752 cpu_model/riscv.c 753 riscv/fp_mode.c 754 riscv/save.S 755 riscv/restore.S 756 ${GENERIC_SOURCES} 757 ${GENERIC_TF_SOURCES} 758) 759set(riscv32_SOURCES 760 riscv/mulsi3.S 761 ${riscv_SOURCES} 762) 763set(riscv64_SOURCES 764 riscv/muldi3.S 765 ${riscv_SOURCES} 766) 767 768set(sparc_SOURCES ${GENERIC_SOURCES} ${GENERIC_TF_SOURCES}) 769set(sparcv9_SOURCES ${GENERIC_SOURCES} ${GENERIC_TF_SOURCES}) 770 771set(wasm32_SOURCES 772 ${GENERIC_TF_SOURCES} 773 ${GENERIC_SOURCES} 774) 775set(wasm64_SOURCES 776 ${GENERIC_TF_SOURCES} 777 ${GENERIC_SOURCES} 778) 779 780set(ve_SOURCES 781 ve/grow_stack.S 782 ve/grow_stack_align.S 783 ${GENERIC_TF_SOURCES} 784 ${GENERIC_SOURCES}) 785 786add_custom_target(builtins) 787set_target_properties(builtins PROPERTIES FOLDER "Compiler-RT/Metatargets") 788 789option(COMPILER_RT_ENABLE_SOFTWARE_INT128 790 "Enable the int128 builtin routines for all targets." 791 OFF) 792 793if (APPLE) 794 add_subdirectory(Darwin-excludes) 795 add_subdirectory(macho_embedded) 796 darwin_add_builtin_libraries(${BUILTIN_SUPPORTED_OS}) 797else () 798 set(BUILTIN_CFLAGS "") 799 add_security_warnings(BUILTIN_CFLAGS 0) 800 801 if (COMPILER_RT_HAS_FCF_PROTECTION_FLAG) 802 append_list_if(COMPILER_RT_ENABLE_CET -fcf-protection=full BUILTIN_CFLAGS) 803 endif() 804 805 append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 BUILTIN_CFLAGS) 806 append_list_if(COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG -Werror=builtin-declaration-mismatch BUILTIN_CFLAGS) 807 808 # Don't embed directives for picking any specific CRT 809 if (MSVC) 810 set(CMAKE_MSVC_RUNTIME_LIBRARY "") 811 append_list_if(COMPILER_RT_HAS_ZL_FLAG /Zl BUILTIN_CFLAGS) 812 endif() 813 814 # These flags would normally be added to CMAKE_C_FLAGS by the llvm 815 # cmake step. Add them manually if this is a standalone build. 816 if(COMPILER_RT_STANDALONE_BUILD) 817 if(COMPILER_RT_BUILTINS_ENABLE_PIC) 818 append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC BUILTIN_CFLAGS) 819 endif() 820 append_list_if(COMPILER_RT_HAS_FNO_BUILTIN_FLAG -fno-builtin BUILTIN_CFLAGS) 821 if(COMPILER_RT_BUILTINS_HIDE_SYMBOLS) 822 append_list_if(COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG -fvisibility=hidden BUILTIN_CFLAGS) 823 endif() 824 if(NOT COMPILER_RT_DEBUG) 825 append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fomit-frame-pointer BUILTIN_CFLAGS) 826 endif() 827 endif() 828 829 # Directly targeting the GPU requires a few extra flags. 830 if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn|nvptx") 831 append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding BUILTIN_CFLAGS) 832 append_list_if(COMPILER_RT_HAS_NOGPULIB_FLAG -nogpulib BUILTIN_CFLAGS) 833 append_list_if(COMPILER_RT_HAS_FLTO_FLAG -flto BUILTIN_CFLAGS) 834 append_list_if(COMPILER_RT_HAS_FCONVERGENT_FUNCTIONS_FLAG 835 -fconvergent-functions BUILTIN_CFLAGS) 836 837 # AMDGPU targets want to use a generic ABI. 838 if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn") 839 append_list_if(COMPILER_RT_HAS_CODE_OBJECT_VERSION_FLAG 840 "SHELL:-Xclang -mcode-object-version=none" BUILTIN_CFLAGS) 841 endif() 842 endif() 843 844 set(BUILTIN_DEFS "") 845 846 if(COMPILER_RT_BUILTINS_HIDE_SYMBOLS) 847 append_list_if(COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG VISIBILITY_HIDDEN BUILTIN_DEFS) 848 endif() 849 850 if(COMPILER_RT_DISABLE_AARCH64_FMV) 851 list(APPEND BUILTIN_DEFS DISABLE_AARCH64_FMV) 852 elseif(COMPILER_RT_BAREMETAL_BUILD) 853 list(APPEND BUILTIN_DEFS ENABLE_BAREMETAL_AARCH64_FMV) 854 endif() 855 856 append_list_if(COMPILER_RT_HAS_ASM_LSE HAS_ASM_LSE BUILTIN_DEFS) 857 858 foreach (arch ${BUILTIN_SUPPORTED_ARCH}) 859 if (CAN_TARGET_${arch}) 860 cmake_push_check_state() 861 # TODO: we should probably make most of the checks in builtin-config depend on the target flags. 862 set(BUILTIN_CFLAGS_${arch} ${BUILTIN_CFLAGS}) 863 # CMAKE_REQUIRED_FLAGS must be a space separated string but unlike TARGET_${arch}_CFLAGS, 864 # BUILTIN_CFLAGS_${arch} is a CMake list, so we have to join it to create a valid command line. 865 list(JOIN BUILTIN_CFLAGS " " CMAKE_REQUIRED_FLAGS) 866 set(CMAKE_REQUIRED_FLAGS "${TARGET_${arch}_CFLAGS} ${BUILTIN_CFLAGS_${arch}}") 867 message(STATUS "Performing additional configure checks with target flags: ${CMAKE_REQUIRED_FLAGS}") 868 # For ARM archs, exclude any VFP builtins if VFP is not supported 869 if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em|armv8m.main|armv8.1m.main)$") 870 string(REPLACE ";" " " _TARGET_${arch}_CFLAGS "${TARGET_${arch}_CFLAGS}") 871 check_compile_definition(__ARM_FP "${CMAKE_C_FLAGS} ${_TARGET_${arch}_CFLAGS}" COMPILER_RT_HAS_${arch}_VFP) 872 if(NOT COMPILER_RT_HAS_${arch}_VFP) 873 list(REMOVE_ITEM ${arch}_SOURCES ${arm_Thumb1_VFPv2_DP_SOURCES} ${arm_Thumb1_VFPv2_SP_SOURCES} ${arm_Thumb1_SjLj_EH_SOURCES}) 874 else() 875 # Exclude any double-precision builtins if VFP is single-precision-only 876 try_compile_only(COMPILER_RT_HAS_${arch}_VFP_DP 877 SOURCE "#if !(__ARM_FP & 0x8) 878 #error No double-precision support! 879 #endif 880 int main(void) { return 0; }") 881 if(NOT COMPILER_RT_HAS_${arch}_VFP_DP) 882 list(REMOVE_ITEM ${arch}_SOURCES ${arm_Thumb1_VFPv2_DP_SOURCES}) 883 endif() 884 endif() 885 endif() 886 check_c_source_compiles("_Float16 foo(_Float16 x) { return x; } 887 int main(void) { return 0; }" 888 COMPILER_RT_HAS_${arch}_FLOAT16) 889 append_list_if(COMPILER_RT_HAS_${arch}_FLOAT16 -DCOMPILER_RT_HAS_FLOAT16 BUILTIN_CFLAGS_${arch}) 890 check_c_source_compiles("__bf16 foo(__bf16 x) { return x; } 891 int main(void) { return 0; }" 892 COMPILER_RT_HAS_${arch}_BFLOAT16) 893 # Build BF16 files only when "__bf16" is available. 894 if(COMPILER_RT_HAS_${arch}_BFLOAT16) 895 list(APPEND ${arch}_SOURCES ${BF16_SOURCES}) 896 endif() 897 898 # Remove a generic C builtin when an arch-specific builtin is specified. 899 filter_builtin_sources(${arch}_SOURCES ${arch}) 900 901 # Needed for clear_cache on debug mode, due to r7's usage in inline asm. 902 # Release mode already sets it via -O2/3, Debug mode doesn't. 903 if (${arch} STREQUAL "armhf") 904 list(APPEND BUILTIN_CFLAGS_${arch} -fomit-frame-pointer -DCOMPILER_RT_ARMHF_TARGET) 905 endif() 906 907 # For RISCV32, we must force enable int128 for compiling long 908 # double routines. 909 if(COMPILER_RT_ENABLE_SOFTWARE_INT128 OR "${arch}" STREQUAL "riscv32") 910 list(APPEND BUILTIN_CFLAGS_${arch} -fforce-enable-int128) 911 endif() 912 913 add_compiler_rt_runtime(clang_rt.builtins 914 STATIC 915 ARCHS ${arch} 916 DEPS ${deps_${arch}} 917 SOURCES ${${arch}_SOURCES} 918 DEFS ${BUILTIN_DEFS} 919 CFLAGS ${BUILTIN_CFLAGS_${arch}} 920 PARENT_TARGET builtins) 921 cmake_pop_check_state() 922 endif () 923 endforeach () 924endif () 925 926add_dependencies(compiler-rt builtins) 927 928option(COMPILER_RT_BUILD_STANDALONE_LIBATOMIC 929 "Build standalone shared atomic library." 930 OFF) 931 932if(COMPILER_RT_BUILD_STANDALONE_LIBATOMIC) 933 add_custom_target(builtins-standalone-atomic) 934 set(BUILTIN_TYPE SHARED) 935 if(OS_NAME MATCHES "AIX") 936 include(CompilerRTAIXUtils) 937 if(NOT COMPILER_RT_LIBATOMIC_LINK_FLAGS) 938 get_aix_libatomic_default_link_flags(COMPILER_RT_LIBATOMIC_LINK_FLAGS 939 "${CMAKE_CURRENT_SOURCE_DIR}/ppc/atomic.exp") 940 endif() 941 # For different versions of cmake, SHARED behaves differently. For some 942 # versions, we might need MODULE rather than SHARED. 943 get_aix_libatomic_type(BUILTIN_TYPE) 944 else() 945 list(APPEND COMPILER_RT_LIBATOMIC_LINK_FLAGS -nodefaultlibs) 946 endif() 947 foreach (arch ${BUILTIN_SUPPORTED_ARCH}) 948 if(CAN_TARGET_${arch}) 949 list(APPEND COMPILER_RT_LIBATOMIC_LINK_LIBS_${arch} clang_rt.builtins-${arch}) 950 append_list_if(MINGW "${MINGW_LIBRARIES}" COMPILER_RT_LIBATOMIC_LINK_LIBS_${arch}) 951 add_compiler_rt_runtime(clang_rt.atomic 952 ${BUILTIN_TYPE} 953 ARCHS ${arch} 954 SOURCES atomic.c 955 LINK_FLAGS ${COMPILER_RT_LIBATOMIC_LINK_FLAGS} 956 LINK_LIBS ${COMPILER_RT_LIBATOMIC_LINK_LIBS_${arch}} 957 PARENT_TARGET builtins-standalone-atomic) 958 endif() 959 endforeach() 960 # FIXME: On AIX, we have to archive built shared libraries into a static 961 # archive, i.e., libatomic.a. Once cmake adds support of such usage for AIX, 962 # this ad-hoc part can be removed. 963 if(OS_NAME MATCHES "AIX") 964 archive_aix_libatomic(clang_rt.atomic libatomic 965 ARCHS ${BUILTIN_SUPPORTED_ARCH} 966 PARENT_TARGET builtins-standalone-atomic) 967 endif() 968 add_dependencies(compiler-rt builtins-standalone-atomic) 969endif() 970 971cmake_dependent_option(COMPILER_RT_BUILD_CRT "Build crtbegin.o/crtend.o" ON "COMPILER_RT_HAS_CRT" OFF) 972 973if (COMPILER_RT_BUILD_CRT) 974 add_compiler_rt_component(crt) 975 976 option(COMPILER_RT_CRT_USE_EH_FRAME_REGISTRY "Use eh_frame in crtbegin.o/crtend.o" ON) 977 978 include(CheckSectionExists) 979 check_section_exists(".init_array" COMPILER_RT_HAS_INITFINI_ARRAY 980 SOURCE "volatile int x;\n__attribute__((constructor)) void f(void) {x = 0;}\nint main(void) { return 0; }\n") 981 982 append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 CRT_CFLAGS) 983 append_list_if(COMPILER_RT_HAS_INITFINI_ARRAY -DCRT_HAS_INITFINI_ARRAY CRT_CFLAGS) 984 append_list_if(COMPILER_RT_CRT_USE_EH_FRAME_REGISTRY -DEH_USE_FRAME_REGISTRY CRT_CFLAGS) 985 append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC CRT_CFLAGS) 986 append_list_if(COMPILER_RT_HAS_WNO_PEDANTIC -Wno-pedantic CRT_CFLAGS) 987 if (COMPILER_RT_HAS_FCF_PROTECTION_FLAG) 988 append_list_if(COMPILER_RT_ENABLE_CET -fcf-protection=full CRT_CFLAGS) 989 endif() 990 991 foreach(arch ${BUILTIN_SUPPORTED_ARCH}) 992 add_compiler_rt_runtime(clang_rt.crtbegin 993 OBJECT 994 ARCHS ${arch} 995 SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crtbegin.c 996 CFLAGS ${CRT_CFLAGS} 997 PARENT_TARGET crt) 998 add_compiler_rt_runtime(clang_rt.crtend 999 OBJECT 1000 ARCHS ${arch} 1001 SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crtend.c 1002 CFLAGS ${CRT_CFLAGS} 1003 PARENT_TARGET crt) 1004 endforeach() 1005 1006 add_dependencies(compiler-rt crt) 1007endif() 1008