Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / native_client / src / trusted / service_runtime / linux / nacl_bootstrap.gyp
1 # Copyright (c) 2012 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 {
6   'includes': [
7     '../../../../build/common.gypi',
8   ],
9   'conditions': [
10     ['target_arch=="x64"', {
11       'variables': {
12         # No extra reservation.
13         'nacl_reserve_top': '0x0',
14       }
15     }],
16     ['target_arch=="ia32"', {
17       'variables': {
18         # 1G address space.
19         'nacl_reserve_top': '0x40000000',
20       }
21     }],
22     ['target_arch=="arm"', {
23       'variables': {
24         # 1G address space, plus 8K guard area above.
25         'nacl_reserve_top': '0x40002000',
26       }
27     }],
28     ['target_arch=="mipsel"', {
29       'variables': {
30         # 1G address space, plus 32K guard area above.
31         'nacl_reserve_top': '0x40008000',
32       }
33     }],
34   ],
35   'targets': [
36     {
37       'target_name': 'nacl_bootstrap_lib',
38       'type': 'static_library',
39       'product_dir': '<(SHARED_INTERMEDIATE_DIR)/nacl_bootstrap',
40       'hard_depencency': 1,
41       'include_dirs': [
42         '..',
43       ],
44       'sources': [
45         'nacl_bootstrap.c',
46       ],
47       'cflags': [
48         # Prevent llvm-opt from replacing my_bzero with a call
49         # to memset.
50         '-fno-builtin',
51         # The tiny standalone bootstrap program is incompatible with
52         # -fstack-protector, which might be on by default.  That switch
53         # requires using the standard libc startup code, which we do not.
54         '-fno-stack-protector',
55         # We don't want to compile it PIC (or its cousin PIE), because
56         # it goes at an absolute address anyway, and because any kind
57         # of PIC complicates life for the x86-32 assembly code.  We
58         # append -fno-* flags here instead of using a 'cflags!' stanza
59         # to remove -f* flags, just in case some system's compiler
60         # defaults to using PIC for everything.
61         '-fno-pic', '-fno-PIC',
62         '-fno-pie', '-fno-PIE',
63       ],
64       'cflags!': [
65         # ld_bfd.py that is used to link nacl_bootstrap_raw doesn't recognize
66         # the Clang driver flags and will fail to link instrumented
67         # nacl_bootstrap.o.
68         # We hope there's nothing to search for in this small program and
69         # disable all the sanitizers for it.
70         '-fsanitize=address',
71         '-fsanitize=memory',
72         '-fsanitize=null',
73         '-fsanitize=vptr',
74         '-fsanitize=undefined',
75         '-w',
76         # We filter these out because release_extra_cflags or another
77         # such thing might be adding them in, and those options wind up
78         # coming after the -fno-stack-protector we added above.
79         '-fstack-protector',
80         '-fstack-protector-all',
81         '-fstack-protector-strong',
82         '-fprofile-generate',
83         '-finstrument-functions',
84         '-funwind-tables',
85         # This causes an "unused argument" warning in C targets.
86         '-stdlib=libc++',
87       ],
88       'conditions': [
89         ['clang==1', {
90           'cflags': [
91             # TODO(bbudge) Remove this when Clang supports -fno-pic.
92             '-Qunused-arguments',
93           ],
94         }],
95       ],
96     },
97     {
98       'target_name': 'nacl_bootstrap_raw',
99       'type': 'none',
100       # This magical flag tells Gyp that the dependencies of this target
101       # are nobody else's business and it should not propagate them up
102       # to things that list this as a dependency.  Without this, it will
103       # wind up adding the nacl_bootstrap_lib static library into the
104       # link of sel_ldr or chrome just because one executable depends on
105       # the other.
106       # TODO(mcgrathr): Maybe one day Gyp will grow a proper target type
107       # for the use we really want here: custom commands for linking an
108       # executable, and no peeking inside this target just because you
109       # depend on it.  Then we could stop using this utterly arcane flag
110       # in favor of something vaguely self-explanatory.
111       # See http://code.google.com/p/gyp/issues/detail?id=239 for the
112       # history of the arcana.
113       'dependencies_traverse': 0,
114       'dependencies': [
115         'nacl_bootstrap_lib',
116       ],
117       'actions': [
118         {
119           'action_name': 'link_with_ld_bfd',
120           'variables': {
121             'bootstrap_lib': '<(SHARED_INTERMEDIATE_DIR)/nacl_bootstrap/<(STATIC_LIB_PREFIX)nacl_bootstrap_lib<(STATIC_LIB_SUFFIX)',
122             'linker_script': 'nacl_bootstrap.x',
123           },
124           'inputs': [
125             '<(linker_script)',
126             '<(bootstrap_lib)',
127             'ld_bfd.py',
128           ],
129           'outputs': [
130             '<(PRODUCT_DIR)/nacl_bootstrap_raw',
131           ],
132           'message': 'Linking nacl_bootstrap_raw',
133           'conditions': [
134             ['target_arch=="x64"', {
135               'variables': {
136                 'linker_emulation': 'elf_x86_64',
137               }
138             }],
139             ['target_arch=="ia32"', {
140               'variables': {
141                 'linker_emulation': 'elf_i386',
142               }
143             }],
144             ['target_arch=="arm"', {
145               'variables': {
146                 'linker_emulation': 'armelf_linux_eabi',
147               }
148             }],
149             ['target_arch=="mipsel"', {
150               'variables': {
151                 'linker_emulation': 'elf32ltsmip',
152               },
153             }],
154             # ld_bfd.py needs to know the target compiler used for the
155             # build but the $CXX environment variable might only be
156             # set at gyp time. This is a hacky way to bake the correct
157             # CXX into the build at gyp time.
158             # TODO(sbc): Do this better by providing some gyp syntax
159             # for accessing the name of the configured compiler, or
160             # even a better way to access gyp time environment
161             # variables from within a gyp file.
162             ['OS=="android"', {
163               'variables': {
164                 'compiler': '<!(/bin/echo -n <(android_toolchain)/*-g++)',
165               }
166             }],
167             # When building for ARM default to arm-linux-gnueabihf-g++ rather
168             # than g++.  This is needed when building with clang (since in
169             # this case $CC and $CXX are not set in the environment).
170             ['OS!="android" and target_arch=="arm"', {
171               'variables': {
172                 'compiler': '<!(echo ${CXX:=arm-linux-gnueabihf-g++})',
173               }
174             }],
175             ['OS!="android" and target_arch!="arm"', {
176               'variables': {
177                 'compiler': '<!(echo ${CXX:=g++})',
178               }
179             }],
180           ],
181           'action': ['python', 'ld_bfd.py',
182                      '--compiler', '<(compiler)',
183                      '-m', '<(linker_emulation)',
184                      '--build-id',
185                      # This program is (almost) entirely
186                      # standalone.  It has its own startup code, so
187                      # no crt1.o for it.  It is statically linked,
188                      # and on x86 it does not use libc at all.
189                      # However, on ARM it needs a few (safe) things
190                      # from libc.
191                      '-static',
192                      # Link with custom linker script for special
193                      # layout.  The script uses the symbol RESERVE_TOP.
194                      '--defsym', 'RESERVE_TOP=<(nacl_reserve_top)',
195                      '--script=<(linker_script)',
196                      '-o', '<@(_outputs)',
197                      # On x86-64, the default page size with some
198                      # linkers is 2M rather than the real Linux page
199                      # size of 4K.  A larger page size is incompatible
200                      # with our custom linker script's special layout.
201                      '-z', 'max-page-size=0x1000',
202                      '--whole-archive', '<(bootstrap_lib)',
203                      '--no-whole-archive',
204                    ],
205         }
206       ],
207     },
208     {
209       'target_name': 'nacl_helper_bootstrap',
210       'dependencies': [
211         'nacl_bootstrap_raw',
212       ],
213       'type': 'none',
214       # See above about this magical flag.
215       # It's actually redundant in practice to have it here as well.
216       # But it expresses the intent: that anything that depends on
217       # this target has no interest in what goes into building it.
218       'dependencies_traverse': 0,
219       'actions': [{
220         'action_name': 'munge_phdr',
221         'inputs': ['nacl_bootstrap_munge_phdr.py',
222                    '<(PRODUCT_DIR)/nacl_bootstrap_raw'],
223         'outputs': ['<(PRODUCT_DIR)/nacl_helper_bootstrap'],
224         'message': 'Munging ELF program header',
225         'action': ['python', '<@(_inputs)', '<@(_outputs)']
226       }],
227     },
228   ],
229 }