Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1 | # Copyright (c) 2014 The Native Client Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | import("//build/config/nacl/config.gni") |
| 6 | |
| 7 | # Native Client Definitions |
| 8 | config("nacl_defines") { |
| 9 | if (is_linux || is_android || is_nacl) { |
| 10 | defines = [ |
| 11 | "_POSIX_C_SOURCE=199506", |
| 12 | "_XOPEN_SOURCE=600", |
| 13 | "_GNU_SOURCE=1", |
| 14 | "__STDC_LIMIT_MACROS=1", |
| 15 | ] |
| 16 | } else if (is_win) { |
| 17 | defines = [ "__STDC_LIMIT_MACROS=1" ] |
| 18 | } |
| 19 | |
| 20 | if (current_cpu == "pnacl" && !is_nacl_nonsfi) { |
| 21 | # TODO: Remove the following definition once NACL_BUILD_ARCH and |
| 22 | # NACL_BUILD_SUBARCH are defined by the PNaCl toolchain. |
| 23 | defines += [ "NACL_BUILD_ARCH=pnacl" ] |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | config("nexe_defines") { |
| 28 | defines = [ |
| 29 | "DYNAMIC_ANNOTATIONS_ENABLED=1", |
| 30 | "DYNAMIC_ANNOTATIONS_PREFIX=NACL_", |
| 31 | ] |
| 32 | } |
| 33 | |
| 34 | config("nacl_warnings") { |
| 35 | if (is_win) { |
| 36 | # Some NaCl code uses forward declarations of static const variables, |
| 37 | # with initialized definitions later on. (The alternative would be |
| 38 | # many, many more forward declarations of everything used in that |
| 39 | # const variable's initializer before the definition.) The Windows |
| 40 | # compiler is too stupid to notice that there is an initializer later |
| 41 | # in the file, and warns about the forward declaration. |
| 42 | cflags = [ "/wd4132" ] |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | # The base target that all targets in the NaCl build should depend on. |
| 47 | # This allows configs to be modified for everything in the NaCl build, even when |
| 48 | # the NaCl build is composed into the Chrome build. (GN has no functionality to |
| 49 | # add flags to everything in //native_client, having a base target works around |
| 50 | # that limitation.) |
| 51 | source_set("nacl_base") { |
| 52 | public_configs = [ |
| 53 | ":nacl_defines", |
| 54 | ":nacl_warnings", |
| 55 | ] |
| 56 | if (current_os == "nacl") { |
| 57 | public_configs += [ ":nexe_defines" ] |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | config("compiler") { |
| 62 | configs = [] |
| 63 | cflags = [] |
| 64 | ldflags = [] |
| 65 | libs = [] |
| 66 | |
| 67 | if (is_clang && current_cpu != "pnacl") { |
| 68 | # -no-integrated-as is the default in nacl-clang for historical |
| 69 | # compatibility with inline assembly code and so forth. But there |
| 70 | # are no such cases in Chromium code, and -integrated-as is nicer in |
| 71 | # general. Moreover, the IRT must be built using LLVM's assembler |
| 72 | # on x86-64 to preserve sandbox base address hiding. Use it |
| 73 | # everywhere for consistency (and possibly quicker builds). |
| 74 | cflags += [ "-integrated-as" ] |
| 75 | } |
| 76 | if (is_nacl_nonsfi) { |
| 77 | cflags += [ "--pnacl-allow-translate" ] |
| 78 | ldflags += [ |
| 79 | "--pnacl-allow-translate", |
| 80 | "--pnacl-allow-native", |
| 81 | "-Wl,--noirt", |
| 82 | "-Wt,--noirt", |
| 83 | "-Wt,--noirtshim", |
| 84 | |
| 85 | # The clang driver automatically injects -lpthread when using libc++, but |
| 86 | # the toolchain doesn't have it yet. To get around this, use |
| 87 | # -nodefaultlibs and make each executable target depend on |
| 88 | # "//native_client/src/nonsfi/irt:nacl_sys_private". |
| 89 | "-nodefaultlibs", |
| 90 | ] |
| 91 | libs += [ |
| 92 | "c++", |
| 93 | "m", |
| 94 | "c", |
| 95 | "pnaclmm", |
| 96 | ] |
| 97 | include_dirs = [ "//native_client/src/public/linux_syscalls" ] |
| 98 | } |
| 99 | |
| 100 | asmflags = cflags |
| 101 | } |
| 102 | |
| 103 | config("compiler_codegen") { |
| 104 | cflags = [] |
| 105 | |
| 106 | if (is_nacl_irt) { |
| 107 | cflags += [ |
| 108 | # A debugger should be able to unwind IRT call frames. This is |
| 109 | # the default behavior on x86-64 and when compiling C++ with |
| 110 | # exceptions enabled; the change is for the benefit of x86-32 C. |
| 111 | # The frame pointer is unnecessary when unwind tables are used. |
| 112 | "-fasynchronous-unwind-tables", |
| 113 | "-fomit-frame-pointer", |
| 114 | ] |
| 115 | |
| 116 | if (current_cpu == "x86") { |
| 117 | # The x86-32 IRT needs to be callable with an under-aligned |
| 118 | # stack; so we disable SSE instructions, which can fault on |
| 119 | # misaligned addresses. See |
| 120 | # https://code.google.com/p/nativeclient/issues/detail?id=3935 |
| 121 | cflags += [ |
| 122 | "-mstackrealign", |
| 123 | "-mno-sse", |
| 124 | ] |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | asmflags = cflags |
| 129 | } |
| 130 | |
| 131 | config("irt_optimize") { |
| 132 | cflags = [ |
| 133 | # Optimize for space, keep the IRT nexe small. |
| 134 | "-Os", |
| 135 | |
| 136 | # These are omitted from non-IRT libraries to keep the libraries |
| 137 | # themselves small. |
| 138 | "-ffunction-sections", |
| 139 | "-fdata-sections", |
| 140 | ] |
| 141 | |
| 142 | ldflags = [ "-Wl,--gc-sections" ] |
| 143 | } |