OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 # Copyright (c) 2011 The Native Client Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 # | 5 # |
6 #@ Untrusted Toolchain Manager | 6 #@ Untrusted Toolchain Test Helper |
7 #@------------------------------------------------------------------- | 7 #@------------------------------------------------------------------- |
8 #@ This script builds the ARM and PNaCl untrusted toolchains. | |
9 #@ It MUST be run from the native_client/ directory. | 8 #@ It MUST be run from the native_client/ directory. |
10 # | 9 #@ |
11 ###################################################################### | 10 #@ The env variables: UTMAN_CONCURRENCY, UTMAN_BUILDBOT, UTMAN_DEBUG |
12 # Directory Layout Description | 11 #@ control behavior of this script |
13 ###################################################################### | 12 #@ |
14 # All directories are relative to BASE which is | 13 |
15 # On Linux X86-64: native_client/toolchain/pnacl_linux_x86_64/ | |
16 # On Linux X86-32: native_client/toolchain/pnacl_linux_i686/ | |
17 # On Mac X86-32 : native_client/toolchain/pnacl_darwin_i386/ | |
18 # | |
19 # /x86-32sfi-lib [experimental] x86 sandboxed libraries and object files | |
20 # /x86-32sfi-tools [experimental] x86-32 crosstool binaries for building | |
21 # and linking x86-32 nexes | |
22 # | |
23 ###################################################################### | 14 ###################################################################### |
24 # Config | 15 # Config |
25 ###################################################################### | 16 ###################################################################### |
26 | 17 |
27 set -o nounset | 18 set -o nounset |
28 set -o errexit | 19 set -o errexit |
29 | 20 |
30 # The script is located in "native_client/tools/llvm". | 21 # The script is located in "native_client/tools/llvm". |
31 # Set pwd to native_client/ | 22 # Set pwd to native_client/ |
32 cd "$(dirname "$0")"/../.. | 23 cd "$(dirname "$0")"/../.. |
33 if [[ $(basename "$(pwd)") != "native_client" ]] ; then | 24 if [[ $(basename "$(pwd)") != "native_client" ]] ; then |
34 echo "ERROR: cannot find native_client/ directory" | 25 echo "ERROR: cannot find native_client/ directory" |
35 exit -1 | 26 exit -1 |
36 fi | 27 fi |
37 readonly NACL_ROOT="$(pwd)" | 28 readonly NACL_ROOT="$(pwd)" |
38 | 29 |
39 source tools/llvm/common-tools.sh | 30 source tools/llvm/common-tools.sh |
40 | 31 SetScriptPath "${NACL_ROOT}/tools/llvm/utman-test.sh" |
41 SetScriptPath "${NACL_ROOT}/tools/llvm/utman.sh" | |
42 SetLogDirectory "${NACL_ROOT}/toolchain/hg-log" | |
43 | |
44 # NOTE: gcc and llvm have to be synchronized | |
45 # we have chosen toolchains which both are based on gcc-4.2.1 | |
46 | |
47 # For different levels of make parallelism change this in your env | 32 # For different levels of make parallelism change this in your env |
48 readonly UTMAN_CONCURRENCY=${UTMAN_CONCURRENCY:-8} | 33 readonly UTMAN_CONCURRENCY=${UTMAN_CONCURRENCY:-8} |
49 UTMAN_BUILD_ARM=true | |
50 | 34 |
51 if ${BUILD_PLATFORM_MAC} ; then | |
52 # We don't yet support building ARM tools for mac. | |
53 UTMAN_BUILD_ARM=false | |
54 fi | |
55 | |
56 # TODO(pdox): Decide what the target should really permanently be | |
57 readonly CROSS_TARGET_ARM=arm-none-linux-gnueabi | |
58 readonly CROSS_TARGET_X86_32=i686-none-linux-gnu | |
59 readonly CROSS_TARGET_X86_64=x86_64-none-linux-gnu | |
60 readonly BINUTILS_TARGET=arm-pc-nacl | |
61 readonly REAL_CROSS_TARGET=pnacl | |
62 | |
63 readonly TC_ROOT="${NACL_ROOT}/toolchain" | |
64 readonly INSTALL_ROOT="${TC_ROOT}/pnacl_${BUILD_PLATFORM}_${BUILD_ARCH}" | |
65 readonly INSTALL_BIN="${INSTALL_ROOT}/bin" | |
66 readonly ARM_ARCH=armv7-a | |
67 readonly ARM_FPU=vfp | |
68 readonly INSTALL_DIR="${INSTALL_ROOT}/${CROSS_TARGET_ARM}" | |
69 readonly LDSCRIPTS_DIR="${INSTALL_ROOT}/ldscripts" | |
70 readonly GCC_VER="4.2.1" | |
71 | |
72 # NOTE: NEWLIB_INSTALL_DIR also server as a SYSROOT | |
73 readonly NEWLIB_INSTALL_DIR="${INSTALL_ROOT}/arm-newlib" | |
74 | |
75 readonly NNACL_ROOT="${TC_ROOT}/${SCONS_BUILD_PLATFORM}_x86_newlib" | |
76 | |
77 readonly BFD_PLUGIN_DIR="${INSTALL_DIR}/lib/bfd-plugins" | |
78 | |
79 readonly MAKE_OPTS="-j${UTMAN_CONCURRENCY} VERBOSE=1" | |
80 | |
81 # For speculative build status output. ( see status function ) | |
82 # Leave this blank, it will be filled during processing. | |
83 SPECULATIVE_REBUILD_SET="" | |
84 | |
85 # The directory in which we we keep src dirs (from hg repos) | |
86 # and objdirs. These should be ABSOLUTE paths. | |
87 | |
88 readonly TC_SRC="${NACL_ROOT}/hg" | |
89 readonly TC_BUILD="${TC_ROOT}/hg-build" | |
90 | |
91 # The location of sources (absolute) | |
92 readonly TC_SRC_LLVM="${TC_SRC}/llvm" | |
93 readonly TC_SRC_LLVM_GCC="${TC_SRC}/llvm-gcc" | |
94 readonly TC_SRC_BINUTILS="${TC_SRC}/binutils" | |
95 readonly TC_SRC_NEWLIB="${TC_SRC}/newlib" | |
96 readonly TC_SRC_LIBSTDCPP="${TC_SRC_LLVM_GCC}/llvm-gcc-4.2/libstdc++-v3" | |
97 | |
98 # Unfortunately, binutils/configure generates this untracked file | |
99 # in the binutils source directory | |
100 readonly BINUTILS_MESS="${TC_SRC_BINUTILS}/binutils-2.20/opcodes/i386-tbl.h" | |
101 | |
102 readonly SERVICE_RUNTIME_SRC="${NACL_ROOT}/src/trusted/service_runtime" | |
103 readonly EXPORT_HEADER_SCRIPT="${SERVICE_RUNTIME_SRC}/export_header.py" | |
104 readonly NACL_SYS_HEADERS="${SERVICE_RUNTIME_SRC}/include" | |
105 readonly NACL_SYS_TS="${TC_SRC}/nacl.sys.timestamp" | |
106 readonly NEWLIB_INCLUDE_DIR="${TC_SRC_NEWLIB}/newlib-trunk/newlib/libc/include" | |
107 | |
108 # The location of each project | |
109 # These should be absolute paths. | |
110 readonly TC_BUILD_LLVM="${TC_BUILD}/llvm" | |
111 readonly TC_BUILD_LLVM_GCC1="${TC_BUILD}/llvm-gcc-stage1" | |
112 readonly TC_BUILD_BINUTILS_ARM="${TC_BUILD}/binutils-arm" | |
113 readonly TC_BUILD_BINUTILS_LIBERTY="${TC_BUILD}/binutils-liberty" | |
114 readonly TC_BUILD_NEWLIB_ARM="${TC_BUILD}/newlib-arm" | |
115 readonly TC_BUILD_NEWLIB_BITCODE="${TC_BUILD}/newlib-bitcode" | |
116 | |
117 # This apparently has to be at this location or gcc install breaks. | |
118 readonly TC_BUILD_LIBSTDCPP="${TC_BUILD_LLVM_GCC1}/${CROSS_TARGET_ARM}/libstdc++
-v3" | |
119 | |
120 readonly TC_BUILD_LIBSTDCPP_BITCODE="${TC_BUILD_LLVM_GCC1}/libstdcpp-bitcode" | |
121 | |
122 # These are fake directories, for storing the timestamp only | |
123 readonly TC_BUILD_EXTRASDK_BITCODE="${TC_BUILD}/extrasdk" | |
124 | |
125 readonly TIMESTAMP_FILENAME="make-timestamp" | |
126 | |
127 # PNaCl toolchain locations (absolute!) | |
128 readonly PNACL_TOOLCHAIN_ROOT="${INSTALL_ROOT}" | |
129 readonly PNACL_ARM_ROOT="${PNACL_TOOLCHAIN_ROOT}/libs-arm" | |
130 readonly PNACL_X8632_ROOT="${PNACL_TOOLCHAIN_ROOT}/libs-x8632" | |
131 readonly PNACL_X8664_ROOT="${PNACL_TOOLCHAIN_ROOT}/libs-x8664" | |
132 readonly PNACL_BITCODE_ROOT="${PNACL_TOOLCHAIN_ROOT}/libs-bitcode" | |
133 | |
134 # PNaCl client-translators (sandboxed) binary locations | |
135 readonly PNACL_SB_ROOT="${INSTALL_ROOT}/tools-sb" | |
136 readonly PNACL_SB_X8632="${PNACL_SB_ROOT}/x8632" | |
137 readonly PNACL_SB_X8664="${PNACL_SB_ROOT}/x8664" | |
138 readonly PNACL_SB_UNIVERSAL="${PNACL_SB_ROOT}/universal" | |
139 | |
140 # Location of PNaCl gcc/g++/as | |
141 readonly PNACL_GCC="${INSTALL_BIN}/pnacl-gcc" | |
142 readonly PNACL_GPP="${INSTALL_BIN}/pnacl-g++" | |
143 readonly PNACL_AR="${INSTALL_BIN}/pnacl-ar" | |
144 readonly PNACL_RANLIB="${INSTALL_BIN}/pnacl-ranlib" | |
145 readonly PNACL_AS="${INSTALL_BIN}/pnacl-as" | |
146 readonly PNACL_LD="${INSTALL_BIN}/pnacl-ld" | |
147 readonly PNACL_NM="${INSTALL_BIN}/pnacl-nm" | |
148 readonly PNACL_TRANSLATE="${INSTALL_BIN}/pnacl-translate" | |
149 readonly PNACL_READELF="${INSTALL_BIN}/readelf" | |
150 readonly PNACL_SIZE="${INSTALL_BIN}/size" | |
151 | |
152 readonly PNACL_AS_ARM="${INSTALL_BIN}/pnacl-arm-as" | |
153 readonly PNACL_AS_X8632="${INSTALL_BIN}/pnacl-i686-as" | |
154 readonly PNACL_AS_X8664="${INSTALL_BIN}/pnacl-x86_64-as" | |
155 | |
156 # For a production (release) build, we want the sandboxed | |
157 # translator to only contain the code needed to handle | |
158 # its own architecture. For example, the translator shipped with | |
159 # an X86-32 browser would only be able to translate to X86-32 code. | |
160 # This is so that the translator binary is as small as possible. | |
161 # | |
162 # If SBTC_PRODUCTION is true, then the translators are built | |
163 # separately, one for each architecture, so that each translator | |
164 # can only target its own architecture. | |
165 # | |
166 # If SBTC_PRODUCTION is false, then we instead use PNaCl to | |
167 # build a `fat` translator which can target all supported | |
168 # architectures. This translator is built as a .pexe | |
169 # which can then be translated to each individual architecture. | |
170 SBTC_PRODUCTION=${SBTC_PRODUCTION:-false} | |
171 | |
172 # Which toolchain to use for each arch. | |
173 SBTC_BUILD_WITH_PNACL="arm x8632 x8664" | |
174 | |
175 # Current milestones in each repo | |
176 # hg-update-all uses these | |
177 readonly LLVM_REV=12da952867e2 | |
178 readonly LLVM_GCC_REV=cfdaa7f26019 | |
179 readonly NEWLIB_REV=9bef47f82918 | |
180 readonly BINUTILS_REV=09eb0704d27f | |
181 | |
182 # Repositories | |
183 readonly REPO_LLVM_GCC="llvm-gcc.nacl-llvm-branches" | |
184 readonly REPO_LLVM="nacl-llvm-branches" | |
185 readonly REPO_NEWLIB="newlib.nacl-llvm-branches" | |
186 readonly REPO_BINUTILS="binutils.nacl-llvm-branches" | |
187 | |
188 | |
189 # These are simple compiler wrappers to force 32bit builds | |
190 # They are unused now. Instead we make sure that the toolchains that we | |
191 # distribute are created on the oldest system we care to support. Currently | |
192 # that is a 32 bit hardy. The advantage of this is that we can build | |
193 # the toolchaing shared, reducing its size and allowing the use of | |
194 # plugins. You can still use them by setting the environment variables | |
195 # when running this script: | |
196 # CC=$(GetAbsolutePath tools/llvm/mygcc32) \ | |
197 # CXX=$(GetAbsolutePath tools/llvm/myg++32) \ | |
198 # tools/llvm/utman.sh untrusted_sdk <file> | |
199 # NOTE: this has not been tried in a while and may no longer work | |
200 CC=${CC:-} | |
201 # TODO(espindola): This should be ${CXX:-}, but llvm-gcc's configure has a | |
202 # bug that brakes the build if we do that. | |
203 CXX=${CXX:-g++} | |
204 | |
205 readonly CROSS_TARGET_AR=${INSTALL_DIR}/bin/${BINUTILS_TARGET}-ar | |
206 readonly CROSS_TARGET_RANLIB=${INSTALL_DIR}/bin/${BINUTILS_TARGET}-ranlib | |
207 readonly ILLEGAL_TOOL=${INSTALL_DIR}/pnacl-illegal | |
208 | |
209 # NOTE: we do not expect the assembler or linker to be used for libs | |
210 # hence the use of ILLEGAL_TOOL. | |
211 STD_ENV_FOR_LIBSTDCPP=( | |
212 CC="${PNACL_GCC}" | |
213 CXX="${PNACL_GPP}" | |
214 RAW_CXX_FOR_TARGET="${PNACL_GPP}" | |
215 LD="${ILLEGAL_TOOL}" | |
216 CFLAGS="--pnacl-arm-bias" | |
217 CPPFLAGS="--pnacl-arm-bias" | |
218 CXXFLAGS="--pnacl-arm-bias" | |
219 CFLAGS_FOR_TARGET="--pnacl-arm-bias" | |
220 CPPFLAGS_FOR_TARGET="--pnacl-arm-bias" | |
221 CC_FOR_TARGET="${PNACL_GCC}" | |
222 GCC_FOR_TARGET="${PNACL_GCC}" | |
223 CXX_FOR_TARGET="${PNACL_GPP}" | |
224 AR="${PNACL_AR}" | |
225 AR_FOR_TARGET="${PNACL_AR}" | |
226 NM_FOR_TARGET="${PNACL_NM}" | |
227 RANLIB="${PNACL_RANLIB}" | |
228 RANLIB_FOR_TARGET="${PNACL_RANLIB}" | |
229 AS_FOR_TARGET="${ILLEGAL_TOOL}" | |
230 LD_FOR_TARGET="${ILLEGAL_TOOL}" | |
231 OBJDUMP_FOR_TARGET="${ILLEGAL_TOOL}" ) | |
232 | |
233 STD_ENV_FOR_NEWLIB=( | |
234 CFLAGS_FOR_TARGET="--pnacl-arm-bias" | |
235 CPPFLAGS_FOR_TARGET="--pnacl-arm-bias" | |
236 CC_FOR_TARGET="${PNACL_GCC}" | |
237 GCC_FOR_TARGET="${PNACL_GCC}" | |
238 CXX_FOR_TARGET="${PNACL_GPP}" | |
239 AR_FOR_TARGET="${PNACL_AR}" | |
240 NM_FOR_TARGET="${PNACL_NM}" | |
241 RANLIB_FOR_TARGET="${PNACL_RANLIB}" | |
242 OBJDUMP_FOR_TARGET="${ILLEGAL_TOOL}" | |
243 AS_FOR_TARGET="${ILLEGAL_TOOL}" | |
244 LD_FOR_TARGET="${ILLEGAL_TOOL}" | |
245 STRIP_FOR_TARGET="${ILLEGAL_TOOL}" ) | |
246 | |
247 | |
248 # The gold plugin that we use is documented at | |
249 # http://llvm.org/docs/GoldPlugin.html | |
250 # Despite its name it is actually used by both gold and bfd. The changes to | |
251 # this file to enable its use are: | |
252 # * Build shared | |
253 # * --enable-gold and --enable-plugin when building binutils | |
254 # * --with-binutils-include when building binutils | |
255 # * linking the plugin in bfd-plugins | |
256 | |
257 | |
258 ###################################################################### | |
259 ###################################################################### | |
260 # | |
261 # < USER ACCESSIBLE FUNCTIONS > | |
262 # | |
263 ###################################################################### | |
264 ###################################################################### | |
265 | |
266 #@------------------------------------------------------------------------- | |
267 | |
268 #@ hg-info-all - Show status of repositories | |
269 hg-info-all() { | |
270 hg-pull-all | |
271 | |
272 hg-info "${TC_SRC_LLVM}" ${LLVM_REV} | |
273 hg-info "${TC_SRC_LLVM_GCC}" ${LLVM_GCC_REV} | |
274 hg-info "${TC_SRC_NEWLIB}" ${NEWLIB_REV} | |
275 hg-info "${TC_SRC_BINUTILS}" ${BINUTILS_REV} | |
276 } | |
277 | |
278 #@ hg-update-all - Update all repos to the latest stable rev | |
279 hg-update-all() { | |
280 hg-update-llvm-gcc | |
281 hg-update-llvm | |
282 hg-update-newlib | |
283 hg-update-binutils | |
284 } | |
285 | |
286 hg-assert-safe-to-update() { | |
287 local name="$1" | |
288 local dir="$2" | |
289 local rev="$3" | |
290 local defstr=$(echo "${name}" | tr '[a-z]-' '[A-Z]_') | |
291 | |
292 if ! hg-on-branch "${dir}" pnacl-sfi ; then | |
293 Banner "hg/${name} is not on branch pnacl-sfi" | |
294 exit -1 | |
295 fi | |
296 | |
297 if ! hg-has-changes "${dir}"; then | |
298 return 0 | |
299 fi | |
300 | |
301 if hg-at-revision "${dir}" "${rev}" ; then | |
302 return 0 | |
303 fi | |
304 | |
305 Banner \ | |
306 " ERROR " \ | |
307 " " \ | |
308 " hg/${name} needs to be updated to the stable revision " \ | |
309 " but has local modifications. " \ | |
310 " " \ | |
311 " If your repository is behind stable, update it using: " \ | |
312 " " \ | |
313 " cd hg/${name}; hg update ${rev} " \ | |
314 " (you may need to resolve conflicts) " \ | |
315 " " \ | |
316 " If your repository is ahead of stable, then modify: " \ | |
317 " ${defstr}_REV (in tools/llvm/utman.sh) " \ | |
318 " to suppress this error message. " | |
319 exit -1 | |
320 } | |
321 | |
322 | |
323 hg-bot-sanity() { | |
324 local name="$1" | |
325 local dir="$2" | |
326 | |
327 if ! ${UTMAN_BUILDBOT} ; then | |
328 return 0 | |
329 fi | |
330 | |
331 if ! hg-on-branch "${dir}" pnacl-sfi || | |
332 hg-has-changes "${dir}" || | |
333 hg-has-untracked "${dir}" ; then | |
334 Banner "WARNING: hg/${name} is in an illegal state." \ | |
335 " Wiping and trying again." | |
336 rm -rf "${dir}" | |
337 hg-checkout-${name} | |
338 fi | |
339 } | |
340 | |
341 hg-update-common() { | |
342 local name="$1" | |
343 local rev="$2" | |
344 local dir="$3" | |
345 | |
346 # If this is a buildbot, do sanity checks here. | |
347 hg-bot-sanity "${name}" "${dir}" | |
348 | |
349 # Make sure it is safe to update | |
350 hg-assert-safe-to-update "${name}" "${dir}" "${rev}" | |
351 | |
352 StepBanner "HG-UPDATE" "Updating ${name} to ${rev}" | |
353 hg-pull "${dir}" | |
354 hg-update "${dir}" ${rev} | |
355 } | |
356 | |
357 #@ hg-update-llvm-gcc - Update LLVM-GCC to the stable revision | |
358 hg-update-llvm-gcc() { | |
359 hg-update-common "llvm-gcc" ${LLVM_GCC_REV} "${TC_SRC_LLVM_GCC}" | |
360 } | |
361 | |
362 #@ hg-update-llvm - Update LLVM to the stable revision | |
363 hg-update-llvm() { | |
364 hg-update-common "llvm" ${LLVM_REV} "${TC_SRC_LLVM}" | |
365 } | |
366 | |
367 #@ hg-update-newlib - Update NEWLIB To the stable revision | |
368 hg-update-newlib() { | |
369 # Clean the headers first, so that sanity checks inside | |
370 # hg-update-common do not see any local modifications. | |
371 newlib-nacl-headers-check | |
372 newlib-nacl-headers-clean | |
373 hg-update-common "newlib" ${NEWLIB_REV} "${TC_SRC_NEWLIB}" | |
374 newlib-nacl-headers | |
375 } | |
376 | |
377 #@ hg-update-binutils - Update BINUTILS to the stable revision | |
378 hg-update-binutils() { | |
379 # Clean the binutils generated file first, so that sanity checks | |
380 # inside hg-update-common do not see any local modifications. | |
381 binutils-mess-hide | |
382 hg-update-common "binutils" ${BINUTILS_REV} "${TC_SRC_BINUTILS}" | |
383 binutils-mess-unhide | |
384 } | |
385 | |
386 #@ hg-pull-all - Pull all repos. (but do not update working copy) | |
387 #@ hg-pull-REPO - Pull repository REPO. | |
388 #@ (REPO can be llvm-gcc, llvm, newlib, binutils) | |
389 hg-pull-all() { | |
390 StepBanner "HG-PULL" "Running 'hg pull' in all repos..." | |
391 hg-pull-llvm-gcc | |
392 hg-pull-llvm | |
393 hg-pull-newlib | |
394 hg-pull-binutils | |
395 } | |
396 | |
397 hg-pull-llvm-gcc() { | |
398 hg-pull "${TC_SRC_LLVM_GCC}" | |
399 } | |
400 | |
401 hg-pull-llvm() { | |
402 hg-pull "${TC_SRC_LLVM}" | |
403 } | |
404 | |
405 hg-pull-newlib() { | |
406 hg-pull "${TC_SRC_NEWLIB}" | |
407 } | |
408 | |
409 hg-pull-binutils() { | |
410 hg-pull "${TC_SRC_BINUTILS}" | |
411 } | |
412 | |
413 #@ hg-checkout-all - check out mercurial repos needed to build toolchain | |
414 #@ (skips repos which are already checked out) | |
415 hg-checkout-all() { | |
416 StepBanner "HG-CHECKOUT-ALL" | |
417 hg-checkout-llvm-gcc | |
418 hg-checkout-llvm | |
419 hg-checkout-binutils | |
420 hg-checkout-newlib | |
421 } | |
422 | |
423 hg-checkout-llvm-gcc() { | |
424 hg-checkout ${REPO_LLVM_GCC} ${TC_SRC_LLVM_GCC} ${LLVM_GCC_REV} | |
425 } | |
426 | |
427 hg-checkout-llvm() { | |
428 hg-checkout ${REPO_LLVM} ${TC_SRC_LLVM} ${LLVM_REV} | |
429 } | |
430 | |
431 hg-checkout-binutils() { | |
432 hg-checkout ${REPO_BINUTILS} ${TC_SRC_BINUTILS} ${BINUTILS_REV} | |
433 } | |
434 | |
435 hg-checkout-newlib() { | |
436 hg-checkout ${REPO_NEWLIB} ${TC_SRC_NEWLIB} ${NEWLIB_REV} | |
437 newlib-nacl-headers | |
438 } | |
439 | |
440 #@ hg-clean - Remove all repos. (WARNING: local changes are lost) | |
441 hg-clean() { | |
442 StepBanner "HG-CLEAN" | |
443 | |
444 echo "Are you sure?" | |
445 echo "This will DELETE all source repositories under 'native_client/hg'" | |
446 echo "Any local changes will be lost." | |
447 echo "" | |
448 echo "Type YES to confirm: " | |
449 read CONFIRM_TEXT | |
450 | |
451 if [ $CONFIRM_TEXT == "YES" ]; then | |
452 StepBanner "HG-CLEAN" "Cleaning Mercurial repositories" | |
453 rm -rf "${TC_SRC}" | |
454 else | |
455 StepBanner "HG-CLEAN" "Clean cancelled by user" | |
456 fi | |
457 } | |
458 | |
459 #@------------------------------------------------------------------------- | |
460 | |
461 #@ download-trusted - Download and Install trusted SDKs (arm,x86-32,x86-64) | |
462 #@ (your untrusted build will not be modified) | |
463 download-trusted() { | |
464 StepBanner "DOWNLOAD-TRUSTED" "Downloading trusted toolchains" | |
465 local installdir="${INSTALL_ROOT}" | |
466 local tmpdir="${installdir}-backup" | |
467 local dldir="${installdir}-downloaded" | |
468 | |
469 rm -rf "${dldir}" | |
470 | |
471 if [ -d "${tmpdir}" ]; then | |
472 echo "ERROR: It is not expected that directory '${tmpdir}' exists." | |
473 echo " Please delete it if you don't need it" | |
474 exit -1 | |
475 fi | |
476 | |
477 if [ -d "${installdir}" ]; then | |
478 mv "${installdir}" "${tmpdir}" | |
479 fi | |
480 | |
481 download-toolchains | |
482 | |
483 if [ -d "${installdir}" ]; then | |
484 mv "${installdir}" "${dldir}" | |
485 fi | |
486 | |
487 if [ -d "${tmpdir}" ]; then | |
488 mv "${tmpdir}" "${installdir}" | |
489 fi | |
490 } | |
491 | |
492 #@------------------------------------------------------------------------- | |
493 | |
494 #@ download-toolchains - Download and Install all SDKs (arm,x86-32,x86-64) | |
495 | |
496 download-toolchains() { | |
497 gclient runhooks --force | |
498 } | |
499 | |
500 #@------------------------------------------------------------------------- | |
501 #@ rebuild-pnacl-libs - organized native libs and build bitcode libs | |
502 rebuild-pnacl-libs() { | |
503 extrasdk-clean | |
504 clean-pnacl | |
505 newlib-bitcode | |
506 libstdcpp-bitcode | |
507 # NOTE: currently also builds some native code | |
508 extrasdk-make-install | |
509 organize-native-code | |
510 } | |
511 | |
512 | |
513 #@ everything - Build and install untrusted SDK. | |
514 everything() { | |
515 | |
516 mkdir -p "${INSTALL_ROOT}" | |
517 | |
518 # This is needed to build misc-tools and run ARM tests. | |
519 # We check this early so that there are no surprises later, and we can | |
520 # handle all user interaction early. | |
521 check-for-trusted | |
522 | |
523 hg-checkout-all | |
524 hg-update-all | |
525 | |
526 clean-install | |
527 RecordRevisionInfo | |
528 | |
529 clean-logs | |
530 | |
531 binutils-arm | |
532 llvm | |
533 driver | |
534 gcc-stage1-sysroot | |
535 gcc-stage1 ${CROSS_TARGET_ARM} | |
536 gcc-stage1 ${CROSS_TARGET_X86_32} | |
537 gcc-stage1 ${CROSS_TARGET_X86_64} | |
538 | |
539 rebuild-pnacl-libs | |
540 | |
541 # NOTE: we delay the tool building till after the sdk is essentially | |
542 # complete, so that sdk sanity checks don't fail | |
543 misc-tools | |
544 | |
545 verify | |
546 } | |
547 | |
548 #@ all - Alias for 'everything' | |
549 all() { | |
550 everything | |
551 } | |
552 | |
553 #@ status - Show status of build directories | |
554 status() { | |
555 # TODO(robertm): this is currently broken | |
556 StepBanner "BUILD STATUS" | |
557 | |
558 status-helper "BINUTILS-ARM" binutils-arm | |
559 status-helper "LLVM" llvm | |
560 status-helper "GCC-STAGE1" gcc-stage1 | |
561 | |
562 status-helper "NEWLIB-ARM" newlib-arm | |
563 | |
564 status-helper "NEWLIB-BITCODE" newlib-bitcode | |
565 status-helper "EXTRASDK-BITCODE" extrasdk | |
566 status-helper "LIBSTDCPP-BITCODE" extrasdk-bitcode | |
567 | |
568 } | |
569 | |
570 status-helper() { | |
571 local title="$1" | |
572 local mod="$2" | |
573 | |
574 if ${mod}-needs-configure; then | |
575 StepBanner "$title" "NEEDS FULL REBUILD" | |
576 speculative-add "${mod}" | |
577 elif ${mod}-needs-make; then | |
578 StepBanner "$title" "NEEDS MAKE (INCREMENTAL)" | |
579 speculative-add "${mod}" | |
580 else | |
581 StepBanner "$title" "OK (UP TO DATE)" | |
582 fi | |
583 } | |
584 | |
585 speculative-add() { | |
586 local mod="$1" | |
587 SPECULATIVE_REBUILD_SET="${SPECULATIVE_REBUILD_SET} ${mod}" | |
588 } | |
589 | |
590 speculative-check() { | |
591 local mod="$1" | |
592 local search=$(echo "${SPECULATIVE_REBUILD_SET}" | grep -F "$mod") | |
593 [ ${#search} -gt 0 ] | |
594 return $? | |
595 } | |
596 | |
597 | |
598 | |
599 #@ clean - Clean the build and install directories. | |
600 clean() { | |
601 StepBanner "CLEAN" "Cleaning build, log, and install directories." | |
602 | |
603 clean-logs | |
604 clean-build | |
605 clean-install | |
606 clean-scons | |
607 } | |
608 | |
609 #@ fast-clean - Clean everything except LLVM. | |
610 fast-clean() { | |
611 local did_backup=false | |
612 local backup_dir="${NACL_ROOT}/llvm-build-backup" | |
613 | |
614 if [ -d "${TC_BUILD_LLVM}" ]; then | |
615 rm -rf "${backup_dir}" | |
616 mv "${TC_BUILD_LLVM}" "${backup_dir}" | |
617 did_backup=true | |
618 fi | |
619 | |
620 clean | |
621 | |
622 if ${did_backup} ; then | |
623 mkdir -p "${TC_BUILD}" | |
624 mv "${backup_dir}" "${TC_BUILD_LLVM}" | |
625 fi | |
626 } | |
627 | |
628 binutils-mess-hide() { | |
629 local messtmp="${TC_SRC}/binutils.tmp" | |
630 if [ -f "${BINUTILS_MESS}" ] ; then | |
631 mv "${BINUTILS_MESS}" "${messtmp}" | |
632 fi | |
633 } | |
634 | |
635 binutils-mess-unhide() { | |
636 local messtmp="${TC_SRC}/binutils.tmp" | |
637 if [ -f "${messtmp}" ] ; then | |
638 mv "${messtmp}" "${BINUTILS_MESS}" | |
639 fi | |
640 } | |
641 | |
642 #+ clean-scons - Clean scons-out directory | |
643 clean-scons() { | |
644 rm -rf scons-out | |
645 } | |
646 | |
647 #+ clean-build - Clean all build directories | |
648 clean-build() { | |
649 rm -rf "${TC_BUILD}" | |
650 } | |
651 | |
652 #+ clean-install - Clean install directories | |
653 clean-install() { | |
654 rm -rf "${INSTALL_ROOT}" | |
655 } | |
656 | |
657 #+ clean-pnacl - Removes the pnacl-untrusted installation directory | |
658 clean-pnacl() { | |
659 StepBanner "pnacl" "cleaning ${PNACL_TOOLCHAIN_ROOT}/libs-*" | |
660 rm -rf ${PNACL_ARM_ROOT} \ | |
661 ${PNACL_BITCODE_ROOT} \ | |
662 ${PNACL_X8632_ROOT} \ | |
663 ${PNACL_X8664_ROOT} | |
664 } | |
665 | |
666 | |
667 | |
668 | |
669 #@------------------------------------------------------------------------- | |
670 | |
671 #@ untrusted_sdk <file> - Create untrusted SDK tarball from scratch | |
672 #@ (clean + all + prune + tarball) | |
673 untrusted_sdk() { | |
674 if [ ! -n "${1:-}" ]; then | |
675 echo "Error: untrusted_sdk needs a tarball name." >&2 | |
676 exit 1 | |
677 fi | |
678 | |
679 clean | |
680 everything | |
681 prune | |
682 install-translators srpc | |
683 prune-translator-install srpc | |
684 tarball $1 | |
685 } | |
686 | |
687 #+ prune - Prune toolchain | |
688 prune() { | |
689 StepBanner "PRUNE" "Pruning toolchain" | |
690 local ACCEPTABLE_SIZE=250 | |
691 local dir_size_before=$(get_dir_size_in_mb ${INSTALL_ROOT}) | |
692 | |
693 SubBanner "Size before: ${INSTALL_ROOT} ${dir_size_before}MB" | |
694 echo "removing some static libs we do not have any use for" | |
695 rm -f "${INSTALL_DIR}"/lib/lib*.a | |
696 | |
697 echo "removing x86-32 frontend" | |
698 rm -rf "${INSTALL_DIR}"/libexec/gcc/i686-none-linux-gnu/ | |
699 rm -rf "${INSTALL_DIR}"/bin/i686-none-linux-gnu-* | |
700 | |
701 echo "removing x86-64 frontend" | |
702 rm -rf "${INSTALL_DIR}"/libexec/gcc/x86_64-none-linux-gnu/ | |
703 rm -rf "${INSTALL_DIR}"/bin/x86_64-none-linux-gnu-* | |
704 | |
705 echo "stripping binaries" | |
706 strip "${INSTALL_DIR}"/libexec/gcc/arm-none-linux-gnueabi/${GCC_VER}/c* | |
707 if ! strip "${INSTALL_DIR}"/bin/* ; then | |
708 echo "NOTE: some failures during stripping are expected" | |
709 fi | |
710 | |
711 echo "removing llvm headers" | |
712 rm -rf "${INSTALL_DIR}"/include/llvm* | |
713 | |
714 local dir_size_after=$(get_dir_size_in_mb ${INSTALL_ROOT}) | |
715 SubBanner "Size after: ${INSTALL_ROOT} ${dir_size_after}MB" | |
716 | |
717 if [[ ${dir_size_after} -gt ${ACCEPTABLE_SIZE} ]] ; then | |
718 echo "ERROR: size of toolchain exceeds ${ACCEPTABLE_SIZE}MB" | |
719 exit -1 | |
720 fi | |
721 | |
722 } | |
723 | |
724 #+ tarball <filename> - Produce tarball file | |
725 tarball() { | |
726 if [ ! -n "${1:-}" ]; then | |
727 echo "Error: tarball needs a tarball name." >&2 | |
728 exit 1 | |
729 fi | |
730 | |
731 local tarball="$1" | |
732 StepBanner "TARBALL" "Creating tar ball ${tarball}" | |
733 | |
734 tar zcf "${tarball}" -C "${INSTALL_ROOT}" . | |
735 } | |
736 | |
737 | |
738 ######################################################################### | |
739 # < LLVM > | |
740 ######################################################################### | |
741 | |
742 | |
743 #+------------------------------------------------------------------------- | |
744 #+ llvm - Configure, build and install LLVM. | |
745 | |
746 llvm() { | |
747 StepBanner "LLVM" | |
748 | |
749 local srcdir="${TC_SRC_LLVM}" | |
750 | |
751 assert-dir "${srcdir}" "You need to checkout LLVM." | |
752 | |
753 if llvm-needs-configure; then | |
754 llvm-configure | |
755 else | |
756 SkipBanner "LLVM" "configure" | |
757 fi | |
758 | |
759 if llvm-needs-make; then | |
760 llvm-make | |
761 else | |
762 SkipBanner "LLVM" "make" | |
763 fi | |
764 | |
765 llvm-install | |
766 } | |
767 | |
768 #+ llvm-clean - Clean LLVM completely | |
769 llvm-clean() { | |
770 StepBanner "LLVM" "Clean" | |
771 local objdir="${TC_BUILD_LLVM}" | |
772 rm -rf ${objdir} | |
773 mkdir -p ${objdir} | |
774 } | |
775 | |
776 # Default case - Optimized configure | |
777 LLVM_EXTRA_OPTIONS="--enable-optimized" | |
778 | |
779 #+ llvm-configure - Run LLVM configure | |
780 llvm-configure() { | |
781 StepBanner "LLVM" "Configure" | |
782 | |
783 local srcdir="${TC_SRC_LLVM}" | |
784 local objdir="${TC_BUILD_LLVM}" | |
785 | |
786 mkdir -p "${objdir}" | |
787 spushd "${objdir}" | |
788 | |
789 # The --with-binutils-include is to allow llvm to build the gold plugin | |
790 local binutils_include="${TC_SRC_BINUTILS}/binutils-2.20/include" | |
791 RunWithLog "llvm.configure" \ | |
792 env -i PATH=/usr/bin/:/bin \ | |
793 MAKE_OPTS=${MAKE_OPTS} \ | |
794 CC=${CC} \ | |
795 CXX=${CXX} \ | |
796 ${srcdir}/llvm-trunk/configure \ | |
797 --disable-jit \ | |
798 --with-binutils-include=${binutils_include} \ | |
799 --enable-targets=x86,x86_64,arm \ | |
800 --target=${CROSS_TARGET_ARM} \ | |
801 --prefix=${INSTALL_DIR} \ | |
802 --with-llvmgccdir=${INSTALL_DIR} \ | |
803 ${LLVM_EXTRA_OPTIONS} | |
804 | |
805 | |
806 spopd | |
807 } | |
808 | |
809 #+ llvm-configure-dbg - Run LLVM configure | |
810 # Not used by default. Call manually. | |
811 llvm-configure-dbg() { | |
812 StepBanner "LLVM" "Configure With Debugging" | |
813 LLVM_EXTRA_OPTIONS="--disable-optimized \ | |
814 --enable-debug-runtime \ | |
815 --enable-assertions " | |
816 llvm-configure | |
817 } | |
818 | |
819 | |
820 llvm-needs-configure() { | |
821 [ ! -f "${TC_BUILD_LLVM}/config.status" ] | |
822 return $? | |
823 } | |
824 | |
825 llvm-needs-make() { | |
826 local srcdir="${TC_SRC_LLVM}" | |
827 local objdir="${TC_BUILD_LLVM}" | |
828 | |
829 ts-modified "$srcdir" "$objdir" | |
830 return $? | |
831 } | |
832 | |
833 #+ llvm-make - Run LLVM 'make' | |
834 llvm-make() { | |
835 StepBanner "LLVM" "Make" | |
836 | |
837 local srcdir="${TC_SRC_LLVM}" | |
838 local objdir="${TC_BUILD_LLVM}" | |
839 | |
840 spushd "${objdir}" | |
841 | |
842 ts-touch-open "${objdir}" | |
843 | |
844 RunWithLog llvm.make \ | |
845 env -i PATH=/usr/bin/:/bin \ | |
846 MAKE_OPTS="${MAKE_OPTS}" \ | |
847 NACL_SANDBOX=0 \ | |
848 CC=${CC} \ | |
849 CXX=${CXX} \ | |
850 make ${MAKE_OPTS} all | |
851 | |
852 ts-touch-commit "${objdir}" | |
853 | |
854 spopd | |
855 } | |
856 | |
857 #+ llvm-install - Install LLVM | |
858 llvm-install() { | |
859 StepBanner "LLVM" "Install" | |
860 | |
861 spushd "${TC_BUILD_LLVM}" | |
862 RunWithLog llvm.install \ | |
863 make ${MAKE_OPTS} install | |
864 | |
865 mkdir -p "${BFD_PLUGIN_DIR}" | |
866 | |
867 if ${BUILD_PLATFORM_MAC} ; then | |
868 ln -sf ../../lib/libLLVMgold.dylib "${BFD_PLUGIN_DIR}" | |
869 ln -sf ../../lib/libLTO.dylib "${BFD_PLUGIN_DIR}" | |
870 elif ${BUILD_PLATFORM_LINUX} ; then | |
871 ln -sf ../../lib/libLLVMgold.so "${BFD_PLUGIN_DIR}" | |
872 ln -sf ../../lib/libLTO.so "${BFD_PLUGIN_DIR}" | |
873 else | |
874 echo "Unhandled host" | |
875 exit -1 | |
876 fi | |
877 | |
878 spopd | |
879 } | |
880 | |
881 | |
882 | |
883 ######################################################################### | |
884 # < GCC STAGE 1 > | |
885 ######################################################################### | |
886 | |
887 # Build "pregcc" which is a gcc that does not depend on having glibc/newlib | |
888 # already compiled. This also generates some important headers (confirm this). | |
889 # | |
890 # NOTE: depends on newlib source being set up so we can use it to set | |
891 # up a sysroot. | |
892 # | |
893 | |
894 #+------------------------------------------------------------------------- | |
895 #+ gcc-stage1 - build and install pre-gcc | |
896 gcc-stage1() { | |
897 local target=$1 | |
898 StepBanner "GCC-${target}" | |
899 | |
900 if gcc-stage1-needs-configure ${target}; then | |
901 gcc-stage1-clean ${target} | |
902 gcc-stage1-configure ${target} | |
903 else | |
904 SkipBanner "GCC-${target}" "configure" | |
905 fi | |
906 | |
907 # We must always make before we do make install, because | |
908 # the build must occur in a patched environment. | |
909 # http://code.google.com/p/nativeclient/issues/detail?id=1128 | |
910 gcc-stage1-make ${target} | |
911 | |
912 gcc-stage1-install ${target} | |
913 } | |
914 | |
915 #+ gcc-stage1-sysroot - setup initial sysroot | |
916 gcc-stage1-sysroot() { | |
917 StepBanner "GCC" "Setting up initial sysroot" | |
918 | |
919 local sys_include="${INSTALL_DIR}/${CROSS_TARGET_ARM}/include" | |
920 local sys_include2="${INSTALL_DIR}/${CROSS_TARGET_ARM}/sys-include" | |
921 | |
922 rm -rf "${sys_include}" "${sys_include2}" | |
923 mkdir -p "${sys_include}" | |
924 ln -sf "${sys_include}" "${sys_include2}" | |
925 cp -r "${NEWLIB_INCLUDE_DIR}"/* ${sys_include} | |
926 } | |
927 | |
928 #+ gcc-stage1-clean - Clean gcc stage 1 | |
929 gcc-stage1-clean() { | |
930 local target=$1 | |
931 | |
932 StepBanner "GCC-${target}" "Clean" | |
933 local objdir="${TC_BUILD_LLVM_GCC1}-${target}" | |
934 rm -rf "${objdir}" | |
935 } | |
936 | |
937 gcc-stage1-needs-configure() { | |
938 local target=$1 | |
939 speculative-check "llvm" && return 0 | |
940 ts-newer-than "${TC_BUILD_LLVM}" \ | |
941 "${TC_BUILD_LLVM_GCC1}-${target}" && return 0 | |
942 [ ! -f "${TC_BUILD_LLVM_GCC1}-${target}/config.status" ] | |
943 return $? | |
944 } | |
945 | |
946 #+ gcc-stage1-configure - Configure GCC stage 1 | |
947 gcc-stage1-configure() { | |
948 local target=$1 | |
949 StepBanner "GCC-${target}" "Configure ${target}" | |
950 | |
951 local srcdir="${TC_SRC_LLVM_GCC}" | |
952 local objdir="${TC_BUILD_LLVM_GCC1}-${target}" | |
953 | |
954 mkdir -p "${objdir}" | |
955 spushd "${objdir}" | |
956 | |
957 # NOTE: hack, assuming presence of x86/32 toolchain (used for both 32/64) | |
958 local config_opts="" | |
959 case ${target} in | |
960 arm-*) | |
961 config_opts="--with-as=${PNACL_AS_ARM} \ | |
962 --with-arch=${ARM_ARCH} \ | |
963 --with-fpu=${ARM_FPU}" | |
964 ;; | |
965 i686-*) | |
966 config_opts="--with-as=${PNACL_AS_X8632}" | |
967 ;; | |
968 x86_64-*) | |
969 config_opts="--with-as=${PNACL_AS_X8664}" | |
970 ;; | |
971 esac | |
972 | |
973 # TODO(robertm): do we really need CROSS_TARGET_* | |
974 RunWithLog llvm-pregcc-${target}.configure \ | |
975 env -i PATH=/usr/bin/:/bin \ | |
976 CC=${CC} \ | |
977 CXX=${CXX} \ | |
978 CFLAGS="-Dinhibit_libc" \ | |
979 ${srcdir}/llvm-gcc-4.2/configure \ | |
980 --prefix=${INSTALL_DIR} \ | |
981 --enable-llvm=${INSTALL_DIR} \ | |
982 --with-newlib \ | |
983 --disable-libmudflap \ | |
984 --disable-decimal-float \ | |
985 --disable-libssp \ | |
986 --disable-libgomp \ | |
987 --disable-multilib \ | |
988 --enable-languages=c,c++ \ | |
989 --disable-threads \ | |
990 --disable-libstdcxx-pch \ | |
991 --disable-shared \ | |
992 --without-headers \ | |
993 ${config_opts} \ | |
994 --target=${target} \ | |
995 --with-sysroot="${NEWLIB_INSTALL_DIR}" | |
996 | |
997 spopd | |
998 } | |
999 | |
1000 gcc-stage1-make() { | |
1001 local target=$1 | |
1002 local srcdir="${TC_SRC_LLVM_GCC}" | |
1003 local objdir="${TC_BUILD_LLVM_GCC1}-${target}" | |
1004 spushd ${objdir} | |
1005 | |
1006 StepBanner "GCC-${target}" "Make (Stage 1)" | |
1007 | |
1008 ts-touch-open "${objdir}" | |
1009 | |
1010 # In case it is still patched from an interrupted make | |
1011 xgcc-unpatch-nofail "${target}" | |
1012 | |
1013 # we built our version of binutil for multiple targets, so they work here | |
1014 local ar=${CROSS_TARGET_AR} | |
1015 local ranlib=${CROSS_TARGET_RANLIB} | |
1016 mkdir -p "${objdir}/dummy-bin" | |
1017 ln -sf ${ar} "${objdir}/dummy-bin/${target}-ar" | |
1018 ln -sf ${ranlib} "${objdir}/dummy-bin/${target}-ranlib" | |
1019 | |
1020 # NOTE: we add ${INSTALL_DIR}/bin to PATH | |
1021 RunWithLog llvm-pregcc-${target}.make \ | |
1022 env -i PATH=/usr/bin/:/bin:${INSTALL_DIR}/bin:${objdir}/dummy-bin \ | |
1023 CC=${CC} \ | |
1024 CXX=${CXX} \ | |
1025 CFLAGS="-Dinhibit_libc" \ | |
1026 make ${MAKE_OPTS} all-gcc | |
1027 | |
1028 xgcc-patch "${target}" | |
1029 | |
1030 RunWithLog libgcc.clean \ | |
1031 env -i PATH=/usr/bin/:/bin:${INSTALL_DIR}/bin \ | |
1032 make clean-target-libgcc | |
1033 | |
1034 StepBanner "GCC-${target}" "Make (Stage 2)" | |
1035 # NOTE: This builds more than what we need right now. For example, | |
1036 # libstdc++ is unused (we always use the bitcode one). This might change | |
1037 # when we start supporting shared libraries. | |
1038 RunWithLog llvm-pregcc2-${target}.make \ | |
1039 env -i PATH=/usr/bin/:/bin:${INSTALL_DIR}/bin:${objdir}/dummy-bin \ | |
1040 CC=${CC} \ | |
1041 CXX=${CXX} \ | |
1042 CFLAGS="-Dinhibit_libc" \ | |
1043 make ${MAKE_OPTS} all | |
1044 | |
1045 xgcc-unpatch "${target}" | |
1046 | |
1047 ts-touch-commit "${objdir}" | |
1048 | |
1049 spopd | |
1050 } | |
1051 | |
1052 #+ xgcc-patch - Patch xgcc and clean libgcc | |
1053 xgcc-patch() { | |
1054 # This is a hack. Ideally gcc would be configured with a pnacl-nacl target | |
1055 # and xgcc would produce sfi code automatically. This is not the case, so | |
1056 # we cheat gcc's build by replacing xgcc behind its back. | |
1057 local target="$1" | |
1058 local objdir="${TC_BUILD_LLVM_GCC1}-${target}" | |
1059 local XGCC="${objdir}/gcc/xgcc" | |
1060 local XGCC_REAL="${XGCC}-real" | |
1061 local arch="" | |
1062 local driver="" | |
1063 | |
1064 StepBanner "GCC-${target}" "Patching xgcc and cleaning libgcc $target" | |
1065 | |
1066 # Make sure XGCC exists | |
1067 if [ ! -f "${XGCC}" ] ; then | |
1068 Abort "xgcc-patch" "Real xgcc does not exist." | |
1069 return | |
1070 fi | |
1071 | |
1072 # Make sure it is a real ELF file | |
1073 if is-shell-script "${XGCC}" ; then | |
1074 Abort "xgcc-patch" "xgcc already patched" | |
1075 return | |
1076 fi | |
1077 | |
1078 # N.B: | |
1079 # * We have to use the arch cc1 istead of the more common practice of using | |
1080 # the ARM cc1 for everything. The reason is that the ARM cc1 will reject a | |
1081 # asm that uses ebx for example | |
1082 # * Because of the previous item, we have to use the arch driver bacuse | |
1083 # the ARM driver will pass options like -mfpu that the x86 cc1 cannot handle. | |
1084 case ${target} in | |
1085 arm-*) arch="arm" ;; | |
1086 i686-*) arch="x86-32" ;; | |
1087 x86_64-*) arch="x86-64" ;; | |
1088 esac | |
1089 | |
1090 mv "${XGCC}" "${XGCC_REAL}" | |
1091 cat > "${XGCC}" <<EOF | |
1092 #!/bin/sh | |
1093 XGCC_ABSPATH=\$(cd \$(dirname \$0) && pwd) | |
1094 XGCC_NAME=\$(basename \$0) | |
1095 XGCC_REAL=\${XGCC_ABSPATH}/\${XGCC_NAME}-real | |
1096 ${PNACL_GCC} \\ | |
1097 --driver="\${XGCC_REAL}" \\ | |
1098 --pnacl-bias=${arch} -arch ${arch} "\$@" | |
1099 EOF | |
1100 | |
1101 chmod 755 "${XGCC}" | |
1102 | |
1103 } | |
1104 | |
1105 xgcc-unpatch() { | |
1106 local target="$1" | |
1107 local objdir="${TC_BUILD_LLVM_GCC1}-${target}" | |
1108 local XGCC="${objdir}/gcc/xgcc" | |
1109 local XGCC_REAL="${XGCC}-real" | |
1110 | |
1111 StepBanner "GCC-${target}" "Unpatching xgcc" | |
1112 | |
1113 # Make sure XGCC exists | |
1114 if [ ! -f "${XGCC}" ] ; then | |
1115 Abort "xgcc-unpatch" "Real xgcc does not exist." | |
1116 return | |
1117 fi | |
1118 | |
1119 # Make sure it isn't a real ELF file | |
1120 if ! is-shell-script "${XGCC}" ; then | |
1121 Abort "xgcc-unpatch" "xgcc already unpatched?" | |
1122 return | |
1123 fi | |
1124 | |
1125 rm "${XGCC}" | |
1126 mv "${XGCC_REAL}" "${XGCC}" | |
1127 } | |
1128 | |
1129 xgcc-unpatch-nofail() { | |
1130 local target="$1" | |
1131 local objdir="${TC_BUILD_LLVM_GCC1}-${target}" | |
1132 local XGCC="${objdir}/gcc/xgcc" | |
1133 local XGCC_REAL="${XGCC}-real" | |
1134 | |
1135 # If the old patch file exists, delete it. | |
1136 if [ -f "${XGCC}" ] && is-shell-script "${XGCC}"; then | |
1137 rm "${XGCC}" | |
1138 fi | |
1139 | |
1140 # If there's a real one around, move it back. | |
1141 if [ -f "${XGCC_REAL}" ]; then | |
1142 mv "${XGCC_REAL}" "${XGCC}" | |
1143 fi | |
1144 } | |
1145 | |
1146 #+ gcc-stage1-install - Install GCC stage 1 | |
1147 gcc-stage1-install() { | |
1148 local target=$1 | |
1149 StepBanner "GCC-${target}" "Install ${target}" | |
1150 | |
1151 local objdir="${TC_BUILD_LLVM_GCC1}-${target}" | |
1152 spushd "${TC_BUILD_LLVM_GCC1}-${target}" | |
1153 | |
1154 # NOTE: we add ${INSTALL_DIR}/bin to PATH | |
1155 RunWithLog llvm-pregcc-${target}.install \ | |
1156 env -i PATH=/usr/bin/:/bin:${INSTALL_DIR}/bin:${objdir}/dummy-bin \ | |
1157 CC=${CC} \ | |
1158 CXX=${CXX} \ | |
1159 CFLAGS="-Dinhibit_libc" \ | |
1160 make ${MAKE_OPTS} install | |
1161 | |
1162 spopd | |
1163 } | |
1164 | |
1165 | |
1166 ######################################################################### | |
1167 ######################################################################### | |
1168 # < LIBSTDCPP-BITCODE > | |
1169 ######################################################################### | |
1170 ######################################################################### | |
1171 | |
1172 #+ libstdcpp-bitcode - build and install libstdcpp in bitcode | |
1173 libstdcpp-bitcode() { | |
1174 StepBanner "LIBSTDCPP-BITCODE" | |
1175 | |
1176 if libstdcpp-bitcode-needs-configure; then | |
1177 libstdcpp-bitcode-clean | |
1178 libstdcpp-bitcode-configure | |
1179 else | |
1180 SkipBanner "LIBSTDCPP-BITCODE" "configure" | |
1181 fi | |
1182 | |
1183 if libstdcpp-bitcode-needs-make; then | |
1184 libstdcpp-bitcode-make | |
1185 else | |
1186 SkipBanner "LIBSTDCPP-BITCODE" "make" | |
1187 fi | |
1188 | |
1189 libstdcpp-bitcode-install | |
1190 } | |
1191 | |
1192 #+ libstdcpp-bitcode-clean - clean libstdcpp in bitcode | |
1193 libstdcpp-bitcode-clean() { | |
1194 StepBanner "LIBSTDCPP-BITCODE" "Clean" | |
1195 rm -rf "${TC_BUILD_LIBSTDCPP_BITCODE}" | |
1196 } | |
1197 | |
1198 libstdcpp-bitcode-needs-configure() { | |
1199 speculative-check "gcc-stage1" && return 0 | |
1200 ts-newer-than "${TC_BUILD_LLVM_GCC1}-${CROSS_TARGET_ARM}" \ | |
1201 "${TC_BUILD_LIBSTDCPP_BITCODE}" && return 0 | |
1202 [ ! -f "${TC_BUILD_LIBSTDCPP_BITCODE}/config.status" ] | |
1203 return #? | |
1204 } | |
1205 | |
1206 #+ libstdcpp-bitcode-configure - configure libstdcpp for bitcode | |
1207 libstdcpp-bitcode-configure() { | |
1208 StepBanner "LIBSTDCPP-BITCODE" "Configure" | |
1209 libstdcpp-configure-common "${TC_BUILD_LIBSTDCPP_BITCODE}" | |
1210 } | |
1211 | |
1212 libstdcpp-configure-common() { | |
1213 local srcdir="${TC_SRC_LIBSTDCPP}" | |
1214 local objdir="$1" | |
1215 | |
1216 mkdir -p "${objdir}" | |
1217 spushd "${objdir}" | |
1218 | |
1219 RunWithLog llvm-gcc.configure_libstdcpp \ | |
1220 env -i PATH=/usr/bin/:/bin:${INSTALL_DIR}/bin \ | |
1221 "${STD_ENV_FOR_LIBSTDCPP[@]}" \ | |
1222 "${srcdir}"/configure \ | |
1223 --host=${CROSS_TARGET_ARM} \ | |
1224 --prefix=${INSTALL_DIR} \ | |
1225 --enable-llvm=${INSTALL_DIR} \ | |
1226 --with-newlib \ | |
1227 --disable-libstdcxx-pch \ | |
1228 --disable-shared \ | |
1229 --enable-languages=c,c++ \ | |
1230 --target=${CROSS_TARGET_ARM} \ | |
1231 --with-sysroot=${NEWLIB_INSTALL_DIR} \ | |
1232 --with-arch=${ARM_ARCH} \ | |
1233 --srcdir="${srcdir}" | |
1234 spopd | |
1235 } | |
1236 | |
1237 libstdcpp-bitcode-needs-make() { | |
1238 local srcdir="${TC_SRC_LIBSTDCPP}" | |
1239 local objdir="${TC_BUILD_LIBSTDCPP_BITCODE}" | |
1240 | |
1241 ts-modified "$srcdir" "$objdir" | |
1242 return $? | |
1243 } | |
1244 | |
1245 #+ libstdcpp-bitcode-make - Make libstdcpp in bitcode | |
1246 libstdcpp-bitcode-make() { | |
1247 StepBanner "LIBSTDCPP-BITCODE" "Make" | |
1248 libstdcpp-make-common "${TC_BUILD_LIBSTDCPP_BITCODE}" | |
1249 } | |
1250 | |
1251 libstdcpp-make-common() { | |
1252 local srcdir="${TC_SRC_LIBSTDCPP}" | |
1253 local objdir="$1" | |
1254 | |
1255 ts-touch-open "${objdir}" | |
1256 | |
1257 spushd "${objdir}" | |
1258 RunWithLog llvm-gcc.make_libstdcpp \ | |
1259 env -i PATH=/usr/bin/:/bin:${INSTALL_DIR}/bin \ | |
1260 make \ | |
1261 "${STD_ENV_FOR_LIBSTDCPP[@]}" \ | |
1262 ${MAKE_OPTS} | |
1263 spopd | |
1264 | |
1265 ts-touch-commit "${objdir}" | |
1266 } | |
1267 | |
1268 #+ libstdcpp-bitcode-install - Install libstdcpp in bitcode | |
1269 libstdcpp-bitcode-install() { | |
1270 StepBanner "LIBSTDCPP-BITCODE" "Install" | |
1271 local objdir="${TC_BUILD_LIBSTDCPP_BITCODE}" | |
1272 local dest="${PNACL_BITCODE_ROOT}" | |
1273 | |
1274 spushd "${objdir}" | |
1275 | |
1276 # install headers (=install-data) | |
1277 # for good measure make sure we do not keep any old headers | |
1278 rm -rf "${INSTALL_ROOT}/include/c++" | |
1279 RunWithLog llvm-gcc.install_libstdcpp \ | |
1280 make \ | |
1281 "${STD_ENV_FOR_LIBSTDCPP[@]}" \ | |
1282 ${MAKE_OPTS} install-data | |
1283 # install bitcode library | |
1284 cp "${objdir}/src/.libs/libstdc++.a" "${dest}" | |
1285 | |
1286 spopd | |
1287 } | |
1288 | |
1289 #+ misc-tools - Build and install sel_ldr and validator for ARM. | |
1290 misc-tools() { | |
1291 if ${UTMAN_BUILD_ARM} ; then | |
1292 StepBanner "MISC-ARM" "Building sel_ldr (ARM)" | |
1293 | |
1294 # TODO(robertm): revisit some of these options | |
1295 RunWithLog arm_sel_ldr \ | |
1296 ./scons MODE=opt-host \ | |
1297 platform=arm \ | |
1298 sdl=none \ | |
1299 naclsdk_validate=0 \ | |
1300 sysinfo=0 \ | |
1301 sel_ldr | |
1302 rm -rf "${INSTALL_ROOT}/tools-arm" | |
1303 mkdir "${INSTALL_ROOT}/tools-arm" | |
1304 local sconsdir="scons-out/opt-${SCONS_BUILD_PLATFORM}-arm" | |
1305 cp "${sconsdir}/obj/src/trusted/service_runtime/sel_ldr" \ | |
1306 "${INSTALL_ROOT}/tools-arm" | |
1307 else | |
1308 StepBanner "MISC-ARM" "Skipping ARM sel_ldr (No trusted ARM toolchain)" | |
1309 fi | |
1310 | |
1311 if ${BUILD_PLATFORM_LINUX} ; then | |
1312 StepBanner "MISC-ARM" "Building validator (ARM)" | |
1313 RunWithLog arm_ncval_core \ | |
1314 ./scons MODE=opt-host \ | |
1315 targetplatform=arm \ | |
1316 sysinfo=0 \ | |
1317 arm-ncval-core | |
1318 rm -rf "${INSTALL_ROOT}/tools-x86" | |
1319 mkdir "${INSTALL_ROOT}/tools-x86" | |
1320 cp scons-out/opt-linux-x86-32-to-arm/obj/src/trusted/validator_arm/\ | |
1321 arm-ncval-core ${INSTALL_ROOT}/tools-x86 | |
1322 else | |
1323 StepBanner "MISC-ARM" "Skipping ARM validator (Not yet supported on Mac)" | |
1324 fi | |
1325 } | |
1326 | |
1327 | |
1328 ######################################################################### | |
1329 # < BINUTILS > | |
1330 ######################################################################### | |
1331 | |
1332 #+------------------------------------------------------------------------- | |
1333 #+ binutils-arm - Build and install binutils for ARM | |
1334 binutils-arm() { | |
1335 StepBanner "BINUTILS-ARM" | |
1336 | |
1337 local srcdir="${TC_SRC_BINUTILS}" | |
1338 | |
1339 assert-dir "${srcdir}" "You need to checkout binutils." | |
1340 | |
1341 if binutils-arm-needs-configure; then | |
1342 binutils-arm-clean | |
1343 binutils-arm-configure | |
1344 else | |
1345 SkipBanner "BINUTILS-ARM" "configure" | |
1346 fi | |
1347 | |
1348 if binutils-arm-needs-make; then | |
1349 binutils-arm-make | |
1350 else | |
1351 SkipBanner "BINUTILS-ARM" "make" | |
1352 fi | |
1353 | |
1354 binutils-arm-install | |
1355 } | |
1356 | |
1357 #+ binutils-arm-clean - Clean binutils | |
1358 binutils-arm-clean() { | |
1359 StepBanner "BINUTILS-ARM" "Clean" | |
1360 local objdir="${TC_BUILD_BINUTILS_ARM}" | |
1361 rm -rf ${objdir} | |
1362 } | |
1363 | |
1364 #+ binutils-arm-configure- Configure binutils for ARM | |
1365 binutils-arm-configure() { | |
1366 StepBanner "BINUTILS-ARM" "Configure" | |
1367 | |
1368 local srcdir="${TC_SRC_BINUTILS}" | |
1369 local objdir="${TC_BUILD_BINUTILS_ARM}" | |
1370 | |
1371 # enable multiple targets so that we can use the same ar with all .o files | |
1372 local targ="arm-pc-nacl,i686-pc-nacl,x86_64-pc-nacl" | |
1373 mkdir -p "${objdir}" | |
1374 spushd "${objdir}" | |
1375 | |
1376 # --enable-checking is to avoid a build failure: | |
1377 # tc-arm.c:2489: warning: empty body in an if-statement | |
1378 # The --enable-gold and --enable-plugins options are on so that we | |
1379 # can use gold's support for plugin to link PNaCl modules. | |
1380 | |
1381 # TODO(pdox): Building binutils for nacl/nacl64 target currently requires | |
1382 # providing NACL_ALIGN_* defines. This should really be defined inside | |
1383 # binutils instead. | |
1384 RunWithLog binutils.arm.configure \ | |
1385 env -i \ | |
1386 PATH="/usr/bin:/bin" \ | |
1387 CC=${CC} \ | |
1388 CXX=${CXX} \ | |
1389 CFLAGS="-DNACL_ALIGN_BYTES=32 -DNACL_ALIGN_POW2=5" \ | |
1390 ${srcdir}/binutils-2.20/configure --prefix=${INSTALL_DIR} \ | |
1391 --target=${BINUTILS_TARGET} \ | |
1392 --enable-targets=${targ} \ | |
1393 --enable-checking \ | |
1394 --enable-gold=yes \ | |
1395 --enable-ld=yes \ | |
1396 --enable-plugins \ | |
1397 --disable-werror \ | |
1398 --with-sysroot=${NEWLIB_INSTALL_DIR} | |
1399 spopd | |
1400 } | |
1401 | |
1402 binutils-arm-needs-configure() { | |
1403 [ ! -f "${TC_BUILD_BINUTILS_ARM}/config.status" ] | |
1404 return $? | |
1405 } | |
1406 | |
1407 binutils-arm-needs-make() { | |
1408 local srcdir="${TC_SRC_BINUTILS}" | |
1409 local objdir="${TC_BUILD_BINUTILS_ARM}" | |
1410 | |
1411 ts-modified "$srcdir" "$objdir" | |
1412 return $? | |
1413 } | |
1414 | |
1415 #+ binutils-arm-make - Make binutils for ARM | |
1416 binutils-arm-make() { | |
1417 StepBanner "BINUTILS-ARM" "Make" | |
1418 local srcdir="${TC_SRC_BINUTILS}" | |
1419 local objdir="${TC_BUILD_BINUTILS_ARM}" | |
1420 spushd "${objdir}" | |
1421 | |
1422 ts-touch-open "${objdir}" | |
1423 | |
1424 RunWithLog binutils.arm.make \ | |
1425 env -i PATH="/usr/bin:/bin" \ | |
1426 make ${MAKE_OPTS} | |
1427 | |
1428 ts-touch-commit "${objdir}" | |
1429 | |
1430 spopd | |
1431 } | |
1432 | |
1433 #+ binutils-arm-install - Install binutils for ARM | |
1434 binutils-arm-install() { | |
1435 StepBanner "BINUTILS-ARM" "Install" | |
1436 local objdir="${TC_BUILD_BINUTILS_ARM}" | |
1437 spushd "${objdir}" | |
1438 | |
1439 RunWithLog binutils.arm.install \ | |
1440 env -i PATH="/usr/bin:/bin" \ | |
1441 make \ | |
1442 install ${MAKE_OPTS} | |
1443 | |
1444 spopd | |
1445 | |
1446 # Binutils builds readelf and size, but doesn't install it. | |
1447 mkdir -p "${INSTALL_BIN}" | |
1448 cp -f "${objdir}"/binutils/readelf "${PNACL_READELF}" | |
1449 cp -f "${objdir}"/binutils/size "${PNACL_SIZE}" | |
1450 } | |
1451 | |
1452 #+------------------------------------------------------------------------- | |
1453 #+ binutils-liberty - Build native binutils libiberty | |
1454 binutils-liberty() { | |
1455 local srcdir="${TC_SRC_BINUTILS}" | |
1456 | |
1457 assert-dir "${srcdir}" "You need to checkout binutils." | |
1458 | |
1459 if binutils-liberty-needs-configure; then | |
1460 binutils-liberty-clean | |
1461 binutils-liberty-configure | |
1462 else | |
1463 SkipBanner "BINUTILS-LIBERTY" "configure" | |
1464 fi | |
1465 | |
1466 if binutils-liberty-needs-make; then | |
1467 binutils-liberty-make | |
1468 else | |
1469 SkipBanner "BINUTILS-LIBERTY" "make" | |
1470 fi | |
1471 } | |
1472 | |
1473 binutils-liberty-needs-configure() { | |
1474 [ ! -f "${TC_BUILD_BINUTILS_LIBERTY}/config.status" ] | |
1475 return $? | |
1476 } | |
1477 | |
1478 #+ binutils-liberty-clean - Clean binutils-liberty | |
1479 binutils-liberty-clean() { | |
1480 StepBanner "BINUTILS-LIBERTY" "Clean" | |
1481 local objdir="${TC_BUILD_BINUTILS_LIBERTY}" | |
1482 rm -rf ${objdir} | |
1483 } | |
1484 | |
1485 #+ binutils-liberty-configure - Configure binutils-liberty for X86 | |
1486 binutils-liberty-configure() { | |
1487 StepBanner "BINUTILS-LIBERTY" "Configure" | |
1488 | |
1489 local srcdir="${TC_SRC_BINUTILS}" | |
1490 local objdir="${TC_BUILD_BINUTILS_LIBERTY}" | |
1491 | |
1492 mkdir -p "${objdir}" | |
1493 spushd "${objdir}" | |
1494 RunWithLog binutils.liberty.configure \ | |
1495 env -i \ | |
1496 PATH="/usr/bin:/bin" \ | |
1497 CC=${CC} \ | |
1498 CXX=${CXX} \ | |
1499 ${srcdir}/binutils-2.20/configure | |
1500 spopd | |
1501 } | |
1502 | |
1503 binutils-liberty-needs-make() { | |
1504 local srcdir="${TC_SRC_BINUTILS}" | |
1505 local objdir="${TC_BUILD_BINUTILS_LIBERTY}" | |
1506 | |
1507 ts-modified "$srcdir" "$objdir" | |
1508 return $? | |
1509 } | |
1510 | |
1511 #+ binutils-liberty-make - Make binutils-liberty for X86 | |
1512 binutils-liberty-make() { | |
1513 StepBanner "BINUTILS-LIBERTY" "Make" | |
1514 local srcdir="${TC_SRC_BINUTILS}" | |
1515 local objdir="${TC_BUILD_BINUTILS_LIBERTY}" | |
1516 spushd "${objdir}" | |
1517 | |
1518 ts-touch-open "${objdir}" | |
1519 | |
1520 RunWithLog binutils.liberty.make \ | |
1521 env -i PATH="/usr/bin:/bin" \ | |
1522 make ${MAKE_OPTS} all-libiberty | |
1523 | |
1524 ts-touch-commit "${objdir}" | |
1525 | |
1526 spopd | |
1527 } | |
1528 | |
1529 ######################################################################### | |
1530 # CLIENT BINARIES (SANDBOXED) | |
1531 ######################################################################### | |
1532 | |
1533 check-sb-mode() { | |
1534 local mode=$1 | |
1535 if [ ${mode} != "srpc" ] && [ ${mode} != "nonsrpc" ]; then | |
1536 echo "ERROR: Unsupported mode. Choose one of: srpc, nonsrpc" | |
1537 exit -1 | |
1538 fi | |
1539 } | |
1540 | |
1541 check-sb-arch() { | |
1542 local arch=$1 | |
1543 for valid_arch in x8632 x8664 arm universal ; do | |
1544 if [ "${arch}" == "${valid_arch}" ] ; then | |
1545 return | |
1546 fi | |
1547 done | |
1548 | |
1549 echo "ERROR: Unsupported arch. Choose one of: x8632, x8664, arm, universal" | |
1550 exit -1 | |
1551 } | |
1552 | |
1553 #+------------------------------------------------------------------------- | |
1554 #+ llvm-tools-sb <arch> <mode> - Build and install llvm tools (sandboxed) | |
1555 llvm-tools-sb() { | |
1556 local srcdir="${TC_SRC_LLVM}" | |
1557 | |
1558 assert-dir "${srcdir}" "You need to checkout llvm." | |
1559 | |
1560 if [ $# -ne 2 ]; then | |
1561 echo "ERROR: Usage llvm-tools-sb <arch> <mode>" | |
1562 exit -1 | |
1563 fi | |
1564 | |
1565 local arch=$1 | |
1566 local mode=$2 | |
1567 check-sb-arch ${arch} | |
1568 check-sb-mode ${mode} | |
1569 | |
1570 if llvm-tools-sb-needs-configure "${arch}" "${mode}" ; then | |
1571 llvm-tools-sb-clean "${arch}" "${mode}" | |
1572 llvm-tools-sb-configure "${arch}" "${mode}" | |
1573 else | |
1574 SkipBanner "LLVM-TOOLS-SB" "configure ${arch} ${mode} " | |
1575 fi | |
1576 | |
1577 if llvm-tools-sb-needs-make "${arch}" "${mode}" ; then | |
1578 llvm-tools-sb-make "${arch}" "${mode}" | |
1579 else | |
1580 SkipBanner "LLVM-TOOLS-SB" "make ${arch} ${mode} " | |
1581 fi | |
1582 | |
1583 llvm-tools-sb-install "${arch}" "${mode}" | |
1584 } | |
1585 | |
1586 llvm-tools-sb-needs-configure() { | |
1587 local arch=$1 | |
1588 local mode=$2 | |
1589 local objdir="${TC_BUILD}/llvm-tools-${arch}-${mode}-sandboxed" | |
1590 [ ! -f "${objdir}/config.status" ] | |
1591 return $? | |
1592 } | |
1593 | |
1594 # llvm-tools-sb-clean - Clean llvm tools (sandboxed) for x86 | |
1595 llvm-tools-sb-clean() { | |
1596 local arch=$1 | |
1597 local mode=$2 | |
1598 StepBanner "LLVM-TOOLS-SB" "Clean ${arch} ${mode}" | |
1599 local objdir="${TC_BUILD}/llvm-tools-${arch}-${mode}-sandboxed" | |
1600 | |
1601 rm -rf "${objdir}" | |
1602 mkdir -p "${objdir}" | |
1603 } | |
1604 | |
1605 llvm-tools-sb-setup() { | |
1606 local arch=$1 | |
1607 local mode=$2 | |
1608 local bitsize | |
1609 local prefix | |
1610 local flags | |
1611 | |
1612 flags="-static" | |
1613 case ${mode} in | |
1614 srpc) flags+=" -DNACL_SRPC" ;; | |
1615 nonsrpc) ;; | |
1616 esac | |
1617 | |
1618 # Speed things up by avoiding an intermediate step | |
1619 flags+=" --pnacl-skip-ll" | |
1620 | |
1621 LLVM_SB_CONFIGURE_ENV=( | |
1622 AR="${PNACL_AR}" \ | |
1623 AS="${PNACL_AS}" \ | |
1624 CC="${PNACL_GCC} ${flags}" \ | |
1625 CXX="${PNACL_GPP} ${flags}" \ | |
1626 LD="${PNACL_LD} ${flags}" \ | |
1627 NM="${PNACL_NM}" \ | |
1628 RANLIB="${PNACL_RANLIB}" \ | |
1629 LDFLAGS="") # TODO(pdox): Support -s | |
1630 } | |
1631 | |
1632 # llvm-tools-sb-configure - Configure llvm tools (sandboxed) for x86 | |
1633 llvm-tools-sb-configure() { | |
1634 local arch=$1 | |
1635 local mode=$2 | |
1636 llvm-tools-sb-setup ${arch} ${mode} | |
1637 | |
1638 StepBanner "LLVM-TOOLS-SB" "Configure ${arch} ${mode}" | |
1639 local srcdir="${TC_SRC_LLVM}" | |
1640 local objdir="${TC_BUILD}/llvm-tools-${arch}-${mode}-sandboxed" | |
1641 local installdir="${PNACL_SB_ROOT}/${arch}/${mode}" | |
1642 local targets="" | |
1643 case ${arch} in | |
1644 x8632) targets=x86 ;; | |
1645 x8664) targets=x86_64 ;; | |
1646 arm) targets=arm ;; | |
1647 universal) targets=x86,x86_64,arm ;; | |
1648 esac | |
1649 | |
1650 spushd ${objdir} | |
1651 RunWithLog \ | |
1652 llvm.tools.${arch}.${mode}.sandboxed.configure \ | |
1653 env -i \ | |
1654 PATH="/usr/bin:/bin" \ | |
1655 ${srcdir}/llvm-trunk/configure \ | |
1656 "${LLVM_SB_CONFIGURE_ENV[@]}" \ | |
1657 --prefix=${installdir} \ | |
1658 --host=nacl \ | |
1659 --disable-jit \ | |
1660 --enable-optimized \ | |
1661 --target=${CROSS_TARGET_ARM} \ | |
1662 --enable-targets=${targets} \ | |
1663 --enable-pic=no \ | |
1664 --enable-static \ | |
1665 --enable-shared=no | |
1666 spopd | |
1667 } | |
1668 | |
1669 llvm-tools-sb-needs-make() { | |
1670 local arch=$1 | |
1671 local mode=$2 | |
1672 local srcdir="${TC_SRC_LLVM}" | |
1673 local objdir="${TC_BUILD}/llvm-tools-${arch}-${mode}-sandboxed" | |
1674 | |
1675 ts-modified "$srcdir" "$objdir" | |
1676 return $? | |
1677 } | |
1678 | |
1679 # llvm-tools-sb-make - Make llvm tools (sandboxed) for x86 | |
1680 llvm-tools-sb-make() { | |
1681 local arch=$1 | |
1682 local mode=$2 | |
1683 llvm-tools-sb-setup ${arch} ${mode} | |
1684 | |
1685 StepBanner "LLVM-TOOLS-SB" "Make ${arch} ${mode}" | |
1686 local objdir="${TC_BUILD}/llvm-tools-${arch}-${mode}-sandboxed" | |
1687 | |
1688 spushd ${objdir} | |
1689 ts-touch-open "${objdir}" | |
1690 | |
1691 local build_with_srpc=0 | |
1692 if [ ${mode} == "srpc" ]; then | |
1693 build_with_srpc=1 | |
1694 fi | |
1695 | |
1696 RunWithLog llvm.tools.${arch}.${mode}.sandboxed.make \ | |
1697 env -i PATH="/usr/bin:/bin" \ | |
1698 ONLY_TOOLS=llc \ | |
1699 NACL_SANDBOX=1 \ | |
1700 NACL_SRPC=${build_with_srpc} \ | |
1701 KEEP_SYMBOLS=1 \ | |
1702 VERBOSE=1 \ | |
1703 make ENABLE_OPTIMIZED=1 OPTIMIZE_OPTION=-O3 \ | |
1704 ${MAKE_OPTS} tools-only | |
1705 | |
1706 ts-touch-commit "${objdir}" | |
1707 | |
1708 spopd | |
1709 } | |
1710 | |
1711 # llvm-tools-sb-install - Install llvm tools (sandboxed) for x86 | |
1712 llvm-tools-sb-install() { | |
1713 local arch=$1 | |
1714 local mode=$2 | |
1715 llvm-tools-sb-setup ${arch} ${mode} | |
1716 | |
1717 StepBanner "LLVM-TOOLS-SB" "Install ${arch} ${mode}" | |
1718 local objdir="${TC_BUILD}/llvm-tools-${arch}-${mode}-sandboxed" | |
1719 spushd ${objdir} | |
1720 | |
1721 RunWithLog llvm.tools.${arch}.${mode}.sandboxed.install \ | |
1722 env -i PATH="/usr/bin:/bin" \ | |
1723 ONLY_TOOLS=llc \ | |
1724 NACL_SANDBOX=1 \ | |
1725 KEEP_SYMBOLS=1 \ | |
1726 make ${MAKE_OPTS} install | |
1727 | |
1728 spopd | |
1729 | |
1730 translate-and-install-sb-tool ${arch} ${mode} llc | |
1731 } | |
1732 | |
1733 translate-and-install-sb-tool() { | |
1734 local arch=$1 | |
1735 local mode=$2 | |
1736 local name=$3 | |
1737 | |
1738 # Translate bitcode program into an actual native executable. | |
1739 # If arch = universal, we need to translate and install multiple times. | |
1740 local bindir="${PNACL_SB_ROOT}/${arch}/${mode}/bin" | |
1741 local pexe="${bindir}/${name}.pexe" | |
1742 | |
1743 # Rename to .pexe | |
1744 mv "${bindir}/${name}" "${pexe}" | |
1745 | |
1746 local arches | |
1747 if [ "${arch}" == "universal" ]; then | |
1748 arches="${SBTC_BUILD_WITH_PNACL}" | |
1749 else | |
1750 arches="${arch}" | |
1751 fi | |
1752 | |
1753 local installer | |
1754 if [ "${arch}" == "universal" ]; then | |
1755 installer="cp -f" | |
1756 else | |
1757 installer="mv -f" | |
1758 fi | |
1759 | |
1760 # In universal/mode/bin directory, we'll end up with every translation: | |
1761 # e.g. llc.arm.nexe, llc.x8632.nexe, llc.x8664.nexe | |
1762 # In arch/mode/bin directories, we'll end up with just one copy | |
1763 local num_arches=$(wc -w <<< "${arches}") | |
1764 local extra="" | |
1765 if [ ${num_arches} -gt 1 ] && QueueConcurrent; then | |
1766 extra=" (background)" | |
1767 fi | |
1768 | |
1769 for tarch in ${arches}; do | |
1770 local nexe="${bindir}/${name}.${tarch}.nexe" | |
1771 StepBanner "TRANSLATE" "Translating ${name}.pexe to ${tarch}${extra}" | |
1772 "${PNACL_TRANSLATE}" -arch ${tarch} "${pexe}" -o "${nexe}" & | |
1773 QueueLastProcess | |
1774 done | |
1775 | |
1776 if [ ${num_arches} -gt 1 ] && ! QueueEmpty ; then | |
1777 StepBanner "TRANSLATE" "Waiting for processes to finish" | |
1778 fi | |
1779 QueueWait | |
1780 | |
1781 for tarch in ${arches}; do | |
1782 local nexe="${bindir}/${name}.${tarch}.nexe" | |
1783 local bindir_tarch="${PNACL_SB_ROOT}/${tarch}/${mode}/bin" | |
1784 mkdir -p "${bindir_tarch}" | |
1785 ${installer} "${nexe}" "${bindir_tarch}/${name}" | |
1786 done | |
1787 } | |
1788 | |
1789 #+------------------------------------------------------------------------- | |
1790 #+ binutils-sb <arch> <mode> - Build and install binutils (sandboxed) | |
1791 binutils-sb() { | |
1792 local srcdir="${TC_SRC_BINUTILS}" | |
1793 | |
1794 assert-dir "${srcdir}" "You need to checkout binutils." | |
1795 | |
1796 if [ $# -ne 2 ]; then | |
1797 echo "ERROR: Usage binutils-sb <arch> <mode>" | |
1798 exit -1 | |
1799 fi | |
1800 | |
1801 local arch=$1 | |
1802 local mode=$2 | |
1803 check-sb-arch ${arch} | |
1804 check-sb-mode ${mode} | |
1805 | |
1806 if [ ! -d "${NNACL_ROOT}" ] ; then | |
1807 echo "ERROR: Install Native Client toolchain" | |
1808 exit -1 | |
1809 fi | |
1810 | |
1811 if [ ! -f "${TC_BUILD_BINUTILS_LIBERTY}/libiberty/libiberty.a" ] ; then | |
1812 echo "ERROR: Missing lib. Run this script with binutils-liberty option" | |
1813 exit -1 | |
1814 fi | |
1815 | |
1816 if binutils-sb-needs-configure "${arch}" "${mode}"; then | |
1817 binutils-sb-clean "${arch}" "${mode}" | |
1818 binutils-sb-configure "${arch}" "${mode}" | |
1819 else | |
1820 SkipBanner "BINUTILS-SB" "configure ${arch} ${mode}" | |
1821 fi | |
1822 | |
1823 if binutils-sb-needs-make "${arch}" "${mode}"; then | |
1824 binutils-sb-make "${arch}" "${mode}" | |
1825 else | |
1826 SkipBanner "BINUTILS-SB" "make ${arch} ${mode}" | |
1827 fi | |
1828 | |
1829 binutils-sb-install "${arch}" "${mode}" | |
1830 } | |
1831 | |
1832 binutils-sb-needs-configure() { | |
1833 local arch=$1 | |
1834 local mode=$2 | |
1835 [ ! -f "${TC_BUILD}/binutils-${arch}-${mode}-sandboxed/config.status" ] | |
1836 return $? | |
1837 } | |
1838 | |
1839 # binutils-sb-clean - Clean binutils (sandboxed) for x86 | |
1840 binutils-sb-clean() { | |
1841 local arch=$1 | |
1842 local mode=$2 | |
1843 StepBanner "BINUTILS-SB" "Clean ${arch} ${mode}" | |
1844 local objdir="${TC_BUILD}/binutils-${arch}-${mode}-sandboxed" | |
1845 rm -rf "${objdir}" | |
1846 mkdir -p "${objdir}" | |
1847 } | |
1848 | |
1849 # binutils-sb-configure - Configure binutils (sandboxed) for x86 | |
1850 binutils-sb-configure() { | |
1851 local arch=$1 | |
1852 local mode=$2 | |
1853 StepBanner "BINUTILS-SB" "Configure ${arch} ${mode}" | |
1854 local bitsize=${arch:3:2} | |
1855 local nacl="nacl${bitsize/"32"/}" | |
1856 local srcdir="${TC_SRC_BINUTILS}" | |
1857 local objdir="${TC_BUILD}/binutils-${arch}-${mode}-sandboxed" | |
1858 local installdir="${PNACL_SB_ROOT}/${arch}/${mode}" | |
1859 | |
1860 local flags="-DNACL_ALIGN_BYTES=32 -DNACL_ALIGN_POW2=5 -DNACL_TOOLCHAIN_PATCH" | |
1861 if [ ${mode} == "srpc" ]; then | |
1862 flags+=" -DNACL_SRPC" | |
1863 fi | |
1864 | |
1865 spushd ${objdir} | |
1866 mkdir -p liberty_tmp | |
1867 cp "${TC_BUILD_BINUTILS_LIBERTY}/libiberty/libiberty.a" liberty_tmp | |
1868 RunWithLog \ | |
1869 binutils.${arch}.${mode}.sandboxed.configure \ | |
1870 env -i \ | |
1871 PATH="/usr/bin:/bin" \ | |
1872 AR="${NNACL_ROOT}/bin/${nacl}-ar" \ | |
1873 AS="${NNACL_ROOT}/bin/${nacl}-as" \ | |
1874 CC="${NNACL_ROOT}/bin/${nacl}-gcc" \ | |
1875 CXX="${NNACL_ROOT}/bin/${nacl}-g++" \ | |
1876 LD="${NNACL_ROOT}/bin/${nacl}-ld" \ | |
1877 RANLIB="${NNACL_ROOT}/bin/${nacl}-ranlib" \ | |
1878 CFLAGS="-m${bitsize} -O3 ${flags} -I${NNACL_ROOT}/${nacl}/include" \ | |
1879 LDFLAGS="-s" \ | |
1880 LDFLAGS_FOR_BUILD="-L../liberty_tmp" \ | |
1881 ${srcdir}/binutils-2.20/configure \ | |
1882 --prefix=${installdir} \ | |
1883 --host=${nacl} \ | |
1884 --target=${nacl} \ | |
1885 --disable-nls \ | |
1886 --disable-werror \ | |
1887 --enable-static \ | |
1888 --enable-shared=no | |
1889 spopd | |
1890 } | |
1891 | |
1892 binutils-sb-needs-make() { | |
1893 local arch=$1 | |
1894 local mode=$2 | |
1895 local srcdir="${TC_SRC_BINUTILS}" | |
1896 local objdir="${TC_BUILD}/binutils-${arch}-${mode}-sandboxed" | |
1897 | |
1898 ts-modified "$srcdir" "$objdir" | |
1899 return $? | |
1900 } | |
1901 | |
1902 # binutils-sb-make - Make binutils (sandboxed) for x86 | |
1903 binutils-sb-make() { | |
1904 local arch=$1 | |
1905 local mode=$2 | |
1906 StepBanner "BINUTILS-SB" "Make ${arch} ${mode}" | |
1907 local objdir="${TC_BUILD}/binutils-${arch}-${mode}-sandboxed" | |
1908 | |
1909 spushd ${objdir} | |
1910 | |
1911 ts-touch-open "${objdir}" | |
1912 | |
1913 local build_with_srpc=0 | |
1914 if [ ${mode} == "srpc" ]; then | |
1915 build_with_srpc=1 | |
1916 fi | |
1917 | |
1918 RunWithLog binutils.${arch}.sandboxed.make \ | |
1919 env -i PATH="/usr/bin:/bin" \ | |
1920 NACL_SRPC=${build_with_srpc} \ | |
1921 make ${MAKE_OPTS} all-gas all-ld | |
1922 | |
1923 ts-touch-commit "${objdir}" | |
1924 | |
1925 spopd | |
1926 } | |
1927 | |
1928 # binutils-sb-install - Install binutils (sandboxed) for x86 | |
1929 binutils-sb-install() { | |
1930 local arch=$1 | |
1931 local mode=$2 | |
1932 StepBanner "BINUTILS-SB" "Install ${arch} ${mode}" | |
1933 local objdir="${TC_BUILD}/binutils-${arch}-${mode}-sandboxed" | |
1934 | |
1935 spushd ${objdir} | |
1936 | |
1937 RunWithLog binutils.${arch}.${mode}.sandboxed.install \ | |
1938 env -i PATH="/usr/bin:/bin" \ | |
1939 make install-gas install-ld | |
1940 | |
1941 spopd | |
1942 } | |
1943 | |
1944 | |
1945 #+ tools-sb {arch} {mode} - Build all sandboxed tools for arch, mode | |
1946 tools-sb() { | |
1947 local arch=$1 | |
1948 local mode=$2 | |
1949 | |
1950 StepBanner "${arch}" "Sandboxing" | |
1951 StepBanner "----------" "--------------------------------------" | |
1952 llvm-tools-sb ${arch} ${mode} | |
1953 | |
1954 # Use regular toolchain for building binutils. | |
1955 # This is a temporary hack because we can't build binutils with pnacl yet. | |
1956 # TODO(pdox): Make binutils buildable with pnacl. | |
1957 local arches | |
1958 if [[ "${arch}" == "universal" ]] ; then | |
1959 arches="${SBTC_BUILD_WITH_PNACL}" | |
1960 else | |
1961 arches="${arch}" | |
1962 fi | |
1963 for arch in ${arches} ; do | |
1964 if [[ "${arch}" == "arm" ]] ; then | |
1965 StepBanner "BINUTILS-SB" "Skipping ARM build (not yet sandboxed)" | |
1966 else | |
1967 binutils-sb ${arch} ${mode} | |
1968 fi | |
1969 done | |
1970 } | |
1971 | |
1972 | |
1973 #+-------------------------------------------------------------------------- | |
1974 #@ install-translators {srpc/nonsrpc} - Builds and installs sandboxed | |
1975 #@ translator components | |
1976 install-translators() { | |
1977 if [ $# -ne 1 ]; then | |
1978 echo "ERROR: Usage install-translators <srpc/nonsrpc>" | |
1979 exit -1 | |
1980 fi | |
1981 | |
1982 local srpc_kind=$1 | |
1983 check-sb-mode ${srpc_kind} | |
1984 | |
1985 StepBanner "INSTALL SANDBOXED TRANSLATORS (${srpc_kind})" | |
1986 | |
1987 binutils-liberty | |
1988 | |
1989 if ${SBTC_PRODUCTION}; then | |
1990 # Build each architecture separately. | |
1991 for arch in ${SBTC_BUILD_WITH_PNACL} ; do | |
1992 tools-sb ${arch} ${srpc_kind} | |
1993 done | |
1994 else | |
1995 # Using arch `universal` builds the sandboxed tools to a .pexe | |
1996 # which support all targets. This .pexe is then translated to | |
1997 # each architecture specified in ${SBTC_BUILD_WITH_PNACL}. | |
1998 tools-sb universal ${srpc_kind} | |
1999 fi | |
2000 | |
2001 echo "Done" | |
2002 } | |
2003 | |
2004 #+------------------------------------------------------------------------- | |
2005 #@ prune-translator-install - Prunes translator install directories | |
2006 prune-translator-install() { | |
2007 if [ $# -ne 1 ]; then | |
2008 echo "ERROR: Usage prune-translator-install <srpc/nonsrpc>" | |
2009 exit -1 | |
2010 fi | |
2011 | |
2012 local srpc_kind=$1 | |
2013 check-sb-mode ${srpc_kind} | |
2014 | |
2015 StepBanner "PRUNE" "Pruning translator installs (${srpc_kind})" | |
2016 | |
2017 spushd "${PNACL_SB_X8632}/${srpc_kind}" | |
2018 rm -rf include lib nacl share | |
2019 rm -rf bin/llvm-config bin/tblgen | |
2020 spopd | |
2021 | |
2022 spushd "${PNACL_SB_X8664}/${srpc_kind}" | |
2023 rm -rf include lib nacl64 share | |
2024 rm -rf bin/llvm-config bin/tblgen | |
2025 spopd | |
2026 | |
2027 if ! ${SBTC_PRODUCTION}; then | |
2028 spushd "${PNACL_SB_UNIVERSAL}/${srpc_kind}" | |
2029 rm -rf include lib share | |
2030 rm -f bin/llvm-config bin/tblgen | |
2031 # Delete intermediate files generated by the driver | |
2032 rm -f -- bin/llc*---llc.pexe---* | |
2033 spopd | |
2034 fi | |
2035 | |
2036 echo "Done" | |
2037 } | |
2038 | |
2039 ######################################################################### | |
2040 # < NEWLIB-ARM > | |
2041 # < NEWLIB-BITCODE > | |
2042 ######################################################################### | |
2043 | |
2044 #+ newlib-bitcode - Build and install newlib in bitcode. | |
2045 newlib-bitcode() { | |
2046 StepBanner "NEWLIB-BITCODE" | |
2047 | |
2048 if newlib-bitcode-needs-configure; then | |
2049 newlib-bitcode-clean | |
2050 newlib-bitcode-configure | |
2051 else | |
2052 SkipBanner "NEWLIB-BITCODE" "configure" | |
2053 fi | |
2054 | |
2055 if newlib-bitcode-needs-make; then | |
2056 newlib-bitcode-make | |
2057 else | |
2058 SkipBanner "NEWLIB-BITCODE" "make" | |
2059 fi | |
2060 | |
2061 newlib-bitcode-install | |
2062 } | |
2063 | |
2064 #+ newlib-bitcode-clean - Clean bitcode newlib. | |
2065 newlib-bitcode-clean() { | |
2066 StepBanner "NEWLIB-BITCODE" "Clean" | |
2067 rm -rf "${TC_BUILD_NEWLIB_BITCODE}" | |
2068 } | |
2069 | |
2070 newlib-bitcode-needs-configure() { | |
2071 speculative-check "gcc-stage1" && return 0 | |
2072 ts-newer-than "${TC_BUILD_LLVM_GCC1}-${CROSS_TARGET_ARM}" \ | |
2073 "${TC_BUILD_NEWLIB_BITCODE}" && return 0 | |
2074 | |
2075 [ ! -f "${TC_BUILD_NEWLIB_BITCODE}/config.status" ] | |
2076 return #? | |
2077 } | |
2078 | |
2079 #+ newlib-bitcode-configure - Configure bitcode Newlib | |
2080 newlib-bitcode-configure() { | |
2081 StepBanner "NEWLIB-BITCODE" "Configure" | |
2082 newlib-configure-common "${TC_BUILD_NEWLIB_BITCODE}" | |
2083 } | |
2084 | |
2085 newlib-configure-common() { | |
2086 local srcdir="${TC_SRC_NEWLIB}" | |
2087 local objdir="$1" | |
2088 mkdir -p "${objdir}" | |
2089 spushd "${objdir}" | |
2090 | |
2091 RunWithLog newlib.configure \ | |
2092 env -i \ | |
2093 PATH="/usr/bin:/bin" \ | |
2094 "${STD_ENV_FOR_NEWLIB[@]}" \ | |
2095 ${srcdir}/newlib-trunk/configure \ | |
2096 --disable-libgloss \ | |
2097 --disable-multilib \ | |
2098 --prefix="${NEWLIB_INSTALL_DIR}" \ | |
2099 --disable-newlib-supplied-syscalls \ | |
2100 --disable-texinfo \ | |
2101 --target="${REAL_CROSS_TARGET}" | |
2102 spopd | |
2103 } | |
2104 | |
2105 newlib-bitcode-needs-make() { | |
2106 local srcdir="${TC_SRC_NEWLIB}" | |
2107 local objdir="${TC_BUILD_NEWLIB_BITCODE}" | |
2108 | |
2109 ts-modified "$srcdir" "$objdir" | |
2110 return $? | |
2111 } | |
2112 | |
2113 #+ newlib-bitcode-make - Make bitcode Newlib | |
2114 newlib-bitcode-make() { | |
2115 StepBanner "NEWLIB-BITCODE" "Make" | |
2116 newlib-make-common "${TC_BUILD_NEWLIB_BITCODE}" | |
2117 } | |
2118 | |
2119 newlib-make-common() { | |
2120 local srcdir="${TC_SRC_NEWLIB}" | |
2121 local objdir="$1" | |
2122 | |
2123 ts-touch-open "${objdir}" | |
2124 | |
2125 spushd "${objdir}" | |
2126 RunWithLog newlib.make \ | |
2127 env -i PATH="/usr/bin:/bin" \ | |
2128 make \ | |
2129 "${STD_ENV_FOR_NEWLIB[@]}" \ | |
2130 ${MAKE_OPTS} | |
2131 spopd | |
2132 | |
2133 ts-touch-commit "${objdir}" | |
2134 | |
2135 } | |
2136 | |
2137 #+ newlib-bitcde-install - Install Bitcode Newlib | |
2138 newlib-bitcode-install() { | |
2139 StepBanner "NEWLIB-BITCODE" "Install" | |
2140 | |
2141 local objdir="${TC_BUILD_NEWLIB_BITCODE}" | |
2142 | |
2143 spushd "${objdir}" | |
2144 | |
2145 # NOTE: we might be better off not using install, as we are already | |
2146 # doing a bunch of copying of headers and libs further down | |
2147 RunWithLog newlib.install \ | |
2148 env -i PATH="/usr/bin:/bin" \ | |
2149 make \ | |
2150 "${STD_ENV_FOR_NEWLIB[@]}" \ | |
2151 install ${MAKE_OPTS} | |
2152 | |
2153 ########################################################### | |
2154 # -- HACK HACK HACK -- | |
2155 # newlib installs into ${REAL_CROSS_TARGET} | |
2156 # For now, move it back to the old ${CROSS_TARGET_ARM} | |
2157 # where everything expects it to be. | |
2158 rm -rf "${NEWLIB_INSTALL_DIR}/${CROSS_TARGET_ARM}" | |
2159 mv "${NEWLIB_INSTALL_DIR}/${REAL_CROSS_TARGET}" \ | |
2160 "${NEWLIB_INSTALL_DIR}/${CROSS_TARGET_ARM}" | |
2161 ########################################################### | |
2162 | |
2163 StepBanner "NEWLIB-BITCODE" "Extra-install" | |
2164 local sys_include=${INSTALL_DIR}/${CROSS_TARGET_ARM}/include | |
2165 local sys_lib=${INSTALL_DIR}/${CROSS_TARGET_ARM}/lib | |
2166 # NOTE: we provide a new one via extra-sdk | |
2167 rm ${NEWLIB_INSTALL_DIR}/${CROSS_TARGET_ARM}/include/pthread.h | |
2168 | |
2169 cp ${NEWLIB_INSTALL_DIR}/${CROSS_TARGET_ARM}/include/machine/endian.h \ | |
2170 ${sys_include} | |
2171 cp ${NEWLIB_INSTALL_DIR}/${CROSS_TARGET_ARM}/include/sys/param.h \ | |
2172 ${sys_include} | |
2173 cp ${NEWLIB_INSTALL_DIR}/${CROSS_TARGET_ARM}/include/newlib.h \ | |
2174 ${sys_include} | |
2175 | |
2176 # NOTE: we provide our own pthread.h via extra-sdk | |
2177 StepBanner "NEWLIB-BITCODE" "Removing old pthreads headers" | |
2178 rm -f "${NEWLIB_INSTALL_DIR}/${CROSS_TARGET_ARM}/usr/include/pthread.h" | |
2179 rm -f "${sys_include}/pthread.h" | |
2180 | |
2181 StepBanner "NEWLIB-BITCODE" "copying libraries" | |
2182 local destdir="${PNACL_BITCODE_ROOT}" | |
2183 # We only install libc/libg/libm | |
2184 mkdir -p "${destdir}" | |
2185 cp ${objdir}/${REAL_CROSS_TARGET}/newlib/lib[cgm].a "${destdir}" | |
2186 | |
2187 spopd | |
2188 } | |
2189 | |
2190 | |
2191 ######################################################################### | |
2192 # < EXTRASDK > | |
2193 ######################################################################### | |
2194 #+ extrasdk-clean - Clean extra-sdk stuff | |
2195 | |
2196 extrasdk-clean() { | |
2197 StepBanner "EXTRASDK-BITCODE" "Clean" | |
2198 rm -rf "${TC_BUILD_EXTRASDK_BITCODE}" | |
2199 | |
2200 StepBanner "EXTRASDK-BITCODE" "Clean bitcode lib" | |
2201 # TODO(robertm): consider having a dedicated dir for this so can | |
2202 # delete this wholesale | |
2203 # Do not clean libc and libstdc++ but everything else | |
2204 rm -f "${PNACL_BITCODE_ROOT}"/*google*.a | |
2205 rm -f "${PNACL_BITCODE_ROOT}"/*nacl* | |
2206 rm -f "${PNACL_BITCODE_ROOT}"/libpthread.a | |
2207 rm -f "${PNACL_BITCODE_ROOT}"/libsrpc.a | |
2208 rm -f "${PNACL_BITCODE_ROOT}"/libnpapi.a | |
2209 rm -f "${PNACL_BITCODE_ROOT}"/libppapi.a | |
2210 rm -f "${PNACL_BITCODE_ROOT}"/libnosys.a | |
2211 rm -f "${PNACL_BITCODE_ROOT}"/libav.a | |
2212 rm -f "${PNACL_BITCODE_ROOT}"/libgio.a | |
2213 | |
2214 StepBanner "EXTRASDK-BITCODE" "Clean arm libs" | |
2215 # Do not clean libgcc but everything else | |
2216 rm -f "${PNACL_ARM_ROOT}"/*crt* | |
2217 | |
2218 StepBanner "EXTRASDK-BITCODE" "Clean x86-32 libs" | |
2219 # Do not clean libgcc but everything else | |
2220 rm -f "${PNACL_X8632_ROOT}"/*crt* | |
2221 | |
2222 StepBanner "EXTRASDK-BITCODE" "Clean x86-64 libs" | |
2223 # Do not clean libgcc but everything else | |
2224 rm -f "${PNACL_X8664_ROOT}"/*crt* | |
2225 | |
2226 # clean scons obj dirs | |
2227 rm -rf scons-out/nacl_extra_sdk-*-pnacl | |
2228 } | |
2229 | |
2230 #+ extrasdk-make-install - build and install all extra sdk components | |
2231 extrasdk-make-install() { | |
2232 StepBanner "EXTRASDK" | |
2233 local headerdir="${NEWLIB_INSTALL_DIR}/${CROSS_TARGET_ARM}/include" | |
2234 | |
2235 StepBanner "EXTRASDK" "Make/Install headers" | |
2236 RunWithLog "extra_sdk.headers" \ | |
2237 ./scons MODE=nacl_extra_sdk \ | |
2238 extra_sdk_lib_destination="${PNACL_BITCODE_ROOT}" \ | |
2239 extra_sdk_include_destination="${headerdir}" \ | |
2240 bitcode=1 \ | |
2241 platform=arm \ | |
2242 sdl=none \ | |
2243 naclsdk_validate=0 \ | |
2244 extra_sdk_update_header | |
2245 | |
2246 StepBanner "EXTRASDK" "Make/Install bitcode libpthread" | |
2247 RunWithLog "extra_sdk.bitcode_libpthread" \ | |
2248 ./scons MODE=nacl_extra_sdk -j 8\ | |
2249 extra_sdk_lib_destination="${PNACL_BITCODE_ROOT}" \ | |
2250 extra_sdk_include_destination="${headerdir}" \ | |
2251 bitcode=1 \ | |
2252 platform=arm \ | |
2253 sdl=none \ | |
2254 naclsdk_validate=0 \ | |
2255 install_libpthread | |
2256 | |
2257 StepBanner "EXTRASDK" "Make/Install bitcode components" | |
2258 RunWithLog "extra_sdk.bitcode_components" \ | |
2259 ./scons MODE=nacl_extra_sdk -j 8\ | |
2260 extra_sdk_lib_destination="${PNACL_BITCODE_ROOT}" \ | |
2261 extra_sdk_include_destination="${headerdir}" \ | |
2262 disable_nosys_linker_warnings=1 \ | |
2263 bitcode=1 \ | |
2264 platform=arm \ | |
2265 sdl=none \ | |
2266 naclsdk_validate=0 \ | |
2267 --verbose \ | |
2268 extra_sdk_libs | |
2269 | |
2270 StepBanner "EXTRASDK" "Make/Install arm components" | |
2271 RunWithLog "extra_sdk.arm_components" \ | |
2272 ./scons MODE=nacl_extra_sdk \ | |
2273 extra_sdk_lib_destination="${PNACL_ARM_ROOT}" \ | |
2274 extra_sdk_include_destination="${headerdir}" \ | |
2275 bitcode=1 \ | |
2276 platform=arm \ | |
2277 sdl=none \ | |
2278 naclsdk_validate=0 \ | |
2279 --verbose \ | |
2280 extra_sdk_libs_platform | |
2281 | |
2282 StepBanner "EXTRASDK" "Make/Install x86-32 components" | |
2283 RunWithLog "extra_sdk.libs_x8632" \ | |
2284 ./scons MODE=nacl_extra_sdk \ | |
2285 extra_sdk_lib_destination="${PNACL_X8632_ROOT}" \ | |
2286 extra_sdk_include_destination="${headerdir}" \ | |
2287 bitcode=1 \ | |
2288 platform=x86-32 \ | |
2289 sdl=none \ | |
2290 naclsdk_validate=0 \ | |
2291 --verbose \ | |
2292 extra_sdk_libs_platform | |
2293 | |
2294 StepBanner "EXTRASDK" "Make/Install x86-64 components" | |
2295 RunWithLog "extra_sdk.libs_x8664" \ | |
2296 ./scons MODE=nacl_extra_sdk \ | |
2297 extra_sdk_lib_destination="${PNACL_X8664_ROOT}" \ | |
2298 extra_sdk_include_destination="${headerdir}" \ | |
2299 bitcode=1 \ | |
2300 platform=x86-64 \ | |
2301 sdl=none \ | |
2302 naclsdk_validate=0 \ | |
2303 --verbose \ | |
2304 extra_sdk_libs_platform | |
2305 } | |
2306 | |
2307 newlib-nacl-headers-clean() { | |
2308 # Clean the include directory and revert it to its pure state | |
2309 if [ -d "${TC_SRC_NEWLIB}" ]; then | |
2310 rm -rf "${NEWLIB_INCLUDE_DIR}" | |
2311 # If the script is interrupted right here, | |
2312 # then NEWLIB_INCLUDE_DIR will not exist, and the repository | |
2313 # will be in a bad state. This will be fixed during the next | |
2314 # invocation by newlib-nacl-headers. | |
2315 | |
2316 # We jump into the parent directory and use a relative path so that | |
2317 # hg does not get confused by pathnames which contain a symlink. | |
2318 spushd "$(dirname "${NEWLIB_INCLUDE_DIR}")" | |
2319 RunWithLog "newlib-freshen" \ | |
2320 hg-revert "$(basename "${NEWLIB_INCLUDE_DIR}")" | |
2321 spopd | |
2322 fi | |
2323 } | |
2324 | |
2325 #+ newlib-nacl-headers - Install NaCl headers to newlib | |
2326 newlib-nacl-headers() { | |
2327 StepBanner "newlib-nacl-headers" "Adding nacl headers to newlib" | |
2328 | |
2329 assert-dir "${TC_SRC_NEWLIB}" "Newlib is not checked out" | |
2330 | |
2331 # Make sure the headers directory has no local changes | |
2332 newlib-nacl-headers-check | |
2333 newlib-nacl-headers-clean | |
2334 | |
2335 # Install the headers | |
2336 "${EXPORT_HEADER_SCRIPT}" \ | |
2337 "${NACL_SYS_HEADERS}" \ | |
2338 "${NEWLIB_INCLUDE_DIR}" | |
2339 | |
2340 # Record the header install time | |
2341 ts-touch "${NACL_SYS_TS}" | |
2342 } | |
2343 | |
2344 #+ newlib-nacl-headers-check - Make sure the newlib nacl headers haven't | |
2345 #+ been modified since the last install. | |
2346 newlib-nacl-headers-check() { | |
2347 # The condition where NEWLIB_INCLUDE_DIR does not exist may have been | |
2348 # caused by an incomplete call to newlib-nacl-headers-clean(). | |
2349 # Let it pass this check so that the clean will be able to finish. | |
2350 # See the comment in newlib-nacl-headers-clean() | |
2351 if ! [ -d "${TC_SRC_NEWLIB}" ] || | |
2352 ! [ -d "${NEWLIB_INCLUDE_DIR}" ]; then | |
2353 return 0 | |
2354 fi | |
2355 | |
2356 # Already clean? | |
2357 if ! hg-has-changes "${NEWLIB_INCLUDE_DIR}" && | |
2358 ! hg-has-untracked "${NEWLIB_INCLUDE_DIR}" ; then | |
2359 return 0 | |
2360 fi | |
2361 | |
2362 if ts-dir-changed "${NACL_SYS_TS}" "${NEWLIB_INCLUDE_DIR}"; then | |
2363 echo "" | |
2364 echo "*******************************************************************" | |
2365 echo "* ERROR *" | |
2366 echo "* The NewLib include directory has local modifications *" | |
2367 echo "*******************************************************************" | |
2368 echo "* The NewLib include directory should not be modified directly. *" | |
2369 echo "* Instead, modifications should be done from: *" | |
2370 echo "* src/trusted/service_runtime/include *" | |
2371 echo "* *" | |
2372 echo "* To destroy the local changes to newlib, run: *" | |
2373 echo "* tools/llvm/utman.sh newlib-nacl-headers-clean *" | |
2374 echo "*******************************************************************" | |
2375 echo "" | |
2376 if ${UTMAN_BUILDBOT} ; then | |
2377 newlib-nacl-headers-clean | |
2378 else | |
2379 exit -1 | |
2380 fi | |
2381 fi | |
2382 } | |
2383 | |
2384 #+------------------------------------------------------------------------- | |
2385 #+ driver - Install driver scripts. | |
2386 driver() { | |
2387 StepBanner "DRIVER" | |
2388 # need to prep the dir just in case.. | |
2389 prep-install-dir | |
2390 # otherwise linker-install will stomp it. | |
2391 linker-install | |
2392 driver-install | |
2393 driver-intrinsics | |
2394 } | |
2395 | |
2396 driver-intrinsics() { | |
2397 StepBanner "DRIVER" "Install LLVM intrinsics" | |
2398 "${INSTALL_DIR}"/bin/llvm-as \ | |
2399 tools/llvm/llvm-intrinsics.ll \ | |
2400 -o "${INSTALL_ROOT}/llvm-intrinsics.bc" | |
2401 } | |
2402 | |
2403 # Just in case we're calling this manually | |
2404 prep-install-dir() { | |
2405 mkdir -p ${INSTALL_DIR} | |
2406 } | |
2407 | |
2408 # We need to adjust the start address and aligment of nacl arm modules | |
2409 linker-install() { | |
2410 StepBanner "DRIVER" "Installing untrusted ld scripts" | |
2411 mkdir -p "${LDSCRIPTS_DIR}" | |
2412 cp tools/llvm/ld_script_arm_untrusted "${LDSCRIPTS_DIR}" | |
2413 cp tools/llvm/ld_script_x8632_untrusted "${LDSCRIPTS_DIR}" | |
2414 cp tools/llvm/ld_script_x8664_untrusted "${LDSCRIPTS_DIR}" | |
2415 } | |
2416 | |
2417 # The driver is a simple python script which changes its behavior | |
2418 # depending on the name it is invoked as. | |
2419 driver-install() { | |
2420 StepBanner "DRIVER" "Installing driver adaptors to ${INSTALL_DIR}" | |
2421 # TODO(robertm): move the driver to their own dir | |
2422 # rm -rf ${INSTALL_DIR} | |
2423 mkdir -p "${INSTALL_BIN}" | |
2424 rm -f "${INSTALL_BIN}/pnacl-*" | |
2425 cp tools/llvm/driver.py "${INSTALL_BIN}" | |
2426 for s in gcc g++ as arm-as i686-as x86_64-as \ | |
2427 bclink opt dis ld strip translate illegal nop \ | |
2428 ar nm ranlib pexecheck ; do | |
2429 local t="pnacl-$s" | |
2430 ln -fs driver.py "${INSTALL_BIN}/$t" | |
2431 done | |
2432 } | |
2433 | |
2434 ###################################################################### | |
2435 ###################################################################### | |
2436 # | |
2437 # HELPER FUNCTIONS | |
2438 # | |
2439 # (These should not generally be used directly) | |
2440 # | |
2441 ###################################################################### | |
2442 ###################################################################### | |
2443 | |
2444 RecordRevisionInfo() { | |
2445 mkdir -p "${INSTALL_ROOT}" | |
2446 svn info > "${INSTALL_ROOT}/REV" | |
2447 } | |
2448 | |
2449 | |
2450 #+ organize-native-code - Saves the native code libraries for each architecture | |
2451 #+ into the toolchain/pnacl-untrusted/<arch> directories
. | |
2452 organize-native-code() { | |
2453 StepBanner "PNACL" "Organizing Native Code" | |
2454 | |
2455 readonly arm_src=${INSTALL_ROOT} | |
2456 readonly arm_llvm_gcc=${INSTALL_DIR} | |
2457 | |
2458 StepBanner "PNaCl" "arm native code: ${PNACL_ARM_ROOT}" | |
2459 mkdir -p ${PNACL_ARM_ROOT} | |
2460 local startup_dir=${arm_llvm_gcc}/lib/gcc/arm-none-linux-gnueabi/${GCC_VER} | |
2461 cp -f ${startup_dir}/libgcc.a ${PNACL_ARM_ROOT} | |
2462 cp -f ${startup_dir}/libgcc_eh.a ${PNACL_ARM_ROOT} | |
2463 DebugRun ls -l ${PNACL_ARM_ROOT} | |
2464 | |
2465 StepBanner "PNaCl" "x86-32 native code: ${PNACL_X8632_ROOT}" | |
2466 mkdir -p ${PNACL_X8632_ROOT} | |
2467 local startup_dir=${arm_llvm_gcc}/lib/gcc/${CROSS_TARGET_X86_32}/${GCC_VER} | |
2468 cp -f ${startup_dir}/libgcc.a ${PNACL_X8632_ROOT} | |
2469 cp -f ${startup_dir}/libgcc_eh.a ${PNACL_X8632_ROOT} | |
2470 DebugRun ls -l ${PNACL_X8632_ROOT} | |
2471 | |
2472 StepBanner "PNaCl" "x86-64 native code: ${PNACL_X8664_ROOT}" | |
2473 mkdir -p ${PNACL_X8664_ROOT} | |
2474 local startup_dir=${arm_llvm_gcc}/lib/gcc/${CROSS_TARGET_X86_64}/${GCC_VER} | |
2475 cp -f ${startup_dir}/libgcc.a ${PNACL_X8664_ROOT} | |
2476 cp -f ${startup_dir}/libgcc_eh.a ${PNACL_X8664_ROOT} | |
2477 DebugRun ls -l ${PNACL_X8664_ROOT} | |
2478 } | |
2479 | |
2480 ###################################################################### | |
2481 ###################################################################### | |
2482 # < VERIFY > | |
2483 ###################################################################### | |
2484 ###################################################################### | |
2485 | |
2486 readonly LLVM_DIS=${INSTALL_DIR}/bin/llvm-dis | |
2487 readonly LLVM_BCANALYZER=${INSTALL_DIR}/bin/llvm-bcanalyzer | |
2488 readonly LLVM_OPT=${INSTALL_DIR}/bin/opt | |
2489 readonly LLVM_AR=${CROSS_TARGET_AR} | |
2490 | |
2491 # Note: we could replace this with a modified version of tools/elf_checker.py | |
2492 # if we do not want to depend on binutils | |
2493 readonly NACL_OBJDUMP=${INSTALL_DIR}/bin/arm-pc-nacl-objdump | |
2494 | |
2495 # Usage: VerifyArchive <checker> <pattern> <filename> | |
2496 ExtractAndCheck() { | |
2497 local checker="$1" | |
2498 local pattern="$2" | |
2499 local archive="$3" | |
2500 local tmp="/tmp/ar-verify-${RANDOM}" | |
2501 rm -rf ${tmp} | |
2502 mkdir -p ${tmp} | |
2503 cp "${archive}" "${tmp}" | |
2504 spushd ${tmp} | |
2505 ${LLVM_AR} x $(basename ${archive}) | |
2506 # extract all the files | |
2507 local count=0 | |
2508 for i in ${pattern} ; do | |
2509 if [ ! -e "$i" ]; then | |
2510 # we may also see the unexpanded pattern here if there is no match | |
2511 continue | |
2512 fi | |
2513 count=$((count+1)) | |
2514 ${checker} $i | |
2515 done | |
2516 if [ "${count}" = "0" ] ; then | |
2517 echo "FAIL - archive empty or wrong contents: ${archive}" | |
2518 ls -l "${tmp}" | |
2519 exit -1 | |
2520 fi | |
2521 echo "PASS (${count} files)" | |
2522 rm -rf "${tmp}" | |
2523 spopd | |
2524 } | |
2525 | |
2526 # Usage: VerifyLinkerScript <filename> | |
2527 VerifyLinkerScript() { | |
2528 local archive="$1" | |
2529 # Use cpp to strip the C-style comments. | |
2530 ${PNACL_GCC} -E -xc "${archive}" | awk -v archive="$(basename ${archive})" ' | |
2531 BEGIN { status = 0 } | |
2532 NF == 0 || $1 == "#" { next } | |
2533 $1 == "INPUT" && $2 == "(" && $NF == ")" { next } | |
2534 { | |
2535 print "FAIL - unexpected linker script(?) contents:", archive | |
2536 status = 1 | |
2537 exit(status) | |
2538 } | |
2539 END { if (status == 0) print "PASS (trivial linker script)" } | |
2540 ' || exit -1 | |
2541 } | |
2542 | |
2543 # Usage: VerifyArchive <checker> <pattern> <filename> | |
2544 VerifyArchive() { | |
2545 local checker="$1" | |
2546 local pattern="$2" | |
2547 local archive="$3" | |
2548 echo -n "verify $(basename "${archive}"): " | |
2549 type="$(file --brief --mime-type "${archive}")" | |
2550 case "$type" in | |
2551 application/x-archive) | |
2552 ExtractAndCheck "$checker" "$pattern" "$archive" | |
2553 ;; | |
2554 text/x-c) | |
2555 # A linker script with C comments looks like C to "file". | |
2556 VerifyLinkerScript "$archive" | |
2557 ;; | |
2558 *) | |
2559 echo "FAIL - unknown file type ($type): ${archive}" | |
2560 exit -1 | |
2561 ;; | |
2562 esac | |
2563 } | |
2564 | |
2565 # | |
2566 # verify-object-llvm <obj> | |
2567 # | |
2568 # Verifies that a given .o file is bitcode and free of ASMSs | |
2569 verify-object-llvm() { | |
2570 local t=$(${LLVM_DIS} $1 -o -) | |
2571 | |
2572 if grep asm <<<$t ; then | |
2573 echo | |
2574 echo "ERROR asm in $1" | |
2575 echo | |
2576 exit -1 | |
2577 fi | |
2578 } | |
2579 | |
2580 | |
2581 | |
2582 check-elf-abi() { | |
2583 local arch_info=$(${NACL_OBJDUMP} -f $1) | |
2584 if ! grep -q $2 <<< ${arch_info} ; then | |
2585 echo "ERROR $1 - bad file format: $2 vs ${arch_info}\n" | |
2586 echo ${arch_info} | |
2587 exit -1 | |
2588 fi | |
2589 } | |
2590 | |
2591 | |
2592 # verify-object-arm <obj> | |
2593 # | |
2594 # Ensure that the ARCH properties are what we expect, this is a little | |
2595 # fragile and needs to be updated when tools change | |
2596 verify-object-arm() { | |
2597 check-elf-abi $1 "elf32-littlearm-nacl" | |
2598 arch_info=$("${PNACL_READELF}" -A $1) | |
2599 #TODO(robertm): some refactoring and cleanup needed | |
2600 if ! grep -q "Tag_FP_arch: VFPv2" <<< ${arch_info} ; then | |
2601 echo "ERROR $1 - bad Tag_FP_arch\n" | |
2602 #TODO(robertm): figure out what the right thing to do is here, c.f. | |
2603 # http://code.google.com/p/nativeclient/issues/detail?id=966 | |
2604 "${PNACL_READELF}" -A $1 | grep Tag_FP_arch | |
2605 exit -1 | |
2606 fi | |
2607 | |
2608 if ! grep -q "Tag_CPU_arch: v7" <<< ${arch_info} ; then | |
2609 echo "FAIL bad $1 Tag_CPU_arch\n" | |
2610 "${PNACL_READELF}" -A $1 | grep Tag_CPU_arch | |
2611 exit -1 | |
2612 fi | |
2613 } | |
2614 | |
2615 | |
2616 # verify-object-x86-32 <obj> | |
2617 # | |
2618 verify-object-x86-32() { | |
2619 check-elf-abi $1 "elf32-nacl" | |
2620 } | |
2621 | |
2622 # verify-object-x86-64 <obj> | |
2623 # | |
2624 verify-object-x86-64() { | |
2625 check-elf-abi $1 "elf64-nacl" | |
2626 } | |
2627 | |
2628 | |
2629 # | |
2630 # verify-archive-llvm <archive> | |
2631 # Verifies that a given archive is bitcode and free of ASMSs | |
2632 # | |
2633 verify-archive-llvm() { | |
2634 if ${LLVM_BCANALYZER} "$1" 2> /dev/null ; then | |
2635 # This fires only when we build in single-bitcode-lib mode | |
2636 echo -n "verify $(basename "$1"): " | |
2637 verify-object-llvm "$1" | |
2638 echo "PASS (single-bitcode)" | |
2639 else | |
2640 # Currently all the files are .o in the llvm archives. | |
2641 # Eventually more and more should be .bc. | |
2642 VerifyArchive verify-object-llvm '*.bc *.o' "$@" | |
2643 fi | |
2644 } | |
2645 | |
2646 # | |
2647 # verify-archive-arm <archive> | |
2648 # Verifies that a given archive is a proper arm achive | |
2649 # | |
2650 verify-archive-arm() { | |
2651 VerifyArchive verify-object-arm '*.o' "$@" | |
2652 } | |
2653 | |
2654 # | |
2655 # verify-archive-x86-32 <archive> | |
2656 # Verifies that a given archive is a proper x86-32 achive | |
2657 # | |
2658 verify-archive-x86-32() { | |
2659 VerifyArchive verify-object-x86-32 '*.o' "$@" | |
2660 } | |
2661 | |
2662 # | |
2663 # verify-archive-x86-64 <archive> | |
2664 # Verifies that a given archive is a proper x86-64 achive | |
2665 # | |
2666 verify-archive-x86-64() { | |
2667 VerifyArchive verify-object-x86-64 '*.o' "$@" | |
2668 } | |
2669 #@------------------------------------------------------------------------- | |
2670 #+ verify - Verifies that toolchain/pnacl-untrusted ELF files | |
2671 #+ are of the correct architecture. | |
2672 verify() { | |
2673 StepBanner "VERIFY" | |
2674 | |
2675 if ${UTMAN_BUILD_ARM}; then | |
2676 SubBanner "VERIFY: ${PNACL_ARM_ROOT}" | |
2677 for i in ${PNACL_ARM_ROOT}/*.o ; do | |
2678 verify-object-arm "$i" | |
2679 done | |
2680 | |
2681 for i in ${PNACL_ARM_ROOT}/*.a ; do | |
2682 verify-archive-arm "$i" | |
2683 done | |
2684 fi | |
2685 | |
2686 SubBanner "VERIFY: ${PNACL_X8632_ROOT}" | |
2687 for i in ${PNACL_X8632_ROOT}/*.o ; do | |
2688 verify-object-x86-32 "$i" | |
2689 done | |
2690 | |
2691 for i in ${PNACL_X8632_ROOT}/*.a ; do | |
2692 verify-archive-x86-32 "$i" | |
2693 done | |
2694 | |
2695 SubBanner "VERIFY: ${PNACL_X8664_ROOT}" | |
2696 for i in ${PNACL_X8664_ROOT}/*.o ; do | |
2697 verify-object-x86-64 "$i" | |
2698 done | |
2699 | |
2700 for i in ${PNACL_X8664_ROOT}/*.a ; do | |
2701 verify-archive-x86-64 "$i" | |
2702 done | |
2703 | |
2704 SubBanner "VERIFY: ${PNACL_BITCODE_ROOT}" | |
2705 for i in ${PNACL_BITCODE_ROOT}/*.a ; do | |
2706 verify-archive-llvm "$i" | |
2707 done | |
2708 | |
2709 # we currently do not expect any .o files in this directory | |
2710 #for i in ${PNACL_BITCODE_ROOT}/*.o ; do | |
2711 #done | |
2712 } | |
2713 | |
2714 #@ verify-triple-build <arch> - Verify that the sandboxed translator produces | |
2715 #@ an identical translation of itself (llc.pexe) | |
2716 #@ as the unsandboxed translator. | |
2717 verify-triple-build() { | |
2718 if [ $# -eq 0 ]; then | |
2719 local arch | |
2720 for arch in ${SBTC_BUILD_WITH_PNACL} ; do | |
2721 verify-triple-build ${arch} | |
2722 done | |
2723 return | |
2724 fi | |
2725 | |
2726 local arch=${1/-/} # Get rid of dashes | |
2727 local mode=srpc | |
2728 | |
2729 check-sb-arch ${arch} | |
2730 check-sb-mode ${mode} | |
2731 | |
2732 StepBanner "VERIFY" "Verifying triple build for ${arch}" | |
2733 | |
2734 local archdir="${PNACL_SB_ROOT}/${arch}/${mode}" | |
2735 local archllc="${archdir}/bin/llc" | |
2736 local pexe | |
2737 | |
2738 if ${SBTC_PRODUCTION} ; then | |
2739 pexe="${archdir}/bin/llc.pexe" | |
2740 else | |
2741 pexe="${PNACL_SB_ROOT}/universal/${mode}/bin/llc.pexe" | |
2742 fi | |
2743 assert-file "${archllc}" "sandboxed llc for ${arch} does not exist" | |
2744 assert-file "${pexe}" "llc.pexe does not exist" | |
2745 | |
2746 local flags="--pnacl-sb --pnacl-driver-verbose" | |
2747 if [ ${mode} == "srpc" ] ; then | |
2748 flags+=" --pnacl-driver-set-SRPC=1" | |
2749 else | |
2750 flags+=" --pnacl-driver-set-SRPC=0" | |
2751 fi | |
2752 | |
2753 if [ ${arch} == "arm" ] ; then | |
2754 # Use emulator if we are not on ARM | |
2755 local hostarch=$(uname -m) | |
2756 if ! [[ "${hostarch}" =~ arm ]]; then | |
2757 flags+=" --pnacl-use-emulator" | |
2758 fi | |
2759 fi | |
2760 | |
2761 local objdir="${TC_BUILD}/triple-build" | |
2762 local newllc="${objdir}/llc.${arch}.rebuild.nexe" | |
2763 mkdir -p "${objdir}" | |
2764 | |
2765 StepBanner "VERIFY" "Translating llc.pexe to ${arch} using sandboxed tools" | |
2766 RunWithLog "verify.triple.build" \ | |
2767 "${PNACL_TRANSLATE}" ${flags} -arch ${arch} "${pexe}" -o "${newllc}" | |
2768 | |
2769 if ! cmp --silent "${archllc}" "${newllc}" ; then | |
2770 Banner "TRIPLE BUILD VERIFY FAILED" | |
2771 echo "Expected these files to be identical, but they are not:" | |
2772 echo " ${archllc}" | |
2773 echo " ${newllc}" | |
2774 exit -1 | |
2775 fi | |
2776 StepBanner "VERIFY" "Verified ${arch} OK" | |
2777 } | |
2778 ###################################################################### | 35 ###################################################################### |
2779 ###################################################################### | 36 ###################################################################### |
2780 # | 37 # |
2781 # < TESTING > | 38 # < TESTING > |
2782 # | 39 # |
2783 ###################################################################### | 40 ###################################################################### |
2784 ###################################################################### | 41 ###################################################################### |
2785 | 42 |
2786 # TODO(robertm): figure out what to do about concurrency in debug mode. | 43 # TODO(robertm): figure out what to do about concurrency in debug mode. |
2787 # Perhaps it is fine just tweaking that via UTMAN_CONCURRENCY. | 44 # Perhaps it is fine just tweaking that via UTMAN_CONCURRENCY. |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3015 ./run_all.sh CleanBenchmarks "$@" | 272 ./run_all.sh CleanBenchmarks "$@" |
3016 ./run_all.sh PopulateFromSpecHarness ${official} "$@" | 273 ./run_all.sh PopulateFromSpecHarness ${official} "$@" |
3017 ./run_all.sh TimedBuildAndRunBenchmarks ${setup} "$@" | 274 ./run_all.sh TimedBuildAndRunBenchmarks ${setup} "$@" |
3018 CollectTimingInfo $(pwd) ${result_file} ${setup} | 275 CollectTimingInfo $(pwd) ${result_file} ${setup} |
3019 spopd | 276 spopd |
3020 } | 277 } |
3021 | 278 |
3022 | 279 |
3023 #@ test-bot-base - tests that must pass on the bots to validate a TC | 280 #@ test-bot-base - tests that must pass on the bots to validate a TC |
3024 test-bot-base() { | 281 test-bot-base() { |
| 282 # TODO(robertm): this is missing adhoc tests. |
3025 test-all | 283 test-all |
3026 } | 284 } |
3027 | 285 |
3028 | 286 |
3029 ###################################################################### | |
3030 ###################################################################### | |
3031 # | |
3032 # UTILITIES | |
3033 # | |
3034 ###################################################################### | |
3035 ###################################################################### | |
3036 | |
3037 #@------------------------------------------------------------------------- | |
3038 #@ show-config | |
3039 show-config() { | |
3040 Banner "Config Settings:" | |
3041 echo "UTMAN_BUILDBOT: ${UTMAN_BUILDBOT}" | |
3042 echo "UTMAN_CONCURRENCY: ${UTMAN_CONCURRENCY}" | |
3043 echo "UTMAN_DEBUG: ${UTMAN_DEBUG}" | |
3044 | |
3045 Banner "Your Environment:" | |
3046 env | grep UTMAN | |
3047 } | |
3048 | |
3049 #@ help - Usage information. | 287 #@ help - Usage information. |
3050 help() { | 288 help() { |
3051 Usage | 289 Usage |
3052 } | 290 } |
3053 | 291 |
3054 #@ help-full - Usage information including internal functions. | 292 #@ help-full - Usage information including internal functions. |
3055 help-full() { | 293 help-full() { |
3056 Usage2 | 294 Usage2 |
3057 } | 295 } |
3058 | 296 |
3059 has-trusted-toolchain() { | |
3060 if [ -f toolchain/linux_arm-trusted/ld_script_arm_trusted ]; then | |
3061 return 0 | |
3062 else | |
3063 return 1 | |
3064 fi | |
3065 } | |
3066 | |
3067 check-for-trusted() { | |
3068 if ! ${UTMAN_BUILD_ARM} ; then | |
3069 return | |
3070 fi | |
3071 | |
3072 if ! has-trusted-toolchain; then | |
3073 echo '*******************************************************************' | |
3074 echo '* The ARM trusted toolchain does not appear to be installed yet *' | |
3075 echo '* It is needed to run ARM tests. *' | |
3076 echo '* *' | |
3077 echo '* To download and install the trusted toolchain, run: *' | |
3078 echo '* *' | |
3079 echo '* $ tools/llvm/utman.sh download-trusted *' | |
3080 echo '* *' | |
3081 echo '* To compile the trusted toolchain, use: *' | |
3082 echo '* *' | |
3083 echo '* $ tools/llvm/trusted-toolchain-creator.sh trusted_sdk *' | |
3084 echo '* (warning: this takes a while) *' | |
3085 echo '*******************************************************************' | |
3086 | |
3087 # If building on the bots, do not continue since it needs to run ARM tests. | |
3088 if ${UTMAN_BUILDBOT} ; then | |
3089 echo "Building on bots --> need ARM trusted toolchain to run tests!" | |
3090 exit -1 | |
3091 elif trusted-tc-confirm ; then | |
3092 echo "Continuing without ARM trusted toolchain" | |
3093 UTMAN_BUILD_ARM=false | |
3094 else | |
3095 echo "Okay, stopping." | |
3096 exit -1 | |
3097 fi | |
3098 fi | |
3099 } | |
3100 | |
3101 trusted-tc-confirm() { | |
3102 echo | |
3103 echo "Do you wish to continue without the ARM trusted TC (skip ARM testing)?" | |
3104 echo "" | |
3105 confirm-yes "Continue" | |
3106 return $? | |
3107 } | |
3108 | |
3109 DebugRun() { | |
3110 if ${UTMAN_DEBUG} || ${UTMAN_BUILDBOT}; then | |
3111 "$@" | |
3112 fi | |
3113 } | |
3114 | |
3115 ###################################################################### | |
3116 ###################################################################### | |
3117 # | |
3118 # < TIME STAMPING > | |
3119 # | |
3120 ###################################################################### | |
3121 ###################################################################### | |
3122 | |
3123 ts-dir-changed() { | |
3124 local tsfile="$1" | |
3125 local dir="$2" | |
3126 | |
3127 if [ -f "${tsfile}" ]; then | |
3128 local MODIFIED=$(find "${dir}" -newer "${tsfile}") | |
3129 [ ${#MODIFIED} -gt 0 ] | |
3130 ret=$? | |
3131 else | |
3132 true | |
3133 ret=$? | |
3134 fi | |
3135 return $ret | |
3136 } | |
3137 | |
3138 # Check if the source for a given build has been modified | |
3139 ts-modified() { | |
3140 local srcdir="$1" | |
3141 local objdir="$2" | |
3142 local tsfile="${objdir}/${TIMESTAMP_FILENAME}" | |
3143 | |
3144 ts-dir-changed "${tsfile}" "${srcdir}" | |
3145 return $? | |
3146 } | |
3147 | |
3148 ts-touch() { | |
3149 local tsfile="$1" | |
3150 touch "${tsfile}" | |
3151 } | |
3152 | |
3153 # Record the time when make begins, but don't yet | |
3154 # write that to the timestamp file. | |
3155 # (Just in case make fails) | |
3156 | |
3157 ts-touch-open() { | |
3158 local objdir="$1" | |
3159 local tsfile="${objdir}/${TIMESTAMP_FILENAME}" | |
3160 local tsfile_open="${objdir}/${TIMESTAMP_FILENAME}_OPEN" | |
3161 | |
3162 rm -f "${tsfile}" | |
3163 touch "${tsfile_open}" | |
3164 } | |
3165 | |
3166 | |
3167 # Write the timestamp. (i.e. make has succeeded) | |
3168 | |
3169 ts-touch-commit() { | |
3170 local objdir="$1" | |
3171 local tsfile="${objdir}/${TIMESTAMP_FILENAME}" | |
3172 local tsfile_open="${objdir}/${TIMESTAMP_FILENAME}_OPEN" | |
3173 | |
3174 mv -f "${tsfile_open}" "${tsfile}" | |
3175 } | |
3176 | |
3177 | |
3178 # ts-newer-than dirA dirB | |
3179 # Compare the make timestamps in both object directories. | |
3180 # returns true (0) if dirA is newer than dirB | |
3181 # returns false (1) otherwise. | |
3182 # | |
3183 # This functions errs on the side of returning 0, since | |
3184 # that forces a rebuild anyway. | |
3185 | |
3186 ts-newer-than() { | |
3187 local objdir1="$1" | |
3188 local objdir2="$2" | |
3189 | |
3190 local tsfile1="${objdir1}/${TIMESTAMP_FILENAME}" | |
3191 local tsfile2="${objdir2}/${TIMESTAMP_FILENAME}" | |
3192 | |
3193 if [ ! -d "${objdir1}" ]; then return 0; fi | |
3194 if [ ! -d "${objdir2}" ]; then return 0; fi | |
3195 | |
3196 if [ ! -f "${tsfile1}" ]; then return 0; fi | |
3197 if [ ! -f "${tsfile2}" ]; then return 0; fi | |
3198 | |
3199 local MODIFIED=$(find "${tsfile1}" -newer "${tsfile2}") | |
3200 if [ ${#MODIFIED} -gt 0 ]; then | |
3201 return 0 | |
3202 fi | |
3203 return 1 | |
3204 } | |
3205 | |
3206 ###################################################################### | 297 ###################################################################### |
3207 ###################################################################### | 298 ###################################################################### |
3208 # | 299 # |
3209 # < MAIN > | 300 # < MAIN > |
3210 # | 301 # |
3211 ###################################################################### | 302 ###################################################################### |
3212 ###################################################################### | 303 ###################################################################### |
3213 | 304 |
3214 mkdir -p "${INSTALL_ROOT}" | |
3215 PackageCheck | |
3216 | |
3217 [ $# = 0 ] && set -- help # Avoid reference to undefined $1. | 305 [ $# = 0 ] && set -- help # Avoid reference to undefined $1. |
3218 if [ "$(type -t $1)" != "function" ]; then | 306 if [ "$(type -t $1)" != "function" ]; then |
3219 #Usage | 307 #Usage |
3220 echo "ERROR: unknown function '$1'." >&2 | 308 echo "ERROR: unknown function '$1'." >&2 |
3221 echo "For help, try:" | 309 echo "For help, try:" |
3222 echo " $0 help" | 310 echo " $0 help" |
3223 exit 1 | 311 exit 1 |
3224 fi | 312 fi |
3225 | 313 |
3226 "$@" | 314 "$@" |
OLD | NEW |