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