From 99b00306162df0984c6040f44b6f317ce9a67322 Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Tue, 19 Dec 2017 14:21:14 -0500 Subject: [PATCH] gn, linux: Build for Linux with GN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is sufficient for a native Linux build using GN. Android is not yet supported. mini_chromium side: https://crrev.com/c/833407 This also updates mini_chromium to 404f6dbf9928. c913ef97a236 gn, linux: Build for Linux with GN 404f6dbf9928 gn: Don’t use .rsp files; rationalize descriptions and output dirs Bug: crashpad:79 Change-Id: I4f3b72fd02884d77812e520fb95231b35815677d Reviewed-on: https://chromium-review.googlesource.com/833408 Commit-Queue: Mark Mentovai Reviewed-by: Scott Graham --- DEPS | 2 +- build/BUILDCONFIG.gn | 32 ++++++++++------ build/crashpad_dependencies.gni | 2 +- compat/BUILD.gn | 19 ++++++++-- snapshot/BUILD.gn | 66 ++++++++++++++++++++++++++++++++- test/BUILD.gn | 9 +++++ tools/BUILD.gn | 11 +++--- util/BUILD.gn | 56 ++++++++++++++++++++++++++++ 8 files changed, 173 insertions(+), 24 deletions(-) diff --git a/DEPS b/DEPS index e221cad1d1..3f15230b32 100644 --- a/DEPS +++ b/DEPS @@ -28,7 +28,7 @@ deps = { '5e2b3ddde7cda5eb6bc09a5546a76b00e49d888f', 'crashpad/third_party/mini_chromium/mini_chromium': Var('chromium_git') + '/chromium/mini_chromium@' + - 'e182031c61072f629494a1f52729a8d29a6acace', + '404f6dbf9928dd19cb437ad5b05abfdd97b5bf67', 'crashpad/third_party/zlib/zlib': Var('chromium_git') + '/chromium/src/third_party/zlib@' + '13dc246a58e4b72104d35f9b1809af95221ebda7', diff --git a/build/BUILDCONFIG.gn b/build/BUILDCONFIG.gn index 581788183a..7444c6f0f6 100644 --- a/build/BUILDCONFIG.gn +++ b/build/BUILDCONFIG.gn @@ -28,12 +28,6 @@ if (current_cpu == "") { current_cpu = target_cpu } -declare_args() { - is_debug = false - is_clang = current_os == "mac" || current_os == "fuchsia" - clang_root = "" -} - is_mac = false is_win = false is_linux = false @@ -52,6 +46,16 @@ if (current_os == "mac") { is_fuchsia = true } +declare_args() { + # When true, enables the debug configuration, with additional run-time checks + # and logging. When false, enables the release configuration, with additional + # optimizations. + is_debug = false + + # When true, configures for compilation with Clang. + is_clang = !is_win +} + if (is_win) { set_default_toolchain( "//third_party/mini_chromium/mini_chromium/build:msvc_toolchain") @@ -60,29 +64,33 @@ if (is_win) { "//third_party/mini_chromium/mini_chromium/build:gcc_like_toolchain") } -default_configs = [ +_default_configs = [ "//third_party/mini_chromium/mini_chromium/build:default", "//third_party/mini_chromium/mini_chromium/build:Wexit_time_destructors", ] +default_executable_configs = + _default_configs + + [ "//third_party/mini_chromium/mini_chromium/build:executable" ] + set_defaults("source_set") { - configs = default_configs + configs = _default_configs } set_defaults("static_library") { - configs = default_configs + configs = _default_configs } set_defaults("executable") { - configs = default_configs + configs = default_executable_configs } set_defaults("loadable_module") { - configs = default_configs + configs = _default_configs } set_defaults("shared_library") { - configs = default_configs + configs = _default_configs } # These are set to constant values for Chromium build file compatibility. This diff --git a/build/crashpad_dependencies.gni b/build/crashpad_dependencies.gni index e786420fa6..1964facd37 100644 --- a/build/crashpad_dependencies.gni +++ b/build/crashpad_dependencies.gni @@ -48,6 +48,6 @@ if (crashpad_is_in_chromium) { } set_defaults("test") { - configs = _default_configs + configs = default_executable_configs } } diff --git a/compat/BUILD.gn b/compat/BUILD.gn index af84513016..bff7d5f8e9 100644 --- a/compat/BUILD.gn +++ b/compat/BUILD.gn @@ -15,15 +15,19 @@ config("compat_config") { include_dirs = [] + if (is_mac) { + include_dirs += [ "mac" ] + } + + if (is_linux) { + include_dirs += [ "linux" ] + } + if (is_win) { include_dirs += [ "win" ] } else { include_dirs += [ "non_win" ] } - - if (is_mac) { - include_dirs += [ "mac" ] - } } template("compat_target") { @@ -55,6 +59,13 @@ compat_target("compat") { sources += [ "non_mac/mach/mach.h" ] } + if (is_linux) { + sources += [ + "linux/signal.h", + "linux/sys/ptrace.h", + ] + } + if (is_win) { sources += [ "win/getopt.h", diff --git a/snapshot/BUILD.gn b/snapshot/BUILD.gn index 5e9a9314b0..2b442211fd 100644 --- a/snapshot/BUILD.gn +++ b/snapshot/BUILD.gn @@ -94,6 +94,34 @@ static_library("snapshot") { ] } + if (is_linux) { + sources += [ + "elf/elf_dynamic_array_reader.cc", + "elf/elf_dynamic_array_reader.h", + "elf/elf_image_reader.cc", + "elf/elf_image_reader.h", + "elf/elf_symbol_table_reader.cc", + "elf/elf_symbol_table_reader.h", + "linux/cpu_context_linux.cc", + "linux/cpu_context_linux.h", + "linux/debug_rendezvous.cc", + "linux/debug_rendezvous.h", + "linux/exception_snapshot_linux.cc", + "linux/exception_snapshot_linux.h", + "linux/memory_snapshot_linux.cc", + "linux/memory_snapshot_linux.h", + "linux/process_reader.cc", + "linux/process_reader.h", + "linux/process_snapshot_linux.cc", + "linux/process_snapshot_linux.h", + "linux/signal_context.h", + "linux/system_snapshot_linux.cc", + "linux/system_snapshot_linux.h", + "linux/thread_snapshot_linux.cc", + "linux/thread_snapshot_linux.h", + ] + } + if (is_win) { sources += [ "win/capture_memory_delegate_win.cc", @@ -218,12 +246,24 @@ static_library("test_support") { } } +config("snapshot_test_link") { + visibility = [ ":*" ] + if (is_linux) { + # There’s no way to make the link depend on this file. “inputs” doesn’t have + # the intended effect in a config. https://crbug.com/781858, + # https://crbug.com/796187. + inputs = [ + "elf/test_exported_symbols.sym", + ] + ldflags = [ "-Wl,--dynamic-list," + rebase_path(inputs[0], root_build_dir) ] + } +} + source_set("snapshot_test") { testonly = true sources = [ "cpu_context_test.cc", - "crashpad_info_client_options_test.cc", "minidump/process_snapshot_minidump_test.cc", ] @@ -239,6 +279,20 @@ source_set("snapshot_test") { ] } + if (is_linux) { + sources += [ + "elf/elf_image_reader_test.cc", + "elf/elf_image_reader_test_note.S", + "elf/test_exported_symbols.sym", + "linux/debug_rendezvous_test.cc", + "linux/exception_snapshot_linux_test.cc", + "linux/process_reader_test.cc", + "linux/system_snapshot_linux_test.cc", + ] + } else { + sources += [ "crashpad_info_client_options_test.cc" ] + } + if (is_win) { sources += [ "api/module_annotations_win_test.cc", @@ -255,6 +309,12 @@ source_set("snapshot_test") { sources += [ "posix/timezone_test.cc" ] } + # public_configs isn’t quite right. snapshot_test_link sets ldflags, and + # what’s really needed is a way to push ldflags to dependent targets that + # produce linker output. Luckily in this case, all dependents do produce + # linker output. https://crbug.com/796183. + public_configs = [ ":snapshot_test_link" ] + deps = [ ":snapshot_api", ":test_support", @@ -281,6 +341,10 @@ source_set("snapshot_test") { ] } + if (is_linux) { + libs = [ "dl" ] + } + if (is_win) { cflags = [ "/wd4201" ] # nonstandard extension used : nameless struct/union diff --git a/test/BUILD.gn b/test/BUILD.gn index e6a08a12fc..6573c3620b 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -65,6 +65,15 @@ static_library("test") { ] } + if (is_linux) { + sources += [ + "linux/fake_ptrace_connection.cc", + "linux/fake_ptrace_connection.h", + "linux/get_tls.cc", + "linux/get_tls.h", + ] + } + if (is_win) { sources += [ "multiprocess_exec_win.cc", diff --git a/tools/BUILD.gn b/tools/BUILD.gn index e81b449303..016daa9666 100644 --- a/tools/BUILD.gn +++ b/tools/BUILD.gn @@ -72,14 +72,15 @@ executable("generate_dump") { if (is_mac) { # This would be better as a config so that it could be shared with # exception_port_tool, but configs can’t alter “inputs”. + # https://crbug.com/781858. inputs = [ - rebase_path("mac/sectaskaccess_info.plist"), + "mac/sectaskaccess_info.plist", ] ldflags = [ "-sectcreate", "__TEXT", "__info_plist", - inputs[0], + rebase_path(inputs[0], root_build_dir), ] } @@ -108,15 +109,15 @@ if (is_mac) { ] # This would be better as a config so that it could be shared with - # generate_dump, but configs can’t alter “inputs”. + # generate_dump, but configs can’t alter “inputs”. https://crbug.com/781858. inputs = [ - rebase_path("mac/sectaskaccess_info.plist"), + "mac/sectaskaccess_info.plist", ] ldflags = [ "-sectcreate", "__TEXT", "__info_plist", - inputs[0], + rebase_path(inputs[0], root_build_dir), ] deps = [ diff --git a/util/BUILD.gn b/util/BUILD.gn index e097f2fab9..b24feeaad2 100644 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -240,6 +240,43 @@ static_library("util") { sources += get_target_outputs(":mig") } + if (is_linux) { + sources += [ + "linux/address_types.h", + "linux/auxiliary_vector.cc", + "linux/auxiliary_vector.h", + "linux/checked_linux_address_range.h", + "linux/direct_ptrace_connection.cc", + "linux/direct_ptrace_connection.h", + "linux/exception_information.h", + "linux/memory_map.cc", + "linux/memory_map.h", + "linux/proc_stat_reader.cc", + "linux/proc_stat_reader.h", + "linux/ptrace_broker.cc", + "linux/ptrace_broker.h", + "linux/ptrace_client.cc", + "linux/ptrace_client.h", + "linux/ptrace_connection.h", + "linux/ptracer.cc", + "linux/ptracer.h", + "linux/scoped_ptrace_attach.cc", + "linux/scoped_ptrace_attach.h", + "linux/thread_info.cc", + "linux/thread_info.h", + "linux/traits.h", + "misc/paths_linux.cc", + "net/http_transport_libcurl.cc", + "posix/process_info_linux.cc", + "process/process_memory_linux.cc", + "process/process_memory_linux.h", + + # TODO: Port to all platforms. + "process/process_memory_range.cc", + "process/process_memory_range.h", + ] + } + if (is_win) { sources += [ "file/directory_reader_win.cc", @@ -349,6 +386,10 @@ static_library("util") { include_dirs += [ "$root_build_dir/gen" ] } + if (is_linux) { + libs = [ "curl" ] + } + if (is_win) { cflags = [ "/wd4201", # nonstandard extension used : nameless struct/union. @@ -449,6 +490,21 @@ source_set("util_test") { ] } + if (is_linux) { + sources += [ + "linux/auxiliary_vector_test.cc", + "linux/memory_map_test.cc", + "linux/proc_stat_reader_test.cc", + "linux/ptrace_broker_test.cc", + "linux/ptracer_test.cc", + "linux/scoped_ptrace_attach_test.cc", + + # TODO: Port to all platforms. + "process/process_memory_range_test.cc", + "process/process_memory_test.cc", + ] + } + if (is_win) { sources += [ "win/capture_context_test.cc",