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