diff --git a/llvm/utils/gn/build/BUILD.gn b/llvm/utils/gn/build/BUILD.gn --- a/llvm/utils/gn/build/BUILD.gn +++ b/llvm/utils/gn/build/BUILD.gn @@ -31,7 +31,6 @@ cflags += [ "-fdiagnostics-color" ] cflags_cc = [ "-std=c++11", - "-fno-exceptions", "-fvisibility-inlines-hidden", ] } else { @@ -139,6 +138,10 @@ } } +config("no_exceptions") { + cflags_cc = [ "-fno-exceptions" ] +} + config("no_rtti") { if (current_os == "win") { cflags_cc = [ "/GR-" ] diff --git a/llvm/utils/gn/build/BUILDCONFIG.gn b/llvm/utils/gn/build/BUILDCONFIG.gn --- a/llvm/utils/gn/build/BUILDCONFIG.gn +++ b/llvm/utils/gn/build/BUILDCONFIG.gn @@ -5,6 +5,7 @@ shared_binary_target_configs = [ "//llvm/utils/gn/build:compiler_defaults", "//llvm/utils/gn/build:llvm_code", + "//llvm/utils/gn/build:no_exceptions", "//llvm/utils/gn/build:no_rtti", "//llvm/utils/gn/build:thin_archive", "//llvm/utils/gn/build:warn_covered_switch_default", diff --git a/llvm/utils/gn/build/symlink_or_copy.gni b/llvm/utils/gn/build/symlink_or_copy.gni --- a/llvm/utils/gn/build/symlink_or_copy.gni +++ b/llvm/utils/gn/build/symlink_or_copy.gni @@ -16,9 +16,9 @@ script = "//llvm/utils/gn/build/symlink_or_copy.py" args = [ "--stamp", - rebase_path(stamp, root_out_dir), + rebase_path(stamp, root_build_dir), invoker.source, - rebase_path(invoker.output, root_out_dir), + rebase_path(invoker.output, root_build_dir), ] } } diff --git a/llvm/utils/gn/build/toolchain/BUILD.gn b/llvm/utils/gn/build/toolchain/BUILD.gn --- a/llvm/utils/gn/build/toolchain/BUILD.gn +++ b/llvm/utils/gn/build/toolchain/BUILD.gn @@ -19,7 +19,7 @@ depsformat = "gcc" description = "CC {{output}}" outputs = [ - "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", + "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.o" ] } @@ -29,7 +29,7 @@ depsformat = "gcc" description = "CXX {{output}}" outputs = [ - "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", + "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.o" ] } @@ -39,7 +39,7 @@ depsformat = "gcc" description = "ASM {{output}}" outputs = [ - "{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.o", + "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.o" ] } @@ -54,10 +54,11 @@ } description = "AR {{output}}" outputs = [ - "{{output_dir}}/{{target_output_name}}.a", + "{{output_dir}}/{{target_output_name}}{{output_extension}}", ] output_prefix = "lib" default_output_dir = "{{root_out_dir}}/lib" + default_output_extension = ".a" } tool("solink") { 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 @@ -6,6 +6,9 @@ deps = [ "//clang-tools-extra/test", "//clang/test", + "//libunwind", + "//libcxxabi", + "//libcxx", "//lld/test", "//llvm/test", ] 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,4 @@ +import("//clang/resource_dir.gni") +import("//llvm/triples.gni") + +runtimes_dir = "$clang_resource_dir/$llvm_target_triple/lib" 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/libcxx/BUILD.gn b/llvm/utils/gn/secondary/libcxx/BUILD.gn new file mode 100644 --- /dev/null +++ b/llvm/utils/gn/secondary/libcxx/BUILD.gn @@ -0,0 +1,6 @@ +group("libcxx") { + deps = [ + "include", + "src(//llvm/utils/gn/build/toolchain:stage2_unix)", + ] +} diff --git a/llvm/utils/gn/secondary/libcxx/config.gni b/llvm/utils/gn/secondary/libcxx/config.gni new file mode 100644 --- /dev/null +++ b/llvm/utils/gn/secondary/libcxx/config.gni @@ -0,0 +1,10 @@ +declare_args() { + # ABI version of libc++. Can be either 1 or 2, where 2 is currently not stable. Defaults to 1. + libcxx_abi_version = 1 + + # The inline ABI namespace used by libc++. It defaults to __n where `n` is the current ABI version. + libcxx_abi_namespace = "" + + # Unstable ABI of libc++. + libcxx_abi_unstable = false +} diff --git a/llvm/utils/gn/secondary/libcxx/include/BUILD.gn b/llvm/utils/gn/secondary/libcxx/include/BUILD.gn new file mode 100644 --- /dev/null +++ b/llvm/utils/gn/secondary/libcxx/include/BUILD.gn @@ -0,0 +1,268 @@ +import("//clang/resource_dir.gni") +import("//libcxx/config.gni") +import("//llvm/utils/gn/build/write_cmake_config.gni") + +declare_args() { + libcxx_install_support_headers = true +} + +libcxx_needs_site_config = + libcxx_abi_version != 1 || libcxx_abi_namespace != "" || libcxx_abi_unstable + +if (libcxx_needs_site_config) { + write_cmake_config("write_config") { + input = "__config_site.in" + output = "$target_gen_dir/__config_site" + + values = [] + if (libcxx_abi_version != 1) { + values += [ "_LIBCPP_ABI_VERSION=$libcxx_abi_version" ] + } + if (libcxx_abi_namespace != "") { + values += [ "_LIBCPP_ABI_NAMESPACE=$libcxx_abi_namespace" ] + } + if (libcxx_abi_unstable) { + values += [ "_LIBCPP_ABI_UNSTABLE=" ] + } + } + + # Generate a custom __config header. The new header is created + # by prepending __config_site to the current __config header. + action("concat_config") { + script = "../utils/cat_files.py" + inputs = [ + "$target_gen_dir/__config_site", + "__config", + ] + outputs = [ + "$target_gen_dir/__config", + ] + args = [ + "$target_gen_dir/__config_site", + "__config", + "-o", + "$target_gen_dir/__config", + ] + deps = [ + ":write_config", + ] + } + + copy("copy_config") { + sources = [ + "$target_gen_dir/__config", + ] + outputs = [ + "$clang_resource_dir/include/c++/v1/{{source_file_part}}", + ] + deps = [ + ":concat_config", + ] + } +} + +copy("include") { + sources = [ + "__bit_reference", + "__bsd_locale_defaults.h", + "__bsd_locale_fallbacks.h", + "__debug", + "__errc", + "__functional_03", + "__functional_base", + "__functional_base_03", + "__hash_table", + "__libcpp_version", + "__locale", + "__mutex_base", + "__node_handle", + "__nullptr", + "__split_buffer", + "__sso_allocator", + "__std_stream", + "__string", + "__threading_support", + "__tree", + "__tuple", + "__undef_macros", + "algorithm", + "any", + "array", + "atomic", + "bit", + "bitset", + "cassert", + "ccomplex", + "cctype", + "cerrno", + "cfenv", + "cfloat", + "charconv", + "chrono", + "cinttypes", + "ciso646", + "climits", + "clocale", + "cmath", + "codecvt", + "compare", + "complex", + "complex.h", + "condition_variable", + "csetjmp", + "csignal", + "cstdarg", + "cstdbool", + "cstddef", + "cstdint", + "cstdio", + "cstdlib", + "cstring", + "ctgmath", + "ctime", + "ctype.h", + "cwchar", + "cwctype", + "deque", + "errno.h", + "exception", + "experimental/__config", + "experimental/__memory", + "experimental/algorithm", + "experimental/any", + "experimental/chrono", + "experimental/coroutine", + "experimental/deque", + "experimental/filesystem", + "experimental/forward_list", + "experimental/functional", + "experimental/iterator", + "experimental/list", + "experimental/map", + "experimental/memory_resource", + "experimental/numeric", + "experimental/optional", + "experimental/propagate_const", + "experimental/ratio", + "experimental/regex", + "experimental/set", + "experimental/simd", + "experimental/string", + "experimental/string_view", + "experimental/system_error", + "experimental/tuple", + "experimental/type_traits", + "experimental/unordered_map", + "experimental/unordered_set", + "experimental/utility", + "experimental/vector", + "ext/__hash", + "ext/hash_map", + "ext/hash_set", + "fenv.h", + "filesystem", + "float.h", + "forward_list", + "fstream", + "functional", + "future", + "initializer_list", + "inttypes.h", + "iomanip", + "ios", + "iosfwd", + "iostream", + "istream", + "iterator", + "limits", + "limits.h", + "list", + "locale", + "locale.h", + "map", + "math.h", + "memory", + "module.modulemap", + "mutex", + "new", + "numeric", + "optional", + "ostream", + "queue", + "random", + "ratio", + "regex", + "scoped_allocator", + "set", + "setjmp.h", + "shared_mutex", + "span", + "sstream", + "stack", + "stdbool.h", + "stddef.h", + "stdexcept", + "stdint.h", + "stdio.h", + "stdlib.h", + "streambuf", + "string", + "string.h", + "string_view", + "strstream", + "system_error", + "tgmath.h", + "thread", + "tuple", + "type_traits", + "typeindex", + "typeinfo", + "unordered_map", + "unordered_set", + "utility", + "valarray", + "variant", + "vector", + "version", + "wchar.h", + "wctype.h", + ] + if (!libcxx_needs_site_config) { + sources += [ "__config" ] + } else { + deps = [ + ":copy_config", + ] + } + if (libcxx_install_support_headers) { + sources += [ + "support/android/locale_bionic.h", + "support/fuchsia/xlocale.h", + "support/ibm/limits.h", + "support/ibm/locale_mgmt_aix.h", + "support/ibm/support.h", + "support/ibm/xlocale.h", + "support/musl/xlocale.h", + "support/newlib/xlocale.h", + "support/xlocale/__nop_locale_mgmt.h", + "support/xlocale/__posix_l_fallback.h", + "support/xlocale/__strtonum_fallback.h", + ] + if (target_os == "solaris") { + sources += [ + "support/solaris/floatingpoint.h", + "support/solaris/wchar.h", + "support/solaris/xlocale.h", + ] + } + if (target_os == "win") { + sources += [ + "support/win32/limits_msvc_win32.h", + "support/win32/locale_win32.h", + ] + } + } + outputs = [ + "$clang_resource_dir/include/c++/v1/{{source_target_relative}}", + ] +} diff --git a/llvm/utils/gn/secondary/libcxx/src/BUILD.gn b/llvm/utils/gn/secondary/libcxx/src/BUILD.gn new file mode 100644 --- /dev/null +++ b/llvm/utils/gn/secondary/libcxx/src/BUILD.gn @@ -0,0 +1,297 @@ +import("//clang/runtimes.gni") +import("//llvm/utils/gn/build/symlink_or_copy.gni") + +declare_args() { + # Build libc++ with definitions for operator new/delete. + libcxx_enable_new_delete_definitions = true + + # Build libc++ as a shared library. + libcxx_enable_shared = true + + # Build libc++ as a static library. + libcxx_enable_static = true + + # Build filesystem as part of libc++fs.a. + libcxx_enable_filesystem = target_os != "win" + + # Build libc++experimental.a. + libcxx_enable_experimental = true + + # Use compiler-rt builtins. + libcxx_use_compiler_rt = true + + # Use exceptions. + libcxx_enable_exceptions = true + + # Use run time type information. + libcxx_enable_rtti = true + + # Do not export any symbols from the static library. + libcxx_hermetic_static_library = false + + # Use and install a linker script for the given ABI library. + libcxx_enable_abi_linker_script = true +} + +config("cxx_config") { + include_dirs = [ + "//libcxxabi/include", + "//libcxx/include", + ] + cflags = [ + "-Wall", + "-Wextra", + "-W", + "-Wwrite-strings", + "-Wno-unused-parameter", + "-Wno-long-long", + "-Werror=return-type", + "-Wextra-semi", + "-Wno-user-defined-literals", + "-Wno-covered-switch-default", + ] + cflags_cc = [ "-nostdinc++" ] + if (target_os == "win") { + cflags_cc += [ "/std:c++11" ] + } else { + cflags_cc += [ "-std=c++11" ] + } + defines = [ "_LIBCPP_BUILDING_LIBRARY" ] + if (target_os == "win") { + cflags += [ "/Zl" ] + defines += [ + # Ignore the -MSC_VER mismatch, as we may build + # with a different compatibility version. + "_ALLOW_MSC_VER_MISMATCH", + + # Don't check the msvcprt iterator debug levels + # as we will define the iterator types; libc++ + # uses a different macro to identify the debug + # level. + "_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH", + + # We are building the c++ runtime, don't pull in + # msvcprt. + "_CRTBLD", + + # Don't warn on the use of "deprecated" + # "insecure" functions which are standards + # specified. + "_CRT_SECURE_NO_WARNINGS", + + # Use the ISO conforming behaviour for conversion + # in printf, scanf. + "_CRT_STDIO_ISO_WIDE_SPECIFIERS", + ] + } + if (libcxx_enable_exceptions) { + if (current_os == "win") { + cflags_cc += [ "/EHsc" ] + } + } else { + if (current_os == "win") { + cflags_cc += [ + "/EHs-", + "/EHa-", + ] + } else { + cflags_cc += [ "-fno-exceptions" ] + } + defines += [ "-D_LIBCPP_NO_EXCEPTIONS" ] + } + if (!libcxx_enable_rtti) { + if (current_os == "win") { + cflags_cc += [ "/GR-" ] + } else { + cflags_cc += [ "-fno-rtti" ] + } + defines += [ "-D_LIBCPP_NO_RTTI" ] + } +} + +cxx_sources = [ + "algorithm.cpp", + "string.cpp", + "ios.cpp", + "condition_variable.cpp", + "hash.cpp", + "random.cpp", + "new.cpp", + "functional.cpp", + "exception.cpp", + "support/runtime/exception_msvc.ipp", + "support/runtime/exception_libcxxabi.ipp", + "support/runtime/exception_glibcxx.ipp", + "support/runtime/new_handler_fallback.ipp", + "support/runtime/exception_libcxxrt.ipp", + "support/runtime/exception_pointer_unimplemented.ipp", + "support/runtime/exception_pointer_cxxabi.ipp", + "support/runtime/exception_pointer_msvc.ipp", + "support/runtime/exception_fallback.ipp", + "support/runtime/exception_pointer_glibcxx.ipp", + "variant.cpp", + "shared_mutex.cpp", + "optional.cpp", + "strstream.cpp", + "include/apple_availability.h", + "include/refstring.h", + "include/config_elast.h", + "include/atomic_support.h", + "future.cpp", + "system_error.cpp", + "bind.cpp", + "iostream.cpp", + "stdexcept.cpp", + "valarray.cpp", + "chrono.cpp", + "typeinfo.cpp", + "locale.cpp", + "debug.cpp", + "charconv.cpp", + "utility.cpp", + "regex.cpp", + "mutex.cpp", + "any.cpp", + "thread.cpp", + "vector.cpp", + "memory.cpp", +] +if (target_os == "solaris") { + cxx_sources += [ + "support/solaris/mbsnrtowcs.inc", + "support/solaris/xlocale.cpp", + "support/solaris/wcsnrtombs.inc", + ] +} +if (target_os == "win") { + cxx_sources += [ + "support/win32/locale_win32.cpp", + "support/win32/support.cpp", + "support/win32/thread_win32.cpp", + ] +} +if (libcxx_enable_filesystem) { + cxx_sources += [ + "filesystem/directory_iterator.cpp", + "filesystem/filesystem_common.h", + "filesystem/operations.cpp", + ] + if (libcxx_use_compiler_rt) { + cxx_sources += [ "filesystem/int128_builtins.cpp" ] + } +} + +if (libcxx_enable_shared) { + shared_library("cxx_shared") { + output_dir = runtimes_dir + output_name = "c++" + if (libcxx_enable_abi_linker_script) { + output_extension = "so.0" + } + if (target_os == "linux" || target_os == "mac") { + cflags = [ "-fPIC" ] + ldflags = [ "-nostdlib++" ] + libs = [ + "dl", + "pthread", + ] + } + sources = cxx_sources + deps = [ + "//compiler-rt/lib/builtins", + "//libcxxabi/src:cxxabi_shared", + "//libunwind/src:unwind_shared", + ] + configs += [ ":cxx_config" ] + configs -= [ + "//llvm/utils/gn/build:no_exceptions", + "//llvm/utils/gn/build:no_rtti", + ] + } + + if (libcxx_enable_abi_linker_script) { + symlink_or_copy("cxx_symlink") { + deps = [ + ":cxx_shared", + ] + source = "libc++.so.0" + output = "$runtimes_dir/libc++.so" + } + + action("cxx_linker_script") { + script = "//libcxx/utils/gen_link_script.py" + outputs = [ + "$runtimes_dir/libc++.so", + ] + args = [ + "--input", + "libc++.so.0", + "--output", + "$runtimes_dir/libc++.so", + "c++abi", + "unwind", + ] + deps = [ + ":cxx_symlink", + ] + } + } +} + +if (libcxx_enable_static) { + static_library("cxx_static") { + output_dir = runtimes_dir + output_name = "c++" + complete_static_lib = true + sources = cxx_sources + if (libcxx_hermetic_static_library) { + cflags = [ "-fvisibility=hidden" ] + cflags_cc = [ "-fvisibility-global-new-delete-hidden" ] + defines = [ "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS" ] + } + deps = [ + "//compiler-rt/lib/builtins", + "//libcxxabi/src:cxxabi_static", + "//libunwind/src:unwind_static", + ] + configs += [ ":cxx_config" ] + configs -= [ + "//llvm/utils/gn/build:no_exceptions", + "//llvm/utils/gn/build:no_rtti", + "//llvm/utils/gn/build:thin_archive", + ] + } +} + +if (libcxx_enable_experimental) { + static_library("cxx_experimental") { + output_dir = runtimes_dir + output_name = "c++experimental" + cflags_cc = [ "-std=c++14" ] + sources = [ + "experimental/memory_resource.cpp", + ] + configs += [ ":cxx_config" ] + configs -= [ + "//llvm/utils/gn/build:no_exceptions", + "//llvm/utils/gn/build:no_rtti", + ] + } +} + +group("src") { + deps = [] + if (libcxx_enable_shared) { + if (libcxx_enable_abi_linker_script) { + deps += [ ":cxx_linker_script" ] + } else { + deps += [ ":cxx_shared" ] + } + } + if (libcxx_enable_static) { + deps += [ ":cxx_static" ] + } + if (libcxx_enable_experimental) { + deps += [ ":cxx_experimental" ] + } +} diff --git a/llvm/utils/gn/secondary/libcxxabi/BUILD.gn b/llvm/utils/gn/secondary/libcxxabi/BUILD.gn new file mode 100644 --- /dev/null +++ b/llvm/utils/gn/secondary/libcxxabi/BUILD.gn @@ -0,0 +1,6 @@ +group("libcxxabi") { + deps = [ + "include", + "src(//llvm/utils/gn/build/toolchain:stage2_unix)", + ] +} diff --git a/llvm/utils/gn/secondary/libcxxabi/include/BUILD.gn b/llvm/utils/gn/secondary/libcxxabi/include/BUILD.gn new file mode 100644 --- /dev/null +++ b/llvm/utils/gn/secondary/libcxxabi/include/BUILD.gn @@ -0,0 +1,11 @@ +import("//clang/resource_dir.gni") + +copy("include") { + sources = [ + "__cxxabi_config.h", + "cxxabi.h", + ] + outputs = [ + "$clang_resource_dir/include/c++/v1/{{source_target_relative}}", + ] +} diff --git a/llvm/utils/gn/secondary/libcxxabi/src/BUILD.gn b/llvm/utils/gn/secondary/libcxxabi/src/BUILD.gn new file mode 100644 --- /dev/null +++ b/llvm/utils/gn/secondary/libcxxabi/src/BUILD.gn @@ -0,0 +1,129 @@ +import("//clang/runtimes.gni") + +declare_args() { + # Use exceptions. + libcxxabi_enable_exceptions = true + + # Build libc++abi with definitions for operator new/delete. + libcxxabi_enable_new_delete_definitions = true + + # Build libcxxabi as a shared library. + libcxxabi_enable_shared = true + + # Build libcxxabi as a static library. + libcxxabi_enable_static = true + + # Do not export any symbols from the static library. + libcxxabi_hermetic_static_library = false +} + +cxxabi_sources = [ + # C++ABI files + "cxa_aux_runtime.cpp", + "cxa_default_handlers.cpp", + "cxa_demangle.cpp", + "cxa_exception_storage.cpp", + "cxa_guard.cpp", + "cxa_handlers.cpp", + "cxa_unexpected.cpp", + "cxa_vector.cpp", + "cxa_virtual.cpp", + + # C++ STL files", + "stdlib_exception.cpp", + "stdlib_stdexcept.cpp", + "stdlib_typeinfo.cpp", + + # Internal files + "abort_message.cpp", + "fallback_malloc.cpp", + "private_typeinfo.cpp", +] +if (libcxxabi_enable_new_delete_definitions) { + cxxabi_sources += [ "stdlib_new_delete.cpp" ] +} +if (libcxxabi_enable_exceptions) { + cxxabi_sources += [ + "cxa_exception.cpp", + "cxa_personality.cpp", + ] +} else { + cxxabi_sources += [ "cxa_noexception.cpp" ] +} +if (target_os == "linux" || target_os == "fuchsia") { + cxxabi_sources += [ "cxa_thread_atexit.cpp" ] +} + +config("cxxabi_config") { + include_dirs = [ + "//libcxxabi/include", + "//libcxx/include", + ] + cflags_cc = [ "-nostdinc++" ] + defines = [ "_LIBCXXABI_BUILDING_LIBRARY" ] + if (target_os == "win") { + defines += [ "_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS" ] + } +} + +if (libcxxabi_enable_shared) { + shared_library("cxxabi_shared") { + output_dir = runtimes_dir + output_name = "c++abi" + if (target_os == "linux" || target_os == "mac") { + cflags = [ "-fPIC" ] + ldflags = [ "-nostdlib++" ] + libs = [ + "dl", + "pthread", + ] + } + sources = cxxabi_sources + deps = [ + "//compiler-rt/lib/builtins", + "//libunwind/src:unwind_shared", + ] + configs += [ ":cxxabi_config" ] + configs -= [ + "//llvm/utils/gn/build:no_exceptions", + "//llvm/utils/gn/build:no_rtti", + ] + } +} + +if (libcxxabi_enable_static) { + static_library("cxxabi_static") { + output_dir = runtimes_dir + output_name = "c++abi" + complete_static_lib = true + sources = cxxabi_sources + if (libcxxabi_hermetic_static_library) { + cflags = [ "-fvisibility=hidden" ] + cflags_cc = [ "-fvisibility-global-new-delete-hidden" ] + defines = [ + "_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS", + "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS", + ] + } + deps = [ + "//compiler-rt/lib/builtins", + "//libunwind/src:unwind_static", + ] + configs += [ ":cxxabi_config" ] + configs -= [ + "//llvm/utils/gn/build:no_exceptions", + "//llvm/utils/gn/build:no_rtti", + "//llvm/utils/gn/build:thin_archive", + ] + } +} + +group("src") { + deps = [] + if (libcxxabi_enable_shared) { + deps += [ ":cxxabi_shared" ] + } + if (libcxxabi_enable_static) { + deps += [ ":cxxabi_static" ] + } +} diff --git a/llvm/utils/gn/secondary/libunwind/BUILD.gn b/llvm/utils/gn/secondary/libunwind/BUILD.gn new file mode 100644 --- /dev/null +++ b/llvm/utils/gn/secondary/libunwind/BUILD.gn @@ -0,0 +1,6 @@ +group("libunwind") { + deps = [ + "include", + "src(//llvm/utils/gn/build/toolchain:stage2_unix)", + ] +} diff --git a/llvm/utils/gn/secondary/libunwind/include/BUILD.gn b/llvm/utils/gn/secondary/libunwind/include/BUILD.gn new file mode 100644 --- /dev/null +++ b/llvm/utils/gn/secondary/libunwind/include/BUILD.gn @@ -0,0 +1,15 @@ +import("//clang/resource_dir.gni") + +copy("include") { + sources = [ + "__libunwind_config.h", + "libunwind.h", + "unwind.h", + ] + if (target_os == "mac") { + sources += [ "mach-o/compact_unwind_encoding.h" ] + } + outputs = [ + "$clang_resource_dir/include/c++/v1/{{source_target_relative}}", + ] +} diff --git a/llvm/utils/gn/secondary/libunwind/src/BUILD.gn b/llvm/utils/gn/secondary/libunwind/src/BUILD.gn new file mode 100644 --- /dev/null +++ b/llvm/utils/gn/secondary/libunwind/src/BUILD.gn @@ -0,0 +1,110 @@ +import("//clang/runtimes.gni") + +declare_args() { + # Build libunwind as a shared library. + libunwind_enable_shared = true + + # Build libunwind as a static library. + libunwind_enable_static = true + + # Do not export any symbols from the static library. + libunwind_hermetic_static_library = false +} + +unwind_sources = [ + "libunwind.cpp", + "Unwind-EHABI.cpp", + "Unwind-seh.cpp", + "UnwindLevel1.c", + "UnwindLevel1-gcc-ext.c", + "Unwind-sjlj.c", + "UnwindRegistersRestore.S", + "UnwindRegistersSave.S", + "AddressSpace.hpp", + "assembly.h", + "CompactUnwinder.hpp", + "config.h", + "dwarf2.h", + "DwarfInstructions.hpp", + "DwarfParser.hpp", + "libunwind_ext.h", + "Registers.hpp", + "RWMutex.hpp", + "UnwindCursor.hpp", +] +if (target_os == "mac") { + sources += [ "src/Unwind_AppleExtras.cpp" ] +} + +config("unwind_config") { + cflags = [] + cflags_c = [ "-std=c99" ] + cflags_cc = [ "-fno-rtti" ] + include_dirs = [ "//libunwind/include" ] + if (target_os == "mac") { + cflags += [ "-U__STRICT_ANSI__" ] + } +} + +if (libunwind_enable_shared) { + shared_library("unwind_shared") { + output_dir = runtimes_dir + output_name = "unwind" + if (target_os == "linux" || target_os == "mac") { + cflags = [ "-fPIC" ] + ldflags = [ "-nostdlib++" ] + libs = [ + "dl", + "pthread", + ] + } + if (target_os == "mac") { + ldflags += [ + "-compatibility_version 1", + "-install_name /usr/lib/libunwind.1.dylib", + ] + } + sources = unwind_sources + deps = [ + "//compiler-rt/lib/builtins", + ] + configs += [ ":unwind_config" ] + configs -= [ + "//llvm/utils/gn/build:no_exceptions", + "//llvm/utils/gn/build:no_rtti", + ] + } +} + +if (libunwind_enable_static) { + static_library("unwind_static") { + output_dir = runtimes_dir + output_name = "unwind" + complete_static_lib = true + sources = unwind_sources + if (libunwind_hermetic_static_library) { + cflags = [ "-fvisibility=hidden" ] + cflags_cc = [ "-fvisibility-global-new-delete-hidden" ] + defines = [ "_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS" ] + } + deps = [ + "//compiler-rt/lib/builtins", + ] + configs += [ ":unwind_config" ] + configs -= [ + "//llvm/utils/gn/build:no_exceptions", + "//llvm/utils/gn/build:no_rtti", + "//llvm/utils/gn/build:thin_archive", + ] + } +} + +group("src") { + deps = [] + if (libunwind_enable_shared) { + deps += [ ":unwind_shared" ] + } + if (libunwind_enable_static) { + deps += [ ":unwind_static" ] + } +}