Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: tools/llvm/utman.sh

Issue 8391032: Part 2 of 3: Moving tools/llvm to pnacl/ (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/llvm/unsupported/patch-libstdc++ ('k') | tools/llvm/utman-test.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/bin/bash
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
4 # found in the LICENSE file.
5 #
6 #@ Untrusted Toolchain Manager
7 #@-------------------------------------------------------------------
8 #@ This script builds the ARM and PNaCl untrusted toolchains.
9 #@ It MUST be run from the native_client/ directory.
10 #
11 ######################################################################
12 # Directory Layout Description
13 ######################################################################
14 #
15 # All directories are relative to BASE which is
16 # On Linux X86-64: native_client/toolchain/pnacl_linux_x86_64/
17 # On Linux X86-32: native_client/toolchain/pnacl_linux_i686/
18 # On Mac X86-32 : native_client/toolchain/pnacl_darwin_i386/
19 #
20 ######################################################################
21 # Config
22 ######################################################################
23
24 set -o nounset
25 set -o errexit
26
27 # The script is located in "native_client/tools/llvm".
28 # Set pwd to native_client/
29 cd "$(dirname "$0")"/../..
30 if [[ $(basename "$(pwd)") != "native_client" ]] ; then
31 echo "ERROR: cannot find native_client/ directory"
32 exit -1
33 fi
34 readonly NACL_ROOT="$(pwd)"
35
36 source tools/llvm/common-tools.sh
37
38 SetScriptPath "${NACL_ROOT}/tools/llvm/utman.sh"
39 SetLogDirectory "${NACL_ROOT}/toolchain/hg-log"
40
41 # NOTE: gcc and llvm have to be synchronized
42 # we have chosen toolchains which both are based on gcc-4.2.1
43
44 # For different levels of make parallelism change this in your env
45 readonly UTMAN_CONCURRENCY=${UTMAN_CONCURRENCY:-8}
46 readonly UTMAN_MERGE_TESTING=${UTMAN_MERGE_TESTING:-false}
47 UTMAN_PRUNE=${UTMAN_PRUNE:-false}
48 UTMAN_BUILD_ARM=true
49
50 if ${BUILD_PLATFORM_MAC} || ${BUILD_PLATFORM_WIN}; then
51 # We don't yet support building ARM tools for mac or windows.
52 UTMAN_BUILD_ARM=false
53 fi
54
55 # Set the library mode
56 readonly LIBMODE=${LIBMODE:-newlib}
57
58 LIBMODE_NEWLIB=false
59 LIBMODE_GLIBC=false
60 if [ ${LIBMODE} == "newlib" ]; then
61 LIBMODE_NEWLIB=true
62 elif [ ${LIBMODE} == "glibc" ]; then
63 LIBMODE_GLIBC=true
64 UTMAN_BUILD_ARM=false
65 else
66 Fatal "Unknown library mode ${LIBMODE}"
67 fi
68 readonly LIBMODE_NEWLIB
69 readonly LIBMODE_GLIBC
70
71 readonly SB_JIT=${SB_JIT:-false}
72
73 # TODO(pdox): Decide what the target should really permanently be
74 readonly CROSS_TARGET_ARM=arm-none-linux-gnueabi
75 readonly BINUTILS_TARGET=arm-pc-nacl
76 readonly REAL_CROSS_TARGET=pnacl
77 readonly NACL64_TARGET=x86_64-nacl
78
79 readonly DRIVER_DIR="${NACL_ROOT}/pnacl/driver"
80 readonly ARM_ARCH=armv7-a
81 readonly ARM_FPU=vfp
82
83
84 readonly NNACL_BASE="${NACL_ROOT}/toolchain/${SCONS_BUILD_PLATFORM}_x86"
85 readonly NNACL_NEWLIB_ROOT="${NNACL_BASE}_newlib"
86 readonly NNACL_GLIBC_ROOT="${NNACL_BASE}"
87
88 readonly MAKE_OPTS="-j${UTMAN_CONCURRENCY} VERBOSE=1"
89
90 readonly NONEXISTENT_PATH="/going/down/the/longest/road/to/nowhere"
91
92 # For speculative build status output. ( see status function )
93 # Leave this blank, it will be filled during processing.
94 SPECULATIVE_REBUILD_SET=""
95
96 readonly PNACL_ROOT="${NACL_ROOT}/pnacl"
97 readonly PNACL_SUPPORT="${PNACL_ROOT}/support"
98
99 readonly GMP_VER=gmp-5.0.2
100 readonly THIRD_PARTY_GMP="${NACL_ROOT}/../third_party/gmp/${GMP_VER}.tar.bz2"
101
102 readonly MPFR_VER=mpfr-3.0.1
103 readonly THIRD_PARTY_MPFR="${NACL_ROOT}/../third_party/mpfr/${MPFR_VER}.tar.bz2"
104
105 readonly MPC_VER=mpc-0.9
106 readonly THIRD_PARTY_MPC="${NACL_ROOT}/../third_party/mpc/${MPC_VER}.tar.gz"
107
108 # The location of Mercurial sources (absolute)
109 readonly PNACL_HG_ROOT="${NACL_ROOT}/hg"
110 readonly TC_SRC_UPSTREAM="${PNACL_HG_ROOT}/upstream"
111 readonly TC_SRC_LLVM="${TC_SRC_UPSTREAM}/llvm"
112 readonly TC_SRC_LLVM_GCC="${TC_SRC_UPSTREAM}/llvm-gcc"
113 readonly TC_SRC_LIBSTDCPP="${TC_SRC_LLVM_GCC}/libstdc++-v3"
114 readonly TC_SRC_BINUTILS="${PNACL_HG_ROOT}/binutils"
115 readonly TC_SRC_NEWLIB="${PNACL_HG_ROOT}/newlib"
116 readonly TC_SRC_COMPILER_RT="${PNACL_HG_ROOT}/compiler-rt"
117 readonly TC_SRC_GOOGLE_PERFTOOLS="${PNACL_HG_ROOT}/google-perftools"
118
119 # LLVM sources (svn)
120 readonly PNACL_SVN_ROOT="${NACL_ROOT}/hg"
121 readonly TC_SRC_LLVM_MASTER="${PNACL_SVN_ROOT}/llvm-master"
122 readonly TC_SRC_LLVM_GCC_MASTER="${PNACL_SVN_ROOT}/llvm-gcc-master"
123 readonly TC_SRC_CLANG="${PNACL_SVN_ROOT}/clang"
124 readonly TC_SRC_DRAGONEGG="${PNACL_SVN_ROOT}/dragonegg"
125
126 # Git sources
127 readonly PNACL_GIT_ROOT="${PNACL_ROOT}/git"
128 readonly TC_SRC_GCC="${PNACL_GIT_ROOT}/gcc"
129 readonly TC_SRC_GMP="${PNACL_ROOT}/third_party/gmp"
130 readonly TC_SRC_MPFR="${PNACL_ROOT}/third_party/mpfr"
131 readonly TC_SRC_MPC="${PNACL_ROOT}/third_party/mpc"
132
133 # Unfortunately, binutils/configure generates this untracked file
134 # in the binutils source directory
135 readonly BINUTILS_MESS="${TC_SRC_BINUTILS}/binutils-2.20/opcodes/i386-tbl.h"
136
137 readonly SERVICE_RUNTIME_SRC="${NACL_ROOT}/src/trusted/service_runtime"
138 readonly EXPORT_HEADER_SCRIPT="${SERVICE_RUNTIME_SRC}/export_header.py"
139 readonly NACL_SYS_HEADERS="${SERVICE_RUNTIME_SRC}/include"
140 readonly NACL_HEADERS_TS="${PNACL_HG_ROOT}/nacl.sys.timestamp"
141 readonly NEWLIB_INCLUDE_DIR="${TC_SRC_NEWLIB}/newlib-trunk/newlib/libc/include"
142
143 # The location of each project. These should be absolute paths.
144 # If a tool below depends on a certain libc, then the build
145 # directory should have ${LIBMODE} in it to distinguish them.
146
147 readonly TC_BUILD="${NACL_ROOT}/toolchain/hg-build-${LIBMODE}"
148 readonly TC_BUILD_LLVM="${TC_BUILD}/llvm"
149 readonly TC_BUILD_LLVM_GCC="${TC_BUILD}/llvm-gcc"
150 readonly TC_BUILD_BINUTILS="${TC_BUILD}/binutils"
151 readonly TC_BUILD_BINUTILS_LIBERTY="${TC_BUILD}/binutils-liberty"
152 readonly TC_BUILD_NEWLIB="${TC_BUILD}/newlib"
153 readonly TC_BUILD_LIBSTDCPP="${TC_BUILD_LLVM_GCC}-arm/libstdcpp"
154 readonly TC_BUILD_COMPILER_RT="${TC_BUILD}/compiler_rt"
155 readonly TC_BUILD_GOOGLE_PERFTOOLS="${TC_BUILD}/google-perftools"
156 readonly TC_BUILD_GCC="${TC_BUILD}/gcc"
157 readonly TC_BUILD_GMP="${TC_BUILD}/gmp"
158 readonly TC_BUILD_MPFR="${TC_BUILD}/mpfr"
159 readonly TC_BUILD_MPC="${TC_BUILD}/mpc"
160 readonly TC_BUILD_DRAGONEGG="${TC_BUILD}/dragonegg"
161
162 readonly TIMESTAMP_FILENAME="make-timestamp"
163
164 # PNaCl toolchain installation directories (absolute paths)
165 readonly TOOLCHAIN_LABEL="pnacl_${BUILD_PLATFORM}_${HOST_ARCH}_${LIBMODE}"
166 readonly INSTALL_ROOT="${NACL_ROOT}/toolchain/${TOOLCHAIN_LABEL}"
167 readonly INSTALL_BIN="${INSTALL_ROOT}/bin"
168
169 # SDK
170 readonly INSTALL_SDK_ROOT="${INSTALL_ROOT}/sdk"
171 readonly INSTALL_SDK_INCLUDE="${INSTALL_SDK_ROOT}/include"
172 readonly INSTALL_SDK_LIB="${INSTALL_SDK_ROOT}/lib"
173
174 # The pattern `lib-${platform}' is implicit in verify() and sdk().
175 readonly INSTALL_LIB="${INSTALL_ROOT}/lib"
176 readonly INSTALL_LIB_ARM="${INSTALL_ROOT}/lib-arm"
177 readonly INSTALL_LIB_X8632="${INSTALL_ROOT}/lib-x86-32"
178 readonly INSTALL_LIB_X8664="${INSTALL_ROOT}/lib-x86-64"
179
180 # PNaCl client-translators (sandboxed) binary locations
181 readonly INSTALL_SB_TOOLS="${INSTALL_ROOT}/tools-sb"
182 readonly INSTALL_SB_TOOLS_X8632="${INSTALL_SB_TOOLS}/x8632"
183 readonly INSTALL_SB_TOOLS_X8664="${INSTALL_SB_TOOLS}/x8664"
184 readonly INSTALL_SB_TOOLS_UNIVERSAL="${INSTALL_SB_TOOLS}/universal"
185
186 # Component installation directories
187 readonly INSTALL_PKG="${INSTALL_ROOT}/pkg"
188 readonly NEWLIB_INSTALL_DIR="${INSTALL_PKG}/newlib"
189 readonly GLIBC_INSTALL_DIR="${INSTALL_PKG}/glibc"
190 readonly LLVM_INSTALL_DIR="${INSTALL_PKG}/llvm"
191 readonly LLVM_GCC_INSTALL_DIR="${INSTALL_PKG}/llvm-gcc"
192 readonly GCC_INSTALL_DIR="${INSTALL_PKG}/gcc"
193 readonly GMP_INSTALL_DIR="${INSTALL_PKG}/gmp"
194 readonly MPFR_INSTALL_DIR="${INSTALL_PKG}/mpfr"
195 readonly MPC_INSTALL_DIR="${INSTALL_PKG}/mpc"
196 readonly LIBSTDCPP_INSTALL_DIR="${INSTALL_PKG}/libstdcpp"
197 readonly BINUTILS_INSTALL_DIR="${INSTALL_PKG}/binutils"
198 readonly BFD_PLUGIN_DIR="${BINUTILS_INSTALL_DIR}/lib/bfd-plugins"
199 readonly SYSROOT_DIR="${INSTALL_ROOT}/sysroot"
200 readonly LDSCRIPTS_DIR="${INSTALL_ROOT}/ldscripts"
201 readonly LLVM_GCC_VER="4.2.1"
202
203 # Location of PNaCl gcc/g++/as
204 readonly PNACL_GCC="${INSTALL_BIN}/pnacl-gcc"
205 readonly PNACL_GXX="${INSTALL_BIN}/pnacl-g++"
206 readonly PNACL_DGCC="${INSTALL_BIN}/pnacl-dgcc"
207 readonly PNACL_DGXX="${INSTALL_BIN}/pnacl-dg++"
208 readonly PNACL_CLANG="${INSTALL_BIN}/pnacl-clang"
209 readonly PNACL_CLANGXX="${INSTALL_BIN}/pnacl-clang++"
210 readonly PNACL_AR="${INSTALL_BIN}/pnacl-ar"
211 readonly PNACL_RANLIB="${INSTALL_BIN}/pnacl-ranlib"
212 readonly PNACL_AS="${INSTALL_BIN}/pnacl-as"
213 readonly PNACL_LD="${INSTALL_BIN}/pnacl-ld"
214 readonly PNACL_NM="${INSTALL_BIN}/pnacl-nm"
215 readonly PNACL_TRANSLATE="${INSTALL_BIN}/pnacl-translate"
216 readonly PNACL_READELF="${INSTALL_BIN}/readelf"
217 readonly PNACL_SIZE="${INSTALL_BIN}/size"
218 readonly PNACL_STRIP="${INSTALL_BIN}/pnacl-strip"
219 readonly ILLEGAL_TOOL="${INSTALL_BIN}"/pnacl-illegal
220
221 readonly PNACL_AS_ARM="${INSTALL_BIN}/pnacl-arm-as"
222 readonly PNACL_AS_X8632="${INSTALL_BIN}/pnacl-i686-as"
223 readonly PNACL_AS_X8664="${INSTALL_BIN}/pnacl-x86_64-as"
224
225 # Set the default frontend.
226 # Can be default, clang, llvm-gcc, or dragonegg
227 # "Default" uses whatever is known to work, preferring Clang by default.
228 readonly DEFAULT_FRONTEND="clang"
229 readonly FRONTEND="${FRONTEND:-default}"
230
231 # For a production (release) build, we want the sandboxed
232 # translator to only contain the code needed to handle
233 # its own architecture. For example, the translator shipped with
234 # an X86-32 browser would only be able to translate to X86-32 code.
235 # This is so that the translator binary is as small as possible.
236 #
237 # If SBTC_PRODUCTION is true, then the translators are built
238 # separately, one for each architecture, so that each translator
239 # can only target its own architecture.
240 #
241 # If SBTC_PRODUCTION is false, then we instead use PNaCl to
242 # build a `fat` translator which can target all supported
243 # architectures. This translator is built as a .pexe
244 # which can then be translated to each individual architecture.
245 SBTC_PRODUCTION=${SBTC_PRODUCTION:-false}
246
247 # Which toolchain to use for each arch.
248 if ${LIBMODE_NEWLIB}; then
249 SBTC_BUILD_WITH_PNACL="arm x8632 x8664"
250 else
251 SBTC_BUILD_WITH_PNACL="x8632 x8664"
252 fi
253
254 # Current milestones in each repo
255 readonly UPSTREAM_REV=${UPSTREAM_REV:-f4269b5e5e4d}
256
257 readonly NEWLIB_REV=c6358617f3fd
258 readonly BINUTILS_REV=17a01203bd48
259 readonly COMPILER_RT_REV=1a3a6ffb31ea
260 readonly GOOGLE_PERFTOOLS_REV=ad820959663d
261
262 readonly LLVM_PROJECT_REV=${LLVM_PROJECT_REV:-142624}
263 readonly LLVM_MASTER_REV=${LLVM_PROJECT_REV}
264 readonly LLVM_GCC_MASTER_REV=${LLVM_PROJECT_REV}
265 readonly CLANG_REV=${LLVM_PROJECT_REV}
266 readonly DRAGONEGG_REV=${LLVM_PROJECT_REV}
267
268 # Repositories
269 readonly REPO_UPSTREAM="nacl-llvm-branches.upstream"
270 readonly REPO_NEWLIB="nacl-llvm-branches.newlib"
271 readonly REPO_BINUTILS="nacl-llvm-branches.binutils"
272 readonly REPO_COMPILER_RT="nacl-llvm-branches.compiler-rt"
273 readonly REPO_GOOGLE_PERFTOOLS="nacl-llvm-branches.google-perftools"
274
275 # LLVM repos (svn)
276 readonly REPO_LLVM_MASTER="http://llvm.org/svn/llvm-project/llvm/trunk"
277 readonly REPO_LLVM_GCC_MASTER="http://llvm.org/svn/llvm-project/llvm-gcc-4.2/tru nk"
278 readonly REPO_CLANG="http://llvm.org/svn/llvm-project/cfe/trunk"
279 readonly REPO_DRAGONEGG="http://llvm.org/svn/llvm-project/dragonegg/trunk"
280
281 # TODO(espindola): This should be ${CXX:-}, but llvm-gcc's configure has a
282 # bug that brakes the build if we do that.
283 CC=${CC:-gcc}
284 CXX=${CXX:-g++}
285 if ${HOST_ARCH_X8632} ; then
286 # These are simple compiler wrappers to force 32bit builds
287 # For bots and releases we build the toolchains
288 # on the oldest system we care to support. Currently
289 # that is a 32 bit hardy. The advantage of this is that we can build
290 # the toolchain shared, reducing its size and allowing the use of
291 # plugins. You can test them on your system by setting the
292 # environment variable HOST_ARCH=x86_32 on a 64 bit system.
293 # Make sure you clean all your build dirs
294 # before switching arches.
295 CC="${NACL_ROOT}/tools/llvm/mygcc32"
296 CXX="${NACL_ROOT}/tools/llvm/myg++32"
297 fi
298
299 force-frontend() {
300 local frontend="$1"
301 if [ "${frontend}" == default ] ; then
302 frontend="${DEFAULT_FRONTEND}"
303 fi
304 case "${frontend}" in
305 clang)
306 PNACL_CC="${PNACL_CLANG}"
307 PNACL_CXX="${PNACL_CLANGXX}"
308 ;;
309 llvm-gcc)
310 PNACL_CC="${PNACL_GCC}"
311 PNACL_CXX="${PNACL_GXX}"
312 ;;
313 dragonegg)
314 PNACL_CC="${PNACL_DGCC}"
315 PNACL_CXX="${PNACL_DGXX}"
316 ;;
317 *)
318 Fatal "Unknown frontend: ${frontend}"
319 ;;
320 esac
321 }
322
323 # Every prefer-frontend should be followed by a reset-frontend.
324 prefer-frontend() {
325 local frontend="$1"
326 if [ "${FRONTEND}" == default ] ; then
327 force-frontend "${frontend}"
328 fi
329 }
330
331 reset-frontend() {
332 force-frontend "${FRONTEND}"
333 }
334
335 setup-libstdcpp-env() {
336 # NOTE: we do not expect the assembler or linker to be used for libs
337 # hence the use of ILLEGAL_TOOL.
338 # TODO: the arm bias should be eliminated
339 # BUG: http://code.google.com/p/nativeclient/issues/detail?id=865
340 STD_ENV_FOR_LIBSTDCPP=(
341 CC_FOR_BUILD="${CC}"
342 CC="${PNACL_CC}"
343 CXX="${PNACL_CXX}"
344 RAW_CXX_FOR_TARGET="${PNACL_CXX}"
345 LD="${ILLEGAL_TOOL}"
346 CFLAGS="--pnacl-arm-bias"
347 CPPFLAGS="--pnacl-arm-bias"
348 CXXFLAGS="--pnacl-arm-bias"
349 CFLAGS_FOR_TARGET="--pnacl-arm-bias"
350 CPPFLAGS_FOR_TARGET="--pnacl-arm-bias"
351 CC_FOR_TARGET="${PNACL_CC}"
352 GCC_FOR_TARGET="${PNACL_CC}"
353 CXX_FOR_TARGET="${PNACL_CXX}"
354 AR="${PNACL_AR}"
355 AR_FOR_TARGET="${PNACL_AR}"
356 NM_FOR_TARGET="${PNACL_NM}"
357 RANLIB="${PNACL_RANLIB}"
358 RANLIB_FOR_TARGET="${PNACL_RANLIB}"
359 AS_FOR_TARGET="${ILLEGAL_TOOL}"
360 LD_FOR_TARGET="${ILLEGAL_TOOL}"
361 OBJDUMP_FOR_TARGET="${ILLEGAL_TOOL}" )
362 }
363
364 setup-newlib-env() {
365 STD_ENV_FOR_NEWLIB=(
366 CFLAGS_FOR_TARGET="--pnacl-arm-bias"
367 CPPFLAGS_FOR_TARGET="--pnacl-arm-bias"
368 CC_FOR_TARGET="${PNACL_CC}"
369 GCC_FOR_TARGET="${PNACL_CC}"
370 CXX_FOR_TARGET="${PNACL_CXX}"
371 AR_FOR_TARGET="${PNACL_AR}"
372 NM_FOR_TARGET="${PNACL_NM}"
373 RANLIB_FOR_TARGET="${PNACL_RANLIB}"
374 OBJDUMP_FOR_TARGET="${ILLEGAL_TOOL}"
375 AS_FOR_TARGET="${ILLEGAL_TOOL}"
376 LD_FOR_TARGET="${ILLEGAL_TOOL}"
377 STRIP_FOR_TARGET="${ILLEGAL_TOOL}" )
378 }
379
380 # The gold plugin that we use is documented at
381 # http://llvm.org/docs/GoldPlugin.html
382 # Despite its name it is actually used by both gold and bfd. The changes to
383 # this file to enable its use are:
384 # * Build shared
385 # * --enable-gold and --enable-plugin when building binutils
386 # * --with-binutils-include when building binutils
387 # * linking the plugin in bfd-plugins
388
389 ######################################################################
390 ######################################################################
391 #
392 # < USER ACCESSIBLE FUNCTIONS >
393 #
394 ######################################################################
395 ######################################################################
396
397 #@-------------------------------------------------------------------------
398
399 #@ hg-info-all - Show status of repositories
400 hg-info-all() {
401 hg-pull-all
402
403 hg-info "${TC_SRC_UPSTREAM}" ${UPSTREAM_REV}
404 hg-info "${TC_SRC_NEWLIB}" ${NEWLIB_REV}
405 hg-info "${TC_SRC_BINUTILS}" ${BINUTILS_REV}
406 hg-info "${TC_SRC_COMPILER_RT}" ${COMPILER_RT_REV}
407 hg-info "${TC_SRC_GOOGLE_PERFTOOLS}" ${GOOGLE_PERFTOOLS_REV}
408 }
409
410 update-all() {
411 hg-update-upstream
412 svn-update-clang
413 svn-update-dragonegg
414 hg-update-newlib
415 hg-update-binutils
416 hg-update-compiler-rt
417 hg-update-google-perftools
418 }
419
420 hg-assert-safe-to-update() {
421 local name="$1"
422 local dir="$2"
423 local rev="$3"
424 local defstr=$(echo "${name}" | tr '[a-z]-' '[A-Z]_')
425
426 if ! hg-has-changes "${dir}"; then
427 return 0
428 fi
429
430 if hg-at-revision "${dir}" "${rev}" ; then
431 return 0
432 fi
433
434 Banner \
435 " ERROR " \
436 " " \
437 " hg/${name} needs to be updated to the stable revision " \
438 " but has local modifications. " \
439 " " \
440 " If your repository is behind stable, update it using: " \
441 " " \
442 " cd hg/${name}; hg update ${rev} " \
443 " (you may need to resolve conflicts) " \
444 " " \
445 " If your repository is ahead of stable, then modify: " \
446 " ${defstr}_REV (in tools/llvm/utman.sh) " \
447 " to suppress this error message. "
448 exit -1
449 }
450
451 svn-assert-safe-to-update() {
452 local name="$1"
453 local dir="$2"
454 local rev="$3"
455 local defstr=$(echo "${name}" | tr '[a-z]-' '[A-Z]_')
456
457 if ! svn-has-changes "${dir}"; then
458 return 0
459 fi
460
461 if svn-at-revision "${dir}" "${rev}" ; then
462 return 0
463 fi
464
465 Banner \
466 " ERROR " \
467 " " \
468 " hg/${name} needs to be updated to the stable revision " \
469 " but has local modifications. " \
470 " " \
471 " If your repository is behind stable, update it using: " \
472 " " \
473 " cd hg/${name}; svn update -r ${rev} " \
474 " (you may need to resolve conflicts) " \
475 " " \
476 " If your repository is ahead of stable, then modify: " \
477 " ${defstr}_REV (in tools/llvm/utman.sh) " \
478 " to suppress this error message. "
479 exit -1
480 }
481
482 hg-bot-sanity() {
483 local name="$1"
484 local dir="$2"
485
486 if ! ${UTMAN_BUILDBOT} ; then
487 return 0
488 fi
489
490 if ! hg-on-branch "${dir}" pnacl-sfi ||
491 hg-has-changes "${dir}" ||
492 hg-has-untracked "${dir}" ; then
493 Banner "WARNING: hg/${name} is in an illegal state." \
494 " Wiping and trying again."
495 rm -rf "${dir}"
496 hg-checkout-${name}
497 fi
498 }
499
500 svn-bot-sanity() {
501 local name="$1"
502 local dir="$2"
503
504 if ! ${UTMAN_BUILDBOT} ; then
505 return 0
506 fi
507
508 if svn-has-changes "${dir}" ; then
509 Banner "WARNING: hg/${name} is in an illegal state." \
510 " Wiping and trying again."
511 rm -rf "${dir}"
512 svn-checkout-${name}
513 fi
514 }
515
516
517 hg-update-common() {
518 local name="$1"
519 local rev="$2"
520 local dir="$3"
521
522 # If this is a buildbot, do sanity checks here.
523 hg-bot-sanity "${name}" "${dir}"
524
525 # Make sure it is safe to update
526 hg-assert-branch "${dir}" pnacl-sfi
527 hg-assert-safe-to-update "${name}" "${dir}" "${rev}"
528
529 if hg-at-revision "${dir}" "${rev}" ; then
530 StepBanner "HG-UPDATE" "Repo ${name} already at ${rev}"
531 else
532 StepBanner "HG-UPDATE" "Updating ${name} to ${rev}"
533 hg-pull "${dir}"
534 hg-update "${dir}" ${rev}
535 fi
536 }
537
538 svn-update-common() {
539 local name="$1"
540 local rev="$2"
541 local dir="$3"
542
543 # If this is a buildbot, do sanity checks here.
544 svn-bot-sanity "${name}" "${dir}"
545
546 # Make sure it is safe to update
547 svn-assert-safe-to-update "${name}" "${dir}" "${rev}"
548
549 if svn-at-revision "${dir}" "${rev}" ; then
550 StepBanner "SVN-UPDATE" "Repo ${name} already at ${rev}"
551 else
552 StepBanner "SVN-UPDATE" "Updating ${name} to ${rev}"
553 svn-update "${dir}" ${rev}
554 fi
555 }
556
557 hg-update-upstream() {
558 llvm-unlink-clang
559 if ! ${UTMAN_MERGE_TESTING} ; then
560 hg-update-common "upstream" ${UPSTREAM_REV} "${TC_SRC_UPSTREAM}"
561 fi
562 llvm-link-clang
563 }
564
565 svn-update-llvm-master() {
566 svn-update-common "llvm-master" ${LLVM_MASTER_REV} "${TC_SRC_LLVM_MASTER}"
567 }
568
569 svn-update-llvm-gcc-master() {
570 svn-update-common "llvm-gcc-master" ${LLVM_GCC_MASTER_REV} \
571 "${TC_SRC_LLVM_GCC_MASTER}"
572 }
573
574 svn-update-clang() {
575 svn-update-common "clang" ${CLANG_REV} "${TC_SRC_CLANG}"
576 }
577
578 svn-update-dragonegg() {
579 svn-update-common "dragonegg" ${DRAGONEGG_REV} "${TC_SRC_DRAGONEGG}"
580 }
581
582 #@ hg-update-newlib - Update NEWLIB To the stable revision
583 hg-update-newlib() {
584 # Clean the headers first, so that sanity checks inside
585 # hg-update-common do not see any local modifications.
586 newlib-nacl-headers-check
587 newlib-nacl-headers-clean
588 hg-update-common "newlib" ${NEWLIB_REV} "${TC_SRC_NEWLIB}"
589 newlib-nacl-headers
590 }
591
592 #@ hg-update-binutils - Update BINUTILS to the stable revision
593 hg-update-binutils() {
594 # Clean the binutils generated file first, so that sanity checks
595 # inside hg-update-common do not see any local modifications.
596 binutils-mess-hide
597 hg-update-common "binutils" ${BINUTILS_REV} "${TC_SRC_BINUTILS}"
598 binutils-mess-unhide
599 }
600
601 #@ hg-update-compiler-rt - Update compiler-rt to the stable revision
602 hg-update-compiler-rt() {
603 hg-update-common "compiler-rt" ${COMPILER_RT_REV} "${TC_SRC_COMPILER_RT}"
604 }
605
606 #@ hg-update-google-perftools - Update google-perftools to the stable revision
607 hg-update-google-perftools() {
608 hg-update-common "google-perftools" ${GOOGLE_PERFTOOLS_REV} \
609 "${TC_SRC_GOOGLE_PERFTOOLS}"
610 }
611
612 #@ hg-pull-all - Pull all repos. (but do not update working copy)
613 #@ hg-pull-REPO - Pull repository REPO.
614 #@ (REPO can be llvm-gcc, llvm, newlib, binutils)
615 hg-pull-all() {
616 StepBanner "HG-PULL" "Running 'hg pull' in all repos..."
617 hg-pull-upstream
618 hg-pull-newlib
619 hg-pull-binutils
620 hg-pull-compiler-rt
621 hg-pull-google-perftools
622 }
623
624 hg-pull-upstream() {
625 hg-pull "${TC_SRC_UPSTREAM}"
626 }
627
628 hg-pull-newlib() {
629 hg-pull "${TC_SRC_NEWLIB}"
630 }
631
632 hg-pull-binutils() {
633 hg-pull "${TC_SRC_BINUTILS}"
634 }
635
636 hg-pull-compiler-rt() {
637 hg-pull "${TC_SRC_COMPILER_RT}"
638 }
639
640 hg-pull-google-perftools() {
641 hg-pull "${TC_SRC_GOOGLE_PERFTOOLS}"
642 }
643
644 #@ checkout-all - check out repos needed to build toolchain
645 #@ (skips repos which are already checked out)
646 checkout-all() {
647 StepBanner "CHECKOUT-ALL"
648 hg-checkout-upstream
649 svn-checkout-clang
650 svn-checkout-dragonegg
651 hg-checkout-binutils
652 hg-checkout-newlib
653 hg-checkout-compiler-rt
654 hg-checkout-google-perftools
655 git-sync
656 }
657
658 hg-checkout-upstream() {
659 if ! ${UTMAN_MERGE_TESTING} ; then
660 hg-checkout ${REPO_UPSTREAM} "${TC_SRC_UPSTREAM}" ${UPSTREAM_REV}
661 fi
662 llvm-link-clang
663 }
664
665 svn-checkout-llvm-master() {
666 svn-checkout "${REPO_LLVM_MASTER}" "${TC_SRC_LLVM_MASTER}" ${LLVM_MASTER_REV}
667 }
668
669 svn-checkout-llvm-gcc-master() {
670 svn-checkout "${REPO_LLVM_GCC_MASTER}" "${TC_SRC_LLVM_GCC_MASTER}" \
671 ${LLVM_GCC_MASTER_REV}
672 }
673
674 svn-checkout-clang() {
675 svn-checkout "${REPO_CLANG}" "${TC_SRC_CLANG}" ${CLANG_REV}
676 }
677
678 svn-checkout-dragonegg() {
679 svn-checkout "${REPO_DRAGONEGG}" "${TC_SRC_DRAGONEGG}" ${DRAGONEGG_REV}
680 }
681
682 hg-checkout-binutils() {
683 hg-checkout ${REPO_BINUTILS} "${TC_SRC_BINUTILS}" ${BINUTILS_REV}
684 }
685
686 hg-checkout-newlib() {
687 hg-checkout ${REPO_NEWLIB} "${TC_SRC_NEWLIB}" ${NEWLIB_REV}
688 newlib-nacl-headers
689 }
690
691 hg-checkout-compiler-rt() {
692 hg-checkout ${REPO_COMPILER_RT} "${TC_SRC_COMPILER_RT}" ${COMPILER_RT_REV}
693 }
694
695 hg-checkout-google-perftools() {
696 hg-checkout ${REPO_GOOGLE_PERFTOOLS} "${TC_SRC_GOOGLE_PERFTOOLS}" \
697 ${GOOGLE_PERFTOOLS_REV}
698 }
699
700 #@ hg-clean - Remove all repos. (WARNING: local changes are lost)
701 hg-clean() {
702 StepBanner "HG-CLEAN"
703
704 echo "Are you sure?"
705 echo "This will DELETE all source repositories under 'native_client/hg'"
706 echo "Any local changes will be lost."
707 echo ""
708 echo "Type YES to confirm: "
709 read CONFIRM_TEXT
710
711 if [ $CONFIRM_TEXT == "YES" ]; then
712 StepBanner "HG-CLEAN" "Cleaning Mercurial repositories"
713 rm -rf "${PNACL_HG_ROOT}"
714 else
715 StepBanner "HG-CLEAN" "Clean cancelled by user"
716 fi
717 }
718
719 git-sync() {
720 local gitbase="${PNACL_GIT_ROOT}"
721
722 mkdir -p "${gitbase}"
723 cp "${PNACL_ROOT}"/gclient_template "${gitbase}/.gclient"
724
725 if ! [ -d "${gitbase}/dummydir" ]; then
726 spushd "${gitbase}"
727 gclient update
728 spopd
729 fi
730
731 cp "${PNACL_ROOT}"/DEPS "${gitbase}"/dummydir
732 spushd "${gitbase}"
733 gclient update
734 spopd
735 }
736
737
738 #@-------------------------------------------------------------------------
739
740 #@ download-trusted - Download and Install trusted SDKs (arm,x86-32,x86-64)
741 #@ (your untrusted build will not be modified)
742 download-trusted() {
743 StepBanner "DOWNLOAD-TRUSTED" "Downloading trusted toolchains"
744 local installdir="${INSTALL_ROOT}"
745 local tmpdir="${installdir}-backup"
746 local dldir="${installdir}-downloaded"
747
748 rm -rf "${dldir}"
749
750 if [ -d "${tmpdir}" ]; then
751 echo "ERROR: It is not expected that directory '${tmpdir}' exists."
752 echo " Please delete it if you don't need it"
753 exit -1
754 fi
755
756 if [ -d "${installdir}" ]; then
757 mv "${installdir}" "${tmpdir}"
758 fi
759
760 download-toolchains
761
762 if [ -d "${installdir}" ]; then
763 mv "${installdir}" "${dldir}"
764 fi
765
766 if [ -d "${tmpdir}" ]; then
767 mv "${tmpdir}" "${installdir}"
768 fi
769 }
770
771 #@-------------------------------------------------------------------------
772
773 #@ download-toolchains - Download and Install all SDKs (arm,x86-32,x86-64)
774
775 download-toolchains() {
776 gclient runhooks --force
777 }
778
779 libc() {
780 if ${LIBMODE_NEWLIB} ; then
781 # TODO(pdox): Why is this step needed?
782 sysroot
783 newlib
784 elif ${LIBMODE_GLIBC} ; then
785 glibc
786 fi
787 }
788
789
790 #@ libs - install native libs and build bitcode libs
791 libs() {
792 libs-clean
793 libs-platform
794 if ${LIBMODE_NEWLIB} ; then
795 # TODO(pdox): Why is this step needed?
796 sysroot
797 newlib
798 elif ${LIBMODE_GLIBC} ; then
799 glibc
800 fi
801
802 if ${LIBMODE_NEWLIB}; then
803 build-compiler-rt
804 # NOTE: this currently depends on "llvm-gcc arm"
805 build-libgcc_eh arm
806 build-libgcc_eh x86-32
807 build-libgcc_eh x86-64
808
809 libstdcpp
810 fi
811 }
812
813 #@ everything - Build and install untrusted SDK. no translator
814 everything() {
815 everything-hg
816
817 everything-post-hg
818 }
819
820 #@ everything - Checkout everything from the repositories
821 everything-hg() {
822 mkdir -p "${INSTALL_ROOT}"
823 if ${UTMAN_IN_CROS_CHROOT}; then
824 # TODO: http://code.google.com/p/nativeclient/issues/detail?id=2295
825 Banner "You are running in a ChromiumOS Chroot." \
826 " You should make sure that the PNaCl sources are properly checked out " \
827 " And updated outside of the chroot"
828 else
829 checkout-all
830 StepBanner "Updating upstreaming repository"
831 update-all
832 fi
833 }
834
835 #@ everything-post-hg does everything AFTER hg setup
836 everything-post-hg() {
837 mkdir -p "${INSTALL_ROOT}"
838 # This is needed to build misc-tools and run ARM tests.
839 # We check this early so that there are no surprises later, and we can
840 # handle all user interaction early.
841 check-for-trusted
842
843 clean-install
844
845 clean-logs
846
847 binutils
848 llvm
849 driver
850 llvm-gcc arm
851
852 libs
853
854 # NOTE: we delay the tool building till after the sdk is essentially
855 # complete, so that sdk sanity checks don't fail
856 misc-tools
857 verify
858 }
859
860 #@ everything-translator - Build and install untrusted SDK AND translator
861 everything-translator() {
862
863 everything
864 # Building the sandboxed tools requires the SDK
865 if ${UTMAN_PRUNE}; then
866 prune
867 fi
868 sdk
869 install-translators srpc
870 if ${UTMAN_PRUNE}; then
871 prune-translator-install srpc
872 track-translator-size ${SBTC_BUILD_WITH_PNACL}
873 fi
874 }
875
876 glibc() {
877 StepBanner "GLIBC" "Copying glibc from NNaCl toolchain"
878
879 mkdir -p "${INSTALL_LIB_X8632}"
880 mkdir -p "${INSTALL_LIB_X8664}"
881 mkdir -p "${GLIBC_INSTALL_DIR}"
882
883 # Files in: lib/gcc/${NACL64_TARGET}/4.4.3/[32]/
884 local LIBS1="crtbegin.o crtbeginT.o crtbeginS.o crtend.o crtendS.o \
885 libgcc_eh.a libgcc.a"
886
887 # Files in: ${NACL64_TARGET}/lib[32]/
888 local LIBS2="crt1.o crti.o crtn.o \
889 libgcc_s.so libgcc_s.so.1 \
890 libstdc++.a libstdc++.so* \
891 libc.a libc_nonshared.a \
892 libc-2.9.so libc.so libc.so.* \
893 libm-2.9.so libm.a libm.so libm.so.* \
894 libdl-2.9.so libdl.so.* libdl.so libdl.a \
895 libpthread-2.9.so libpthread.a libpthread.so \
896 libpthread.so.* libpthread_nonshared.a \
897 runnable-ld.so \
898 ld-2.9.so"
899
900 for lib in ${LIBS1} ; do
901 cp -a "${NNACL_GLIBC_ROOT}/lib/gcc/${NACL64_TARGET}/4.4.3/32/"${lib} \
902 "${INSTALL_LIB_X8632}"
903 cp -a "${NNACL_GLIBC_ROOT}/lib/gcc/${NACL64_TARGET}/4.4.3/"${lib} \
904 "${INSTALL_LIB_X8664}"
905 done
906
907 for lib in ${LIBS2} ; do
908 cp -a "${NNACL_GLIBC_ROOT}/${NACL64_TARGET}/lib32/"${lib} \
909 "${INSTALL_LIB_X8632}"
910 cp -a "${NNACL_GLIBC_ROOT}/${NACL64_TARGET}/lib/"${lib} \
911 "${INSTALL_LIB_X8664}"
912 done
913
914 # Copy linker scripts
915 # We currently only depend on elf[64]_nacl.x,
916 # elf[64]_nacl.xs, and elf[64]_nacl.x.static.
917 cp -a "${NNACL_GLIBC_ROOT}/${NACL64_TARGET}/lib/ldscripts/elf_nacl.x"* \
918 "${INSTALL_LIB_X8632}"
919 cp -a "${NNACL_GLIBC_ROOT}/${NACL64_TARGET}/lib/ldscripts/elf64_nacl.x"* \
920 "${INSTALL_LIB_X8664}"
921
922 # ld-nacl have different sonames across 32/64.
923 # Create symlinks to make them look the same.
924 # TODO(pdox): Can this be fixed in glibc?
925 ln -sf "ld-2.9.so" "${INSTALL_LIB_X8632}"/ld-nacl-x86-32.so.1
926 ln -sf "ld-2.9.so" "${INSTALL_LIB_X8632}"/ld-nacl-x86-64.so.1
927 ln -sf "ld-2.9.so" "${INSTALL_LIB_X8664}"/ld-nacl-x86-32.so.1
928 ln -sf "ld-2.9.so" "${INSTALL_LIB_X8664}"/ld-nacl-x86-64.so.1
929
930 # Copy the glibc headers
931 cp -a "${NNACL_GLIBC_ROOT}"/${NACL64_TARGET}/include \
932 "${GLIBC_INSTALL_DIR}"
933 }
934
935 #@ all - Alias for 'everything'
936 all() {
937 everything
938 }
939
940 #@ status - Show status of build directories
941 status() {
942 # TODO(robertm): this is currently broken
943 StepBanner "BUILD STATUS"
944
945 status-helper "BINUTILS" binutils
946 status-helper "LLVM" llvm
947 status-helper "GCC-STAGE1" llvm-gcc
948
949 status-helper "NEWLIB" newlib
950 status-helper "LIBSTDCPP" libstdcpp
951
952 }
953
954 status-helper() {
955 local title="$1"
956 local mod="$2"
957
958 if ${mod}-needs-configure; then
959 StepBanner "$title" "NEEDS FULL REBUILD"
960 speculative-add "${mod}"
961 elif ${mod}-needs-make; then
962 StepBanner "$title" "NEEDS MAKE (INCREMENTAL)"
963 speculative-add "${mod}"
964 else
965 StepBanner "$title" "OK (UP TO DATE)"
966 fi
967 }
968
969 speculative-add() {
970 local mod="$1"
971 SPECULATIVE_REBUILD_SET="${SPECULATIVE_REBUILD_SET} ${mod}"
972 }
973
974 speculative-check() {
975 local mod="$1"
976 local search=$(echo "${SPECULATIVE_REBUILD_SET}" | grep -F "$mod")
977 [ ${#search} -gt 0 ]
978 return $?
979 }
980
981
982
983 #@ clean - Clean the build and install directories.
984 clean() {
985 StepBanner "CLEAN" "Cleaning build, log, and install directories."
986
987 clean-logs
988 clean-build
989 clean-install
990 clean-scons
991 }
992
993 #@ fast-clean - Clean everything except LLVM.
994 fast-clean() {
995 local did_backup=false
996 local backup_dir="${NACL_ROOT}/llvm-build-backup"
997
998 if [ -d "${TC_BUILD_LLVM}" ]; then
999 rm -rf "${backup_dir}"
1000 mv "${TC_BUILD_LLVM}" "${backup_dir}"
1001 did_backup=true
1002 fi
1003
1004 clean
1005
1006 if ${did_backup} ; then
1007 mkdir -p "${TC_BUILD}"
1008 mv "${backup_dir}" "${TC_BUILD_LLVM}"
1009 fi
1010 }
1011
1012 binutils-mess-hide() {
1013 local messtmp="${PNACL_HG_ROOT}/binutils.tmp"
1014 if [ -f "${BINUTILS_MESS}" ] ; then
1015 mv "${BINUTILS_MESS}" "${messtmp}"
1016 fi
1017 }
1018
1019 binutils-mess-unhide() {
1020 local messtmp="${PNACL_HG_ROOT}/binutils.tmp"
1021 if [ -f "${messtmp}" ] ; then
1022 mv "${messtmp}" "${BINUTILS_MESS}"
1023 fi
1024 }
1025
1026 #+ clean-scons - Clean scons-out directory
1027 clean-scons() {
1028 rm -rf scons-out
1029 }
1030
1031 #+ clean-build - Clean all build directories
1032 clean-build() {
1033 rm -rf "${TC_BUILD}"
1034 }
1035
1036 #+ clean-install - Clean install directories
1037 clean-install() {
1038 rm -rf "${INSTALL_ROOT}"
1039 }
1040
1041 #+ libs-clean - Removes the library directories
1042 libs-clean() {
1043 StepBanner "LIBS-CLEAN" "Cleaning ${INSTALL_ROOT}/libs-*"
1044 rm -rf "${INSTALL_LIB}"/*
1045 rm -rf "${INSTALL_LIB}"-*/*
1046 }
1047
1048
1049 #@-------------------------------------------------------------------------
1050
1051 #@ untrusted_sdk <file> - Create untrusted SDK tarball from scratch
1052 #@ (clean + all + prune + tarball)
1053 untrusted_sdk() {
1054 if [ ! -n "${1:-}" ]; then
1055 echo "Error: untrusted_sdk needs a tarball name." >&2
1056 exit 1
1057 fi
1058
1059 clean
1060 everything-translator
1061
1062 # Remove the SDK so it doesn't end up in the tarball
1063 sdk-clean
1064
1065 if ${UTMAN_PRUNE}; then
1066 prune
1067 fi
1068 tarball $1
1069 }
1070
1071 #+ prune - Prune toolchain
1072 prune() {
1073 StepBanner "PRUNE" "Pruning toolchain"
1074 # ACCEPTABLE_SIZE should be much lower for real release,
1075 # but we are currently doing a debug build and not pruning
1076 # as aggressively as we could.
1077 local ACCEPTABLE_SIZE=300
1078 local dir_size_before=$(get_dir_size_in_mb ${INSTALL_ROOT})
1079
1080 SubBanner "Size before: ${INSTALL_ROOT} ${dir_size_before}MB"
1081 echo "removing some static libs we do not have any use for"
1082 rm -f "${NEWLIB_INSTALL_DIR}"/lib/lib*.a
1083
1084 echo "stripping binaries (llvm-gcc, llvm, binutils)"
1085 strip \
1086 "${LLVM_GCC_INSTALL_DIR}"/libexec/gcc/${CROSS_TARGET_ARM}/${LLVM_GCC_VER}/c*
1087 strip "${BINUTILS_INSTALL_DIR}"/bin/*
1088 if ! strip "${LLVM_INSTALL_DIR}"/bin/* ; then
1089 echo "NOTE: some failures during stripping are expected"
1090 fi
1091 if ! strip "${LLVM_GCC_INSTALL_DIR}"/bin/* ; then
1092 echo "NOTE: some failures during stripping are expected"
1093 fi
1094
1095 echo "removing llvm headers"
1096 rm -rf "${LLVM_INSTALL_DIR}"/include/llvm*
1097
1098 echo "removing .pyc files"
1099 rm -f "${INSTALL_BIN}"/*.pyc
1100
1101 if ${LIBMODE_GLIBC}; then
1102 echo "remove pnacl_cache directory"
1103 rm -rf "${INSTALL_LIB}"/pnacl_cache
1104 rm -rf "${INSTALL_SDK_LIB}"/pnacl_cache
1105 fi
1106
1107 echo "remove driver log"
1108 rm -f "${INSTALL_ROOT}"/driver.log
1109
1110 local dir_size_after=$(get_dir_size_in_mb "${INSTALL_ROOT}")
1111 SubBanner "Size after: ${INSTALL_ROOT} ${dir_size_after}MB"
1112
1113 if [[ ${dir_size_after} -gt ${ACCEPTABLE_SIZE} ]] ; then
1114 # TODO(pdox): Move this to the buildbot script so that
1115 # it can make the bot red without ruining the toolchain archive.
1116 echo "WARNING: size of toolchain exceeds ${ACCEPTABLE_SIZE}MB"
1117 fi
1118
1119 }
1120
1121 #+ tarball <filename> - Produce tarball file
1122 tarball() {
1123 if [ ! -n "${1:-}" ]; then
1124 echo "Error: tarball needs a tarball name." >&2
1125 exit 1
1126 fi
1127
1128 RecordRevisionInfo
1129 local tarball="$1"
1130 StepBanner "TARBALL" "Creating tar ball ${tarball}"
1131
1132 tar zcf "${tarball}" -C "${INSTALL_ROOT}" .
1133 }
1134
1135
1136 #########################################################################
1137 # < LLVM >
1138 #########################################################################
1139
1140
1141 #+-------------------------------------------------------------------------
1142 #+ llvm - Configure, build and install LLVM.
1143
1144 llvm() {
1145 StepBanner "LLVM (HOST)"
1146
1147 local srcdir="${TC_SRC_LLVM}"
1148
1149 assert-dir "${srcdir}" "You need to checkout LLVM."
1150
1151 if llvm-needs-configure; then
1152 llvm-clean
1153 llvm-configure
1154 else
1155 SkipBanner "LLVM" "configure"
1156 fi
1157
1158 if llvm-needs-make; then
1159 llvm-make
1160 else
1161 SkipBanner "LLVM" "make"
1162 fi
1163
1164 llvm-install
1165 }
1166
1167 #+ llvm-clean - Clean LLVM completely
1168 llvm-clean() {
1169 StepBanner "LLVM" "Clean"
1170 local objdir="${TC_BUILD_LLVM}"
1171 rm -rf ${objdir}
1172 mkdir -p ${objdir}
1173 }
1174
1175 #+ llvm-link-clang - Add tools/clang symlink into llvm directory
1176 llvm-link-clang() {
1177 rm -f "${TC_SRC_LLVM}"/tools/clang
1178 ln -sf "../../../clang" "${TC_SRC_LLVM}"/tools/clang
1179 }
1180
1181 #+ llvm-unlink-clang - Remove tools/clang symlink from llvm directory
1182 llvm-unlink-clang() {
1183 if [ -d "${TC_SRC_LLVM}" ]; then
1184 rm -f "${TC_SRC_LLVM}"/tools/clang
1185 fi
1186 }
1187
1188 # Default case - Optimized configure
1189 LLVM_EXTRA_OPTIONS="--enable-optimized"
1190
1191 #+ llvm-configure - Run LLVM configure
1192 llvm-configure() {
1193 StepBanner "LLVM" "Configure"
1194
1195 local srcdir="${TC_SRC_LLVM}"
1196 local objdir="${TC_BUILD_LLVM}"
1197
1198 mkdir -p "${objdir}"
1199 spushd "${objdir}"
1200
1201 llvm-link-clang
1202 # The --with-binutils-include is to allow llvm to build the gold plugin
1203 local binutils_include="${TC_SRC_BINUTILS}/binutils-2.20/include"
1204 RunWithLog "llvm.configure" \
1205 env -i PATH=/usr/bin/:/bin \
1206 MAKE_OPTS=${MAKE_OPTS} \
1207 CC="${CC}" \
1208 CXX="${CXX}" \
1209 ${srcdir}/configure \
1210 --disable-jit \
1211 --with-binutils-include=${binutils_include} \
1212 --enable-targets=x86,x86_64,arm \
1213 --target=${CROSS_TARGET_ARM} \
1214 --prefix="${LLVM_INSTALL_DIR}" \
1215 --with-llvmgccdir="${LLVM_GCC_INSTALL_DIR}" \
1216 ${LLVM_EXTRA_OPTIONS}
1217
1218
1219 spopd
1220 }
1221
1222 #+ llvm-configure-dbg - Run LLVM configure
1223 # Not used by default. Call manually.
1224 llvm-configure-dbg() {
1225 StepBanner "LLVM" "Configure With Debugging"
1226 LLVM_EXTRA_OPTIONS="--disable-optimized \
1227 --enable-debug-runtime \
1228 --enable-assertions "
1229 llvm-configure
1230 }
1231
1232
1233 llvm-needs-configure() {
1234 [ ! -f "${TC_BUILD_LLVM}/config.status" ]
1235 return $?
1236 }
1237
1238 llvm-needs-make() {
1239 local objdir="${TC_BUILD_LLVM}"
1240 ts-modified "${TC_SRC_LLVM}" "${objdir}" ||
1241 ts-modified "${TC_SRC_CLANG}" "${objdir}"
1242 return $?
1243 }
1244
1245 #+ llvm-make - Run LLVM 'make'
1246 llvm-make() {
1247 StepBanner "LLVM" "Make"
1248
1249 local srcdir="${TC_SRC_LLVM}"
1250 local objdir="${TC_BUILD_LLVM}"
1251 llvm-link-clang
1252
1253 spushd "${objdir}"
1254
1255 ts-touch-open "${objdir}"
1256
1257 RunWithLog llvm.make \
1258 env -i PATH=/usr/bin/:/bin \
1259 MAKE_OPTS="${MAKE_OPTS}" \
1260 NACL_SANDBOX=0 \
1261 CC="${CC}" \
1262 CXX="${CXX}" \
1263 make ${MAKE_OPTS} all
1264
1265 ts-touch-commit "${objdir}"
1266
1267 spopd
1268 }
1269
1270 #+ llvm-install - Install LLVM
1271 llvm-install() {
1272 StepBanner "LLVM" "Install"
1273
1274 spushd "${TC_BUILD_LLVM}"
1275 llvm-link-clang
1276 RunWithLog llvm.install \
1277 make ${MAKE_OPTS} install
1278 spopd
1279
1280 llvm-install-links
1281 }
1282
1283 llvm-install-links() {
1284 local makelink="ln -sf"
1285
1286 # On Windows, these can't be symlinks.
1287 if ${BUILD_PLATFORM_WIN}; then
1288 makelink="cp -a"
1289 fi
1290
1291 mkdir -p "${BFD_PLUGIN_DIR}"
1292
1293 # TODO(pdox): These may no longer be necessary.
1294 if [ -f "${BFD_PLUGIN_DIR}/../../../llvm/${SO_DIR}/LLVMgold${SO_EXT}" ]; then
1295 # this is to make sure whatever name LLVMgold.so is, it is always
1296 # libLLVMgold.so as far as PNaCl is concerned
1297
1298 StepBanner "Symlinking LLVMgold.so to libLLVMgold.so in " \
1299 "${BFD_PLUGIN_DIR}/../../../llvm/${SO_DIR}"
1300
1301 (cd "${BFD_PLUGIN_DIR}/../../../llvm/${SO_DIR}";
1302 ${makelink} "LLVMgold${SO_EXT}" "${SO_PREFIX}LLVMgold${SO_EXT}";
1303 )
1304 fi
1305
1306 spushd "${BFD_PLUGIN_DIR}"
1307
1308 ${makelink} ../../../llvm/${SO_DIR}/${SO_PREFIX}LLVMgold${SO_EXT} .
1309 ${makelink} ../../../llvm/${SO_DIR}/${SO_PREFIX}LTO${SO_EXT} .
1310 spopd
1311
1312 spushd "${BINUTILS_INSTALL_DIR}/${SO_DIR}"
1313 ${makelink} ../../llvm/${SO_DIR}/${SO_PREFIX}LTO${SO_EXT} .
1314 ${makelink} ../../llvm/${SO_DIR}/${SO_PREFIX}LLVMgold${SO_EXT} .
1315 spopd
1316 }
1317
1318 #########################################################################
1319 #########################################################################
1320 # GCC/DragonEgg based front-end
1321 #########################################################################
1322 #########################################################################
1323
1324 ############################### GMP ###############################
1325 #+ gmp - Build and install gmp
1326 gmp() {
1327 gmp-unpack
1328 if gmp-needs-configure; then
1329 gmp-clean
1330 gmp-configure
1331 else
1332 SkipBanner "GMP" "Already configured"
1333 fi
1334 gmp-install
1335 }
1336
1337 gmp-needs-configure() {
1338 ! [ -f "${TC_BUILD_GMP}/config.status" ]
1339 return $?
1340 }
1341
1342 gmp-clean() {
1343 StepBanner "GMP" "Clean"
1344 rm -rf "${TC_BUILD_GMP}"
1345 }
1346
1347 gmp-unpack() {
1348 if ! [ -d "${TC_SRC_GMP}" ]; then
1349 mkdir -p "${TC_SRC_GMP}"
1350 tar -jxf "${THIRD_PARTY_GMP}" -C "${TC_SRC_GMP}"
1351 fi
1352 }
1353
1354 gmp-configure() {
1355 StepBanner "GMP" "Configure"
1356 mkdir -p "${TC_BUILD_GMP}"
1357 spushd "${TC_BUILD_GMP}"
1358 RunWithLog gmp.configure \
1359 env -i \
1360 PATH="/usr/bin:/bin" \
1361 CC="${CC}" \
1362 CXX="${CXX}" \
1363 "${TC_SRC_GMP}"/${GMP_VER}/configure \
1364 --prefix="${GMP_INSTALL_DIR}" \
1365 --disable-shared --enable-static
1366 spopd
1367 }
1368
1369 gmp-install() {
1370 StepBanner "GMP" "Install"
1371 spushd "${TC_BUILD_GMP}"
1372 RunWithLog gmp.install \
1373 env -i PATH=/usr/bin/:/bin \
1374 CC="${CC}" \
1375 CXX="${CXX}" \
1376 make ${MAKE_OPTS} install
1377 spopd
1378 }
1379
1380 ############################### MPFR ###############################
1381 #+ mpfr - Build and install mpfr
1382 mpfr() {
1383 mpfr-unpack
1384 if mpfr-needs-configure; then
1385 mpfr-clean
1386 mpfr-configure
1387 else
1388 SkipBanner "MPFR" "Already configured"
1389 fi
1390
1391 mpfr-install
1392 }
1393
1394 mpfr-needs-configure() {
1395 ! [ -f "${TC_BUILD_MPFR}/config.status" ]
1396 return $?
1397 }
1398
1399 mpfr-clean() {
1400 StepBanner "MPFR" "Clean"
1401 rm -rf "${TC_BUILD_MPFR}"
1402 }
1403
1404 mpfr-unpack() {
1405 if ! [ -d "${TC_SRC_MPFR}" ]; then
1406 mkdir -p "${TC_SRC_MPFR}"
1407 tar -jxf "${THIRD_PARTY_MPFR}" -C "${TC_SRC_MPFR}"
1408 fi
1409 }
1410
1411 mpfr-configure() {
1412 StepBanner "MPFR" "Configure"
1413 mkdir -p "${TC_BUILD_MPFR}"
1414 spushd "${TC_BUILD_MPFR}"
1415
1416 RunWithLog mpfr.configure \
1417 env -i \
1418 PATH="/usr/bin:/bin" \
1419 CC="${CC}" \
1420 CXX="${CXX}" \
1421 "${TC_SRC_MPFR}"/${MPFR_VER}/configure \
1422 --prefix="${MPFR_INSTALL_DIR}" \
1423 --with-gmp="${GMP_INSTALL_DIR}" \
1424 --disable-shared --enable-static
1425 spopd
1426 }
1427
1428 mpfr-install() {
1429 StepBanner "MPFR" "Install"
1430 spushd "${TC_BUILD_MPFR}"
1431 RunWithLog mpfr.install \
1432 env -i PATH=/usr/bin/:/bin \
1433 CC="${CC}" \
1434 CXX="${CXX}" \
1435 make ${MAKE_OPTS} install
1436 spopd
1437 }
1438
1439 ############################### MPC ###############################
1440 #+ mpc - Build and install mpc
1441 mpc() {
1442 mpc-unpack
1443 if mpc-needs-configure; then
1444 mpc-clean
1445 mpc-configure
1446 else
1447 SkipBanner "MPC" "Already configured"
1448 fi
1449 mpc-install
1450 }
1451
1452 mpc-needs-configure() {
1453 ! [ -f "${TC_BUILD_MPC}/config.status" ]
1454 return $?
1455 }
1456
1457 mpc-unpack() {
1458 if ! [ -d "${TC_SRC_MPC}" ]; then
1459 mkdir -p "${TC_SRC_MPC}"
1460 tar -zxf "${THIRD_PARTY_MPC}" -C "${TC_SRC_MPC}"
1461 fi
1462 }
1463
1464 mpc-clean() {
1465 StepBanner "MPC" "Clean"
1466 rm -rf "${TC_BUILD_MPC}"
1467 }
1468
1469 mpc-configure() {
1470 StepBanner "MPC" "Configure"
1471 mkdir -p "${TC_BUILD_MPC}"
1472 spushd "${TC_BUILD_MPC}"
1473 RunWithLog mpc.configure \
1474 env -i \
1475 PATH="/usr/bin:/bin" \
1476 CC="${CC}" \
1477 CXX="${CXX}" \
1478 "${TC_SRC_MPC}"/${MPC_VER}/configure \
1479 --prefix="${MPC_INSTALL_DIR}" \
1480 --with-gmp="${GMP_INSTALL_DIR}" \
1481 --with-mpfr="${MPFR_INSTALL_DIR}" \
1482 --disable-shared --enable-static
1483 spopd
1484 }
1485
1486 mpc-install() {
1487 StepBanner "MPC" "Install"
1488 spushd "${TC_BUILD_MPC}"
1489 RunWithLog mpc.install \
1490 env -i PATH=/usr/bin/:/bin \
1491 CC="${CC}" \
1492 CXX="${CXX}" \
1493 make ${MAKE_OPTS} install
1494 spopd
1495 }
1496
1497
1498 ########################## GCC FRONT-END ############################
1499 #+ gccfe - Build and install the gcc frontend
1500 gccfe() {
1501 StepBanner "GCC FRONTEND"
1502 gccfe-deps
1503 if gccfe-needs-configure ; then
1504 gccfe-clean
1505 gccfe-configure
1506 else
1507 SkipBanner "GCC-FE" "Already configured"
1508 fi
1509 gccfe-make
1510 gccfe-install
1511 dragonegg-plugin
1512 }
1513
1514 gccfe-deps-clean() {
1515 gmp-clean
1516 mpfr-clean
1517 mpc-clean
1518 }
1519
1520 gccfe-deps() {
1521 gmp
1522 mpfr
1523 mpc
1524 }
1525
1526 gccfe-needs-configure() {
1527 [ ! -f "${TC_BUILD_GCC}/config.status" ]
1528 return $?
1529 }
1530
1531 gccfe-clean() {
1532 StepBanner "GCC-FE" "Clean"
1533 rm -rf "${TC_BUILD_GCC}"
1534 }
1535
1536 gccfe-configure() {
1537 StepBanner "GCC-FE" "Configure"
1538 mkdir -p "${TC_BUILD_GCC}"
1539 spushd "${TC_BUILD_GCC}"
1540 RunWithLog gccfe.configure \
1541 env -i \
1542 PATH="/usr/bin:/bin" \
1543 CC="${CC}" \
1544 CXX="${CXX}" \
1545 ${TC_SRC_GCC}/configure \
1546 --prefix="${GCC_INSTALL_DIR}" \
1547 --with-gmp="${GMP_INSTALL_DIR}" \
1548 --with-mpfr="${MPFR_INSTALL_DIR}" \
1549 --with-mpc="${MPC_INSTALL_DIR}" \
1550 --disable-libmudflap \
1551 --disable-decimal-float \
1552 --disable-libssp \
1553 --disable-libgomp \
1554 --disable-multilib \
1555 --disable-libquadmath \
1556 --disable-libquadmath-support \
1557 --enable-languages=c,c++ \
1558 --disable-threads \
1559 --disable-libstdcxx-pch \
1560 --disable-shared \
1561 --without-headers \
1562 --enable-lto \
1563 --enable-plugin \
1564 --target=i686-unknown-linux-gnu
1565 spopd
1566 }
1567
1568 gccfe-make() {
1569 StepBanner "GCC-FE" "Make"
1570 spushd "${TC_BUILD_GCC}"
1571 RunWithLog gccfe.make \
1572 env -i \
1573 PATH="/usr/bin:/bin" \
1574 CC="${CC}" \
1575 CXX="${CXX}" \
1576 make ${MAKE_OPTS} all-gcc
1577 spopd
1578 }
1579
1580 gccfe-install() {
1581 StepBanner "GCC-FE" "Install"
1582 rm -rf "${GCC_INSTALL_DIR}"
1583 spushd "${TC_BUILD_GCC}"
1584 RunWithLog gccfe.install \
1585 env -i \
1586 PATH="/usr/bin:/bin" \
1587 CC="${CC}" \
1588 CXX="${CXX}" \
1589 make ${MAKE_OPTS} install-gcc
1590 spopd
1591 }
1592
1593 #+-------------------------------------------------------------------------
1594 #+ dragonegg-plugin - build and install dragon-egg plugin
1595 dragonegg-plugin() {
1596 StepBanner "DRAGONEGG" "Building and installing plugin"
1597 rm -rf "${TC_BUILD_DRAGONEGG}"
1598 cp -a "${TC_SRC_DRAGONEGG}" "${TC_BUILD_DRAGONEGG}"
1599 spushd "${TC_BUILD_DRAGONEGG}"
1600 RunWithLog dragonegg.make \
1601 env -i \
1602 PATH="/usr/bin:/bin" \
1603 PWD="$(pwd)" \
1604 CC="${CC}" \
1605 CXX="${CXX}" \
1606 CFLAGS="-I${GMP_INSTALL_DIR}/include -L${GMP_INSTALL_DIR}/lib" \
1607 CXXFLAGS="-I${GMP_INSTALL_DIR}/include -L${GMP_INSTALL_DIR}/lib" \
1608 GCC="${GCC_INSTALL_DIR}/bin/i686-unknown-linux-gnu-gcc" \
1609 LLVM_CONFIG="${LLVM_INSTALL_DIR}"/bin/llvm-config \
1610 make ${MAKE_OPTS}
1611 cp dragonegg.so "${GCC_INSTALL_DIR}/lib"
1612 spopd
1613 }
1614
1615 #########################################################################
1616 # < GCC STAGE 1 >
1617 #########################################################################
1618
1619 # Build "pregcc" which is a gcc that does not depend on having glibc/newlib
1620 # already compiled. This also generates some important headers (confirm this).
1621 #
1622 # NOTE: depends on newlib source being set up so we can use it to set
1623 # up a sysroot.
1624 #
1625
1626
1627 LLVM_GCC_SETUP=false
1628 llvm-gcc-setup() {
1629 # If this is an internal invocation, don't setup again.
1630 if ${LLVM_GCC_SETUP} && [ $# -eq 0 ]; then
1631 return 0
1632 fi
1633
1634 if [ $# -ne 1 ] ; then
1635 Fatal "Please specify architecture: x86-32, x86-64, arm"
1636 fi
1637 local arch=$1
1638
1639 case ${arch} in
1640 arm) LLVM_GCC_TARGET=${CROSS_TARGET_ARM} ;;
1641 x86-32) LLVM_GCC_TARGET=${CROSS_TARGET_X86_32} ;;
1642 x86-64) LLVM_GCC_TARGET=${CROSS_TARGET_X86_64} ;;
1643 *) Fatal "Unrecognized architecture ${arch}" ;;
1644 esac
1645 LLVM_GCC_SETUP=true
1646 LLVM_GCC_ARCH=${arch}
1647 LLVM_GCC_BUILD_DIR="${TC_BUILD_LLVM_GCC}-${LLVM_GCC_ARCH}"
1648 return 0
1649 }
1650
1651 #+-------------------------------------------------------------------------
1652 #+ llvm-gcc - build and install pre-gcc
1653 llvm-gcc() {
1654 llvm-gcc-setup "$@"
1655 StepBanner "LLVM-GCC (HOST) for ${LLVM_GCC_ARCH}"
1656
1657 if llvm-gcc-needs-configure; then
1658 llvm-gcc-clean
1659 llvm-gcc-configure
1660 else
1661 SkipBanner "LLVM-GCC ${LLVM_GCC_ARCH}" "configure"
1662 fi
1663
1664 # We must always make before we do make install, because
1665 # the build must occur in a patched environment.
1666 # http://code.google.com/p/nativeclient/issues/detail?id=1128
1667 llvm-gcc-make
1668
1669 llvm-gcc-install
1670 }
1671
1672 #+ sysroot - setup initial sysroot
1673 sysroot() {
1674 StepBanner "LLVM-GCC" "Setting up initial sysroot"
1675
1676 local sys_include="${SYSROOT_DIR}/include"
1677 local sys_include2="${SYSROOT_DIR}/sys-include"
1678
1679 rm -rf "${sys_include}" "${sys_include2}"
1680 mkdir -p "${sys_include}"
1681 ln -sf "${sys_include}" "${sys_include2}"
1682 cp -r "${NEWLIB_INCLUDE_DIR}"/* "${sys_include}"
1683 }
1684
1685 #+ llvm-gcc-clean - Clean gcc stage 1
1686 llvm-gcc-clean() {
1687 llvm-gcc-setup "$@"
1688 StepBanner "LLVM-GCC" "Clean"
1689 local objdir="${LLVM_GCC_BUILD_DIR}"
1690 rm -rf "${objdir}"
1691 }
1692
1693 llvm-gcc-needs-configure() {
1694 llvm-gcc-setup "$@"
1695 speculative-check "llvm" && return 0
1696 ts-newer-than "${TC_BUILD_LLVM}" \
1697 "${LLVM_GCC_BUILD_DIR}" && return 0
1698 [ ! -f "${LLVM_GCC_BUILD_DIR}/config.status" ]
1699 return $?
1700 }
1701
1702 #+ llvm-gcc-configure - Configure GCC stage 1
1703 llvm-gcc-configure() {
1704 llvm-gcc-setup "$@"
1705 StepBanner "LLVM-GCC" "Configure ${LLVM_GCC_TARGET}"
1706
1707 local srcdir="${TC_SRC_LLVM_GCC}"
1708 local objdir="${LLVM_GCC_BUILD_DIR}"
1709
1710 mkdir -p "${objdir}"
1711 spushd "${objdir}"
1712
1713 # NOTE: hack, assuming presence of x86/32 toolchain (used for both 32/64)
1714 local config_opts=""
1715 case ${LLVM_GCC_ARCH} in
1716 arm)
1717 config_opts="--with-as=${PNACL_AS_ARM} \
1718 --with-arch=${ARM_ARCH} \
1719 --with-fpu=${ARM_FPU}"
1720 ;;
1721 x86-32)
1722 config_opts="--with-as=${PNACL_AS_X8632}"
1723 ;;
1724 x86-64)
1725 config_opts="--with-as=${PNACL_AS_X8664}"
1726 ;;
1727 esac
1728
1729 local flags=""
1730 if ${LIBMODE_NEWLIB}; then
1731 flags+="--with-newlib"
1732 fi
1733
1734 RunWithLog llvm-pregcc-${LLVM_GCC_ARCH}.configure \
1735 env -i PATH=/usr/bin/:/bin \
1736 CC="${CC}" \
1737 CXX="${CXX}" \
1738 CFLAGS="-Dinhibit_libc" \
1739 AR_FOR_TARGET="${PNACL_AR}" \
1740 RANLIB_FOR_TARGET="${PNACL_RANLIB}" \
1741 NM_FOR_TARGET="${PNACL_NM}" \
1742 ${srcdir}/configure \
1743 --prefix="${LLVM_GCC_INSTALL_DIR}" \
1744 --enable-llvm="${LLVM_INSTALL_DIR}" \
1745 ${flags} \
1746 --disable-libmudflap \
1747 --disable-decimal-float \
1748 --disable-libssp \
1749 --disable-libgomp \
1750 --disable-multilib \
1751 --enable-languages=c,c++ \
1752 --disable-threads \
1753 --disable-libstdcxx-pch \
1754 --disable-shared \
1755 --without-headers \
1756 ${config_opts} \
1757 --target=${LLVM_GCC_TARGET}
1758
1759 spopd
1760 }
1761
1762 llvm-gcc-make() {
1763 llvm-gcc-setup "$@"
1764 local srcdir="${TC_SRC_LLVM_GCC}"
1765 local objdir="${LLVM_GCC_BUILD_DIR}"
1766 spushd ${objdir}
1767
1768 StepBanner "LLVM-GCC" "Make (Stage 1)"
1769
1770 ts-touch-open "${objdir}"
1771
1772 RunWithLog llvm-pregcc-${LLVM_GCC_ARCH}.make \
1773 env -i PATH=/usr/bin/:/bin \
1774 CC="${CC}" \
1775 CXX="${CXX}" \
1776 CFLAGS="-Dinhibit_libc" \
1777 make ${MAKE_OPTS} all-gcc
1778
1779 ts-touch-commit "${objdir}"
1780
1781 spopd
1782 }
1783
1784 #+ llvm-gcc-install - Install GCC stage 1
1785 llvm-gcc-install() {
1786 llvm-gcc-setup "$@"
1787 StepBanner "LLVM-GCC" "Install ${LLVM_GCC_ARCH}"
1788
1789 local objdir="${LLVM_GCC_BUILD_DIR}"
1790 spushd "${objdir}"
1791
1792 RunWithLog llvm-pregcc-${LLVM_GCC_ARCH}.install \
1793 env -i PATH=/usr/bin/:/bin \
1794 CC="${CC}" \
1795 CXX="${CXX}" \
1796 CFLAGS="-Dinhibit_libc" \
1797 make ${MAKE_OPTS} install
1798
1799 spopd
1800 }
1801
1802 #########################################################################
1803 #########################################################################
1804 # < LIBGCC_EH >
1805 #########################################################################
1806 #########################################################################
1807
1808 #+ build-libgcc_eh - build/install libgcc_eh
1809 build-libgcc_eh() {
1810 # TODO(pdox): This process needs some major renovation.
1811 # We are using the llvm-gcc ARM build directory, but varying '-arch'
1812 # to get different versions of libgcc_eh.
1813 # NOTE: For simplicity we piggyback the libgcc_eh build onto a preconfigured
1814 # objdir. So, to be safe, you have to run gcc-stage1-make first
1815 local arch=$1
1816 local srcdir="${TC_SRC_LLVM_GCC}"
1817 local objdir="${TC_BUILD_LLVM_GCC}-arm"
1818 spushd "${objdir}"/gcc
1819 StepBanner "libgcc_eh-${arch}" "cleaning"
1820 RunWithLog libgcc_eh.clean \
1821 env -i PATH=/usr/bin/:/bin \
1822 make clean-target-libgcc
1823 rm -f "${objdir}"/gcc/libgcc_eh.a
1824
1825 # NOTE: usually gcc/libgcc.mk is generate and invoked implicitly by
1826 # gcc/Makefile.
1827 # Since we are calling it directly we need to make up for some
1828 # missing flags, e.g. include paths ann defines like
1829 # 'ATTRIBUTE_UNUSED' which is used to mark unused function
1830 # parameters.
1831 # The arguments were gleaned from build logs.
1832 StepBanner "libgcc_eh-${arch}" "building ($1)"
1833 local flags
1834 flags="-arch ${arch} --pnacl-bias=${arch} --pnacl-allow-translate"
1835 flags+=" -DATTRIBUTE_UNUSED= -DHOST_BITS_PER_INT=32 -Dinhibit_libc"
1836 flags+=" -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE "
1837
1838 setup-libstdcpp-env
1839 RunWithLog libgcc_eh.${arch}.make \
1840 env -i PATH=/usr/bin/:/bin \
1841 "${STD_ENV_FOR_LIBSTDCPP[@]}" \
1842 "INCLUDES=-I${srcdir}/include -I${srcdir}/gcc -I." \
1843 "LIBGCC2_CFLAGS=${flags}" \
1844 "AR_CREATE_FOR_TARGET=${PNACL_AR} rc" \
1845 make ${MAKE_OPTS} -f libgcc.mk libgcc_eh.a
1846 spopd
1847
1848 StepBanner "libgcc_eh-${arch}" "installing"
1849 mkdir -p "${INSTALL_LIB}-${arch}"
1850 cp "${objdir}"/gcc/libgcc_eh.a "${INSTALL_LIB}-${arch}"
1851 }
1852
1853 #########################################################################
1854 #########################################################################
1855 # < COMPILER-RT >
1856 #########################################################################
1857 #########################################################################
1858
1859 #+ build-compiler-rt - build/install llvm's replacement for libgcc.a
1860 build-compiler-rt() {
1861 local src="${TC_SRC_COMPILER_RT}/compiler-rt/lib"
1862 mkdir -p "${TC_BUILD_COMPILER_RT}"
1863 spushd "${TC_BUILD_COMPILER_RT}"
1864 StepBanner "COMPILER-RT (LIBGCC)"
1865 for arch in arm x86-32 x86-64; do
1866 StepBanner "compiler rt" "build ${arch}"
1867 rm -rf "${arch}"
1868 mkdir -p "${arch}"
1869 spushd "${arch}"
1870 RunWithLog libgcc.${arch}.make \
1871 make -j ${UTMAN_CONCURRENCY} -f ${src}/Makefile-pnacl libgcc.a \
1872 CC="${PNACL_CC}" \
1873 AR="${PNACL_AR}" \
1874 "SRC_DIR=${src}" \
1875 "CFLAGS=-arch ${arch} --pnacl-allow-translate -O3 -fPIC"
1876 spopd
1877 done
1878
1879 StepBanner "compiler rt" "install all"
1880 ls -l */libgcc.a
1881
1882 mkdir -p "${INSTALL_LIB_ARM}"
1883 cp arm/libgcc.a "${INSTALL_LIB_ARM}/"
1884
1885 mkdir -p "${INSTALL_LIB_X8632}"
1886 cp x86-32/libgcc.a "${INSTALL_LIB_X8632}/"
1887
1888 mkdir -p "${INSTALL_LIB_X8664}"
1889 cp x86-64/libgcc.a "${INSTALL_LIB_X8664}/"
1890 spopd
1891 }
1892
1893 #########################################################################
1894 #########################################################################
1895 # < LIBSTDCPP >
1896 #########################################################################
1897 #########################################################################
1898
1899 libstdcpp() {
1900 StepBanner "LIBSTDCPP (BITCODE)"
1901
1902 if libstdcpp-needs-configure; then
1903 libstdcpp-clean
1904 libstdcpp-configure
1905 else
1906 SkipBanner "LIBSTDCPP" "configure"
1907 fi
1908
1909 if libstdcpp-needs-make; then
1910 libstdcpp-make
1911 else
1912 SkipBanner "LIBSTDCPP" "make"
1913 fi
1914
1915 libstdcpp-install
1916 reset-frontend
1917 }
1918
1919 #+ libstdcpp-clean - clean libstdcpp in bitcode
1920 libstdcpp-clean() {
1921 StepBanner "LIBSTDCPP" "Clean"
1922 rm -rf "${TC_BUILD_LIBSTDCPP}"
1923 }
1924
1925 libstdcpp-needs-configure() {
1926 speculative-check "llvm-gcc" && return 0
1927 ts-newer-than "${TC_BUILD_LLVM_GCC}-${CROSS_TARGET_ARM}" \
1928 "${TC_BUILD_LIBSTDCPP}" && return 0
1929 [ ! -f "${TC_BUILD_LIBSTDCPP}/config.status" ]
1930 return #?
1931 }
1932
1933 libstdcpp-configure() {
1934 StepBanner "LIBSTDCPP" "Configure"
1935 local srcdir="${TC_SRC_LIBSTDCPP}"
1936 local objdir="${TC_BUILD_LIBSTDCPP}"
1937
1938 mkdir -p "${objdir}"
1939 spushd "${objdir}"
1940
1941 local flags=""
1942 if ${LIBMODE_NEWLIB}; then
1943 flags+="--with-newlib --disable-shared"
1944 elif ${LIBMODE_GLIBC}; then
1945 # TODO(pdox): Fix right away.
1946 flags+="--disable-shared"
1947 else
1948 Fatal "Unknown library mode"
1949 fi
1950
1951 setup-libstdcpp-env
1952 RunWithLog llvm-gcc.configure_libstdcpp \
1953 env -i PATH=/usr/bin/:/bin \
1954 "${STD_ENV_FOR_LIBSTDCPP[@]}" \
1955 "${srcdir}"/configure \
1956 --host="${CROSS_TARGET_ARM}" \
1957 --prefix="${LIBSTDCPP_INSTALL_DIR}" \
1958 --enable-llvm="${LLVM_INSTALL_DIR}" \
1959 ${flags} \
1960 --disable-libstdcxx-pch \
1961 --enable-languages=c,c++ \
1962 --target=${CROSS_TARGET_ARM} \
1963 --with-arch=${ARM_ARCH} \
1964 --srcdir="${srcdir}"
1965 spopd
1966 }
1967
1968 libstdcpp-needs-make() {
1969 local srcdir="${TC_SRC_LIBSTDCPP}"
1970 local objdir="${TC_BUILD_LIBSTDCPP}"
1971
1972 ts-modified "${srcdir}" "${objdir}"
1973 return $?
1974 }
1975
1976 libstdcpp-make() {
1977 StepBanner "LIBSTDCPP" "Make"
1978 local srcdir="${TC_SRC_LIBSTDCPP}"
1979 local objdir="${TC_BUILD_LIBSTDCPP}"
1980
1981 ts-touch-open "${objdir}"
1982
1983 spushd "${objdir}"
1984 setup-libstdcpp-env
1985 RunWithLog llvm-gcc.make_libstdcpp \
1986 env -i PATH=/usr/bin/:/bin \
1987 make \
1988 "${STD_ENV_FOR_LIBSTDCPP[@]}" \
1989 ${MAKE_OPTS}
1990 spopd
1991
1992 ts-touch-commit "${objdir}"
1993 }
1994
1995 libstdcpp-install() {
1996 StepBanner "LIBSTDCPP" "Install"
1997 local objdir="${TC_BUILD_LIBSTDCPP}"
1998
1999 spushd "${objdir}"
2000
2001 # install headers (=install-data)
2002 # for good measure make sure we do not keep any old headers
2003 rm -rf "${INSTALL_ROOT}/include/c++"
2004 setup-libstdcpp-env
2005 RunWithLog llvm-gcc.install_libstdcpp \
2006 make \
2007 "${STD_ENV_FOR_LIBSTDCPP[@]}" \
2008 ${MAKE_OPTS} install-data
2009
2010 # Install bitcode library
2011 mkdir -p "${INSTALL_LIB}"
2012 cp "${objdir}/src/.libs/libstdc++.a" "${INSTALL_LIB}"
2013
2014 spopd
2015 }
2016
2017 #+ misc-tools - Build and install sel_ldr and validator for ARM.
2018 misc-tools() {
2019 if ${UTMAN_BUILD_ARM} ; then
2020 StepBanner "MISC-ARM" "Building sel_ldr (ARM)"
2021
2022 # TODO(robertm): revisit some of these options
2023 RunWithLog arm_sel_ldr \
2024 ./scons MODE=opt-host \
2025 platform=arm \
2026 sdl=none \
2027 naclsdk_validate=0 \
2028 sysinfo=0 \
2029 sel_ldr
2030 rm -rf "${INSTALL_ROOT}/tools-arm"
2031 mkdir "${INSTALL_ROOT}/tools-arm"
2032 local sconsdir="scons-out/opt-${SCONS_BUILD_PLATFORM}-arm"
2033 cp "${sconsdir}/obj/src/trusted/service_runtime/sel_ldr" \
2034 "${INSTALL_ROOT}/tools-arm"
2035 else
2036 StepBanner "MISC-ARM" "Skipping ARM sel_ldr (No trusted ARM toolchain)"
2037 fi
2038
2039 if ${BUILD_PLATFORM_LINUX} ; then
2040 StepBanner "MISC-ARM" "Building validator (ARM)"
2041 RunWithLog arm_ncval_core \
2042 ./scons MODE=opt-host \
2043 targetplatform=arm \
2044 sysinfo=0 \
2045 arm-ncval-core
2046 rm -rf "${INSTALL_ROOT}/tools-x86"
2047 mkdir "${INSTALL_ROOT}/tools-x86"
2048 cp scons-out/opt-linux-x86-32-to-arm/obj/src/trusted/validator_arm/\
2049 arm-ncval-core ${INSTALL_ROOT}/tools-x86
2050 else
2051 StepBanner "MISC-ARM" "Skipping ARM validator (Not yet supported on Mac)"
2052 fi
2053 }
2054
2055
2056 #########################################################################
2057 # < BINUTILS >
2058 #########################################################################
2059
2060 #+-------------------------------------------------------------------------
2061 #+ binutils - Build and install binutils for ARM
2062 binutils() {
2063 StepBanner "BINUTILS (HOST)"
2064
2065 local srcdir="${TC_SRC_BINUTILS}"
2066
2067 assert-dir "${srcdir}" "You need to checkout binutils."
2068
2069 if binutils-needs-configure; then
2070 binutils-clean
2071 binutils-configure
2072 else
2073 SkipBanner "BINUTILS" "configure"
2074 fi
2075
2076 if binutils-needs-make; then
2077 binutils-make
2078 else
2079 SkipBanner "BINUTILS" "make"
2080 fi
2081
2082 binutils-install
2083 }
2084
2085 #+ binutils-clean - Clean binutils
2086 binutils-clean() {
2087 StepBanner "BINUTILS" "Clean"
2088 local objdir="${TC_BUILD_BINUTILS}"
2089 rm -rf ${objdir}
2090 }
2091
2092 #+ binutils-configure- Configure binutils for ARM
2093 binutils-configure() {
2094 StepBanner "BINUTILS" "Configure"
2095
2096 local srcdir="${TC_SRC_BINUTILS}"
2097 local objdir="${TC_BUILD_BINUTILS}"
2098
2099 # enable multiple targets so that we can use the same ar with all .o files
2100 local targ="arm-pc-nacl,i686-pc-nacl,x86_64-pc-nacl"
2101 mkdir -p "${objdir}"
2102 spushd "${objdir}"
2103
2104 # The --enable-gold and --enable-plugins options are on so that we
2105 # can use gold's support for plugin to link PNaCl modules.
2106
2107 # TODO(pdox): Building binutils for nacl/nacl64 target currently requires
2108 # providing NACL_ALIGN_* defines. This should really be defined inside
2109 # binutils instead.
2110 RunWithLog binutils.configure \
2111 env -i \
2112 PATH="/usr/bin:/bin" \
2113 CC="${CC}" \
2114 CXX="${CXX}" \
2115 CFLAGS="-DNACL_ALIGN_BYTES=32 -DNACL_ALIGN_POW2=5" \
2116 ${srcdir}/binutils-2.20/configure --prefix="${BINUTILS_INSTALL_DIR}" \
2117 --target=${BINUTILS_TARGET} \
2118 --enable-targets=${targ} \
2119 --enable-gold=yes \
2120 --enable-ld=yes \
2121 --enable-plugins \
2122 --disable-werror \
2123 --with-sysroot="${NONEXISTENT_PATH}"
2124 # There's no point in setting the correct path as sysroot, because we
2125 # want the toolchain to be relocatable. The driver will use ld command-line
2126 # option --sysroot= to override this value and set it to the correct path.
2127 # However, we need to include --with-sysroot during configure to get this
2128 # option. So fill in a non-sense, non-existent path.
2129
2130 spopd
2131 }
2132
2133 binutils-needs-configure() {
2134 [ ! -f "${TC_BUILD_BINUTILS}/config.status" ]
2135 return $?
2136 }
2137
2138 binutils-needs-make() {
2139 local srcdir="${TC_SRC_BINUTILS}"
2140 local objdir="${TC_BUILD_BINUTILS}"
2141 local ret=1
2142 binutils-mess-hide
2143 ts-modified "$srcdir" "$objdir" && ret=0
2144 binutils-mess-unhide
2145 return ${ret}
2146 }
2147
2148 #+ binutils-make - Make binutils for ARM
2149 binutils-make() {
2150 StepBanner "BINUTILS" "Make"
2151 local srcdir="${TC_SRC_BINUTILS}"
2152 local objdir="${TC_BUILD_BINUTILS}"
2153 spushd "${objdir}"
2154
2155 ts-touch-open "${objdir}"
2156
2157 RunWithLog binutils.make \
2158 env -i PATH="/usr/bin:/bin" \
2159 make ${MAKE_OPTS}
2160
2161 ts-touch-commit "${objdir}"
2162
2163 spopd
2164 }
2165
2166 #+ binutils-install - Install binutils for ARM
2167 binutils-install() {
2168 StepBanner "BINUTILS" "Install"
2169 local objdir="${TC_BUILD_BINUTILS}"
2170 spushd "${objdir}"
2171
2172 RunWithLog binutils.install \
2173 env -i PATH="/usr/bin:/bin" \
2174 make \
2175 install ${MAKE_OPTS}
2176
2177 spopd
2178 }
2179
2180 #+-------------------------------------------------------------------------
2181 #+ binutils-liberty - Build native binutils libiberty
2182 binutils-liberty() {
2183 local srcdir="${TC_SRC_BINUTILS}"
2184
2185 assert-dir "${srcdir}" "You need to checkout binutils."
2186
2187 if binutils-liberty-needs-configure; then
2188 binutils-liberty-clean
2189 binutils-liberty-configure
2190 else
2191 SkipBanner "BINUTILS-LIBERTY" "configure"
2192 fi
2193
2194 if binutils-liberty-needs-make; then
2195 binutils-liberty-make
2196 else
2197 SkipBanner "BINUTILS-LIBERTY" "make"
2198 fi
2199 }
2200
2201 binutils-liberty-needs-configure() {
2202 [ ! -f "${TC_BUILD_BINUTILS_LIBERTY}/config.status" ]
2203 return $?
2204 }
2205
2206 #+ binutils-liberty-clean - Clean binutils-liberty
2207 binutils-liberty-clean() {
2208 StepBanner "BINUTILS-LIBERTY" "Clean"
2209 local objdir="${TC_BUILD_BINUTILS_LIBERTY}"
2210 rm -rf ${objdir}
2211 }
2212
2213 #+ binutils-liberty-configure - Configure binutils-liberty
2214 binutils-liberty-configure() {
2215 StepBanner "BINUTILS-LIBERTY" "Configure"
2216
2217 local srcdir="${TC_SRC_BINUTILS}"
2218 local objdir="${TC_BUILD_BINUTILS_LIBERTY}"
2219
2220 mkdir -p "${objdir}"
2221 spushd "${objdir}"
2222 RunWithLog binutils.liberty.configure \
2223 env -i \
2224 PATH="/usr/bin:/bin" \
2225 CC="${CC}" \
2226 CXX="${CXX}" \
2227 ${srcdir}/binutils-2.20/configure
2228 spopd
2229 }
2230
2231 binutils-liberty-needs-make() {
2232 local srcdir="${TC_SRC_BINUTILS}"
2233 local objdir="${TC_BUILD_BINUTILS_LIBERTY}"
2234
2235 ts-modified "$srcdir" "$objdir"
2236 return $?
2237 }
2238
2239 #+ binutils-liberty-make - Make binutils-liberty
2240 binutils-liberty-make() {
2241 StepBanner "BINUTILS-LIBERTY" "Make"
2242 local srcdir="${TC_SRC_BINUTILS}"
2243 local objdir="${TC_BUILD_BINUTILS_LIBERTY}"
2244 spushd "${objdir}"
2245
2246 ts-touch-open "${objdir}"
2247
2248 RunWithLog binutils.liberty.make \
2249 env -i \
2250 PATH="/usr/bin:/bin" \
2251 CC="${CC}" \
2252 CXX="${CXX}" \
2253 make ${MAKE_OPTS} all-libiberty
2254
2255 ts-touch-commit "${objdir}"
2256
2257 spopd
2258 }
2259
2260 #########################################################################
2261 # CLIENT BINARIES (SANDBOXED)
2262 #########################################################################
2263
2264 check-sb-mode() {
2265 local mode=$1
2266 if [ ${mode} != "srpc" ] && [ ${mode} != "nonsrpc" ]; then
2267 echo "ERROR: Unsupported mode. Choose one of: srpc, nonsrpc"
2268 exit -1
2269 fi
2270 }
2271
2272 check-sb-arch() {
2273 local arch=$1
2274 for valid_arch in x8632 x8664 arm universal ; do
2275 if [ "${arch}" == "${valid_arch}" ] ; then
2276 return
2277 fi
2278 done
2279
2280 Fatal "ERROR: Unsupported arch. Choose one of: x8632, x8664, arm, universal"
2281 }
2282
2283 LLVM_SB_SETUP=false
2284 llvm-sb-setup() {
2285 local flags=""
2286 if ${SB_JIT}; then
2287 llvm-sb-setup-jit "$@"
2288 return
2289 fi
2290
2291 if ${LLVM_SB_SETUP} && [ $# -eq 0 ]; then
2292 return 0
2293 fi
2294
2295 if [ $# -ne 2 ] ; then
2296 Fatal "Please specify arch and mode"
2297 fi
2298
2299 LLVM_SB_SETUP=true
2300
2301 LLVM_SB_ARCH=$1
2302 LLVM_SB_MODE=$2
2303 check-sb-arch ${LLVM_SB_ARCH}
2304 check-sb-mode ${LLVM_SB_MODE}
2305
2306 LLVM_SB_LOG_PREFIX="llvm.sb.${LLVM_SB_ARCH}.${LLVM_SB_MODE}"
2307 LLVM_SB_OBJDIR="${TC_BUILD}/llvm-sb-${LLVM_SB_ARCH}-${LLVM_SB_MODE}"
2308 if ${LIBMODE_NEWLIB}; then
2309 flags+=" -static"
2310 fi
2311
2312 case ${LLVM_SB_MODE} in
2313 srpc) flags+=" -DNACL_SRPC" ;;
2314 nonsrpc) ;;
2315 esac
2316
2317 # Speed things up by avoiding an intermediate step
2318 flags+=" --pnacl-skip-ll"
2319
2320 LLVM_SB_EXTRA_CONFIG_FLAGS="--disable-jit --enable-optimized \
2321 --target=${CROSS_TARGET_ARM}"
2322
2323 if ${LIBMODE_GLIBC} ; then
2324 prefer-frontend clang
2325 else
2326 prefer-frontend llvm-gcc
2327 fi
2328
2329 LLVM_SB_CONFIGURE_ENV=(
2330 AR="${PNACL_AR}" \
2331 AS="${PNACL_AS}" \
2332 CC="${PNACL_CC} ${flags}" \
2333 CXX="${PNACL_CXX} ${flags}" \
2334 LD="${PNACL_LD} ${flags}" \
2335 NM="${PNACL_NM}" \
2336 RANLIB="${PNACL_RANLIB}" \
2337 LDFLAGS="") # TODO(pdox): Support -s
2338
2339 reset-frontend
2340 }
2341
2342 llvm-sb-setup-jit() {
2343 local flags=""
2344
2345 if ${LLVM_SB_SETUP} && [ $# -eq 0 ]; then
2346 return 0
2347 fi
2348
2349 if [ $# -ne 2 ] ; then
2350 Fatal "Please specify arch and mode"
2351 fi
2352
2353 LLVM_SB_SETUP=true
2354
2355 LLVM_SB_ARCH=$1
2356 LLVM_SB_MODE=$2
2357 check-sb-arch ${LLVM_SB_ARCH}
2358 check-sb-mode ${LLVM_SB_MODE}
2359
2360 LLVM_SB_LOG_PREFIX="llvm.sb.${LLVM_SB_ARCH}.${LLVM_SB_MODE}.jit"
2361 LLVM_SB_OBJDIR="${TC_BUILD}/llvm-sb-${LLVM_SB_ARCH}-${LLVM_SB_MODE}.jit"
2362 case ${LLVM_SB_MODE} in
2363 srpc) flags+=" -DNACL_SRPC" ;;
2364 nonsrpc) ;;
2365 esac
2366
2367 local naclgcc_root="";
2368 naclgcc_root="${NNACL_GLIBC_ROOT}"
2369
2370 LLVM_SB_EXTRA_CONFIG_FLAGS="--enable-jit --disable-optimized \
2371 --target=${LLVM_SB_ARCH}-nacl"
2372
2373 LLVM_SB_CONFIGURE_ENV=(
2374 AR="${naclgcc_root}/bin/i686-nacl-ar" \
2375 As="${naclgcc_root}/bin/i686-nacl-as" \
2376 CC="${naclgcc_root}/bin/i686-nacl-gcc ${flags}" \
2377 CXX="${naclgcc_root}/bin/i686-nacl-g++ ${flags}" \
2378 LD="${naclgcc_root}/bin/i686-nacl-ld" \
2379 NM="${naclgcc_root}/bin/i686-nacl-nm" \
2380 RANLIB="${naclgcc_root}/bin/i686-nacl-ranlib" \
2381 LDFLAGS="") # TODO(pdox): Support -s
2382 }
2383
2384 #+-------------------------------------------------------------------------
2385 #+ llvm-sb <arch> <mode> - Build and install llvm tools (sandboxed)
2386 llvm-sb() {
2387 llvm-sb-setup "$@"
2388 local srcdir="${TC_SRC_LLVM}"
2389 assert-dir "${srcdir}" "You need to checkout llvm."
2390
2391 if llvm-sb-needs-configure ; then
2392 llvm-sb-clean
2393 llvm-sb-configure
2394 else
2395 SkipBanner "LLVM-SB" "configure ${LLVM_SB_ARCH} ${LLVM_SB_MODE}"
2396 fi
2397
2398 if llvm-sb-needs-make; then
2399 llvm-sb-make
2400 else
2401 SkipBanner "LLVM-SB" "make"
2402 fi
2403
2404 llvm-sb-install
2405 }
2406
2407 llvm-sb-needs-configure() {
2408 llvm-sb-setup "$@"
2409 [ ! -f "${LLVM_SB_OBJDIR}/config.status" ]
2410 return $?
2411 }
2412
2413 # llvm-sb-clean - Clean llvm tools (sandboxed)
2414 llvm-sb-clean() {
2415 llvm-sb-setup "$@"
2416 StepBanner "LLVM-SB" "Clean ${LLVM_SB_ARCH} ${LLVM_SB_MODE}"
2417 local objdir="${LLVM_SB_OBJDIR}"
2418
2419 rm -rf "${objdir}"
2420 mkdir -p "${objdir}"
2421 }
2422
2423 # llvm-sb-configure - Configure llvm tools (sandboxed)
2424 llvm-sb-configure() {
2425 llvm-sb-setup "$@"
2426
2427 StepBanner "LLVM-SB" "Configure ${LLVM_SB_ARCH} ${LLVM_SB_MODE}"
2428 local srcdir="${TC_SRC_LLVM}"
2429 local objdir="${LLVM_SB_OBJDIR}"
2430 local installdir="${INSTALL_SB_TOOLS}/${LLVM_SB_ARCH}/${LLVM_SB_MODE}"
2431 local targets=""
2432 case ${LLVM_SB_ARCH} in
2433 x8632) targets=x86 ;;
2434 x8664) targets=x86_64 ;;
2435 arm) targets=arm ;;
2436 universal) targets=x86,x86_64,arm ;;
2437 esac
2438
2439 spushd "${objdir}"
2440 RunWithLog \
2441 ${LLVM_SB_LOG_PREFIX}.configure \
2442 env -i \
2443 PATH="/usr/bin:/bin" \
2444 ${srcdir}/configure \
2445 "${LLVM_SB_CONFIGURE_ENV[@]}" \
2446 --prefix=${installdir} \
2447 --host=nacl \
2448 --enable-targets=${targets} \
2449 --enable-pic=no \
2450 --enable-static \
2451 --enable-shared=no \
2452 ${LLVM_SB_EXTRA_CONFIG_FLAGS}
2453 spopd
2454 }
2455
2456 llvm-sb-needs-make() {
2457 llvm-sb-setup "$@"
2458 ts-modified "${TC_SRC_LLVM}" "${LLVM_SB_OBJDIR}"
2459 return $?
2460 }
2461
2462 # llvm-sb-make - Make llvm tools (sandboxed)
2463 llvm-sb-make() {
2464 llvm-sb-setup "$@"
2465
2466 StepBanner "LLVM-SB" "Make ${LLVM_SB_ARCH} ${LLVM_SB_MODE}"
2467 local objdir="${LLVM_SB_OBJDIR}"
2468
2469 spushd "${objdir}"
2470 ts-touch-open "${objdir}"
2471
2472 local build_with_srpc=0
2473 if [ "${LLVM_SB_MODE}" == "srpc" ]; then
2474 build_with_srpc=1
2475 fi
2476
2477 local use_tcmalloc=0
2478 # TODO(dschuff): Decide whether we should switch back to tcmalloc
2479 #if ${LIBMODE_NEWLIB} && ! ${SB_JIT}; then
2480 # # only use tcmalloc with newlib (glibc malloc should be pretty good)
2481 # # (also, SB_JIT implies building with glibc, but for now it uses nacl-gcc)
2482 # use_tcmalloc=1
2483 #fi
2484
2485 RunWithLog ${LLVM_SB_LOG_PREFIX}.make \
2486 env -i PATH="/usr/bin:/bin" \
2487 ONLY_TOOLS="llc lli"\
2488 NACL_SANDBOX=1 \
2489 NACL_SRPC=${build_with_srpc} \
2490 KEEP_SYMBOLS=1 \
2491 VERBOSE=1 \
2492 make USE_TCMALLOC=$use_tcmalloc \
2493 ${MAKE_OPTS} tools-only
2494
2495 ts-touch-commit "${objdir}"
2496
2497 spopd
2498 }
2499
2500 # llvm-sb-install - Install llvm tools (sandboxed)
2501 llvm-sb-install() {
2502 llvm-sb-setup "$@"
2503
2504 StepBanner "LLVM-SB" "Install ${LLVM_SB_ARCH} ${LLVM_SB_MODE}"
2505 local objdir="${LLVM_SB_OBJDIR}"
2506 spushd "${objdir}"
2507
2508 RunWithLog ${LLVM_SB_LOG_PREFIX}.install \
2509 env -i PATH="/usr/bin:/bin" \
2510 ONLY_TOOLS="llc lli"\
2511 NACL_SANDBOX=1 \
2512 KEEP_SYMBOLS=1 \
2513 make ${MAKE_OPTS} install
2514
2515 spopd
2516
2517 if ! ${SB_JIT} ; then
2518 translate-and-install-sb-tool ${LLVM_SB_ARCH} ${LLVM_SB_MODE} llc
2519 else
2520 install-naclgcc-tool ${LLVM_SB_ARCH} ${LLVM_SB_MODE} llc
2521 install-naclgcc-tool ${LLVM_SB_ARCH} ${LLVM_SB_MODE} lli
2522 fi
2523 }
2524
2525 install-naclgcc-tool() {
2526 local arch=$1
2527 local mode=$2
2528 local name=$3
2529
2530 local bindir="${INSTALL_SB_TOOLS}/${arch}/${mode}/bin"
2531 local tarch=x8632
2532 mv "${bindir}/${name}" "${bindir}/${name}.${tarch}.nexe"
2533
2534 local bindir_tarch="${INSTALL_SB_TOOLS}/${tarch}/${mode}/bin"
2535 local nexe="${bindir}/${name}.${tarch}.nexe"
2536 mkdir -p "${bindir_tarch}"
2537 cp -f "${nexe}" "${bindir_tarch}/${name}"
2538 }
2539
2540 translate-and-install-sb-tool() {
2541 local arch=$1
2542 local mode=$2
2543 local name=$3
2544
2545 # Translate bitcode program into an actual native executable.
2546 # If arch = universal, we need to translate and install multiple times.
2547 local bindir="${INSTALL_SB_TOOLS}/${arch}/${mode}/bin"
2548 local pexe="${bindir}/${name}.pexe"
2549
2550 # Rename to .pexe
2551 mv "${bindir}/${name}" "${pexe}"
2552
2553 local arches
2554 if [ "${arch}" == "universal" ]; then
2555 arches="${SBTC_BUILD_WITH_PNACL}"
2556 else
2557 arches="${arch}"
2558 fi
2559
2560 local installer
2561 if [ "${arch}" == "universal" ]; then
2562 installer="cp -f"
2563 else
2564 installer="mv -f"
2565 fi
2566
2567 # In universal/mode/bin directory, we'll end up with every translation:
2568 # e.g. ${name}.arm.nexe, ${name}.x8632.nexe, ${name}.x8664.nexe
2569 # In arch/mode/bin directories, we'll end up with just one copy
2570 local num_arches=$(wc -w <<< "${arches}")
2571 local extra=""
2572 if [ ${num_arches} -gt 1 ] && QueueConcurrent; then
2573 extra=" (background)"
2574 fi
2575
2576 for tarch in ${arches}; do
2577 local nexe="${bindir}/${name}.${tarch}.nexe"
2578 StepBanner "TRANSLATE" "Translating ${name}.pexe to ${tarch}${extra}"
2579 "${PNACL_TRANSLATE}" -arch ${tarch} "${pexe}" -o "${nexe}" &
2580 QueueLastProcess
2581 done
2582
2583 if [ ${num_arches} -gt 1 ] && ! QueueEmpty ; then
2584 StepBanner "TRANSLATE" "Waiting for processes to finish"
2585 fi
2586 QueueWait
2587
2588 for tarch in ${arches}; do
2589 local nexe="${bindir}/${name}.${tarch}.nexe"
2590 local bindir_tarch="${INSTALL_SB_TOOLS}/${tarch}/${mode}/bin"
2591 mkdir -p "${bindir_tarch}"
2592 ${installer} "${nexe}" "${bindir_tarch}/${name}"
2593 done
2594 }
2595
2596 google-perftools-clean() {
2597 rm -rf "${TC_BUILD_GOOGLE_PERFTOOLS}"
2598 }
2599
2600 google-perftools-needs-configure() {
2601 [ ! -f "${TC_BUILD_GOOGLE_PERFTOOLS}/config.status" ]
2602 return $?
2603 }
2604
2605 google-perftools-needs-make() {
2606 local srcdir="${TC_SRC_GOOGLE_PERFTOOLS}"
2607 local objdir="${TC_BUILD_GOOGLE_PERFTOOLS}"
2608 ts-modified "${srcdir}" "${objdir}"
2609 }
2610
2611 #+ google-perftools-configure - conifgure tcmalloc-minimal for bitcode
2612 google-perftools-configure() {
2613 local src="${TC_SRC_GOOGLE_PERFTOOLS}"/google-perftools
2614 local flags="-static"
2615 local configure_env=(
2616 CC="${PNACL_CC} ${flags}" \
2617 CXX="${PNACL_CXX} ${flags}" \
2618 LD="${PNACL_LD} ${flags}" \
2619 AR="${PNACL_AR}" \
2620 RANLIB="${PNACL_RANLIB}")
2621 local install="${TC_BUILD_GOOGLE_PERFTOOLS}"/install
2622
2623 StepBanner "GOOGLE-PERFTOOLS" "Configure"
2624 mkdir -p "${TC_BUILD_GOOGLE_PERFTOOLS}"
2625 mkdir -p "${install}"
2626 spushd "${TC_BUILD_GOOGLE_PERFTOOLS}"
2627 RunWithLog google-perftools.configure \
2628 ${src}/configure --prefix="${install}" \
2629 --enable-minimal \
2630 --host=nacl \
2631 "${configure_env[@]}"
2632 spopd
2633 }
2634
2635 #+ google-perftools-make - Make tcmalloc-minimal in bitcode
2636 google-perftools-make() {
2637 local objdir="${TC_BUILD_GOOGLE_PERFTOOLS}"
2638 spushd "${objdir}"
2639 StepBanner "GOOGLE-PERFTOOLS" "Make"
2640 ts-touch-open "${objdir}"
2641 RunWithLog google-perftools.make \
2642 make -j ${UTMAN_CONCURRENCY}
2643 ts-touch-commit "${objdir}"
2644 spopd
2645 }
2646
2647 #+ google-perftools-install - Install libtcmalloc_minimal.a into toolchain
2648 google-perftools-install() {
2649 StepBanner "GOOGLE-PERFTOOLS" "Install"
2650 spushd "${TC_BUILD_GOOGLE_PERFTOOLS}"
2651 RunWithLog google-perftools.install \
2652 make install
2653
2654 mkdir -p "${INSTALL_LIB}"
2655 cp "${TC_BUILD_GOOGLE_PERFTOOLS}"/install/lib/libtcmalloc_minimal.a \
2656 "${INSTALL_LIB}"
2657 spopd
2658 }
2659
2660 #+ google-perftools - Build libtcmalloc_minimal for use with newlib
2661 # sandboxed binaries
2662 google-perftools() {
2663 StepBanner "GOOGLE-PERFTOOLS (tcmalloc)"
2664
2665 if google-perftools-needs-configure; then
2666 google-perftools-clean
2667 google-perftools-configure
2668 else
2669 SkipBanner "GOOGLE-PERFTOOLS" "Configure"
2670 fi
2671
2672 if google-perftools-needs-make; then
2673 google-perftools-make
2674 else
2675 SkipBanner "GOOGLE-PERFTOOLS" "Make"
2676 fi
2677 google-perftools-install
2678 }
2679
2680 #---------------------------------------------------------------------
2681
2682 BINUTILS_SB_SETUP=false
2683 binutils-sb-setup() {
2684 # TODO(jvoung): investigate if these are only needed by AS or not.
2685 local flags="-DNACL_ALIGN_BYTES=32 -DNACL_ALIGN_POW2=5 -DNACL_TOOLCHAIN_PATCH"
2686
2687 if ${BINUTILS_SB_SETUP} && [ $# -eq 0 ]; then
2688 return 0
2689 fi
2690
2691 if [ $# -ne 2 ] ; then
2692 Fatal "Please specify arch and mode"
2693 fi
2694
2695 BINUTILS_SB_SETUP=true
2696
2697 BINUTILS_SB_ARCH=$1
2698 BINUTILS_SB_MODE=$2
2699 check-sb-arch ${BINUTILS_SB_ARCH}
2700 check-sb-mode ${BINUTILS_SB_MODE}
2701
2702 BINUTILS_SB_LOG_PREFIX="binutils.sb.${BINUTILS_SB_ARCH}.${BINUTILS_SB_MODE}"
2703 BINUTILS_SB_OBJDIR="${TC_BUILD}/"\
2704 "binutils-sb-${BINUTILS_SB_ARCH}-${BINUTILS_SB_MODE}"
2705 if ${LIBMODE_NEWLIB}; then
2706 flags+=" -static"
2707 fi
2708
2709 case ${BINUTILS_SB_MODE} in
2710 srpc) flags+=" -DNACL_SRPC" ;;
2711 nonsrpc) ;;
2712 esac
2713
2714 if [ ! -f "${TC_BUILD_BINUTILS_LIBERTY}/libiberty/libiberty.a" ] ; then
2715 echo "ERROR: Missing lib. Run this script with binutils-liberty option"
2716 exit -1
2717 fi
2718
2719 # Speed things up by avoiding an intermediate step
2720 flags+=" --pnacl-skip-ll"
2721
2722 if ${LIBMODE_GLIBC} ; then
2723 prefer-frontend clang
2724 else
2725 prefer-frontend llvm-gcc
2726 fi
2727
2728 BINUTILS_SB_CONFIGURE_ENV=(
2729 AR="${PNACL_AR}" \
2730 AS="${PNACL_AS}" \
2731 CC="${PNACL_CC} ${flags}" \
2732 CXX="${PNACL_CXX} ${flags}" \
2733 CC_FOR_BUILD="${CC}" \
2734 CXX_FOR_BUILD="${CXX}" \
2735 LD="${PNACL_LD} ${flags}" \
2736 NM="${PNACL_NM}" \
2737 RANLIB="${PNACL_RANLIB}" \
2738 LDFLAGS_FOR_BUILD="-L${TC_BUILD_BINUTILS_LIBERTY}/libiberty/" \
2739 LDFLAGS="")
2740
2741 reset-frontend
2742 }
2743
2744 #+-------------------------------------------------------------------------
2745 #+ binutils-sb <arch> <mode> - Build and install binutils (sandboxed)
2746 binutils-sb() {
2747 binutils-sb-setup "$@"
2748 local srcdir="${TC_SRC_BINUTILS}"
2749 assert-dir "${srcdir}" "You need to checkout binutils."
2750
2751 if binutils-sb-needs-configure ; then
2752 binutils-sb-clean
2753 binutils-sb-configure
2754 else
2755 SkipBanner "BINUTILS-SB" "configure ${BINUTILS_SB_ARCH} ${BINUTILS_SB_MODE}"
2756 fi
2757
2758 if binutils-sb-needs-make; then
2759 binutils-sb-make
2760 else
2761 SkipBanner "BINUTILS-SB" "make"
2762 fi
2763
2764 binutils-sb-install
2765 }
2766
2767 binutils-sb-needs-configure() {
2768 binutils-sb-setup "$@"
2769 [ ! -f "${BINUTILS_SB_OBJDIR}/config.status" ]
2770 return $?
2771 }
2772
2773 # binutils-sb-clean - Clean binutils (sandboxed)
2774 binutils-sb-clean() {
2775 binutils-sb-setup "$@"
2776 StepBanner "BINUTILS-SB" "Clean ${BINUTILS_SB_ARCH} ${BINUTILS_SB_MODE}"
2777 local objdir="${BINUTILS_SB_OBJDIR}"
2778
2779 rm -rf "${objdir}"
2780 mkdir -p "${objdir}"
2781 }
2782
2783 # binutils-sb-configure - Configure binutils (sandboxed)
2784 binutils-sb-configure() {
2785 binutils-sb-setup "$@"
2786
2787 StepBanner "BINUTILS-SB" "Configure ${BINUTILS_SB_ARCH} ${BINUTILS_SB_MODE}"
2788 local srcdir="${TC_SRC_BINUTILS}"
2789 local objdir="${BINUTILS_SB_OBJDIR}"
2790 local installdir="${INSTALL_SB_TOOLS}/${BINUTILS_SB_ARCH}/${BINUTILS_SB_MODE}"
2791
2792 case ${BINUTILS_SB_ARCH} in
2793 x8632) targets=i686-pc-nacl ;;
2794 x8664) targets=x86_64-pc-nacl ;;
2795 arm) targets=arm-pc-nacl ;;
2796 universal) targets=arm-pc-nacl,i686-pc-nacl,x86_64-pc-nacl ;;
2797 esac
2798
2799 spushd "${objdir}"
2800 RunWithLog \
2801 ${BINUTILS_SB_LOG_PREFIX}.configure \
2802 env -i \
2803 PATH="/usr/bin:/bin" \
2804 ${srcdir}/binutils-2.20/configure \
2805 "${BINUTILS_SB_CONFIGURE_ENV[@]}" \
2806 --prefix=${installdir} \
2807 --host=nacl \
2808 --target=${BINUTILS_TARGET} \
2809 --enable-targets=${targets} \
2810 --disable-nls \
2811 --disable-werror \
2812 --enable-static \
2813 --enable-shared=no
2814 spopd
2815 }
2816
2817 binutils-sb-needs-make() {
2818 binutils-sb-setup "$@"
2819 ts-modified "${TC_SRC_BINUTILS}" "${BINUTILS_SB_OBJDIR}"
2820 return $?
2821 }
2822
2823 # binutils-sb-make - Make binutils (sandboxed)
2824 binutils-sb-make() {
2825 binutils-sb-setup "$@"
2826
2827 StepBanner "BINUTILS-SB" "Make ${BINUTILS_SB_ARCH} ${BINUTILS_SB_MODE}"
2828 local objdir="${BINUTILS_SB_OBJDIR}"
2829
2830 spushd "${objdir}"
2831 ts-touch-open "${objdir}"
2832
2833 local build_with_srpc=0
2834 if [ "${BINUTILS_SB_MODE}" == "srpc" ]; then
2835 build_with_srpc=1
2836 fi
2837
2838 RunWithLog ${BINUTILS_SB_LOG_PREFIX}.make \
2839 env -i PATH="/usr/bin:/bin" \
2840 NACL_SRPC=${build_with_srpc} \
2841 make ${MAKE_OPTS} all-ld
2842
2843 ts-touch-commit "${objdir}"
2844
2845 spopd
2846 }
2847
2848 # binutils-sb-install - Install binutils (sandboxed)
2849 binutils-sb-install() {
2850 binutils-sb-setup "$@"
2851
2852 StepBanner "BINUTILS-SB" "Install ${BINUTILS_SB_ARCH} ${BINUTILS_SB_MODE}"
2853 local objdir="${BINUTILS_SB_OBJDIR}"
2854 spushd "${objdir}"
2855
2856 RunWithLog ${BINUTILS_SB_LOG_PREFIX}.install \
2857 env -i PATH="/usr/bin:/bin" \
2858 make install-ld
2859
2860 spopd
2861
2862 # First rename and *strip* the installed file. (Beware for debugging).
2863 local installdir="${INSTALL_SB_TOOLS}/${BINUTILS_SB_ARCH}/${BINUTILS_SB_MODE}"
2864 ${PNACL_STRIP} "${installdir}/bin/${BINUTILS_TARGET}-ld" \
2865 -o "${installdir}/bin/ld"
2866 # Remove old file plus a redundant file.
2867 rm "${installdir}/bin/${BINUTILS_TARGET}-ld"
2868 rm "${installdir}/bin/${BINUTILS_TARGET}-ld.bfd"
2869
2870 # Then translate.
2871 translate-and-install-sb-tool ${BINUTILS_SB_ARCH} ${BINUTILS_SB_MODE} ld
2872 }
2873
2874 #+ tools-sb {arch} {mode} - Build all sandboxed tools for arch, mode
2875 tools-sb() {
2876 local arch=$1
2877 local mode=$2
2878
2879 StepBanner "${arch}" "Sandboxing"
2880 StepBanner "----------" "--------------------------------------"
2881 llvm-sb ${arch} ${mode}
2882 binutils-sb ${arch} ${mode}
2883 }
2884
2885
2886 #+--------------------------------------------------------------------------
2887 #@ install-translators {srpc/nonsrpc} - Builds and installs sandboxed
2888 #@ translator components
2889 install-translators() {
2890 if [ $# -ne 1 ]; then
2891 echo "ERROR: Usage install-translators <srpc/nonsrpc>"
2892 exit -1
2893 fi
2894
2895 if ! [ -d "${INSTALL_SDK_ROOT}" ]; then
2896 echo "ERROR: SDK must be installed to build translators."
2897 echo "You can install the SDK by running: $0 sdk"
2898 exit -1
2899 fi
2900
2901 # TODO(dschuff): Decide whether we should switch back to tcmalloc
2902 #if ${LIBMODE_NEWLIB}; then
2903 # google-perftools
2904 #fi
2905 local srpc_kind=$1
2906 check-sb-mode ${srpc_kind}
2907
2908 StepBanner "INSTALL SANDBOXED TRANSLATORS (${srpc_kind})"
2909
2910 binutils-liberty
2911
2912 if ${SBTC_PRODUCTION}; then
2913 # Build each architecture separately.
2914 for arch in ${SBTC_BUILD_WITH_PNACL} ; do
2915 tools-sb ${arch} ${srpc_kind}
2916 done
2917 else
2918 # Using arch `universal` builds the sandboxed tools to a .pexe
2919 # which support all targets. This .pexe is then translated to
2920 # each architecture specified in ${SBTC_BUILD_WITH_PNACL}.
2921 tools-sb universal ${srpc_kind}
2922 fi
2923
2924 echo "Done"
2925 }
2926
2927 #+-------------------------------------------------------------------------
2928 #@ prune-translator-install - Prunes translator install directories
2929 prune-translator-install() {
2930 if [ $# -ne 1 ]; then
2931 echo "ERROR: Usage prune-translator-install <srpc/nonsrpc>"
2932 exit -1
2933 fi
2934
2935 local srpc_kind=$1
2936 check-sb-mode ${srpc_kind}
2937
2938 StepBanner "PRUNE" "Pruning translator installs (${srpc_kind})"
2939
2940 spushd "${INSTALL_SB_TOOLS_X8632}/${srpc_kind}"
2941 rm -rf include lib nacl share
2942 rm -rf bin/llvm-config bin/tblgen
2943 spopd
2944
2945 spushd "${INSTALL_SB_TOOLS_X8664}/${srpc_kind}"
2946 rm -rf include lib nacl64 share
2947 rm -rf bin/llvm-config bin/tblgen
2948 spopd
2949
2950 if ! ${SBTC_PRODUCTION}; then
2951 rm -rf "${INSTALL_SB_TOOLS_UNIVERSAL}"
2952 fi
2953
2954 echo "Stripping tools-sb nexes"
2955 for arch in ${SBTC_BUILD_WITH_PNACL} ; do
2956 ${PNACL_STRIP} "${INSTALL_SB_TOOLS}/${arch}/${srpc_kind}"/bin/*
2957 done
2958
2959 echo "remove driver log"
2960 rm -f "${INSTALL_ROOT}"/driver.log
2961
2962 echo "Done"
2963 }
2964
2965 #########################################################################
2966 # < NEWLIB-BITCODE >
2967 #########################################################################
2968
2969 #+ newlib - Build and install newlib in bitcode.
2970 newlib() {
2971 StepBanner "NEWLIB (BITCODE)"
2972
2973 if newlib-needs-configure; then
2974 newlib-clean
2975 newlib-configure
2976 else
2977 SkipBanner "NEWLIB" "configure"
2978 fi
2979
2980 if newlib-needs-make; then
2981 newlib-make
2982 else
2983 SkipBanner "NEWLIB" "make"
2984 fi
2985
2986 newlib-install
2987 }
2988
2989 #+ newlib-clean - Clean bitcode newlib.
2990 newlib-clean() {
2991 StepBanner "NEWLIB" "Clean"
2992 rm -rf "${TC_BUILD_NEWLIB}"
2993 }
2994
2995 newlib-needs-configure() {
2996 speculative-check "llvm-gcc" && return 0
2997 ts-newer-than "${TC_BUILD_LLVM_GCC}-${CROSS_TARGET_ARM}" \
2998 "${TC_BUILD_NEWLIB}" && return 0
2999
3000 [ ! -f "${TC_BUILD_NEWLIB}/config.status" ]
3001 return #?
3002 }
3003
3004 #+ newlib-configure - Configure bitcode Newlib
3005 newlib-configure() {
3006 StepBanner "NEWLIB" "Configure"
3007
3008 local srcdir="${TC_SRC_NEWLIB}"
3009 local objdir="${TC_BUILD_NEWLIB}"
3010 mkdir -p "${objdir}"
3011 spushd "${objdir}"
3012
3013 setup-newlib-env
3014 RunWithLog newlib.configure \
3015 env -i \
3016 PATH="/usr/bin:/bin" \
3017 "${STD_ENV_FOR_NEWLIB[@]}" \
3018 ${srcdir}/newlib-trunk/configure \
3019 --disable-multilib \
3020 --prefix="${NEWLIB_INSTALL_DIR}" \
3021 --disable-newlib-supplied-syscalls \
3022 --disable-texinfo \
3023 --disable-libgloss \
3024 --enable-newlib-iconv \
3025 --enable-newlib-io-long-long \
3026 --enable-newlib-io-long-double \
3027 --enable-newlib-io-c99-formats \
3028 --enable-newlib-io-mb \
3029 --target="${REAL_CROSS_TARGET}"
3030 spopd
3031 }
3032
3033 newlib-needs-make() {
3034 local srcdir="${TC_SRC_NEWLIB}"
3035 local objdir="${TC_BUILD_NEWLIB}"
3036
3037 ts-modified "$srcdir" "$objdir"
3038 return $?
3039 }
3040
3041 #+ newlib-make - Make bitcode Newlib
3042 newlib-make() {
3043 StepBanner "NEWLIB" "Make"
3044 local srcdir="${TC_SRC_NEWLIB}"
3045 local objdir="${TC_BUILD_NEWLIB}"
3046
3047 ts-touch-open "${objdir}"
3048
3049 setup-newlib-env
3050 spushd "${objdir}"
3051 RunWithLog newlib.make \
3052 env -i PATH="/usr/bin:/bin" \
3053 make \
3054 "${STD_ENV_FOR_NEWLIB[@]}" \
3055 ${MAKE_OPTS}
3056 spopd
3057
3058 ts-touch-commit "${objdir}"
3059
3060 }
3061
3062 #+ newlib-install - Install Bitcode Newlib using build env.
3063 newlib-install() {
3064 StepBanner "NEWLIB" "Install"
3065 local objdir="${TC_BUILD_NEWLIB}"
3066
3067 spushd "${objdir}"
3068
3069 # NOTE: we might be better off not using install, as we are already
3070 # doing a bunch of copying of headers and libs further down
3071 setup-newlib-env
3072 RunWithLog newlib.install \
3073 env -i PATH="/usr/bin:/bin" \
3074 make \
3075 "${STD_ENV_FOR_NEWLIB[@]}" \
3076 install ${MAKE_OPTS}
3077
3078 ###########################################################
3079 # -- HACK HACK HACK --
3080 # newlib installs into ${REAL_CROSS_TARGET}
3081 # For now, move it back to the old ${CROSS_TARGET_ARM}
3082 # where everything expects it to be.
3083 rm -rf "${NEWLIB_INSTALL_DIR}/${CROSS_TARGET_ARM}"
3084 mv "${NEWLIB_INSTALL_DIR}/${REAL_CROSS_TARGET}" \
3085 "${NEWLIB_INSTALL_DIR}/${CROSS_TARGET_ARM}"
3086 ###########################################################
3087
3088 StepBanner "NEWLIB" "Extra-install"
3089 local sys_include=${SYSROOT_DIR}/include
3090 # NOTE: we provide a new one via extra-sdk
3091 rm ${NEWLIB_INSTALL_DIR}/${CROSS_TARGET_ARM}/include/pthread.h
3092
3093 cp ${NEWLIB_INSTALL_DIR}/${CROSS_TARGET_ARM}/include/machine/endian.h \
3094 ${sys_include}
3095 cp ${NEWLIB_INSTALL_DIR}/${CROSS_TARGET_ARM}/include/sys/param.h \
3096 ${sys_include}
3097 cp ${NEWLIB_INSTALL_DIR}/${CROSS_TARGET_ARM}/include/newlib.h \
3098 ${sys_include}
3099
3100 # NOTE: we provide our own pthread.h via extra-sdk
3101 StepBanner "NEWLIB" "Removing old pthreads headers"
3102 rm -f "${NEWLIB_INSTALL_DIR}/${CROSS_TARGET_ARM}/usr/include/pthread.h"
3103 rm -f "${sys_include}/pthread.h"
3104
3105 StepBanner "NEWLIB" "copying libraries"
3106 local destdir="${INSTALL_LIB}"
3107 # We only install libc/libg/libm
3108 mkdir -p "${destdir}"
3109 cp ${objdir}/${REAL_CROSS_TARGET}/newlib/lib[cgm].a "${destdir}"
3110
3111 spopd
3112
3113 # Clang claims posix thread model, not single as llvm-gcc does.
3114 # It means that libstdcpp needs pthread.h to be in place.
3115 # This should go away when we properly import pthread.h with
3116 # the other newlib headers. This hack is tracked by
3117 # http://code.google.com/p/nativeclient/issues/detail?id=2333
3118 StepBanner "NEWLIB" "Copying pthreads headers ahead of time "\
3119 "(HACK. See http://code.google.com/p/nativeclient/issues/detail?id=2333)"
3120 sdk-headers
3121 }
3122
3123 # TODO(pdox): Organize these objects better, so that this code is simpler.
3124 libs-platform() {
3125 # There are currently no platform libs in the glibc build.
3126 if ${LIBMODE_GLIBC}; then
3127 return 0
3128 fi
3129
3130 local pnacl_cc="${PNACL_CC} --pnacl-allow-native"
3131 local src="${PNACL_SUPPORT}"
3132 local tmpdir="${TC_BUILD}/libs-platform"
3133 rm -rf "${tmpdir}"
3134 mkdir -p "${tmpdir}"
3135
3136 # Install crt1.o (linker script)
3137 StepBanner "LIBS-PLATFORM" "Install crt1.o"
3138 mkdir -p "${INSTALL_LIB}"
3139 cp "${src}"/crt1.x ${INSTALL_LIB}/crt1.o
3140
3141 # Install nacl_startup.bc
3142 StepBanner "LIBS-PLATFORM" "Install nacl_startup.bc"
3143 ${pnacl_cc} -c "${src}"/nacl_startup.c -o "${tmpdir}"/nacl_startup.bc
3144 cp "${tmpdir}"/nacl_startup.bc "${INSTALL_LIB}"
3145
3146 for platform in arm x86-32 x86-64; do
3147 StepBanner "LIBS-PLATFORM" "libcrt_platform.a for ${platform}"
3148 local dest="${INSTALL_LIB}-${platform}"
3149 local sources="setjmp_${platform/-/_}"
3150 mkdir -p "${dest}"
3151
3152 # For ARM, also compile aeabi_read_tp.S
3153 if [ ${platform} == arm ] ; then
3154 sources+=" aeabi_read_tp"
3155 fi
3156
3157 local objs=""
3158 for name in ${sources}; do
3159 ${pnacl_cc} -arch ${platform} -c "${src}"/${name}.S -o ${tmpdir}/${name}.o
3160 objs+=" ${tmpdir}/${name}.o"
3161 done
3162
3163 ${PNACL_AR} rc "${dest}"/libcrt_platform.a ${objs}
3164 done
3165 }
3166
3167 #########################################################################
3168 # < SDK >
3169 #########################################################################
3170 SCONS_COMMON=(./scons
3171 MODE=nacl
3172 -j${UTMAN_CONCURRENCY}
3173 bitcode=1
3174 sdl=none
3175 disable_nosys_linker_warnings=1
3176 naclsdk_validate=0
3177 --verbose)
3178
3179 sdk() {
3180 StepBanner "SDK"
3181 sdk-clean
3182 sdk-headers
3183 sdk-libs
3184 sdk-verify
3185 }
3186
3187 #+ sdk-clean - Clean sdk stuff
3188 sdk-clean() {
3189 StepBanner "SDK" "Clean"
3190 rm -rf "${INSTALL_SDK_ROOT}"
3191
3192 # clean scons obj dirs
3193 rm -rf scons-out/nacl-*-pnacl*
3194 }
3195
3196 sdk-headers() {
3197 mkdir -p "${INSTALL_SDK_INCLUDE}"
3198
3199 local extra_flags=""
3200 local neutral_platform="x86-32"
3201 if ${LIBMODE_GLIBC}; then
3202 extra_flags="--nacl_glibc"
3203 fi
3204
3205 StepBanner "SDK" "Install headers"
3206 RunWithLog "sdk.headers" \
3207 "${SCONS_COMMON[@]}" \
3208 ${extra_flags} \
3209 platform=${neutral_platform} \
3210 install_headers \
3211 includedir="$(PosixToSysPath "${INSTALL_SDK_INCLUDE}")"
3212 }
3213
3214 sdk-libs() {
3215 StepBanner "SDK" "Install libraries"
3216 mkdir -p "${INSTALL_SDK_LIB}"
3217
3218 local extra_flags=""
3219 local neutral_platform="x86-32"
3220 if ${LIBMODE_GLIBC}; then
3221 extra_flags="--nacl_glibc"
3222 fi
3223
3224 RunWithLog "sdk.libs.bitcode" \
3225 "${SCONS_COMMON[@]}" \
3226 ${extra_flags} \
3227 platform=${neutral_platform} \
3228 install_lib \
3229 libdir="$(PosixToSysPath "${INSTALL_SDK_LIB}")"
3230 }
3231
3232 sdk-verify() {
3233 # This avoids errors when *.o finds no matches.
3234 shopt -s nullglob
3235
3236 StepBanner "SDK" "Verify"
3237
3238 # Verify bitcode libraries
3239 SubBanner "VERIFY: ${INSTALL_SDK_LIB}"
3240 for i in ${INSTALL_SDK_LIB}/*.a ; do
3241 verify-archive-llvm "$i"
3242 done
3243
3244 for i in ${INSTALL_SDK_LIB}/*.pso ; do
3245 verify-pso "$i"
3246 done
3247
3248 shopt -u nullglob
3249 }
3250
3251 newlib-nacl-headers-clean() {
3252 # Clean the include directory and revert it to its pure state
3253 if [ -d "${TC_SRC_NEWLIB}" ]; then
3254 rm -rf "${NEWLIB_INCLUDE_DIR}"
3255 # If the script is interrupted right here,
3256 # then NEWLIB_INCLUDE_DIR will not exist, and the repository
3257 # will be in a bad state. This will be fixed during the next
3258 # invocation by newlib-nacl-headers.
3259
3260 # We jump into the parent directory and use a relative path so that
3261 # hg does not get confused by pathnames which contain a symlink.
3262 spushd "$(dirname "${NEWLIB_INCLUDE_DIR}")"
3263 RunWithLog "newlib-freshen" \
3264 hg-revert "$(basename "${NEWLIB_INCLUDE_DIR}")"
3265 spopd
3266 fi
3267 }
3268
3269 #+ newlib-nacl-headers - Install NaCl headers to newlib
3270 newlib-nacl-headers() {
3271 StepBanner "newlib-nacl-headers" "Adding nacl headers to newlib"
3272
3273 assert-dir "${TC_SRC_NEWLIB}" "Newlib is not checked out"
3274
3275 # Make sure the headers directory has no local changes
3276 newlib-nacl-headers-check
3277 newlib-nacl-headers-clean
3278
3279 # Install the headers
3280 "${EXPORT_HEADER_SCRIPT}" \
3281 "${NACL_SYS_HEADERS}" \
3282 "${NEWLIB_INCLUDE_DIR}"
3283
3284 # Record the header install time
3285 ts-touch "${NACL_HEADERS_TS}"
3286 }
3287
3288 #+ newlib-nacl-headers-check - Make sure the newlib nacl headers haven't
3289 #+ been modified since the last install.
3290 newlib-nacl-headers-check() {
3291 # The condition where NEWLIB_INCLUDE_DIR does not exist may have been
3292 # caused by an incomplete call to newlib-nacl-headers-clean().
3293 # Let it pass this check so that the clean will be able to finish.
3294 # See the comment in newlib-nacl-headers-clean()
3295 if ! [ -d "${TC_SRC_NEWLIB}" ] ||
3296 ! [ -d "${NEWLIB_INCLUDE_DIR}" ]; then
3297 return 0
3298 fi
3299
3300 # Already clean?
3301 if ! hg-has-changes "${NEWLIB_INCLUDE_DIR}" &&
3302 ! hg-has-untracked "${NEWLIB_INCLUDE_DIR}" ; then
3303 return 0
3304 fi
3305
3306 if ts-dir-changed "${NACL_HEADERS_TS}" "${NEWLIB_INCLUDE_DIR}"; then
3307 echo ""
3308 echo "*******************************************************************"
3309 echo "* ERROR *"
3310 echo "* The NewLib include directory has local modifications *"
3311 echo "*******************************************************************"
3312 echo "* The NewLib include directory should not be modified directly. *"
3313 echo "* Instead, modifications should be done from: *"
3314 echo "* src/trusted/service_runtime/include *"
3315 echo "* *"
3316 echo "* To destroy the local changes to newlib, run: *"
3317 echo "* tools/llvm/utman.sh newlib-nacl-headers-clean *"
3318 echo "*******************************************************************"
3319 echo ""
3320 if ${UTMAN_BUILDBOT} ; then
3321 newlib-nacl-headers-clean
3322 else
3323 exit -1
3324 fi
3325 fi
3326 }
3327
3328 #+-------------------------------------------------------------------------
3329 #+ driver - Install driver scripts.
3330 driver() {
3331 StepBanner "DRIVER"
3332 driver-install
3333 }
3334
3335 # The driver is a simple python script which changes its behavior
3336 # depending on the name it is invoked as.
3337 driver-install() {
3338 StepBanner "DRIVER" "Installing driver adaptors to ${INSTALL_BIN}"
3339 mkdir -p "${INSTALL_BIN}"
3340 rm -f "${INSTALL_BIN}"/pnacl-*
3341
3342 spushd "${DRIVER_DIR}"
3343 cp driver_tools.py "${INSTALL_BIN}"
3344 cp artools.py "${INSTALL_BIN}"
3345 cp ldtools.py "${INSTALL_BIN}"
3346 cp pathtools.py "${INSTALL_BIN}"
3347 for t in pnacl-*; do
3348 local name=$(basename "$t")
3349 cp "${t}" "${INSTALL_BIN}/${name/.py}"
3350 if ${BUILD_PLATFORM_WIN}; then
3351 cp redirect.bat "${INSTALL_BIN}/${name/.py}.bat"
3352 fi
3353 done
3354 spopd
3355
3356 # Tell the driver the library mode
3357 touch "${INSTALL_BIN}"/${LIBMODE}.cfg
3358
3359 # Install readelf and size
3360 cp -a "${BINUTILS_INSTALL_DIR}/bin/${BINUTILS_TARGET}-readelf" \
3361 "${INSTALL_BIN}/readelf"
3362 cp -a "${BINUTILS_INSTALL_DIR}/bin/${BINUTILS_TARGET}-size" \
3363 "${INSTALL_BIN}/size"
3364
3365 # On windows, copy the cygwin DLLs needed by the driver tools
3366 if ${BUILD_PLATFORM_WIN}; then
3367 StepBanner "DRIVER" "Copying cygwin libraries"
3368 local deps="gcc_s-1 iconv-2 win1 intl-8 stdc++-6 z"
3369 for name in ${deps}; do
3370 cp "/bin/cyg${name}.dll" "${INSTALL_BIN}"
3371 done
3372 fi
3373 }
3374
3375 ######################################################################
3376 ######################################################################
3377 #
3378 # HELPER FUNCTIONS
3379 #
3380 # (These should not generally be used directly)
3381 #
3382 ######################################################################
3383 ######################################################################
3384
3385 RecordRevisionInfo() {
3386 svn info > "${INSTALL_ROOT}/REV"
3387 }
3388
3389 ######################################################################
3390 ######################################################################
3391 # < VERIFY >
3392 ######################################################################
3393 ######################################################################
3394
3395 readonly LLVM_DIS=${LLVM_INSTALL_DIR}/bin/llvm-dis
3396 readonly LLVM_BCANALYZER=${LLVM_INSTALL_DIR}/bin/llvm-bcanalyzer
3397 readonly LLVM_OPT=${LLVM_INSTALL_DIR}/bin/opt
3398
3399 # Note: we could replace this with a modified version of tools/elf_checker.py
3400 # if we do not want to depend on binutils
3401 readonly NACL_OBJDUMP=${BINUTILS_INSTALL_DIR}/bin/${BINUTILS_TARGET}-objdump
3402
3403 # Usage: VerifyArchive <checker> <pattern> <filename>
3404 ExtractAndCheck() {
3405 local checker="$1"
3406 local pattern="$2"
3407 local archive="$3"
3408 local tmp="/tmp/ar-verify-${RANDOM}"
3409 rm -rf ${tmp}
3410 mkdir -p ${tmp}
3411 cp "${archive}" "${tmp}"
3412 spushd ${tmp}
3413 ${PNACL_AR} x $(basename ${archive})
3414 # extract all the files
3415 local count=0
3416 for i in ${pattern} ; do
3417 if [ ! -e "$i" ]; then
3418 # we may also see the unexpanded pattern here if there is no match
3419 continue
3420 fi
3421 count=$((count+1))
3422 ${checker} $i
3423 done
3424 if [ "${count}" = "0" ] ; then
3425 echo "FAIL - archive empty or wrong contents: ${archive}"
3426 ls -l "${tmp}"
3427 exit -1
3428 fi
3429 echo "PASS (${count} files)"
3430 rm -rf "${tmp}"
3431 spopd
3432 }
3433
3434 IsLinkerScript() {
3435 local fname="$1"
3436 local type="$(file --brief --mime-type "${fname}")"
3437 case "$type" in
3438 text/x-c)
3439 # A linker script with C comments looks like C to "file".
3440 return 0
3441 ;;
3442 text/plain)
3443 return 0
3444 ;;
3445 esac
3446 return 1
3447 }
3448
3449 # Usage: VerifyLinkerScript <filename>
3450 VerifyLinkerScript() {
3451 local archive="$1"
3452 # Use cpp to strip the C-style comments.
3453 ${PNACL_CC} -E -xc "${archive}" | awk -v archive="$(basename ${archive})" '
3454 BEGIN { status = 0 }
3455 NF == 0 || $1 == "#" { next }
3456 $1 == "INPUT" && $2 == "(" && $NF == ")" { next }
3457 {
3458 print "FAIL - unexpected linker script(?) contents:", archive
3459 status = 1
3460 exit(status)
3461 }
3462 END { if (status == 0) print "PASS (trivial linker script)" }
3463 ' || exit -1
3464 }
3465
3466 # Usage: VerifyArchive <checker> <pattern> <filename>
3467 VerifyArchive() {
3468 local checker="$1"
3469 local pattern="$2"
3470 local archive="$3"
3471 echo -n "verify $(basename "${archive}"): "
3472 if IsLinkerScript "${archive}"; then
3473 VerifyLinkerScript "${archive}"
3474 else
3475 ExtractAndCheck "$checker" "$pattern" "$archive"
3476 fi
3477 }
3478
3479 #
3480 # verify-object-llvm <obj>
3481 #
3482 # Verifies that a given .o file is bitcode and free of ASMSs
3483 verify-object-llvm() {
3484 if ${LLVM_DIS} "$1" -o - | grep asm ; then
3485 echo
3486 echo "ERROR asm in $1"
3487 echo
3488 exit -1
3489 fi
3490 if [ ${PIPESTATUS[0]} -ne 0 ]; then
3491 exit -1
3492 fi
3493 }
3494
3495
3496
3497 check-elf-abi() {
3498 # Temporarily disable ELF abi check until DEPS roll
3499 return 0
3500
3501 local arch_info="$(${NACL_OBJDUMP} -f $1)"
3502 if ! grep -q $2 <<< ${arch_info} ; then
3503 echo "ERROR $1 - bad file format: $2 vs ${arch_info}\n"
3504 echo ${arch_info}
3505 exit -1
3506 fi
3507 }
3508
3509
3510 # verify-object-arm <obj>
3511 #
3512 # Ensure that the ARCH properties are what we expect, this is a little
3513 # fragile and needs to be updated when tools change
3514 verify-object-arm() {
3515 check-elf-abi $1 "elf32-littlearm"
3516 arch_info="$("${PNACL_READELF}" -A "$1")"
3517 #TODO(robertm): some refactoring and cleanup needed
3518 if ! grep -q "Tag_FP_arch: VFPv2" <<< ${arch_info} ; then
3519 echo "ERROR $1 - bad Tag_FP_arch\n"
3520 #TODO(robertm): figure out what the right thing to do is here, c.f.
3521 # http://code.google.com/p/nativeclient/issues/detail?id=966
3522 "${PNACL_READELF}" -A $1 | grep Tag_FP_arch
3523 exit -1
3524 fi
3525
3526 if ! grep -q "Tag_CPU_arch: v7" <<< ${arch_info} ; then
3527 echo "FAIL bad $1 Tag_CPU_arch\n"
3528 "${PNACL_READELF}" -A $1 | grep Tag_CPU_arch
3529 exit -1
3530 fi
3531 }
3532
3533
3534 # verify-object-x86-32 <obj>
3535 #
3536 verify-object-x86-32() {
3537 check-elf-abi $1 "elf32-i386"
3538 }
3539
3540 # verify-object-x86-64 <obj>
3541 #
3542 verify-object-x86-64() {
3543 check-elf-abi $1 "elf64-x86-64"
3544 }
3545
3546 #
3547 # verify-pso <psofile>
3548 #
3549 verify-pso() {
3550 local psofile="$1"
3551 echo -n "verify $(basename "${psofile}"): "
3552 if IsLinkerScript "${psofile}"; then
3553 VerifyLinkerScript "${psofile}"
3554 else
3555 verify-object-llvm "$1"
3556 echo "PASS"
3557 # TODO(pdox): Add a call to pnacl-meta to check for the "shared" property.
3558 fi
3559 }
3560
3561 #
3562 # verify-archive-llvm <archive>
3563 # Verifies that a given archive is bitcode and free of ASMSs
3564 #
3565 verify-archive-llvm() {
3566 if ${LLVM_BCANALYZER} "$1" 2> /dev/null ; then
3567 # This fires only when we build in single-bitcode-lib mode
3568 echo -n "verify $(basename "$1"): "
3569 verify-object-llvm "$1"
3570 echo "PASS (single-bitcode)"
3571 else
3572 # Currently all the files are .o in the llvm archives.
3573 # Eventually more and more should be .bc.
3574 VerifyArchive verify-object-llvm '*.bc *.o' "$@"
3575 fi
3576 }
3577
3578 #
3579 # verify-archive-arm <archive>
3580 # Verifies that a given archive is a proper arm achive
3581 #
3582 verify-archive-arm() {
3583 VerifyArchive verify-object-arm '*.o *.ons' "$@"
3584 }
3585
3586 #
3587 # verify-archive-x86-32 <archive>
3588 # Verifies that a given archive is a proper x86-32 achive
3589 #
3590 verify-archive-x86-32() {
3591 VerifyArchive verify-object-x86-32 '*.o *.ons' "$@"
3592 }
3593
3594 #
3595 # verify-archive-x86-64 <archive>
3596 # Verifies that a given archive is a proper x86-64 achive
3597 #
3598 verify-archive-x86-64() {
3599 VerifyArchive verify-object-x86-64 '*.o *.ons' "$@"
3600 }
3601
3602 #@-------------------------------------------------------------------------
3603 #+ verify - Verifies that toolchain/pnacl-untrusted ELF files
3604 #+ are of the correct architecture.
3605 verify() {
3606 StepBanner "VERIFY"
3607
3608 # Verify bitcode libraries in lib/
3609 # The GLibC build does not currently have any bitcode
3610 # libraries in this location.
3611 if ${LIBMODE_NEWLIB}; then
3612 SubBanner "VERIFY: ${INSTALL_LIB}"
3613 for i in ${INSTALL_LIB}/*.a ; do
3614 verify-archive-llvm "$i"
3615 done
3616 fi
3617
3618 # Verify platform libraries
3619 for platform in arm x86-32 x86-64; do
3620 if [ "${platform}" == "arm" ] && ${LIBMODE_GLIBC}; then
3621 continue
3622 fi
3623
3624 SubBanner "VERIFY: ${INSTALL_LIB}-${platform}"
3625 # There are currently no .o files here
3626 #for i in "${INSTALL_LIB}-${platform}"/*.o ; do
3627 # verify-object-${platform} "$i"
3628 #done
3629
3630 for i in "${INSTALL_LIB}-${platform}"/*.a ; do
3631 verify-archive-${platform} "$i"
3632 done
3633 done
3634 }
3635
3636 #@ verify-triple-build <arch> - Verify that the sandboxed translator produces
3637 #@ an identical translation of itself (llc.pexe)
3638 #@ as the unsandboxed translator.
3639 verify-triple-build() {
3640 if [ $# -eq 0 ]; then
3641 local arch
3642 for arch in ${SBTC_BUILD_WITH_PNACL} ; do
3643 verify-triple-build ${arch}
3644 done
3645 return
3646 fi
3647
3648 local arch=${1/-/} # Get rid of dashes
3649 local mode=srpc
3650
3651 check-sb-arch ${arch}
3652 check-sb-mode ${mode}
3653
3654 StepBanner "VERIFY" "Verifying triple build for ${arch}"
3655
3656 local archdir="${INSTALL_SB_TOOLS}/${arch}/${mode}"
3657 local archllc="${archdir}/bin/llc"
3658 local pexe
3659
3660 if ${SBTC_PRODUCTION} ; then
3661 pexe="${archdir}/bin/llc.pexe"
3662 else
3663 pexe="${INSTALL_SB_TOOLS}/universal/${mode}/bin/llc.pexe"
3664 fi
3665 assert-file "${archllc}" "sandboxed llc for ${arch} does not exist"
3666 assert-file "${pexe}" "llc.pexe does not exist"
3667
3668 local flags="--pnacl-sb --pnacl-driver-verbose"
3669 if [ ${mode} == "srpc" ] ; then
3670 flags+=" --pnacl-driver-set-SRPC=1"
3671 else
3672 flags+=" --pnacl-driver-set-SRPC=0"
3673 fi
3674
3675 if [ ${arch} == "arm" ] ; then
3676 # Use emulator if we are not on ARM
3677 local hostarch=$(uname -m)
3678 if ! [[ "${hostarch}" =~ arm ]]; then
3679 flags+=" --pnacl-use-emulator"
3680 fi
3681 fi
3682
3683 local objdir="${TC_BUILD}/triple-build"
3684 local newllc="${objdir}/llc.${arch}.rebuild.nexe"
3685 mkdir -p "${objdir}"
3686
3687 StepBanner "VERIFY" "Translating llc.pexe to ${arch} using sandboxed tools"
3688 RunWithLog "verify.triple.build" \
3689 "${PNACL_TRANSLATE}" ${flags} -arch ${arch} "${pexe}" -o "${newllc}"
3690
3691 if ! cmp --silent "${archllc}" "${newllc}" ; then
3692 Banner "TRIPLE BUILD VERIFY FAILED"
3693 echo "Expected these files to be identical, but they are not:"
3694 echo " ${archllc}"
3695 echo " ${newllc}"
3696 exit -1
3697 fi
3698 StepBanner "VERIFY" "Verified ${arch} OK"
3699 }
3700
3701 ######################################################################
3702 ######################################################################
3703 #
3704 # UTILITIES
3705 #
3706 ######################################################################
3707 ######################################################################
3708
3709 #@-------------------------------------------------------------------------
3710 #@ show-config
3711 show-config() {
3712 Banner "Config Settings:"
3713 echo "UTMAN_BUILDBOT: ${UTMAN_BUILDBOT}"
3714 echo "UTMAN_CONCURRENCY: ${UTMAN_CONCURRENCY}"
3715 echo "UTMAN_DEBUG: ${UTMAN_DEBUG}"
3716 echo "UTMAN_PRUNE: ${UTMAN_PRUNE}"
3717 echo "UTMAN_VERBOSE: ${UTMAN_VERBOSE}"
3718 echo "LIBMODE: ${LIBMODE}"
3719 Banner "Your Environment:"
3720 env | grep UTMAN
3721 }
3722
3723 #@ help - Usage information.
3724 help() {
3725 Usage
3726 }
3727
3728 #@ help-full - Usage information including internal functions.
3729 help-full() {
3730 Usage2
3731 }
3732
3733 has-trusted-toolchain() {
3734 if [ -f toolchain/linux_arm-trusted/ld_script_arm_trusted ]; then
3735 return 0
3736 else
3737 return 1
3738 fi
3739 }
3740
3741 check-for-trusted() {
3742 if ! ${UTMAN_BUILD_ARM} ; then
3743 return
3744 fi
3745
3746 if ! has-trusted-toolchain; then
3747 echo '*******************************************************************'
3748 echo '* The ARM trusted toolchain does not appear to be installed yet *'
3749 echo '* It is needed to run ARM tests. *'
3750 echo '* *'
3751 echo '* To download and install the trusted toolchain, run: *'
3752 echo '* *'
3753 echo '* $ tools/llvm/utman.sh download-trusted *'
3754 echo '* *'
3755 echo '* To compile the trusted toolchain, use: *'
3756 echo '* *'
3757 echo '* $ tools/llvm/trusted-toolchain-creator.sh trusted_sdk *'
3758 echo '* (warning: this takes a while) *'
3759 echo '*******************************************************************'
3760
3761 # If building on the bots, do not continue since it needs to run ARM tests.
3762 if ${UTMAN_BUILDBOT} ; then
3763 echo "Building on bots --> need ARM trusted toolchain to run tests!"
3764 exit -1
3765 elif trusted-tc-confirm ; then
3766 echo "Continuing without ARM trusted toolchain"
3767 UTMAN_BUILD_ARM=false
3768 else
3769 echo "Okay, stopping."
3770 exit -1
3771 fi
3772 fi
3773 }
3774
3775 trusted-tc-confirm() {
3776 echo
3777 echo "Do you wish to continue without the ARM trusted TC (skip ARM testing)?"
3778 echo ""
3779 confirm-yes "Continue"
3780 return $?
3781 }
3782
3783 DebugRun() {
3784 if ${UTMAN_DEBUG} || ${UTMAN_BUILDBOT}; then
3785 "$@"
3786 fi
3787 }
3788
3789 ######################################################################
3790 # Generate chromium perf bot logs for tracking the size of
3791 # translator binaries.
3792
3793 track-translator-size() {
3794 local platforms="$@"
3795 for platform in ${platforms}; do
3796 print-size-of-sb-tool ${platform} llc
3797 print-size-of-sb-tool ${platform} ld
3798 done
3799 }
3800
3801 print-size-of-sb-tool() {
3802 local platform=$1
3803 local tool=$2
3804 local bin_dir="${INSTALL_SB_TOOLS}/${platform}/srpc/bin"
3805 local tool_size_string=$(${PNACL_SIZE} -B "${bin_dir}/${tool}" | \
3806 grep '[0-9]\+')
3807 set -- ${tool_size_string}
3808 echo "RESULT ${tool}_${platform}_size: text= $1 bytes"
3809 echo "RESULT ${tool}_${platform}_size: data= $2 bytes"
3810 echo "RESULT ${tool}_${platform}_size: bss= $3 bytes"
3811 echo "RESULT ${tool}_${platform}_size: total= $4 bytes"
3812 }
3813
3814 ######################################################################
3815 ######################################################################
3816 #
3817 # < TIME STAMPING >
3818 #
3819 ######################################################################
3820 ######################################################################
3821
3822 ts-dir-changed() {
3823 local tsfile="$1"
3824 local dir="$2"
3825
3826 if [ -f "${tsfile}" ]; then
3827 local MODIFIED=$(find "${dir}" -type f -newer "${tsfile}")
3828 [ ${#MODIFIED} -gt 0 ]
3829 ret=$?
3830 else
3831 true
3832 ret=$?
3833 fi
3834 return $ret
3835 }
3836
3837 # Check if the source for a given build has been modified
3838 ts-modified() {
3839 local srcdir="$1"
3840 local objdir="$2"
3841 local tsfile="${objdir}/${TIMESTAMP_FILENAME}"
3842
3843 ts-dir-changed "${tsfile}" "${srcdir}"
3844 return $?
3845 }
3846
3847 ts-touch() {
3848 local tsfile="$1"
3849 touch "${tsfile}"
3850 }
3851
3852 # Record the time when make begins, but don't yet
3853 # write that to the timestamp file.
3854 # (Just in case make fails)
3855
3856 ts-touch-open() {
3857 local objdir="$1"
3858 local tsfile="${objdir}/${TIMESTAMP_FILENAME}"
3859 local tsfile_open="${objdir}/${TIMESTAMP_FILENAME}_OPEN"
3860
3861 rm -f "${tsfile}"
3862 touch "${tsfile_open}"
3863 }
3864
3865
3866 # Write the timestamp. (i.e. make has succeeded)
3867
3868 ts-touch-commit() {
3869 local objdir="$1"
3870 local tsfile="${objdir}/${TIMESTAMP_FILENAME}"
3871 local tsfile_open="${objdir}/${TIMESTAMP_FILENAME}_OPEN"
3872
3873 mv -f "${tsfile_open}" "${tsfile}"
3874 }
3875
3876
3877 # ts-newer-than dirA dirB
3878 # Compare the make timestamps in both object directories.
3879 # returns true (0) if dirA is newer than dirB
3880 # returns false (1) otherwise.
3881 #
3882 # This functions errs on the side of returning 0, since
3883 # that forces a rebuild anyway.
3884
3885 ts-newer-than() {
3886 local objdir1="$1"
3887 local objdir2="$2"
3888
3889 local tsfile1="${objdir1}/${TIMESTAMP_FILENAME}"
3890 local tsfile2="${objdir2}/${TIMESTAMP_FILENAME}"
3891
3892 if [ ! -d "${objdir1}" ]; then return 0; fi
3893 if [ ! -d "${objdir2}" ]; then return 0; fi
3894
3895 if [ ! -f "${tsfile1}" ]; then return 0; fi
3896 if [ ! -f "${tsfile2}" ]; then return 0; fi
3897
3898 local MODIFIED=$(find "${tsfile1}" -newer "${tsfile2}")
3899 if [ ${#MODIFIED} -gt 0 ]; then
3900 return 0
3901 fi
3902 return 1
3903 }
3904
3905
3906 # Don't define any functions after this or they won't show up in completions
3907 function-completions() {
3908 if [ $# = 0 ]; then set -- ""; fi
3909 compgen -A function -- $1
3910 exit 0
3911 }
3912
3913 ######################################################################
3914 ######################################################################
3915 #
3916 # < MAIN >
3917 #
3918 ######################################################################
3919 ######################################################################
3920
3921 mkdir -p "${INSTALL_ROOT}"
3922 PackageCheck
3923
3924 # Setup the initial frontend configuration
3925 reset-frontend
3926
3927 if [ $# = 0 ]; then set -- help; fi # Avoid reference to undefined $1.
3928
3929 # Accept one -- argument for some compatibility with google3
3930 if [ $1 = "--tab_completion_word" ]; then
3931 set -- function-completions $2
3932 fi
3933
3934 if [ "$(type -t $1)" != "function" ]; then
3935 #Usage
3936 echo "ERROR: unknown function '$1'." >&2
3937 echo "For help, try:"
3938 echo " $0 help"
3939 exit 1
3940 fi
3941
3942 "$@"
OLDNEW
« no previous file with comments | « tools/llvm/unsupported/patch-libstdc++ ('k') | tools/llvm/utman-test.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698