summaryrefslogtreecommitdiff
path: root/chromium/native_client/src/trusted/service_runtime/linux/nacl_bootstrap.gyp
blob: 784e8fff4cfedd565f0029a40555855103eb0c3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

{
  'includes': [
    '../../../../build/common.gypi',
  ],
  'conditions': [
    ['target_arch=="x64"', {
      'variables': {
        # No extra reservation.
        'nacl_reserve_top': '0x0',
      }
    }],
    ['target_arch=="ia32"', {
      'variables': {
        # 1G address space.
        'nacl_reserve_top': '0x40000000',
      }
    }],
    ['target_arch=="arm"', {
      'variables': {
        # 1G address space, plus 8K guard area above.
        'nacl_reserve_top': '0x40002000',
      }
    }],
  ],
  'targets': [
    {
      'target_name': 'nacl_bootstrap_munge_phdr',
      'type': 'executable',
      'toolsets': ['host'],
      'sources': [
        'nacl_bootstrap_munge_phdr.c',
      ],
      'libraries': [
        '-lelf',
      ],
      # This is an ugly kludge because gyp doesn't actually treat
      # host_arch=x64 target_arch=ia32 as proper cross compilation.
      # It still wants to compile the "host" program with -m32 et
      # al.  Though a program built that way can indeed run on the
      # x86-64 host, we cannot reliably build this program on such a
      # host because Ubuntu does not provide the full suite of
      # x86-32 libraries in packages that can be installed on an
      # x86-64 host; in particular, libelf is missing.  So here we
      # use the hack of eliding all the -m* flags from the
      # compilation lines, getting the command close to what they
      # would be if gyp were to really build properly for the host.
      # TODO(bradnelson): Clean up with proper cross support.
      'cflags/': [['exclude', '-m.*'],
                  ['exclude', '--sysroot=.*']],
      'ldflags/': [['exclude', '-m.*'],
                   ['exclude', '--sysroot=.*']],
    },
    {
      'target_name': 'nacl_bootstrap_lib',
      'type': 'static_library',
      'product_dir': '<(SHARED_INTERMEDIATE_DIR)/nacl_bootstrap',
      'hard_depencency': 1,
      'include_dirs': [
        '..',
      ],
      'sources': [
        'nacl_bootstrap.c',
      ],
      'cflags': [
        # Prevent llvm-opt from replacing my_bzero with a call
        # to memset.
        '-fno-builtin',
        # The tiny standalone bootstrap program is incompatible with
        # -fstack-protector, which might be on by default.  That switch
        # requires using the standard libc startup code, which we do not.
        '-fno-stack-protector',
        # We don't want to compile it PIC (or its cousin PIE), because
        # it goes at an absolute address anyway, and because any kind
        # of PIC complicates life for the x86-32 assembly code.  We
        # append -fno-* flags here instead of using a 'cflags!' stanza
        # to remove -f* flags, just in case some system's compiler
        # defaults to using PIC for everything.
        '-fno-pic', '-fno-PIC',
        '-fno-pie', '-fno-PIE',
      ],
      'cflags!': [
        '-fsanitize=address',
        '-w',
        # We filter these out because release_extra_cflags or another
        # such thing might be adding them in, and those options wind up
        # coming after the -fno-stack-protector we added above.
        '-fstack-protector',
        '-fstack-protector-all',
        '-fprofile-generate',
        '-finstrument-functions',
        '-funwind-tables',
      ],
      'conditions': [
        ['clang==1', {
          'cflags': [
            # TODO(bbudge) Remove this when Clang supports -fno-pic.
            '-Qunused-arguments',
          ],
        }],
      ],
    },
    {
      'target_name': 'nacl_bootstrap_raw',
      'type': 'none',
      # This magical flag tells Gyp that the dependencies of this target
      # are nobody else's business and it should not propagate them up
      # to things that list this as a dependency.  Without this, it will
      # wind up adding the nacl_bootstrap_lib static library into the
      # link of sel_ldr or chrome just because one executable depends on
      # the other.
      # TODO(mcgrathr): Maybe one day Gyp will grow a proper target type
      # for the use we really want here: custom commands for linking an
      # executable, and no peeking inside this target just because you
      # depend on it.  Then we could stop using this utterly arcane flag
      # in favor of something vaguely self-explanatory.
      # See http://code.google.com/p/gyp/issues/detail?id=239 for the
      # history of the arcana.
      'dependencies_traverse': 0,
      'dependencies': [
        'nacl_bootstrap_lib',
      ],
      'actions': [
        {
          'action_name': 'link_with_ld_bfd',
          'variables': {
            'bootstrap_lib': '<(SHARED_INTERMEDIATE_DIR)/nacl_bootstrap/<(STATIC_LIB_PREFIX)nacl_bootstrap_lib<(STATIC_LIB_SUFFIX)',
            'linker_script': 'nacl_bootstrap.x',
          },
          'inputs': [
            '<(linker_script)',
            '<(bootstrap_lib)',
            'ld_bfd.py',
          ],
          'outputs': [
            '<(PRODUCT_DIR)/nacl_bootstrap_raw',
          ],
          'message': 'Linking nacl_bootstrap_raw',
          'conditions': [
            ['target_arch=="x64"', {
              'variables': {
                'linker_emulation': 'elf_x86_64',
              }
            }],
            ['target_arch=="ia32"', {
              'variables': {
                'linker_emulation': 'elf_i386',
              }
            }],
            ['target_arch=="arm"', {
              'variables': {
                'linker_emulation': 'armelf_linux_eabi',
              }
            }],
          ],
          'action': ['python', 'ld_bfd.py',
                     # ld_bfd.py needs to know the target compiler used for the
                     # build but the $CXX environment variable might only be
                     # set at gyp time. This is a hacky way to bake the correct
                     # CXX into the build at gyp time.
                     # TODO(sbc): Do this better by providing some gyp syntax
                     # for accessing the name of the configured compiler, or
                     # even a better way to access gyp time environment
                     # variables from within a gyp file.
                     '--compiler', '<!(echo ${CXX:=g++})',
                     '-m', '<(linker_emulation)',
                     '--build-id',
                     # This program is (almost) entirely
                     # standalone.  It has its own startup code, so
                     # no crt1.o for it.  It is statically linked,
                     # and on x86 it does not use libc at all.
                     # However, on ARM it needs a few (safe) things
                     # from libc.
                     '-static',
                     # Link with custom linker script for special
                     # layout.  The script uses the symbol RESERVE_TOP.
                     '--defsym', 'RESERVE_TOP=<(nacl_reserve_top)',
                     '--script=<(linker_script)',
                     '-o', '<@(_outputs)',
                     # On x86-64, the default page size with some
                     # linkers is 2M rather than the real Linux page
                     # size of 4K.  A larger page size is incompatible
                     # with our custom linker script's special layout.
                     '-z', 'max-page-size=0x1000',
                     '--whole-archive', '<(bootstrap_lib)',
                     '--no-whole-archive',
                   ],
        }
      ],
    },
    {
      'target_name': 'nacl_helper_bootstrap',
      'dependencies': [
        'nacl_bootstrap_raw',
        'nacl_bootstrap_munge_phdr#host',
      ],
      'type': 'none',
      # See above about this magical flag.
      # It's actually redundant in practice to have it here as well.
      # But it expresses the intent: that anything that depends on
      # this target has no interest in what goes into building it.
      'dependencies_traverse': 0,
      'actions': [{
        'action_name': 'munge_phdr',
        'inputs': ['nacl_bootstrap_munge_phdr.py',
                   '<(PRODUCT_DIR)/nacl_bootstrap_munge_phdr',
                   '<(PRODUCT_DIR)/nacl_bootstrap_raw'],
        'outputs': ['<(PRODUCT_DIR)/nacl_helper_bootstrap'],
        'message': 'Munging ELF program header',
        'action': ['python', '<@(_inputs)', '<@(_outputs)']
      }],
    },
  ],
}