Upstream version 10.39.225.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         '-fsanitize=address',
66         '-fsanitize=memory',
67         '-fsanitize=null',
68         '-fsanitize=vptr',
69         '-w',
70         # We filter these out because release_extra_cflags or another
71         # such thing might be adding them in, and those options wind up
72         # coming after the -fno-stack-protector we added above.
73         '-fstack-protector',
74         '-fstack-protector-all',
75         '-fstack-protector-strong',
76         '-fprofile-generate',
77         '-finstrument-functions',
78         '-funwind-tables',
79         # This causes an "unused argument" warning in C targets.
80         '-stdlib=libc++',
81       ],
82       'conditions': [
83         ['clang==1', {
84           'cflags': [
85             # TODO(bbudge) Remove this when Clang supports -fno-pic.
86             '-Qunused-arguments',
87           ],
88         }],
89       ],
90     },
91     {
92       'target_name': 'nacl_bootstrap_raw',
93       'type': 'none',
94       # This magical flag tells Gyp that the dependencies of this target
95       # are nobody else's business and it should not propagate them up
96       # to things that list this as a dependency.  Without this, it will
97       # wind up adding the nacl_bootstrap_lib static library into the
98       # link of sel_ldr or chrome just because one executable depends on
99       # the other.
100       # TODO(mcgrathr): Maybe one day Gyp will grow a proper target type
101       # for the use we really want here: custom commands for linking an
102       # executable, and no peeking inside this target just because you
103       # depend on it.  Then we could stop using this utterly arcane flag
104       # in favor of something vaguely self-explanatory.
105       # See http://code.google.com/p/gyp/issues/detail?id=239 for the
106       # history of the arcana.
107       'dependencies_traverse': 0,
108       'dependencies': [
109         'nacl_bootstrap_lib',
110       ],
111       'actions': [
112         {
113           'action_name': 'link_with_ld_bfd',
114           'variables': {
115             'bootstrap_lib': '<(SHARED_INTERMEDIATE_DIR)/nacl_bootstrap/<(STATIC_LIB_PREFIX)nacl_bootstrap_lib<(STATIC_LIB_SUFFIX)',
116             'linker_script': 'nacl_bootstrap.x',
117           },
118           'inputs': [
119             '<(linker_script)',
120             '<(bootstrap_lib)',
121             'ld_bfd.py',
122           ],
123           'outputs': [
124             '<(PRODUCT_DIR)/nacl_bootstrap_raw',
125           ],
126           'message': 'Linking nacl_bootstrap_raw',
127           'conditions': [
128             ['target_arch=="x64"', {
129               'variables': {
130                 'linker_emulation': 'elf_x86_64',
131               }
132             }],
133             ['target_arch=="ia32"', {
134               'variables': {
135                 'linker_emulation': 'elf_i386',
136               }
137             }],
138             ['target_arch=="arm"', {
139               'variables': {
140                 'linker_emulation': 'armelf_linux_eabi',
141               }
142             }],
143             ['target_arch=="mipsel"', {
144               'variables': {
145                 'linker_emulation': 'elf32ltsmip',
146               },
147             }],
148             # ld_bfd.py needs to know the target compiler used for the
149             # build but the $CXX environment variable might only be
150             # set at gyp time. This is a hacky way to bake the correct
151             # CXX into the build at gyp time.
152             # TODO(sbc): Do this better by providing some gyp syntax
153             # for accessing the name of the configured compiler, or
154             # even a better way to access gyp time environment
155             # variables from within a gyp file.
156             ['OS=="android"', {
157               'variables': {
158                 'compiler': '<!(/bin/echo -n <(android_toolchain)/*-g++)',
159               }
160             }],
161             # When building for ARM default to arm-linux-gnueabihf-g++ rather
162             # than g++.  This is needed when building with clang (since in
163             # this case $CC and $CXX are not set in the environment).
164             ['OS!="android" and target_arch=="arm"', {
165               'variables': {
166                 'compiler': '<!(echo ${CXX:=arm-linux-gnueabihf-g++})',
167               }
168             }],
169             ['OS!="android" and target_arch!="arm"', {
170               'variables': {
171                 'compiler': '<!(echo ${CXX:=g++})',
172               }
173             }],
174           ],
175           'action': ['python', 'ld_bfd.py',
176                      '--compiler', '<(compiler)',
177                      '-m', '<(linker_emulation)',
178                      '--build-id',
179                      # This program is (almost) entirely
180                      # standalone.  It has its own startup code, so
181                      # no crt1.o for it.  It is statically linked,
182                      # and on x86 it does not use libc at all.
183                      # However, on ARM it needs a few (safe) things
184                      # from libc.
185                      '-static',
186                      # Link with custom linker script for special
187                      # layout.  The script uses the symbol RESERVE_TOP.
188                      '--defsym', 'RESERVE_TOP=<(nacl_reserve_top)',
189                      '--script=<(linker_script)',
190                      '-o', '<@(_outputs)',
191                      # On x86-64, the default page size with some
192                      # linkers is 2M rather than the real Linux page
193                      # size of 4K.  A larger page size is incompatible
194                      # with our custom linker script's special layout.
195                      '-z', 'max-page-size=0x1000',
196                      '--whole-archive', '<(bootstrap_lib)',
197                      '--no-whole-archive',
198                    ],
199         }
200       ],
201     },
202     {
203       'target_name': 'nacl_helper_bootstrap',
204       'dependencies': [
205         'nacl_bootstrap_raw',
206       ],
207       'type': 'none',
208       # See above about this magical flag.
209       # It's actually redundant in practice to have it here as well.
210       # But it expresses the intent: that anything that depends on
211       # this target has no interest in what goes into building it.
212       'dependencies_traverse': 0,
213       'actions': [{
214         'action_name': 'munge_phdr',
215         'inputs': ['nacl_bootstrap_munge_phdr.py',
216                    '<(PRODUCT_DIR)/nacl_bootstrap_raw'],
217         'outputs': ['<(PRODUCT_DIR)/nacl_helper_bootstrap'],
218         'message': 'Munging ELF program header',
219         'action': ['python', '<@(_inputs)', '<@(_outputs)']
220       }],
221     },
222   ],
223 }