Skip to content

Commit

Permalink
Build nacl_helper_nonsfi with GN
Browse files Browse the repository at this point in the history
Support building nacl_helper_nonsfi under GN.

BUG=462791

Review URL: https://codereview.chromium.org/1395573003

Cr-Commit-Position: refs/heads/master@{#356234}
  • Loading branch information
petrhosek authored and Commit bot committed Oct 27, 2015
1 parent 5d9a5a8 commit 636bceb
Show file tree
Hide file tree
Showing 16 changed files with 337 additions and 37 deletions.
34 changes: 29 additions & 5 deletions base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# found in the LICENSE file.

import("//build/config/compiler/compiler.gni")
import("//build/config/nacl/config.gni")
import("//build/config/ui.gni")
import("//testing/test.gni")

Expand Down Expand Up @@ -36,6 +37,16 @@ if (is_win) {
}
}

if (is_nacl_nonsfi) {
# Must be in a config because of how GN orders flags (otherwise -Wall will
# appear after this, and turn it back on).
config("nacl_nonsfi_warnings") {
# file_util_posix.cc contains a function which is not
# being used by nacl_helper_nonsfi.
cflags = [ "-Wno-unused-function" ]
}
}

source_set("base_paths") {
sources = [
"base_paths.cc",
Expand Down Expand Up @@ -746,21 +757,34 @@ component("base") {
"cpu.cc",
"files/file_enumerator_posix.cc",
"files/file_proxy.cc",
"files/file_util.cc",
"files/file_util_posix.cc",
"files/file_util_proxy.cc",
"files/important_file_writer.cc",
"files/important_file_writer.h",
"files/scoped_temp_dir.cc",
"message_loop/message_pump_libevent.cc",
"native_library_posix.cc",
"path_service.cc",
"rand_util_posix.cc",
"scoped_native_library.cc",
"sync_socket_posix.cc",
"sys_info.cc",
"sys_info_posix.cc",
]

if (is_nacl_nonsfi) {
set_sources_assignment_filter([])
sources += [ "posix/unix_domain_socket_linux.cc" ]
set_sources_assignment_filter(sources_assignment_filter)
sources -= [ "rand_util_nacl.cc" ]
configs += [ ":nacl_nonsfi_warnings" ]
} else {
sources -= [
"files/file_util.cc",
"files/file_util.h",
"files/file_util_posix.cc",
"message_loop/message_pump_libevent.cc",
"message_loop/message_pump_libevent.h",
"rand_util_posix.cc",
]
}
} else {
# Remove NaCl stuff.
sources -= [
Expand Down Expand Up @@ -820,7 +844,7 @@ component("base") {
"setupapi.lib",
]
all_dependent_configs = [ ":base_win_linker_flags" ]
} else if (!is_nacl) {
} else if (!is_nacl || is_nacl_nonsfi) {
# Non-Windows.
deps += [ "//third_party/libevent" ]
}
Expand Down
14 changes: 10 additions & 4 deletions base/process/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/nacl/config.gni")

source_set("process") {
sources = [
"internal_linux.cc",
Expand Down Expand Up @@ -82,10 +84,6 @@ source_set("process") {
sources -= [
"kill.cc",
"kill.h",
"kill_posix.cc",
"launch.cc",
"launch.h",
"launch_posix.cc",
"memory.cc",
"memory.h",
"process_iterator.cc",
Expand All @@ -94,6 +92,14 @@ source_set("process") {
"process_metrics_posix.cc",
"process_posix.cc",
]
if (!is_nacl_nonsfi) {
sources -= [
"kill_posix.cc",
"launch.cc",
"launch.h",
"launch_posix.cc",
]
}
}

if (is_nacl) {
Expand Down
32 changes: 32 additions & 0 deletions build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,30 @@ config("compiler_cpu_abi") {
]
ldflags += [ "-mips64r2" ]
}
} else if (current_cpu == "pnacl" && is_nacl_nonsfi) {
if (target_cpu == "x86" || target_cpu == "x64") {
cflags += [
"-arch",
"x86-32-nonsfi",
"--pnacl-bias=x86-32-nonsfi",
"--target=i686-unknown-nacl",
]
ldflags += [
"-arch",
"x86-32-nonsfi",
"--target=i686-unknown-nacl",
]
} else if (target_cpu == "arm") {
cflags += [
"-arch",
"arm-nonsfi",
"--pnacl-bias=arm-nonsfi",
]
ldflags += [
"-arch",
"arm-nonsfi",
]
}
}
}

Expand Down Expand Up @@ -753,6 +777,14 @@ config("default_warnings") {
"-Wno-bitfield-width",
]
}

if (is_nacl_nonsfi) {
cflags += [
# TODO(phosek): Enable after https://codereview.chromium.org/1419373002/
# is rolled into Chrome.
"-Wno-sign-compare",
]
}
}
}

Expand Down
25 changes: 25 additions & 0 deletions build/config/nacl/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ source_set("nacl_base") {
config("compiler") {
configs = []
cflags = []
ldflags = []
libs = []

if (is_clang && current_cpu != "pnacl") {
# -no-integrated-as is the default in nacl-clang for historical
Expand All @@ -48,6 +50,29 @@ config("compiler") {
# everywhere for consistency (and possibly quicker builds).
cflags += [ "-integrated-as" ]
}
if (is_nacl_nonsfi) {
cflags += [ "--pnacl-allow-translate" ]
ldflags += [
"--pnacl-allow-translate",
"--pnacl-allow-native",
"-Wl,--noirt",
"-Wt,--noirt",
"-Wt,--noirtshim",

# The clang driver automatically injects -lpthread when using libc++, but
# the toolchain doesn't have it yet. To get around this, use
# -nodefaultlibs and make each executable target depend on
# "//native_client/src/nonsfi/irt:nacl_sys_private".
"-nodefaultlibs",
]
libs += [
"c++",
"m",
"c",
"pnaclmm",
]
include_dirs = [ "//native_client/src/public/linux_syscalls" ]
}

asmflags = cflags
}
Expand Down
5 changes: 5 additions & 0 deletions build/config/nacl/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ nacl_toolchain_dir = "//native_client/toolchain/${host_os}_x86"

nacl_irt_toolchain = "//build/toolchain/nacl:irt_" + target_cpu
is_nacl_irt = current_toolchain == nacl_irt_toolchain

# Non-SFI mode is a lightweight sandbox used by Chrome OS for running ARC
# applications.
nacl_nonsfi_toolchain = "//build/toolchain/nacl:newlib_pnacl_nonsfi"
is_nacl_nonsfi = current_toolchain == nacl_nonsfi_toolchain
16 changes: 16 additions & 0 deletions build/toolchain/nacl/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ nacl_toolchain("newlib_pnacl") {
link_outputs = [ finalized_file ]
}

nacl_toolchain("newlib_pnacl_nonsfi") {
toolchain_package = "pnacl_newlib"
toolchain_revision = pnacl_newlib_rev
toolchain_cpu = "pnacl"
toolprefix =
rebase_path("${nacl_toolchain_dir}/${toolchain_package}/bin/pnacl-",
root_build_dir)

is_clang = true
cc = toolprefix + "clang"
cxx = toolprefix + "clang++"
ar = toolprefix + "ar"
ld = cxx
executable_extension = ""
}

template("nacl_glibc_toolchain") {
toolchain_cpu = target_name
assert(defined(invoker.toolchain_tuple), "Must define toolchain_tuple")
Expand Down
6 changes: 3 additions & 3 deletions chrome/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,9 @@ if (!is_android) {
]

if (enable_nacl) {
deps += [
data_deps += [
"//components/nacl:nacl_helper",
# '../components/nacl_nonsfi.gyp:nacl_helper_nonsfi', TODO(GYP)
"//components/nacl:helper_nonsfi",
]
}

Expand Down Expand Up @@ -984,7 +984,7 @@ if (!is_android) {
if (is_linux) {
data_deps += [
"//components/nacl:nacl_helper",
# "//components/nacl_nonsfi.gyp:nacl_helper_nonsfi", # TODO(GYP) bug 512912.
"//components/nacl:helper_nonsfi",
]
}
}
Expand Down
71 changes: 68 additions & 3 deletions components/nacl/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import("//build/config/crypto.gni")
import("//build/config/features.gni")
import("//build/config/nacl/config.gni")
import("//build/config/ui.gni")
import("//testing/test.gni")

Expand Down Expand Up @@ -236,10 +237,74 @@ if (enable_nacl) {
}
}
}
} else {
group("nacl") {

if (is_nacl_nonsfi) {
executable("nacl_helper_nonsfi_nexe") {
output_name = "nacl_helper_nonsfi"
set_sources_assignment_filter([])
sources = [
"common/nacl_messages.cc",
"common/nacl_messages.h",
"common/nacl_types.cc",
"common/nacl_types.h",
"common/nacl_types_param_traits.cc",
"common/nacl_types_param_traits.h",
"loader/nacl_helper_linux.cc",
"loader/nacl_helper_linux.h",
"loader/nacl_trusted_listener.cc",
"loader/nacl_trusted_listener.h",
"loader/nonsfi/nonsfi_listener.cc",
"loader/nonsfi/nonsfi_listener.h",
"loader/nonsfi/nonsfi_main.cc",
"loader/nonsfi/nonsfi_main.h",
]
deps = [
":nacl_switches",
":nacl_helper_nonsfi_sandbox",
"//base",
"//components/tracing",
"//content",
"//ipc",
"//native_client/src/nonsfi/irt:nacl_sys_private",
"//native_client/src/nonsfi/loader:elf_loader",
"//native_client/src/untrusted/nacl:nacl",
"//ppapi/proxy",
"//sandbox/linux:sandbox",
]
}

source_set("nacl_helper_nonsfi_sandbox") {
set_sources_assignment_filter([])
sources = [
"loader/nonsfi/nonsfi_sandbox.cc",
"loader/nonsfi/nonsfi_sandbox.h",
"loader/sandbox_linux/nacl_sandbox_linux.cc",
"loader/sandbox_linux/nacl_sandbox_linux.h",
]
deps = [
"//base",
"//content",
"//sandbox/linux:sandbox",
]
}

copy("nacl_helper_nonsfi_copy") {
sources = [
"${root_out_dir}/nacl_helper_nonsfi",
]
outputs = [
"${root_build_dir}/{{source_file_part}}",
]
deps = [
":nacl_helper_nonsfi_nexe",
]
}
}
group("nacl_helper") {

group("helper_nonsfi") {
deps = [
":nacl_helper_nonsfi_copy(//build/toolchain/nacl:newlib_pnacl_nonsfi)",
]
}
}

Expand Down
43 changes: 32 additions & 11 deletions content/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# found in the LICENSE file.

import("//tools/grit/grit_rule.gni")
import("//build/config/nacl/config.gni")

# Applied by targets internal to content.
config("content_implementation") {
Expand Down Expand Up @@ -37,18 +38,21 @@ config("content_implementation") {
# targets make sure the dependency goes through the content shared library
# when doing a component build).

content_shared_components = [
"//content/gpu:gpu_sources",
"//content/public/browser:browser_sources",
"//content/public/child:child_sources",
"//content/public/common:common_sources",
"//content/public/plugin:plugin_sources",
"//content/public/renderer:renderer_sources",
"//content/public/utility:utility_sources",
]
if (!is_nacl_nonsfi) {
content_shared_components = [
"//content/gpu:gpu_sources",
"//content/public/browser:browser_sources",
"//content/public/child:child_sources",
"//content/public/common:common_sources",
"//content/public/plugin:plugin_sources",
"//content/public/renderer:renderer_sources",
"//content/public/utility:utility_sources",
]

if (enable_plugins) {
content_shared_components += [ "//content/ppapi_plugin:ppapi_plugin_sources" ]
if (enable_plugins) {
content_shared_components +=
[ "//content/ppapi_plugin:ppapi_plugin_sources" ]
}
}

if (is_component_build) {
Expand All @@ -59,6 +63,23 @@ if (is_component_build) {
"//build/config/sanitizers:deps",
]
}
} else if (is_nacl_nonsfi) {
source_set("content") {
set_sources_assignment_filter([])
sources = [
"common/sandbox_linux/sandbox_init_linux.cc",
"common/sandbox_linux/sandbox_seccomp_bpf_linux.cc",
"common/send_zygote_child_ping_linux.cc",
"public/common/content_switches.cc",
]
set_sources_assignment_filter(sources_assignment_filter)

defines = [ "USE_SECCOMP_BPF=1" ]

deps = [
"//base",
]
}
} else {
group("content") {
deps = content_shared_components
Expand Down
Loading

0 comments on commit 636bceb

Please sign in to comment.