BUILD.gn (4003B)
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("//chromium/build/config/nacl/config.gni") 6 7 # Native Client Definitions 8 config("nacl_defines") { 9 if (is_linux || is_chromeos || 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 (target_cpu == "pnacl") { 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 doesn't see that there is an initializer later in the file, 41 # and warns about the forward declaration. 42 cflags = [ "/wd4132" ] 43 } 44 } 45 46 config("nacl_static_libstdc++") { 47 # The sysroot of linux x86 bots can have a different version of libstdc++ 48 # than the one that is on the bots natively. Linking dynamically against 49 # libstdc++ can then lead to linking against symbols that are not found when 50 # running the executable. 51 # Therefore, link statically instead. 52 if (is_linux && target_cpu == "x86") { 53 ldflags = [ "-static-libstdc++" ] 54 } 55 } 56 57 # The base target that all targets in the NaCl build should depend on. 58 # This allows configs to be modified for everything in the NaCl build, even when 59 # the NaCl build is composed into the Chrome build. (GN has no functionality to 60 # add flags to everything in //native_client, having a base target works around 61 # that limitation.) 62 source_set("nacl_base") { 63 public_configs = [ 64 ":nacl_defines", 65 ":nacl_warnings", 66 ":nacl_static_libstdc++", 67 ] 68 if (current_os == "nacl") { 69 public_configs += [ ":nexe_defines" ] 70 } 71 } 72 73 config("compiler") { 74 configs = [] 75 cflags = [] 76 ldflags = [] 77 libs = [] 78 79 if (is_clang && target_cpu != "pnacl") { 80 # -no-integrated-as is the default in nacl-clang for historical 81 # compatibility with inline assembly code and so forth. But there 82 # are no such cases in Chromium code, and -integrated-as is nicer in 83 # general. Moreover, the IRT must be built using LLVM's assembler 84 # on x86-64 to preserve sandbox base address hiding. Use it 85 # everywhere for consistency (and possibly quicker builds). 86 cflags += [ "-integrated-as" ] 87 } 88 89 asmflags = cflags 90 } 91 92 config("compiler_codegen") { 93 cflags = [] 94 95 if (is_nacl_irt) { 96 cflags += [ 97 # A debugger should be able to unwind IRT call frames. This is 98 # the default behavior on x86-64 and when compiling C++ with 99 # exceptions enabled; the change is for the benefit of x86-32 C. 100 # The frame pointer is unnecessary when unwind tables are used. 101 "-fasynchronous-unwind-tables", 102 "-fomit-frame-pointer", 103 ] 104 105 if (target_cpu == "x86") { 106 # The x86-32 IRT needs to be callable with an under-aligned 107 # stack; so we disable SSE instructions, which can fault on 108 # misaligned addresses. See 109 # https://code.google.com/p/nativeclient/issues/detail?id=3935 110 cflags += [ 111 "-mstackrealign", 112 "-mno-sse", 113 ] 114 } 115 } 116 117 asmflags = cflags 118 } 119 120 config("irt_optimize") { 121 cflags = [ 122 # Optimize for space, keep the IRT nexe small. 123 "-Os", 124 125 # These are omitted from non-IRT libraries to keep the libraries 126 # themselves small. 127 "-ffunction-sections", 128 "-fdata-sections", 129 ] 130 131 ldflags = [ "-Wl,--gc-sections" ] 132 }