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.
7 '../../../../build/common.gypi',
10 ['target_arch=="x64"', {
12 # No extra reservation.
13 'nacl_reserve_top': '0x0',
16 ['target_arch=="ia32"', {
19 'nacl_reserve_top': '0x40000000',
22 ['target_arch=="arm"', {
24 # 1G address space, plus 8K guard area above.
25 'nacl_reserve_top': '0x40002000',
28 ['target_arch=="mipsel"', {
30 # 1G address space, plus 32K guard area above.
31 'nacl_reserve_top': '0x40008000',
37 'target_name': 'nacl_bootstrap_munge_phdr',
41 'nacl_bootstrap_munge_phdr.c',
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=.*']],
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.
68 '-fsanitize-memory-track-origins',
69 # This causes an "unused argument" warning in C targets.
77 'target_name': 'nacl_bootstrap_lib',
78 'type': 'static_library',
79 'product_dir': '<(SHARED_INTERMEDIATE_DIR)/nacl_bootstrap',
88 # Prevent llvm-opt from replacing my_bzero with a call
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',
105 '-fsanitize=address',
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.
112 '-fstack-protector-all',
113 '-fprofile-generate',
114 '-finstrument-functions',
116 # This causes an "unused argument" warning in C targets.
122 # TODO(bbudge) Remove this when Clang supports -fno-pic.
123 '-Qunused-arguments',
129 'target_name': 'nacl_bootstrap_raw',
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
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,
146 'nacl_bootstrap_lib',
150 'action_name': 'link_with_ld_bfd',
152 'bootstrap_lib': '<(SHARED_INTERMEDIATE_DIR)/nacl_bootstrap/<(STATIC_LIB_PREFIX)nacl_bootstrap_lib<(STATIC_LIB_SUFFIX)',
153 'linker_script': 'nacl_bootstrap.x',
161 '<(PRODUCT_DIR)/nacl_bootstrap_raw',
163 'message': 'Linking nacl_bootstrap_raw',
165 ['target_arch=="x64"', {
167 'linker_emulation': 'elf_x86_64',
170 ['target_arch=="ia32"', {
172 'linker_emulation': 'elf_i386',
175 ['target_arch=="arm"', {
177 'linker_emulation': 'armelf_linux_eabi',
180 ['target_arch=="mipsel"', {
182 'linker_emulation': 'elf32ltsmip',
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)',
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
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',
222 'target_name': 'nacl_helper_bootstrap',
224 'nacl_bootstrap_raw',
225 'nacl_bootstrap_munge_phdr#host',
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,
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)']