diff --git a/llvm/utils/gn/secondary/BUILD.gn b/llvm/utils/gn/secondary/BUILD.gn --- a/llvm/utils/gn/secondary/BUILD.gn +++ b/llvm/utils/gn/secondary/BUILD.gn @@ -9,6 +9,9 @@ "//lld/test", "//llvm/test", ] + if (current_os == "linux") { + deps += [ "//compiler-rt" ] + } if (current_os == "linux" || current_os == "android") { deps += [ "//compiler-rt/test/hwasan" ] } diff --git a/llvm/utils/gn/secondary/clang/runtimes.gni b/llvm/utils/gn/secondary/clang/runtimes.gni new file mode 100644 --- /dev/null +++ b/llvm/utils/gn/secondary/clang/runtimes.gni @@ -0,0 +1,13 @@ +import("//clang/resource_dir.gni") +import("//llvm/triples.gni") + +declare_args() { + # Enable per-target runtimes directory. + clang_enable_per_target_runtime_dir = false +} + +if (clang_enable_per_target_runtime_dir) { + runtimes_dir = "$clang_resource_dir/$llvm_target_triple/lib" +} else { + runtimes_dir = "$root_build_dir/lib" +} diff --git a/llvm/utils/gn/secondary/compiler-rt/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/BUILD.gn new file mode 100644 --- /dev/null +++ b/llvm/utils/gn/secondary/compiler-rt/BUILD.gn @@ -0,0 +1,5 @@ +group("compiler-rt") { + deps = [ + "lib(//llvm/utils/gn/build/toolchain:stage2_unix)", + ] +} diff --git a/llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn new file mode 100644 --- /dev/null +++ b/llvm/utils/gn/secondary/compiler-rt/lib/BUILD.gn @@ -0,0 +1,5 @@ +group("lib") { + deps = [ + "builtins", + ] +} diff --git a/llvm/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn new file mode 100644 --- /dev/null +++ b/llvm/utils/gn/secondary/compiler-rt/lib/builtins/BUILD.gn @@ -0,0 +1,269 @@ +import("//compiler-rt/target.gni") +import("//llvm/utils/gn/build/buildflags.gni") + +declare_args() { + # Skip the atomic builtin (these should normally be provided by a shared library) + compiler_rt_exclude_atomic_builtin = true + + # Compile builtins for baremetal. + compiler_rt_baremetal_build = false +} + +static_library("builtins") { + output_dir = crt_current_out_dir + output_name = "clang_rt.builtins-$crt_current_target" + complete_static_lib = true + cflags = [ + "-fPIC", + "-fno-builtin", + ] + if (target_os != "android") { + cflags += [ "-fvisibility=hidden" ] + } + if (!is_debug) { + cflags += [ "-fomit-frame-pointer" ] + } + cflags_c = [ "-std=c11" ] + configs -= [ "//llvm/utils/gn/build:thin_archive" ] + + sources = [ + "absvdi2.c", + "absvsi2.c", + "absvti2.c", + "adddf3.c", + "addsf3.c", + "addtf3.c", + "addvdi3.c", + "addvsi3.c", + "addvti3.c", + "apple_versioning.c", + "ashldi3.c", + "ashlti3.c", + "ashrdi3.c", + "ashrti3.c", + "bswapdi2.c", + "bswapsi2.c", + "clzdi2.c", + "clzsi2.c", + "clzti2.c", + "cmpdi2.c", + "cmpti2.c", + "comparedf2.c", + "comparesf2.c", + "ctzdi2.c", + "ctzsi2.c", + "ctzti2.c", + "divdc3.c", + "divdf3.c", + "divdi3.c", + "divmoddi4.c", + "divmodsi4.c", + "divsc3.c", + "divsf3.c", + "divsi3.c", + "divtc3.c", + "divti3.c", + "divtf3.c", + "extendsfdf2.c", + "extendhfsf2.c", + "ffsdi2.c", + "ffssi2.c", + "ffsti2.c", + "fixdfdi.c", + "fixdfsi.c", + "fixdfti.c", + "fixsfdi.c", + "fixsfsi.c", + "fixsfti.c", + "fixunsdfdi.c", + "fixunsdfsi.c", + "fixunsdfti.c", + "fixunssfdi.c", + "fixunssfsi.c", + "fixunssfti.c", + "floatdidf.c", + "floatdisf.c", + "floatsidf.c", + "floatsisf.c", + "floattidf.c", + "floattisf.c", + "floatundidf.c", + "floatundisf.c", + "floatunsidf.c", + "floatunsisf.c", + "floatuntidf.c", + "floatuntisf.c", + "int_util.c", + "lshrdi3.c", + "lshrti3.c", + "moddi3.c", + "modsi3.c", + "modti3.c", + "muldc3.c", + "muldf3.c", + "muldi3.c", + "mulodi4.c", + "mulosi4.c", + "muloti4.c", + "mulsc3.c", + "mulsf3.c", + "multi3.c", + "multf3.c", + "mulvdi3.c", + "mulvsi3.c", + "mulvti3.c", + "negdf2.c", + "negdi2.c", + "negsf2.c", + "negti2.c", + "negvdi2.c", + "negvsi2.c", + "negvti2.c", + "os_version_check.c", + "paritydi2.c", + "paritysi2.c", + "parityti2.c", + "popcountdi2.c", + "popcountsi2.c", + "popcountti2.c", + "powidf2.c", + "powisf2.c", + "powitf2.c", + "subdf3.c", + "subsf3.c", + "subvdi3.c", + "subvsi3.c", + "subvti3.c", + "subtf3.c", + "trampoline_setup.c", + "truncdfhf2.c", + "truncdfsf2.c", + "truncsfhf2.c", + "ucmpdi2.c", + "ucmpti2.c", + "udivdi3.c", + "udivmoddi4.c", + "udivmodsi4.c", + "udivmodti4.c", + "udivsi3.c", + "udivti3.c", + "umoddi3.c", + "umodsi3.c", + "umodti3.c", + ] + + if (target_os != "fuchsia") { + sources += [ + "emutls.c ", + "enable_execute_stack.c", + "eprintf.c", + ] + } + + if (target_os != "fuchsia" && !compiler_rt_baremetal_build) { + sources += [ "clear_cache.c" ] + } + + if (target_os == "mac") { + sources += [ + "atomic_flag_clear.c", + "atomic_flag_clear_explicit.c", + "atomic_flag_test_and_set.c", + "atomic_flag_test_and_set_explicit.c", + "atomic_signal_fence.c", + "atomic_thread_fence.c", + ] + } + + if (target_cpu == "x86" || target_cpu == "x64") { + sources += [ + "cpu_model.c", + "divxc3.c", + "fixxfdi.c", + "fixxfti.c", + "fixunsxfdi.c", + "fixunsxfsi.c", + "fixunsxfti.c", + "floatdixf.c", + "floattixf.c", + "floatundixf.c", + "floatuntixf.c", + "mulxc3.c", + "powixf2.c", + ] + + if (target_os == "win") { + # Use C versions of functions when building on MSVC + # MSVC's assembler takes Intel syntax, not AT&T syntax. + # Also use only MSVC compilable builtin implementations. + sources += [ + "x86_64/floatdidf.c", + "x86_64/floatdisf.c", + "x86_64/floatdixf.c", + ] + } + } + + if (target_cpu == "arm") { + sources += [ + "arm/bswapdi2.S", + "arm/bswapsi2.S", + "arm/clzdi2.S", + "arm/clzsi2.S", + "arm/comparesf2.S", + "arm/divmodsi4.S", + "arm/divsi3.S", + "arm/modsi3.S", + "arm/sync_fetch_and_add_4.S", + "arm/sync_fetch_and_add_8.S", + "arm/sync_fetch_and_and_4.S", + "arm/sync_fetch_and_and_8.S", + "arm/sync_fetch_and_max_4.S", + "arm/sync_fetch_and_max_8.S", + "arm/sync_fetch_and_min_4.S", + "arm/sync_fetch_and_min_8.S", + "arm/sync_fetch_and_nand_4.S", + "arm/sync_fetch_and_nand_8.S", + "arm/sync_fetch_and_or_4.S", + "arm/sync_fetch_and_or_8.S", + "arm/sync_fetch_and_sub_4.S", + "arm/sync_fetch_and_sub_8.S", + "arm/sync_fetch_and_umax_4.S", + "arm/sync_fetch_and_umax_8.S", + "arm/sync_fetch_and_umin_4.S", + "arm/sync_fetch_and_umin_8.S", + "arm/sync_fetch_and_xor_4.S", + "arm/sync_fetch_and_xor_8.S", + "arm/udivmodsi4.S", + "arm/udivsi3.S", + "arm/umodsi3.S", + ] + } + + if (target_cpu == "arm64") { + sources += [ + "comparetf2.c", + "extenddftf2.c", + "extendsftf2.c", + "fixtfdi.c", + "fixtfsi.c", + "fixtfti.c", + "fixunstfdi.c", + "fixunstfsi.c", + "fixunstfti.c", + "floatditf.c", + "floatsitf.c", + "floattitf.c", + "floatunditf.c", + "floatunsitf.c", + "floatuntitf.c", + "multc3.c", + "trunctfdf2.c", + "trunctfsf2.c", + ] + } + + if (!compiler_rt_exclude_atomic_builtin) { + sources += [ "atomic.c" ] + } +} diff --git a/llvm/utils/gn/secondary/compiler-rt/target.gni b/llvm/utils/gn/secondary/compiler-rt/target.gni --- a/llvm/utils/gn/secondary/compiler-rt/target.gni +++ b/llvm/utils/gn/secondary/compiler-rt/target.gni @@ -1,6 +1,9 @@ import("//clang/resource_dir.gni") +import("//clang/runtimes.gni") -if (current_os == "linux" || current_os == "android") { +if (clang_enable_per_target_runtime_dir) { + crt_current_out_dir = runtimes_dir +} else if (current_os == "linux" || current_os == "android") { crt_current_out_dir = "$clang_resource_dir/lib/linux" } else { assert(false, "unimplemented current_os " + current_os)