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_lib',
38 'type': 'static_library',
39 'product_dir': '<(SHARED_INTERMEDIATE_DIR)/nacl_bootstrap',
48 # Prevent llvm-opt from replacing my_bzero with a call
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',
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
68 # We hope there's nothing to search for in this small program and
69 # disable all the sanitizers for it.
74 '-fsanitize=undefined',
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.
80 '-fstack-protector-all',
81 '-fstack-protector-strong',
83 '-finstrument-functions',
85 # This causes an "unused argument" warning in C targets.
91 # TODO(bbudge) Remove this when Clang supports -fno-pic.
98 'target_name': 'nacl_bootstrap_raw',
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
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,
115 'nacl_bootstrap_lib',
119 'action_name': 'link_with_ld_bfd',
121 'bootstrap_lib': '<(SHARED_INTERMEDIATE_DIR)/nacl_bootstrap/<(STATIC_LIB_PREFIX)nacl_bootstrap_lib<(STATIC_LIB_SUFFIX)',
122 'linker_script': 'nacl_bootstrap.x',
130 '<(PRODUCT_DIR)/nacl_bootstrap_raw',
132 'message': 'Linking nacl_bootstrap_raw',
134 ['target_arch=="x64"', {
136 'linker_emulation': 'elf_x86_64',
139 ['target_arch=="ia32"', {
141 'linker_emulation': 'elf_i386',
144 ['target_arch=="arm"', {
146 'linker_emulation': 'armelf_linux_eabi',
149 ['target_arch=="mipsel"', {
151 'linker_emulation': 'elf32ltsmip',
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.
164 'compiler': '<!(/bin/echo -n <(android_toolchain)/*-g++)',
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"', {
172 'compiler': '<!(echo ${CXX:=arm-linux-gnueabihf-g++})',
175 ['OS!="android" and target_arch!="arm"', {
177 'compiler': '<!(echo ${CXX:=g++})',
181 'action': ['python', 'ld_bfd.py',
182 '--compiler', '<(compiler)',
183 '-m', '<(linker_emulation)',
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
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',
209 'target_name': 'nacl_helper_bootstrap',
211 'nacl_bootstrap_raw',
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,
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)']