Upstream version 7.36.149.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_munge_phdr',
38       'type': 'executable',
39       'toolsets': ['host'],
40       'sources': [
41         'nacl_bootstrap_munge_phdr.c',
42       ],
43       'libraries': [
44         '-lelf',
45       ],
46       # This is an ugly kludge because gyp doesn't actually treat
47       # host_arch=x64 target_arch=ia32 as proper cross compilation.
48       # It still wants to compile the "host" program with -m32 et
49       # al.  Though a program built that way can indeed run on the
50       # x86-64 host, we cannot reliably build this program on such a
51       # host because Ubuntu does not provide the full suite of
52       # x86-32 libraries in packages that can be installed on an
53       # x86-64 host; in particular, libelf is missing.  So here we
54       # use the hack of eliding all the -m* flags from the
55       # compilation lines, getting the command close to what they
56       # would be if gyp were to really build properly for the host.
57       # TODO(bradnelson): Clean up with proper cross support.
58       'cflags/': [['exclude', '^-m.*'],
59                   ['exclude', '^--sysroot=.*']],
60       'ldflags/': [['exclude', '^-m.*'],
61                    ['exclude', '^--sysroot=.*']],
62       'cflags!': [
63         # MemorySanitizer reports an error in this binary unless instrumented
64         # libelf is supplied. Because libelf source code uses gcc extensions,
65         # building it with MemorySanitizer (which implies clang) is challenging,
66         # and it's much simpler to just disable MSan for this target.
67         '-fsanitize=memory',
68         '-fsanitize-memory-track-origins',
69         # This causes an "unused argument" warning in C targets.
70         '-stdlib=libc++',
71       ],
72       'ldflags!': [
73         '-fsanitize=memory',
74       ],
75     },
76     {
77       'target_name': 'nacl_bootstrap_lib',
78       'type': 'static_library',
79       'product_dir': '<(SHARED_INTERMEDIATE_DIR)/nacl_bootstrap',
80       'hard_depencency': 1,
81       'include_dirs': [
82         '..',
83       ],
84       'sources': [
85         'nacl_bootstrap.c',
86       ],
87       'cflags': [
88         # Prevent llvm-opt from replacing my_bzero with a call
89         # to memset.
90         '-fno-builtin',
91         # The tiny standalone bootstrap program is incompatible with
92         # -fstack-protector, which might be on by default.  That switch
93         # requires using the standard libc startup code, which we do not.
94         '-fno-stack-protector',
95         # We don't want to compile it PIC (or its cousin PIE), because
96         # it goes at an absolute address anyway, and because any kind
97         # of PIC complicates life for the x86-32 assembly code.  We
98         # append -fno-* flags here instead of using a 'cflags!' stanza
99         # to remove -f* flags, just in case some system's compiler
100         # defaults to using PIC for everything.
101         '-fno-pic', '-fno-PIC',
102         '-fno-pie', '-fno-PIE',
103       ],
104       'cflags!': [
105         '-fsanitize=address',
106         '-fsanitize=memory',
107         '-w',
108         # We filter these out because release_extra_cflags or another
109         # such thing might be adding them in, and those options wind up
110         # coming after the -fno-stack-protector we added above.
111         '-fstack-protector',
112         '-fstack-protector-all',
113         '-fprofile-generate',
114         '-finstrument-functions',
115         '-funwind-tables',
116         # This causes an "unused argument" warning in C targets.
117         '-stdlib=libc++',
118       ],
119       'conditions': [
120         ['clang==1', {
121           'cflags': [
122             # TODO(bbudge) Remove this when Clang supports -fno-pic.
123             '-Qunused-arguments',
124           ],
125         }],
126       ],
127     },
128     {
129       'target_name': 'nacl_bootstrap_raw',
130       'type': 'none',
131       # This magical flag tells Gyp that the dependencies of this target
132       # are nobody else's business and it should not propagate them up
133       # to things that list this as a dependency.  Without this, it will
134       # wind up adding the nacl_bootstrap_lib static library into the
135       # link of sel_ldr or chrome just because one executable depends on
136       # the other.
137       # TODO(mcgrathr): Maybe one day Gyp will grow a proper target type
138       # for the use we really want here: custom commands for linking an
139       # executable, and no peeking inside this target just because you
140       # depend on it.  Then we could stop using this utterly arcane flag
141       # in favor of something vaguely self-explanatory.
142       # See http://code.google.com/p/gyp/issues/detail?id=239 for the
143       # history of the arcana.
144       'dependencies_traverse': 0,
145       'dependencies': [
146         'nacl_bootstrap_lib',
147       ],
148       'actions': [
149         {
150           'action_name': 'link_with_ld_bfd',
151           'variables': {
152             'bootstrap_lib': '<(SHARED_INTERMEDIATE_DIR)/nacl_bootstrap/<(STATIC_LIB_PREFIX)nacl_bootstrap_lib<(STATIC_LIB_SUFFIX)',
153             'linker_script': 'nacl_bootstrap.x',
154           },
155           'inputs': [
156             '<(linker_script)',
157             '<(bootstrap_lib)',
158             'ld_bfd.py',
159           ],
160           'outputs': [
161             '<(PRODUCT_DIR)/nacl_bootstrap_raw',
162           ],
163           'message': 'Linking nacl_bootstrap_raw',
164           'conditions': [
165             ['target_arch=="x64"', {
166               'variables': {
167                 'linker_emulation': 'elf_x86_64',
168               }
169             }],
170             ['target_arch=="ia32"', {
171               'variables': {
172                 'linker_emulation': 'elf_i386',
173               }
174             }],
175             ['target_arch=="arm"', {
176               'variables': {
177                 'linker_emulation': 'armelf_linux_eabi',
178               }
179             }],
180             ['target_arch=="mipsel"', {
181               'variables': {
182                 'linker_emulation': 'elf32ltsmip',
183               },
184             }],
185           ],
186           'action': ['python', 'ld_bfd.py',
187                      # ld_bfd.py needs to know the target compiler used for the
188                      # build but the $CXX environment variable might only be
189                      # set at gyp time. This is a hacky way to bake the correct
190                      # CXX into the build at gyp time.
191                      # TODO(sbc): Do this better by providing some gyp syntax
192                      # for accessing the name of the configured compiler, or
193                      # even a better way to access gyp time environment
194                      # variables from within a gyp file.
195                      '--compiler', '<!(echo ${CXX:=g++})',
196                      '-m', '<(linker_emulation)',
197                      '--build-id',
198                      # This program is (almost) entirely
199                      # standalone.  It has its own startup code, so
200                      # no crt1.o for it.  It is statically linked,
201                      # and on x86 it does not use libc at all.
202                      # However, on ARM it needs a few (safe) things
203                      # from libc.
204                      '-static',
205                      # Link with custom linker script for special
206                      # layout.  The script uses the symbol RESERVE_TOP.
207                      '--defsym', 'RESERVE_TOP=<(nacl_reserve_top)',
208                      '--script=<(linker_script)',
209                      '-o', '<@(_outputs)',
210                      # On x86-64, the default page size with some
211                      # linkers is 2M rather than the real Linux page
212                      # size of 4K.  A larger page size is incompatible
213                      # with our custom linker script's special layout.
214                      '-z', 'max-page-size=0x1000',
215                      '--whole-archive', '<(bootstrap_lib)',
216                      '--no-whole-archive',
217                    ],
218         }
219       ],
220     },
221     {
222       'target_name': 'nacl_helper_bootstrap',
223       'dependencies': [
224         'nacl_bootstrap_raw',
225         'nacl_bootstrap_munge_phdr#host',
226       ],
227       'type': 'none',
228       # See above about this magical flag.
229       # It's actually redundant in practice to have it here as well.
230       # But it expresses the intent: that anything that depends on
231       # this target has no interest in what goes into building it.
232       'dependencies_traverse': 0,
233       'actions': [{
234         'action_name': 'munge_phdr',
235         'inputs': ['nacl_bootstrap_munge_phdr.py',
236                    '<(PRODUCT_DIR)/nacl_bootstrap_munge_phdr',
237                    '<(PRODUCT_DIR)/nacl_bootstrap_raw'],
238         'outputs': ['<(PRODUCT_DIR)/nacl_helper_bootstrap'],
239         'message': 'Munging ELF program header',
240         'action': ['python', '<@(_inputs)', '<@(_outputs)']
241       }],
242     },
243   ],
244 }